Skip to content
/ cowfig Public

A JSON format template parser to generate config.json files

License

Notifications You must be signed in to change notification settings

kywk/cowfig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cowfig

Cowfig in a JSON format template parser to generate config.json files.

JSON file is easy to use for a developer, but hard for non-developer.

In most real cases, project always co-works with some non-RD team. They are used to use Excel file to evaluate value set. JSON file is too hard to read and maintenance for them. A tool to translate excel to JSON config file is necessary.

Also, different develop staging uses different setting. Ex: IP, port, account ... etc. It also needs a config management tools.

Cowfig is a JSON format template parser. It parse Excel, JSON, YAML files, provides query method to get value set.

Developer write the cowfig template files. Cowfig take care Excel parsing, different environment value set maping then generate final config.json files.

Features

  • Environment awared
    • Parse same template with different environment value set
    • Extend environment only template _ Parser plugin system
    • Write your file parser as plugin and use it
    • Builtin parser: JSON, Excel, YAML, INI
  • Customize scripts
    • Macro function for on-the-fly processing
    • Post process after template been parsed

Installation

npm install -g https://github.com/kywk/cowfig

Quick Start

Write your template

$ mkdir config config/template config/source
$ vi config/template/configTemplate.cowfig
  ...
$ vi config/source/dataSet.json
  ...

Generate config.json files

$ cowfig -h
Usage: cowfig [-t TEMPLATE] [-s RESOURCE] [-d DESTINATION] [-e ENV] [-o overwrite]
$ cowfig -d .

Arguments descript

  • -t TemplateBase: The cowfig template files path.
    Cowfig find all .cowfig files includes sub directory under TemplateBase. Build the files tree, then parse those template files.
  • -s ResourceBase: The value set files path.
    Store your excel or json value set file. Cowfig load the .xlsx .json files and provides query method to get value set.
  • -d DestinationBase: Where the final JSON file stores.
    Cowfig write out find JSON files based on where they find under TemplateBase.
  • -e Environment: Specify the target enviroment.
  • -o Overwrite:
    If target file is already exist, overwrite it or not?
    • 'auto': (default) auto detect last modified date. Overwrite if newer verseion is out.
    • 'always': always overwrite target file.
    • 'never': never overwrite target file.
  • -c Cowfig option file:
    A cowfigOpt config file for those setting.

Simple example

Cowfig config file: cowfig.json

{
  "env": "stage",
  "templateBase": "example/template/",
  "parser": {
    "srcBase": "example/source/"
  },
  "writer": {
    "destBase": "config",
    "overwrite": "auto",
  }
};

Source file tree

└── example
    ├── source
    │   ├── valueSet.xlsx
    │   ├── hostInfo.json
    │   └── stage
    │       └── hostInfo.json
    └── template
        ├── host
        │   └── servers.cowfig
        └── config.cowfig

Generate config.json Use CLI args

$ cowfig -t example/template -s example/source -d config -e stage

or Use cowfig config file

$ cowfig -c cowfig.json

Result target files

└── config
    ├── host
    │   └── servers.json
    └── config.json

More Information

Read the documentation

License

MIT

About

A JSON format template parser to generate config.json files

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published