UNPKG

2.03 kBJavaScriptView Raw
1"use strict";
2/**
3 * © 2013 Liferay, Inc. <https://liferay.com> and Node GH contributors
4 * (see file: README.md)
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7Object.defineProperty(exports, "__esModule", { value: true });
8const childProcess = require("child_process");
9const logger = require("./logger");
10function spawnSync(cmd, args, options) {
11 let exec;
12 logger.debug(`spawnSync: ${cmd} ${args.join(' ')}`);
13 exec = childProcess.spawnSync(cmd, args, options);
14 if (exec.error && exec.error.code === 'ENOENT' && process.platform === 'win32') {
15 logger.debug("Invoking patched sapwnSync due to Windows' libuv bug");
16 exec = childProcess.spawnSync(`${cmd}.cmd`, args, options);
17 }
18 return {
19 stdout: exec.stdout.toString().trim(),
20 stderr: exec.stderr.toString().trim(),
21 status: exec.status,
22 };
23}
24exports.spawnSync = spawnSync;
25function spawnSyncStream(cmd, args, options) {
26 let proc;
27 let err;
28 if (!options) {
29 options = {};
30 }
31 options.stdio = ['pipe', process.stdout, process.stderr];
32 logger.debug(`spawnSyncStream: ${cmd} ${args.join(' ')}`);
33 proc = childProcess.spawnSync(cmd, args, options);
34 if (proc.status !== 0) {
35 err = new Error();
36 err.code = proc.status;
37 err.message = `Child process terminated with error code ${err.code}`;
38 throw err;
39 }
40 return proc;
41}
42exports.spawnSyncStream = spawnSyncStream;
43function execSync(cmd, options) {
44 if (!options) {
45 options = {};
46 }
47 logger.debug(`execSync: ${cmd}`);
48 options.stdio = ['pipe', process.stdout, process.stderr];
49 return childProcess.execSync(cmd, options);
50}
51exports.execSync = execSync;
52function execSyncInteractiveStream(cmd, options) {
53 if (!options) {
54 options = {};
55 }
56 logger.debug(`execSyncInteractiveStream: ${cmd}`);
57 options.stdio = 'inherit';
58 return childProcess.execSync(cmd, options);
59}
60exports.execSyncInteractiveStream = execSyncInteractiveStream;
61//# sourceMappingURL=exec.js.map
\No newline at end of file