forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.js
79 lines (69 loc) · 1.57 KB
/
tasks.js
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
71
72
73
74
75
76
77
78
79
//@ts-check
process.env["BS_VSCODE"] = '1'
var fs = require('fs')
var path = require('path')
var cp = require('child_process')
var sourceDirs =
['ext',
'common',
'syntax',
'depends',
'core',
'super_errors',
'outcome_printer',
'bsb',
'main',
'stdlib-402',
'others',
'stdlib-406',
'runtime',
'test',
'ounit_tests'
]
var buildAppending = false
var isBuilding = false
var jscompDir = path.join('..','jscomp')
function rebuild(){
console.log(">>>> Start compiling")
if(isBuilding){
buildAppending = true
} else {
isBuilding = true
var p = cp.spawn(`ninja`, [], {stdio:['inherit','inherit','pipe'], shell : true})
p.on('exit',buildFinished)
}
}
/**
*
* @param {number} code
* @param {string} signal
*/
function buildFinished(code,signal){
isBuilding = false
if(buildAppending ) {
buildAppending = false
rebuild()
} else{
console.log(">>>> Finish compiling")
// TODO: check ninja exit error code
if(code===0){
// This is not always correct
require('./ninja.js').updateDev()
}
}
}
/**
*
* @param {string} eventType
* @param {string} filename
*/
function onSourceChange(eventType, filename){
// console.log('event ', eventType,filename)
if(filename.endsWith('.ml') || filename.endsWith('.mli')){
rebuild()
}
}
sourceDirs.forEach(x=>{
fs.watch(path.join(jscompDir,x), 'utf8',onSourceChange)
})
rebuild()