@nx/expo
Version:
73 lines (72 loc) • 2.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = exportExecutor;
exports.createExportOptions = createExportOptions;
const devkit_1 = require("@nx/devkit");
const child_process_1 = require("child_process");
const path_1 = require("path");
let childProcess;
async function* exportExecutor(options, context) {
const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
try {
await exportAsync(context.root, projectRoot, options);
yield {
success: true,
};
}
finally {
if (childProcess) {
childProcess.kill();
}
}
}
function exportAsync(workspaceRoot, projectRoot, options) {
return new Promise((resolve, reject) => {
childProcess = (0, child_process_1.fork)(require.resolve('@expo/cli/build/bin/cli'), [`export`, ...createExportOptions(options, projectRoot)], { 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);
}
});
});
}
const nxOptions = ['bundler', 'interactive']; // interactive is passed in by e2e tests
// options from https://github.com/expo/expo/blob/main/packages/@expo/cli/src/export/index.ts
function createExportOptions(options, projectRoot) {
return Object.keys(options).reduce((acc, k) => {
if (!nxOptions.includes(k)) {
const v = options[k];
switch (k) {
case 'outputDir':
const path = (0, devkit_1.joinPathFragments)((0, devkit_1.offsetFromRoot)(projectRoot), v); // need to add offset for the outputDir
acc.push('--output-dir', path);
break;
case 'minify':
if (v === false) {
acc.push('--no-minify'); // cli only accpets --no-minify
}
break;
default:
if (typeof v === 'boolean') {
if (v === true) {
// when true, does not need to pass the value true, just need to pass the flag in kebob case
acc.push(`--${(0, devkit_1.names)(k).fileName}`);
}
}
else {
acc.push(`--${(0, devkit_1.names)(k).fileName}`, v);
}
}
}
return acc;
}, []);
}