@@ -2,15 +2,47 @@ import express from "express";
22import { exec } from "child_process" ;
33import chokidar from "chokidar" ;
44import cors from "cors" ;
5+ import fs from "fs" ;
6+ import path from "path" ;
7+ import { fileURLToPath } from "url" ;
58import fromConsole from "./fromConsole.js" ;
69import * as chalkUtils from "./chalkUtils.js" ;
710import { basePort } from "../devConfig.js" ;
11+ import cleanup from "./cleanup.js" ;
12+
13+ const __filename = fileURLToPath ( import . meta. url ) ;
14+ const __dirname = path . dirname ( __filename ) ;
15+ const DEV_LOCK_FILE = path . resolve ( __dirname , "../.dev-server-running" ) ;
816
917let port = basePort ;
1018const localHostURL = ( ) => `http://localhost:${ port } /addon.json` ;
1119let buildRunning = false ;
1220
1321export default async function dev ( ) {
22+ // Create lock file to indicate dev server is running
23+ fs . writeFileSync ( DEV_LOCK_FILE , String ( process . pid ) ) ;
24+ chalkUtils . info ( "Dev server lock file created" ) ;
25+
26+ // Clean up lock file on exit
27+ const cleanupLockFile = ( ) => {
28+ if ( fs . existsSync ( DEV_LOCK_FILE ) ) {
29+ fs . unlinkSync ( DEV_LOCK_FILE ) ;
30+ chalkUtils . info ( "Dev server lock file removed" ) ;
31+ }
32+ cleanup ( ) ;
33+ } ;
34+
35+ process . on ( "SIGINT" , ( ) => {
36+ cleanupLockFile ( ) ;
37+ process . exit ( 0 ) ;
38+ } ) ;
39+
40+ process . on ( "SIGTERM" , ( ) => {
41+ cleanupLockFile ( ) ;
42+ process . exit ( 0 ) ;
43+ } ) ;
44+
45+ process . on ( "exit" , cleanupLockFile ) ;
1446 // Execute build command
1547 const runBuild = ( ) => {
1648 if ( buildRunning ) return ;
0 commit comments