command.js 1.2 KB

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