exec.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  3. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  4. return new (P || (P = Promise))(function (resolve, reject) {
  5. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  6. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  7. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  8. step((generator = generator.apply(thisArg, _arguments || [])).next());
  9. });
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. const tr = require("./toolrunner");
  13. /**
  14. * Exec a command.
  15. * Output will be streamed to the live console.
  16. * Returns promise with return code
  17. *
  18. * @param commandLine command to execute (can include additional args). Must be correctly escaped.
  19. * @param args optional arguments for tool. Escaping is handled by the lib.
  20. * @param options optional exec options. See ExecOptions
  21. * @returns Promise<number> exit code
  22. */
  23. function exec(commandLine, args, options) {
  24. return __awaiter(this, void 0, void 0, function* () {
  25. const commandArgs = tr.argStringToArray(commandLine);
  26. if (commandArgs.length === 0) {
  27. throw new Error(`Parameter 'commandLine' cannot be null or empty.`);
  28. }
  29. // Path to tool to execute should be first arg
  30. const toolPath = commandArgs[0];
  31. args = commandArgs.slice(1).concat(args || []);
  32. const runner = new tr.ToolRunner(toolPath, args, options);
  33. return runner.exec();
  34. });
  35. }
  36. exports.exec = exec;
  37. //# sourceMappingURL=exec.js.map