1- import { spawn } from 'child_process' ;
1+ import { spawn , exec } from 'child_process' ;
22
3- console . log ( 'Starting Jekyll server in detached mode ...' ) ;
3+ console . log ( 'Checking for processes on port 4000 ...' ) ;
44
5- const jekyllProcess = spawn ( 'bundle' , [ 'exec' , 'jekyll' , 'serve' , '--detach' ] , {
6- cwd : 'docs' ,
7- stdio : 'inherit' , // Ensures output is displayed in the terminal
8- shell : true , // Allows running shell commands
9- } ) ;
10-
11- jekyllProcess . on ( 'error' , ( error ) => {
12- console . error ( 'Error starting Jekyll server:' , error . message ) ;
13- process . exit ( 1 ) ;
14- } ) ;
15-
16- jekyllProcess . on ( 'close' , ( code ) => {
17- if ( code === 0 ) {
18- console . log ( 'Jekyll server started successfully!' ) ;
5+ // Kill any process using port 4000
6+ exec ( 'lsof -ti:4000 | xargs kill -9 2>/dev/null || true' , ( error , stdout , stderr ) => {
7+ if ( stdout ) {
8+ console . log ( 'Killed process on port 4000' ) ;
199 } else {
20- console . error ( `Jekyll server exited with code ${ code } ` ) ;
10+ console . log ( 'No process found on port 4000' ) ;
2111 }
22- process . exit ( code ) ;
12+
13+ console . log ( 'Starting Jekyll server in detached mode...' ) ;
14+
15+ const jekyllProcess = spawn ( 'bundle' , [ 'exec' , 'jekyll' , 'serve' , '--detach' ] , {
16+ cwd : 'docs' ,
17+ stdio : 'inherit' ,
18+ shell : true ,
19+ env : {
20+ ...process . env ,
21+ LANG : 'en_US.UTF-8' ,
22+ LC_ALL : 'en_US.UTF-8' ,
23+ LC_CTYPE : 'en_US.UTF-8'
24+ }
25+ } ) ;
26+
27+ jekyllProcess . on ( 'error' , ( error ) => {
28+ console . error ( 'Error starting Jekyll server:' , error . message ) ;
29+ process . exit ( 1 ) ;
30+ } ) ;
31+
32+ jekyllProcess . on ( 'close' , ( code ) => {
33+ if ( code === 0 ) {
34+ console . log ( 'Jekyll server started successfully!' ) ;
35+ } else {
36+ console . error ( `Jekyll server exited with code ${ code } ` ) ;
37+ }
38+ process . exit ( code ) ;
39+ } ) ;
2340} ) ;
0 commit comments