Skip to content

Commit

Permalink
fix(*): allow to run plugins as subsequent commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ledin committed Jul 30, 2019
1 parent 5adc2ac commit 709056a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ function resolvePlugin(command, options) {
return {args, command, options};
}

function runCommand(command, args, config, options) {
function runCommand(command, args, config, configName, options) {
if (command === null) {
return null;
} else if (typeof command === 'function') {
return command(args, config, (c, runnerOptions) => resolveAndRunCommand(c, [], config, merge(options, runnerOptions || {})));
return command(args, config, (c, runnerOptions) => module.exports(c, configName, merge(options, runnerOptions || {})));
}

const child = require('child_process'),
Expand All @@ -112,16 +112,13 @@ function resolveCommand(command, args, config, options) {
return resolveConfigCommand(command, args, config, options);
}

function resolveAndRunCommand(command, args, config, options) {
({args, command} = resolveCommand(command, args, config, options));
return runCommand(command, args, config, options);
}

module.exports = (command, configName, options) => {
options = merge(module.exports.defaultOptions, options);
let args;
({args, command, options} = resolvePlugin(command, options));
return resolveAndRunCommand(command, args, require('.')(configName, options), options);
const config = require('.')(configName, options);
({args, command} = resolveCommand(command, args, config, options));
return runCommand(command, args, config, configName, options);
};

module.exports.defaultOptions = {
Expand Down
2 changes: 1 addition & 1 deletion test/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function testPath(...names) {
}

function outputEqual(expected, args, dir = '', env = {}) {
assert.deepStrictEqual(child.execFileSync(`${cliPath}`, args, {
assert.deepStrictEqual(child.execFileSync(cliPath, args, {
cwd: testPath(dir),
env: Object.assign({}, process.env, env)
}).toString(), expected + '\n');
Expand Down

0 comments on commit 709056a

Please sign in to comment.