UNPKG

1.25 kBJavaScriptView Raw
1module.exports = command;
2
3/**
4 * command constructs the executable command to run in a shell including the
5 * user script, the command arguments.
6 *
7 * @param {Object} settings Object as:
8 * { execOptions: {
9 * exec: String,
10 * [script: String],
11 * [scriptPosition: Number],
12 * [execArgs: Array<string>]
13 * }
14 * }
15 * @return {Object} an object with the node executable and the
16 * arguments to the command
17 */
18function command(settings) {
19 var options = settings.execOptions;
20 var executable = options.exec;
21 var args = [];
22
23 // after "executable" go the exec args (like --debug, etc)
24 if (options.execArgs) {
25 [].push.apply(args, options.execArgs);
26 }
27
28 // then goes the user's script arguments
29 if (options.args) {
30 [].push.apply(args, options.args);
31 }
32
33 // after the "executable" goes the user's script
34 if (options.script) {
35 args.splice((options.scriptPosition || 0) +
36 options.execArgs.length, 0, options.script);
37 }
38
39 return {
40 executable: executable,
41 args: args,
42 };
43}