UNPKG

@moonee/nx-next12-plugin

Version:

Nx plugin for Next.js 12 integration

42 lines 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const child_process_1 = require("child_process"); const path = tslib_1.__importStar(require("path")); async function runExecutor(options, context) { var _a; const projectRoot = (_a = context.workspace) === null || _a === void 0 ? void 0 : _a.projects[context.projectName].root; const projectPath = path.join(context.root, projectRoot); const port = options.port || 3000; const hostname = options.hostname || 'localhost'; const dev = options.dev !== false; try { console.log(`Starting Next.js ${dev ? 'development' : 'production'} server...`); const nextCommand = dev ? 'next dev' : 'next start'; const nextProcess = (0, child_process_1.spawn)('npx', [...nextCommand.split(' '), '-p', port.toString(), '-H', hostname], { stdio: 'inherit', cwd: projectPath, env: { ...process.env, NODE_ENV: dev ? 'development' : 'production', }, }); return new Promise((resolve) => { nextProcess.on('close', (code) => { if (code === 0) { resolve({ success: true }); } else { console.error(`Next.js server exited with code ${code}`); resolve({ success: false }); } }); }); } catch (error) { console.error('Failed to start Next.js server:', error); return { success: false }; } } exports.default = runExecutor; //# sourceMappingURL=executor.js.map