basis.config support for basisjs-tools commands.
Module provide single function that extends
clap command with
var clap = ;var configSupport = ;var command = clap;// extend command;// orcommand;
It adds two options to command:
-n, --no-config– to prevent config using
-c, --config-file <filename>- to specify path to config file
Also it adds
getConfig(options) method to command that search and fetch config content if needed and
globalConfig property to get global config content.
getConfig(options) usualy uses in command's
init method and could accepts command options to decide is config should be fetched or not.
// this call will search and fetch config contentvar config = command;// but this call doesn'tvar config = command;// specify config locationvar config = command;
If config file doesn't found or could be parsed error outputs in console and exit process.
Searching for config file
Extended command tries to find and use
basis.config file by default. It attempts to find
basis.config at the current working directory. If it's not found, then it moves to the parent directory, and so on, until the file system root is reached.
basis.config module also check for
package.json. Config may be stored with
basisjsConfig key. If no
basisjsConfig found then
package.json ignores and searching is continue.
basis.config found, it's content parses as
json. Usualy properties treats as corresponding command options, and could be overridden by options in command line.
Any command's option could be declared in config, as it's long name. All option names should be camelize, i.e.
cssPack. If flag contains
-no-, it should be omited, i.e.
You can disable
basis.config usage by
--no-config option or specify your own file with
Config file useful to set up command's defaults option values.
Config also can be stored in
basis.confighas higher priority. Config in
In both cases doesn't matter at what directory you run
basis build command, for example. File
/path/to/config/app.html will be used for built and result will be put at
/path/to/config/output directory. But you still able to override settings in config but using option with command, for example, if you run
basis build -o temp at
/path/to/config/foo/bar than result will be put at
Relative path resolving
Basis works with many various paths, and often it is relative paths. There are two general rules for relative path resolving.
- path defined in config file (
basis.config) resolves to config file location
- path defined in command line resolves to current working directory