Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/grassedge/node-config-refactor
A refactoring tool for configuration files of node-config.
https://github.com/grassedge/node-config-refactor
Last synced: about 1 month ago
JSON representation
A refactoring tool for configuration files of node-config.
- Host: GitHub
- URL: https://github.com/grassedge/node-config-refactor
- Owner: grassedge
- Created: 2020-04-13T02:13:20.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T03:51:13.000Z (almost 2 years ago)
- Last Synced: 2024-10-12T13:33:07.355Z (about 1 month ago)
- Language: JavaScript
- Size: 548 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# node-config-refactor
`config-refactor` helps you to refactor your configurations which you load by [node-config](https://github.com/lorenwest/node-config).
This tool generates config files from your actual configurations.For example, from following configurations,
```js
# NODE_CONFIG_ENV=development NODE_APP_INSTANCE=foo
{
"a": "default",
"b": "development",
"c": "foo",
"d": "development-foo",
}
# NODE_CONFIG_ENV=development NODE_APP_INSTANCE=bar
{
"a": "default",
"b": "development",
"c": "bar",
"d": "development-bar",
}
# NODE_CONFIG_ENV=production NODE_APP_INSTANCE=foo
{
"a": "default",
"b": "production",
"c": "foo",
"d": "production-foo",
}
# NODE_CONFIG_ENV=production NODE_APP_INSTANCE=bar
{
"a": "default",
"b": "production",
"c": "bar",
"d": "production-bar",
}
```Generates following files.
```js
# default.json
{ a: "default" }# default-foo.json
{ c: 'foo' }# default-bar.json
{ c: 'bar' }# development.json
{ b: 'development' }# development-foo.json
{ d: 'development-foo' }# development-bar.json
{ d: 'development-bar' }# production.json
{ b: 'production' }# production-foo.json
{ d: 'production-foo' }# production-bar.json
{ d: 'production-bar' }
```## Usage
If your environments are like followings,
- `NODE_CONFIG_ENV=development NODE_APP_INSTANCE=foo`
- `NODE_CONFIG_ENV=development NODE_APP_INSTANCE=bar`
- `NODE_CONFIG_ENV=production NODE_APP_INSTANCE=foo`
- `NODE_CONFIG_ENV=production NODE_APP_INSTANCE=bar`Execute the following command.
```sh
$ NODE_CONFIG_DIR=... npx config-refactor \
-c development:foo \
-c development:bar \
-c production:foo \
-c production:bar
```By default, `config-refactor` outputs generated JSON to the stdout.
To output config files, use `-o/--out` option.```sh
$ NODE_CONFIG_DIR=... npx config-refactor \
... \
-o path/to/configDir
```### Atomic config object
Sometimes we want to treat data object as a set.
```js
# config A
{ "obj": { "a": "A", "x": "common" } }# config B
{ "obj": { "b": "B", "x": "common" } }
```if keys are specified by `-a/--atomic` option, the value is treated as atomic.
```sh
$ config-refactor ...
# outputs following
{
"default": { "obj": { "x": "common" } }
"A": { "obj": { "a": "A" } }
"B": { "obj": { "b": "B" } }
}$ config-refactor ... --atomic obj
{
"default": {}
"A": { "obj": { "a": "A", "x": "common" } }
"B": { "obj": { "b": "B", "x": "common" } }
}
```## Note
This tool currently supports `deployment` and `instance`. See [https://github.com/lorenwest/node-config/wiki/Configuration-Files#file-load-order](Configuration-Files) about `deployment` and `instance`.
```
default.EXT
default-{instance}.EXT
{deployment}.EXT
{deployment}-{instance}.EXT
````EXT` of the input file can be the formats `node-config` supports.
But this tool outputs only json format.