forked from flyover/box2d.ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
52 lines (45 loc) · 1.39 KB
/
gulpfile.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
const gulp = require('gulp');
const child_process = require("child_process");
const fs = require("fs");
const path = require("path");
function tsc(cb) {
genSpawn("tsc", [], cb);
}
function genBox2dJS(cb) {
changeCon(true);
genSpawn("rollup", ["-c"], cb);
}
function genBox2dDTS(cb) {
changeCon(false);
genSpawn("rollup", ["-c"], cb);
}
function changeBox2d(cb) {
const box2dJSPath = "./dist/box2d.js";
let con = fs.readFileSync(box2dJSPath, "utf-8");
con = con.replace("var box2d =", "var box2d = window.box2d =");
fs.writeFileSync(box2dJSPath, con, "utf-8");
return cb();
}
function genSpawn(command, args, cb) {
const cs = child_process.spawn(command, args, {
shell: true
});
cs.stdout.on('data', (data) => {
console.log(`${data}`);
});
cs.stderr.on('data', (err) => {
console.log(`${err}`);
});
cs.on('close', (code) => {
console.log(`子进程退出码:${code}`);
cb();
});
}
function changeCon(flag) {
let searchStr = flag ? "const gendts = true;" : "const gendts = false;";
let replaceStr = flag ? "const gendts = false;" : "const gendts = true;";
let con = fs.readFileSync("./rollup.config.js", "utf-8");
con = con.replace(searchStr, replaceStr);
fs.writeFileSync("./rollup.config.js", con, "utf-8");
}
exports.default = gulp.series(tsc, genBox2dJS, genBox2dDTS, changeBox2d)