@nx/plugin
Version:
64 lines (63 loc) • 2.05 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.runNxCommand = runNxCommand;
exports.runCommand = runCommand;
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 nx command inside the e2e directory
* @param command
* @param opts
*
* @see tmpProjPath
*/
function runNxCommand(command, opts = {
silenceError: false,
}) {
function _runNxCommand(c) {
const cwd = opts.cwd ?? (0, paths_1.tmpProjPath)();
const execSyncOptions = {
cwd,
env: { ...process.env, ...opts.env },
windowsHide: false,
};
if ((0, utils_1.fileExists)((0, paths_1.tmpProjPath)('package.json'))) {
const pmc = (0, devkit_1.getPackageManagerCommand)((0, devkit_1.detectPackageManager)(cwd));
return (0, child_process_1.execSync)(`${pmc.exec} nx ${command}`, execSyncOptions);
}
else if (process.platform === 'win32') {
return (0, child_process_1.execSync)(`./nx.bat %${command}`, execSyncOptions);
}
else {
return (0, child_process_1.execSync)(`./nx %${command}`, execSyncOptions);
}
}
try {
return _runNxCommand(command)
.toString()
.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
}
catch (e) {
if (opts.silenceError) {
return e.stdout.toString();
}
else {
console.log(e.stdout.toString(), e.stderr.toString());
throw e;
}
}
}
function runCommand(command, opts) {
try {
return (0, child_process_1.execSync)(command, {
cwd: opts.cwd ?? (0, paths_1.tmpProjPath)(),
stdio: ['pipe', 'pipe', 'pipe'],
env: { ...process.env, ...opts?.env },
}).toString();
}
catch (e) {
return e.stdout.toString() + e.stderr.toString();
}
}
;