mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-30 06:12:03 +00:00
feat: add runNpmAndWait function for improved npm command handling
- Introduced a new function, runNpmAndWait, to execute npm commands and wait for their completion, enhancing error handling. - Updated the main function to build shared packages before starting the backend server, ensuring necessary dependencies are ready. - Adjusted server and web process commands to use a consistent naming convention.
This commit is contained in:
22
init.mjs
22
init.mjs
@@ -268,6 +268,20 @@ function runNpm(args, options = {}) {
|
||||
return crossSpawn('npm', args, spawnOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run an npm command and wait for completion
|
||||
*/
|
||||
function runNpmAndWait(args, options = {}) {
|
||||
const child = runNpm(args, options);
|
||||
return new Promise((resolve, reject) => {
|
||||
child.on('close', (code) => {
|
||||
if (code === 0) resolve();
|
||||
else reject(new Error(`npm ${args.join(' ')} failed with code ${code}`));
|
||||
});
|
||||
child.on('error', (err) => reject(err));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Run npx command using cross-spawn for Windows compatibility
|
||||
*/
|
||||
@@ -525,6 +539,10 @@ async function main() {
|
||||
console.log('');
|
||||
log('Launching Web Application...', 'blue');
|
||||
|
||||
// Build shared packages once (dev:server and dev:web both do this at the root level)
|
||||
log('Building shared packages...', 'blue');
|
||||
await runNpmAndWait(['run', 'build:packages'], { stdio: 'inherit' });
|
||||
|
||||
// Start the backend server
|
||||
log(`Starting backend server on port ${serverPort}...`, 'blue');
|
||||
|
||||
@@ -535,7 +553,7 @@ async function main() {
|
||||
|
||||
// Start server in background, showing output in console AND logging to file
|
||||
const logStream = fs.createWriteStream(path.join(__dirname, 'logs', 'server.log'));
|
||||
serverProcess = runNpm(['run', 'dev:server'], {
|
||||
serverProcess = runNpm(['run', '_dev:server'], {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
env: {
|
||||
PORT: String(serverPort),
|
||||
@@ -582,7 +600,7 @@ async function main() {
|
||||
console.log('');
|
||||
|
||||
// Start web app
|
||||
webProcess = runNpm(['run', 'dev:web'], {
|
||||
webProcess = runNpm(['run', '_dev:web'], {
|
||||
stdio: 'inherit',
|
||||
env: {
|
||||
TEST_PORT: String(webPort),
|
||||
|
||||
Reference in New Issue
Block a user