1-
21//@ts -check
32
4- process . env [ "BS_VSCODE" ] = '1'
5-
6- var fs = require ( 'fs' )
7- var path = require ( 'path' )
8- var cp = require ( 'child_process' )
9- var sourceDirs =
10- [ 'ext' ,
11- 'common' ,
12- 'syntax' ,
13- 'depends' ,
14- 'core' ,
15- 'super_errors' ,
16- 'outcome_printer' ,
17- 'bsb' ,
18- 'main' ,
19- 'others' ,
20- 'stdlib-406' ,
21- 'runtime' ,
22- 'test' ,
23- 'ounit_tests' ,
24- 'bsb_helper'
25- ]
3+ process . env [ "BS_VSCODE" ] = "1" ;
264
5+ var fs = require ( "fs" ) ;
6+ var path = require ( "path" ) ;
7+ var cp = require ( "child_process" ) ;
8+ var sourceDirs = [
9+ "ext" ,
10+ "common" ,
11+ "syntax" ,
12+ "depends" ,
13+ "core" ,
14+ "super_errors" ,
15+ "outcome_printer" ,
16+ "bsb" ,
17+ "main" ,
18+ "others" ,
19+ "stdlib-406" ,
20+ "runtime" ,
21+ "test" ,
22+ "ounit_tests" ,
23+ "bsb_helper"
24+ ] ;
2725
28- var buildAppending = false
29- var isBuilding = false
30- var ninjaFile = require ( './ninja.js' )
31- var jscompDir = path . join ( '..' , 'jscomp' )
32- function rebuild ( ) {
33- console . log ( ">>>> Start compiling" )
34- if ( isBuilding ) {
35- buildAppending = true
36- } else {
37- isBuilding = true
38- var p = cp . spawn ( ninjaFile . vendorNinjaPath , [ ] , { stdio :[ 'inherit' , 'inherit' , 'pipe' ] } )
39- p . on ( 'exit' , buildFinished )
40- }
26+ var buildAppending = false ;
27+ var isBuilding = false ;
28+ var ninjaFile = require ( "./ninja.js" ) ;
29+ var jscompDir = path . join ( ".." , "jscomp" ) ;
30+ function rebuild ( ) {
31+ if ( isBuilding ) {
32+ buildAppending = true ;
33+ } else {
34+ console . log ( ">>>> Start compiling" ) ;
35+ isBuilding = true ;
36+ var p = cp . spawn ( ninjaFile . vendorNinjaPath , [ ] , {
37+ stdio : [ "inherit" , "inherit" , "pipe" ]
38+ } ) ;
39+ p . on ( "exit" , buildFinished ) ;
40+ }
4141}
4242/**
43- *
43+ *
4444 * @param {number } code
4545 * @param {string } signal
4646 */
47- function buildFinished ( code , signal ) {
48- isBuilding = false
49- if ( buildAppending ) {
50- buildAppending = false
51- rebuild ( )
52- } else {
53- if ( code !== 0 ) {
54- console . log ( `File "BUILD", line 1, characters 1-1:` )
55- console . log ( `Error: Failed to build` )
56- }
57- console . log ( ">>>> Finish compiling" )
58- // TODO: check ninja exit error code
59- if ( code === 0 ) {
60- // This is not always correct
61- ninjaFile . updateDev ( )
62- }
63-
47+ function buildFinished ( code , signal ) {
48+ isBuilding = false ;
49+ if ( buildAppending ) {
50+ buildAppending = false ;
51+ rebuild ( ) ;
52+ } else {
53+ if ( code !== 0 ) {
54+ console . log ( `File "BUILD", line 1, characters 1-1:` ) ;
55+ console . log ( `Error: Failed to build` ) ;
56+ }
57+ console . log ( ">>>> Finish compiling (options: R|clean|config)" ) ;
58+ // TODO: check ninja exit error code
59+ if ( code === 0 ) {
60+ // This is not always correct
61+ ninjaFile . updateDev ( ) ;
6462 }
65-
63+ }
6664}
6765/**
68- *
69- * @param {string } eventType
70- * @param {string } filename
66+ *
67+ * @param {string } eventType
68+ * @param {string } filename
7169 */
72- function onSourceChange ( eventType , filename ) {
73- // console.log('event ', eventType,filename)
74- if ( filename . endsWith ( '.ml' ) || filename . endsWith ( '.mli' ) ) {
75- rebuild ( )
76- }
77-
70+ function onSourceChange ( eventType , filename ) {
71+ // console.log('event ', eventType,filename)
72+ if ( filename . endsWith ( ".ml" ) || filename . endsWith ( ".mli" ) ) {
73+ rebuild ( ) ;
74+ }
7875}
7976
80- sourceDirs . forEach ( x => {
81- fs . watch ( path . join ( jscompDir , x ) , 'utf8' , onSourceChange )
82- } )
83- rebuild ( )
77+ sourceDirs . forEach ( x => {
78+ fs . watch ( path . join ( jscompDir , x ) , "utf8" , onSourceChange ) ;
79+ } ) ;
80+ rebuild ( ) ;
81+
82+ var child_process = require ( "child_process" ) ;
83+ var readline = require ( "readline" ) ;
84+ readline
85+ . createInterface ( {
86+ input : process . stdin ,
87+ output : process . stdout
88+ } )
89+ . on ( "line" , input => {
90+ switch ( input . toLowerCase ( ) ) {
91+ case "r" :
92+ rebuild ( ) ;
93+ break ;
94+ case "config" :
95+ if ( isBuilding ) {
96+ console . log ( `it's building` ) ;
97+ } else {
98+ isBuilding = true ;
99+ child_process
100+ . fork ( path . join ( __dirname , "ninja.js" ) , [ "config" ] )
101+ . on ( "close" , ( ) => {
102+ isBuilding = false ;
103+ rebuild ( ) ;
104+ } ) ;
105+ }
106+ break ;
107+ case "clean" :
108+ if ( isBuilding ) {
109+ console . log ( `it's building` ) ;
110+ } else {
111+ isBuilding = true ;
112+ child_process
113+ . fork ( path . join ( __dirname , "ninja.js" ) , [ "cleanbuild" ] )
114+ . on ( "close" , ( ) => {
115+ isBuilding = false ;
116+ } ) ;
117+ }
118+
119+ break ;
120+ }
121+ } ) ;
0 commit comments