@nx/plugin
Version:
51 lines (50 loc) • 1.6 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.runCommandAsync = runCommandAsync;
exports.runNxCommandAsync = runNxCommandAsync;
const child_process_1 = require("child_process");
const paths_1 = require("./paths");
const devkit_1 = require("@nx/devkit");
const utils_1 = require("./utils");
/**
* Run a command asynchronously inside the e2e directory.
*
* @param command
* @param opts
*/
function runCommandAsync(command, opts = {
silenceError: false,
}) {
return new Promise((resolve, reject) => {
(0, child_process_1.exec)(command, {
cwd: opts.cwd ?? (0, paths_1.tmpProjPath)(),
env: { ...process.env, ...opts.env },
windowsHide: false,
}, (err, stdout, stderr) => {
if (!opts.silenceError && err) {
reject(err);
}
resolve({ stdout, stderr });
});
});
}
/**
* Run a nx command asynchronously inside the e2e directory
* @param command
* @param opts
*/
function runNxCommandAsync(command, opts = {
silenceError: false,
}) {
const cwd = opts.cwd ?? (0, paths_1.tmpProjPath)();
if ((0, utils_1.fileExists)((0, paths_1.tmpProjPath)('package.json'))) {
const pmc = (0, devkit_1.getPackageManagerCommand)((0, devkit_1.detectPackageManager)(cwd));
return runCommandAsync(`${pmc.exec} nx ${command}`, opts);
}
else if (process.platform === 'win32') {
return runCommandAsync(`./nx.bat %${command}`, opts);
}
else {
return runCommandAsync(`./nx %${command}`, opts);
}
}
;