config-tree

0.3.1 • Public • Published

Config Tree

A reworking of init-package-json to make reusable prompt-based CLIs for making config.json files.

Why?

This package generalizes npm's npm init interface so you can require it as its own module and set your project-specific prompts in your project -- where they belong -- in a file called default-input.js,

Opinions

This package assumes that in your project root folder you have config.sample.json and default-input.js files that contain any default options or examples of what users could input.

It bakes out a config.json file in ~/.conf/, so your project should look to load that file by default.

Setup

A config.sample.json example with example or default values:

{
    "name": "my-project",
    "description": "A default value",
    "awesome": false
}

A default-input.js example:

exports.name        = prompt('Name', package.name)
exports.description = prompt('Description', package.description)
exports.awesome     = prompt('Is it awesome?', package.awesome.toString(), function(response){
    return JSON.parse(response)
})
 

Note: Cast booleans to string so they show up in the interface as text and parse them with JSON so they don't end up as strings. See Promzard for more info about prompt.

Calling it from your project

Once you have those two files set up, point your command-line script to a javascript file that looks like this.

In the gif above, this is what main.js looks like.

var config_tree = require('config-tree');
 
config_tree.sprout(__dirname, 'name-prefix');

.sprout takes two arguments:

  1. The directory that contains your default-input.js and config.sample.json file.
  2. A name prefix so that multple config files in ~/.conf/ don't conflict.

That's it!

Logo by Clarisa Diaz
Name by Brian Abelson

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.3.1
    12
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.3.1
    12
  • 0.3.0
    0
  • 0.2.1
    0
  • 0.2.0
    0
  • 0.1.1
    0

Package Sidebar

Install

npm i config-tree

Weekly Downloads

12

Version

0.3.1

License

ISC

Last publish

Collaborators

  • mhkeller0