-
Notifications
You must be signed in to change notification settings - Fork 32
/
gulpfile.js
51 lines (41 loc) · 1.19 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
const gulp = require('gulp');
const bs = require('browser-sync').create();
const child = require('child_process');
const exec = require('child_process').exec;
const fs = require('fs');
gulp.task('default', ['server', 'recompile', 'browser-sync']);
gulp.task('server', () => {
let server = child.spawn('node', ['server.js']);
});
gulp.task('recompile', (cb) => {
const compileCommand = getCompileCommand();
exec(compileCommand, (err, stdout, stderr) => {
if (isWin()) {
const data = fs.readFileSync('lib/webdsp_c.js', 'utf8');
const newData = data.replace(/else\{doRun\(\)\}/g, '$&script.dispatchEvent(doneEvent);');
fs.writeFileSync('lib/webdsp_c.js', newData);
}
console.log(stderr);
cb(err);
bs.reload();
});
});
gulp.task('browser-sync', ['recompile'], () => {
bs.init({
proxy: 'localhost:3000',
});
});
gulp.watch('cpp/webdsp.cpp', ['recompile']);
gulp.watch(['demo.js', 'webdsp.js', 'index.html', 'style.css', 'compileWASM.sh'], () => {
bs.reload();
});
function getCompileCommand() {
if (isWin()) {
return 'compileWASM.bat';
} else {
return '. ./compileWASM.sh';
}
}
function isWin() {
return /^win/.test(process.platform);
}