Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,17 +678,31 @@ Examples:
easyjs doctor
`);
}
activeChildProcess = null;

runEasyJS(filePath) {
const { spawn } = require('child_process');
const indexPath = path.resolve(__dirname, '../index.js');
exec(`node "${indexPath}" "${filePath}"`, (error) => {
if (error) {
Logger.error(error.message);
process.exit(1);

if (this.activeChildProcess) {
this.activeChildProcess.kill('SIGTERM');
this.activeChildProcess = null;
}

const child = spawn('node', [indexPath, filePath], { stdio: 'inherit' });
this.activeChildProcess = child;


child.on('error', (error) => {
Logger.error(`Failed to start process: ${error.message}`);
});

child.on('close', (code) => {
if (this.activeChildProcess === child) {
this.activeChildProcess = null;
}
});
}

runWithWatcher(filePath) {
const dir = path.dirname(filePath);
Logger.info(`Watching directory: ${dir}`);
Expand All @@ -697,7 +711,7 @@ Examples:
fs.watch(dir, { recursive: true }, (eventType, filename) => {
if (filename && filename.endsWith('.easy')) {
Logger.info(`File changed: ${filename}`);
Logger.info('Restarting server...');
Logger.info('Restarting server cleanly...');
this.runEasyJS(filePath);
}
});
Expand Down
Loading
Loading