-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
60 lines (55 loc) · 2.38 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
53
54
55
56
57
58
59
60
var gulp = require('gulp');
var pexec = require('child-process-promise').exec;
var watch = require('gulp-watch');
var fs = require('fs');
var md5 = require('md5');
var chalk = require('chalk');
var cwd = process.cwd();
var paths = {
src: `${cwd}/src/`,
tmp: `${cwd}/tmp/`,
dest: `${cwd}/bin/`
};
var filemd5s = [];
gulp.task('build', function () {
fs.readdir(paths.src, function (err, items) {
console.log(chalk.magenta(items));
items.forEach(function (item) {
if (!item.includes('~')) {
fs.readFile(`${paths.src}${item}`, function (err, buf) {
if (err) {
console.log(err);
} else {
var newmd5 = md5(buf);
if (filemd5s[item] == undefined || filemd5s[item] != newmd5) {
filemd5s[item] = newmd5;
var cppBuild = `clang++ -std=c++11 -stdlib=libc++ ${paths.src}${item.split('.')[0]}.cpp -o ${paths.dest}${item.split('.cpp')[0]}`;
pexec(cppBuild)
.then(r => r.stdout)
.then(() => {
var bashRun = `cd ${paths.dest} && ./${item.split('.cpp')[0]}`;
console.log(chalk.magenta(`[${item}]`.toUpperCase()));
pexec(bashRun)
.then(r => r.stdout)
.then(console.log)
.then(() => {
console.log('-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+');
})
.catch(console.error);
})
.then(console.log)
.catch(console.error);
} else {
console.log(chalk.blue(`[${item}]`.toUpperCase()));
console.log(chalk.blue('No change, no build!'));
}
}
})
}
});
});
});
gulp.task('watch', function () {
gulp.watch(`${paths.src}*.*`, ['build']);
});
gulp.task('default', ['watch'], function () {});