@nx/detox
Version:
56 lines (55 loc) • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = detoxBuildExecutor;
exports.runCliBuild = runCliBuild;
const path_1 = require("path");
const child_process_1 = require("child_process");
let childProcess;
async function* detoxBuildExecutor(options, context) {
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
try {
await runCliBuild(context.root, projectRoot, options);
yield { success: true };
}
finally {
if (childProcess) {
childProcess.kill();
}
}
}
function runCliBuild(workspaceRoot, projectRoot, options) {
return new Promise((resolve, reject) => {
childProcess = (0, child_process_1.fork)(require.resolve('detox/local-cli/cli.js'), ['build', ...createDetoxBuildOptions(options)], {
cwd: (0, path_1.resolve)(workspaceRoot, projectRoot),
env: process.env,
});
// Ensure the child process is killed when the parent exits
process.on('exit', () => childProcess.kill());
process.on('SIGTERM', () => childProcess.kill());
childProcess.on('error', (err) => {
reject(err);
});
childProcess.on('exit', (code) => {
if (code === 0) {
resolve(code);
}
else {
reject(code);
}
});
});
}
function createDetoxBuildOptions(options) {
return Object.keys(options).reduce((acc, k) => {
const v = options[k];
if (k === 'detoxConfiguration') {
acc.push('--configuration', v);
}
else if (k === 'configPath') {
acc.push('--config-path', v);
}
else
acc.push(`--${k}`, options[k]);
return acc;
}, []);
}