5.0.1 • Published 5 years ago

flavors-runner v5.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

npm Build Status David semantic-release Join the chat at https://gitter.im/flavors-js/flavors

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-runner

Usage

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:

  1. string: shell command, executable name or its path;
runner('echo $value', configName, options);
runner('/path/to/your/executable', configName, options);
  1. 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);
  1. structure with the following fields:
  • command: required, see 1;
  • args: optional arguments;
runner({command: 'echo', args: ['Hello, ', '$value', '!'] }, configName, options);
  1. function receiving flavors configuration and returning value of the one of listed above types or undefined (i.e. without return statement);
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);
  1. plugin structure:
  • command: see 4;
  • options - plugin specific flavors options, which is merged with options parameter;

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!"
  1. 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

Flavors configuration name.

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 content

command.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.

5.0.1

5 years ago

5.0.0

5 years ago

4.0.3

5 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago