UNPKG

create-nx-workspace

Version:

Smart Repos · Fast Builds

52 lines (51 loc) 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.spawnAndWait = spawnAndWait; exports.execAndWait = execAndWait; const child_process_1 = require("child_process"); const fs_1 = require("fs"); const path_1 = require("path"); const error_utils_1 = require("./error-utils"); /** * Use spawn only for interactive shells */ function spawnAndWait(command, args, cwd) { return new Promise((res, rej) => { const childProcess = (0, child_process_1.spawn)(command, args, { cwd, stdio: 'inherit', env: { ...process.env, NX_DAEMON: 'false', // This is the same environment variable that ESLint uses to determine if it should use a flat config. // Default to true for all new workspaces. ESLINT_USE_FLAT_CONFIG: process.env.ESLINT_USE_FLAT_CONFIG ?? 'true', }, shell: true, windowsHide: false, }); childProcess.on('exit', (code) => { if (code !== 0) { rej({ code: code }); } else { res({ code: 0 }); } }); }); } function execAndWait(command, cwd) { return new Promise((res, rej) => { (0, child_process_1.exec)(command, { cwd, env: { ...process.env, NX_DAEMON: 'false' }, windowsHide: false }, (error, stdout, stderr) => { if (error) { const logFile = (0, path_1.join)(cwd, 'error.log'); (0, fs_1.writeFileSync)(logFile, `${stdout}\n${stderr}`); const message = stderr && stderr.trim().length ? stderr : stdout; rej(new error_utils_1.CreateNxWorkspaceError(message, error.code, logFile)); } else { res({ code: 0, stdout }); } }); }); }