flavors-runner v5.0.1
This module is deprecated. It was embedded in flavors. See flavors command runner.
flavors-runner
Command runner powered by Flavors configuration management library. It allows to run commands in the pre-configured environment.
Install
$ npm install --save-dev flavors-runnerUsage
const runner = require('flavors-runner');
runner(command, configName, options);$ FLAVORS_CONFIG_NAME=release-beta npx flavors-runner echo $app_version Parameters
command parameter
Can be a one of the following types:
- string: shell command, executable name or its path;
runner('echo $value', configName, options);
runner('/path/to/your/executable', configName, options);- non-empty string array containing shell command, executable name or its path as first elements and its arguments as other elements;
runner(['echo', '$value'], configName, options);- structure with the following fields:
command: required, see 1;args: optional arguments;
runner({command: 'echo', args: ['Hello, ', '$value', '!'] }, configName, options);- function receiving flavors configuration and returning value of the one of listed above types or
undefined(i.e. withoutreturnstatement);
runner(config => ['echo', config.value], configName, options);
runner(config => ({ command: 'echo', args: ['Hello, ', config.value, '!'] }), configName, options);
runner(config => { console.log(config.value); }, configName, options);- plugin structure:
command: see 4;options- plugin specific flavors options, which is merged withoptionsparameter;
example/config.js:
module.exports = {
value: 'world'
};echoPlugin.js:
module.exports = {
command: config => ['echo', 'Hello, ' + config.value],
options: {
transform: config => {
config.value += '!';
return config;
}
}
};runner(require('./echoPlugin'), 'example', options);
// prints "Hello, world!"- structure with the following fields:
plugin: see 5;args: array with additional plugin arguments or function receiving flavors configuration and returning this array;
runner({plugin: require('./echoPlugin'), args: config => [' And goodbye, ' + config.value]}, 'example', options);
// prints "Hello, world! And goodbye, world!"configName parameter
options parameter
Contains the same fields as flavors options parameter with following additional parameters:
command options
When command resolved to executable name and its arguments runner will try to resolve it to command defined in flavors configuration.
This command must be a string or a function, that accepts arguments, loaded flavors configuration and runner function that allows to run subsequent commands.
commandTest/config.js:
module.exports = {
value: 'Hello, world!',
command: {
echo: args => {
console.log('custom echo: ' + args.join(' '));
},
dockerCompose: {
test: (args, config) => console.log(config.value)
},
// "command.enabled" option is set to false to avoid calling this "ls" command recursively and call system "ls" executable
ls: (args, config, runner) => runner(['ls', ...args], {command: {enabled: false}})
}
};runner(['echo', 'a', 'b', 'c'], 'commandTest');
// prints "custom echo: a b c"
runner(['dockerCompose', 'test'], 'commandTest');
// prints "Hello, world!"
runner(['ls', '.'], 'commandTest');
//prints current directory contentcommand.property option
Default is command. Runner will search commands in flavors configuration under the property name specified in this option.
command.enabled option
Default is true.
Set to false to disable command resolving from flavors configuration.
spawn option
spawn.options option
Options passed to child_process.spawnSync() or child_process.spawn() method (see spawn.sync option).
For example, use { shell: true } to execute command inside shell to enable variable expansion:
runner('echo $someValue', configName, {shell: true});spawn.async option
Set this options to true to use child_process.spawn() to run command asynchronously.
By default child.process.spawnSync() is used.
Returned value
Returns result of child_process.spawn() or child_process.spawnSync() call (see sync option).
Maintainers
License
See the LICENSE file for details.