forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.js
83 lines (74 loc) · 1.75 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
80
81
82
83
//@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',
'others',
'stdlib-406',
'runtime',
'test',
'ounit_tests',
'bsb_helper'
]
var buildAppending = false
var isBuilding = false
var ninjaFile = require('./ninja.js')
var jscompDir = path.join('..','jscomp')
function rebuild(){
console.log(">>>> Start compiling")
if(isBuilding){
buildAppending = true
} else {
isBuilding = true
var p = cp.spawn(ninjaFile.vendorNinjaPath, [], {stdio:['inherit','inherit','pipe']})
p.on('exit',buildFinished)
}
}
/**
*
* @param {number} code
* @param {string} signal
*/
function buildFinished(code,signal){
isBuilding = false
if(buildAppending ) {
buildAppending = false
rebuild()
} else{
if(code !== 0){
console.log(`File "BUILD", line 1, characters 1-1:`)
console.log(`Error: Failed to build`)
}
console.log(">>>> Finish compiling")
// TODO: check ninja exit error code
if(code===0){
// This is not always correct
ninjaFile.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()