@nx/gatsby
Version:
Gatsby Plugin for Nx
63 lines • 2.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.runGatsbyBuild = void 0;
const tslib_1 = require("tslib");
const child_process_1 = require("child_process");
const path_1 = require("path");
function buildExecutor(options, context) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const projectRoot = context.workspace.projects[context.projectName].root;
yield runGatsbyBuild(context.root, projectRoot, context.projectName, options);
return { success: true };
});
}
exports.default = buildExecutor;
function runGatsbyBuild(workspaceRoot, projectRoot, projectName, options) {
return new Promise((resolve, reject) => {
const cp = (0, child_process_1.fork)(require.resolve('gatsby-cli'), ['build', ...createGatsbyBuildOptions(options)], {
cwd: (0, path_1.join)(workspaceRoot, projectRoot),
});
// Ensure the child process is killed when the parent exits
process.on('exit', () => cp.kill());
process.on('SIGTERM', () => cp.kill());
cp.on('error', (err) => {
reject(err);
});
cp.on('exit', (code) => {
if (code === 0) {
resolve();
}
else {
reject(new Error(`Could not build "${projectName}". See errors above.`));
}
});
});
}
exports.runGatsbyBuild = runGatsbyBuild;
function createGatsbyBuildOptions(options) {
return Object.keys(options).reduce((acc, k) => {
const val = options[k];
if (typeof val === 'undefined')
return acc;
switch (k) {
case 'prefixPaths':
return val ? acc.concat(`--prefix-paths`) : acc;
case 'uglify':
return val ? acc : acc.concat('--no-uglify');
case 'color':
return val ? acc : acc.concat('--no-color');
case 'profile':
return val ? acc.concat('--profile') : acc;
case 'openTracingConfigFile':
return val ? acc.concat([`--open-tracing-config-file`, val]) : acc;
case 'graphqlTracing':
return val ? acc.concat('--graphql-tracing') : acc;
case 'serve':
case 'host':
case 'port':
default:
return acc;
}
}, []);
}
//# sourceMappingURL=build.impl.js.map