版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

43 строки
1.1 KiB

  1. "use strict";
  2. const normalizeArgs = require("./normalize-args");
  3. const normalizeResult = require("./normalize-result");
  4. const spawnSync = require("cross-spawn").sync;
  5. module.exports = sync;
  6. /**
  7. * Executes the given command synchronously, and returns the buffered results.
  8. *
  9. * @param {string|string[]} command - The command to run
  10. * @param {string|string[]} [args] - The command arguments
  11. * @param {object} [options] - options
  12. * @returns {Process}
  13. *
  14. * @see {@link normalizeArgs} for argument details
  15. */
  16. function sync () {
  17. // Normalize the function arguments
  18. let { command, args, options, error } = normalizeArgs(arguments);
  19. if (error) {
  20. // Invalid arguments
  21. normalizeResult({ command, args, options, error });
  22. }
  23. else {
  24. let result;
  25. try {
  26. // Run the program
  27. result = spawnSync(command, args, options);
  28. }
  29. catch (error) {
  30. // An error occurred while spawning or killing the process
  31. normalizeResult({ error, command, args, options });
  32. }
  33. // Return the results or throw an error
  34. return normalizeResult(Object.assign({}, result, { command, args, options }));
  35. }
  36. }