Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.js
More file actions
Latest commit
70 lines (56 loc) · 1.72 KB
/
Copy pathdev.js
File metadata and controls
70 lines (56 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
const{ spawn }=require('child_process')
constfs=require('fs')
constpath=require('path')
constos=require('os')
constgetPort=()=>{
constportsPath=path.join(os.homedir(),'Code','ports.csv')
if(!fs.existsSync(portsPath)){
console.log('⚠️ ~/Code/ports.csv not found, using default port')
returnnull
}
constpackageJson=JSON.parse(fs.readFileSync('package.json','utf8'))
constprojectName=packageJson.name
constcsv=fs.readFileSync(portsPath,'utf8')
constlines=csv.trim().split('\n').slice(1)
for(constlineoflines){
const[name,port]=line.split(',')
if(name===projectName){
returnparseInt(port,10)
}
}
console.log(`⚠️ ${projectName} not found in ports.csv, using default port`)
returnnull
}
constport=getPort()
constserveArgs=port ? ['serve','build','-l',port.toString()] : ['serve','build']
if(port)console.log(`🚀 Starting dev server on port ${port}...\n`)
constbuild=spawn('node',['build','--dev','--watch'],{stdio: 'inherit'})
constserve=spawn('npx',serveArgs,{stdio: 'inherit'})
build.on('error',err=>{
console.error('❌ Build process failed:',err.message)
process.exit(1)
})
build.on('exit',code=>{
if(code!==0){
console.error(`❌ Build process exited with code ${code}`)
serve.kill()
process.exit(code)
}
})
serve.on('error',err=>{
console.error('❌ Serve process failed:',err.message)
process.exit(1)
})
serve.on('exit',code=>{
if(code!==0){
console.error(`❌ Serve process exited with code ${code}`)
build.kill()
process.exit(code)
}
})
process.on('SIGINT',()=>{
build.kill()
serve.kill()
process.exit()
})