Git Product home page Git Product logo

config's Introduction

Figure

YAML-based configuration library for NodeJS/TypeScript. Uses JSON schema to validate configurations and provide additional metadata.

WARNING!

Library is still under active development, API may not be stable.

Table of Contents

Getting Started
Error Handling

Installation

npm install figure-config --save
npm install -g figure-cli

Getting started

Create a configuration schema

Figure will look for a configuration schema named "schema.yaml" in the configuration directory.

File: config/schema.yaml

title: "Figure CLI config"
type: object
properties:
  azureDevops:
    type: object
    properties:
      pat:
        type: string
        env: "AZURE_PAT" #Figure will use this environment variable as a value for this property if present
      organisation:
        type: string
        env: "AZURE_ORG"
      project:
        type: string
        env: "AZURE_PROJECT"
    required:
      - pat
      - organisation
      - project
required:
  - azureDevops

Additional metadata

env: "ENVIRONMENT_VARIABLE_NAME" - Links a configuration property to an environment variable

isSecret: true - Specifies a configuration property as secret, for generating kubernetes resources + creating azure variable groups

Create configuration

Figure will load configuration files in the following order:

  • default.yaml
  • {env}.yaml (where {env} is the value of process.env.NODE_ENV, unless overridden)

After the files have been loaded, values are substituted with corresponding environment variables (if present).

File: config/default.yaml

azureDevops:
  pat: 'some_token'
  organisation: 'some_org'
  project: 'some_project'

File: config/development.yaml

azureDevops:
  pat: 'dev_token'

Generate type definitions

figure generate -o src/config.ts

Instantiate configuration instance

import figure from "figure"
import {Configuration} from "./config.ts" //Import generated type

process.env.NODE_ENV = "development"
process.env.AZURE_PROJECT = "env_project"

const config = figure<Configuration>({ configFolderPath: process.env.CONFIG_FOLDER_PATH }).config

// Value from default.yaml
console.log(config.azureDevops.pat) //"dev_token"

// Value from development.yaml
console.log(config.azureDevops.organisation) //"some_org"

// Value from process.env.AZURE_PROJECT
console.log(config.azureDevops.project) //"env_project"

Error Handling

By default, if a validation error is encountered, figure will print the errors to STDOUT and process.exit(1).

If logErrors is set to false, an instance of Figure will be returned. Validation errors can be found in instance.validatorResult.

If the prompt option is set, it will interactively prompt for missing values before validating.

config's People

Contributors

tristangodfrey avatar

Watchers

 avatar

config's Issues

CLI feature: render bash exports

Command: figure render <environment> --format=bash_exports | source

Example output:

export FOO="bar"
export PROP2="http://www.google.com"

This can be used to use figure in other contexts such as when using env substitution in files

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.