@fulminate/fulminate-config-builder
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Fulminate Config Builder

FCB simplifies the process of handling sensitive data required by software and shared among coders via git.

The idea originated from the way Symfony handles parameters.yml and parameters.yml.dist files.

Installation

npm install --save @fulminate/fulminate-config-builder

After the package was successfully installed, it is required to run the following script once to simplify usage of FCB:

node ./node_modules/@fulminate/fulminate-config-builder/prepare.js

It will first ask you if you want to make changes to ignore files (currently, only .gitignore is supported).

You can provide js or ts as a parameter. If no parameter was provided, the script will prompt for preferred type of dist file (TypeScript or JavaScript).

Usage

In the root directory of your project you will find config.ts.dist or config.js.dist file (depending on the preference you'd stated).

config.ts.dist

// Add config fields here if you need them in your config.ts file
// Comments may be given at new lines and begin with "//" or "/*"


You can populate this file line by line in the following manner:

...

db.host:localhost
db.name:database
db.username:root
db.password:root

// App settings:

app.domain:example.com

// API keys:

googleMapsAPIKey:AIza

=========================================================================

You can use //, /* or simply / to indicate comments that should be ignored by runner. Empty lines will also be ignored.

The first part of the line is the property of config object. If it has a . the first part will be assumed as child of config while the second one will be a property of the child object, e.g.:

config.ts.dist
app

db.host
config.ts
{
  "app": "YOUR_VALUE",
  "db": {
    "host": "YOUR_VALUE"
  }
}

The value that goes after : is optional and provides default value for the property and automatically applies if no other input is given by the user.

After you've done all the preparations, simply run

npm run ifc

that was automatically injected to your package.json by the preparation script.

What the runner does is:

  • Create config.ts in the root folder of your project
  • Analyse your config.ts.dist
  • Prompt for input for each line of config.ts.dist
  • Write provided data to config.ts object and make it available as config object.

Example usage

config.ts.dist

// Add config fields here if you need them in your config.ts file
// Comments may be given at new lines and begin with "//" or "/*"

something.awesome:FSB!!

Run npm run ifc

config.ts

const json = {
  "something": {
    "awesome": "FSB!!"
  }
};

export const config = JSON.parse(JSON.stringify(json));

app.ts

let config = require("./config.ts").config;

console.log(config.something.awesome);

// Output: FSB!!

ToDo

  • Unit testing
  • Improving usability

Package Sidebar

Install

npm i @fulminate/fulminate-config-builder

Weekly Downloads

2

Version

1.2.0

License

MIT

Last publish

Collaborators

  • fulminate