-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbuild.js
35 lines (27 loc) · 822 Bytes
/
build.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
const $path = require('path')
const $fs = require('fs')
const TIMESTAMP = Date.now()
function include(file) {
let js = $fs.readFileSync(file, 'utf-8')
// "@include path"
js = js.replace(/"@include (.+?)"\n/g, (s, path) => {
path = $path.join($path.dirname(file), path)
return include(path)
})
// <@embed path>
js = js.replace(/<@embed (.+?)>/g, (s, path) => {
path = $path.join($path.dirname(file), path)
return include(path)
.replace(/\\/g, '\\\\')
.replace(/\n/g, '\\n')
.replace(/\"/g, '\\"')
})
js = js.replace(/__TIMESTAMP__/g, TIMESTAMP)
return js
}
function main(args) {
let s = include(args[0])
$fs.writeFileSync(args[1], s)
}
main(['sw/boot.js', '../dst/x.js'])
// main(process.argv.slice(2))