UNPKG

@nx-dart/nx-dart

Version:

A Nx plugin, that adds support for developing Dart and Flutter packages in a Nx workspace

52 lines 2.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeCommand = void 0; const child_process_1 = require("child_process"); const os_1 = require("os"); function executeCommand(command) { return new Promise((resolve, reject) => { const childProcess = (0, child_process_1.execFile)(command.executable, command.arguments, { cwd: command.cwd, // Ensures that we can use executable names without extensions like .bat on Windows. shell: (0, os_1.platform)() === 'win32', }); childProcess.on('error', reject); childProcess.on('exit', (exitCode) => { var _a; if (exitCode !== 0) { let isExpectedExitCode = false; if (!command.throwOnFailure) { const expectedErrorExitCodes = (_a = command.expectedErrorExitCodes) !== null && _a !== void 0 ? _a : []; if (expectedErrorExitCodes) { isExpectedExitCode = expectedErrorExitCodes.includes(exitCode); } else { isExpectedExitCode = true; } } if (isExpectedExitCode) { resolve(false); } else { reject(new Error(`Command '${[command.executable, ...command.arguments].join(' ')}' exited with unexpected code: ${exitCode}`)); } } else { resolve(true); } }); if (!command.silent) { childProcess.stdout.pipe(process.stdout); childProcess.stderr.pipe(process.stderr); } else { // We need to consume the output to prevent the child process from blocking. // eslint-disable-next-line @typescript-eslint/no-empty-function childProcess.stdout.on('data', () => { }); // eslint-disable-next-line @typescript-eslint/no-empty-function childProcess.stderr.on('data', () => { }); } }); } exports.executeCommand = executeCommand; //# sourceMappingURL=execute-command.js.map