-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
83 lines (72 loc) · 2.13 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//useful links
//https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html
//https://www.typescriptlang.org/docs/handbook/gulp.html
//https://jasmine.github.io/setup/nodejs.html
//https://www.npmjs.com/package/gulp-jasmine
const gulp = require('gulp');
const ts = require('gulp-typescript');
const tsProject = ts.createProject('tsconfig.json');
const clean = require('gulp-clean');
const runSequence = require('run-sequence');
const process = require("child_process");
const q = require("q");
var paths = {
src: 'src/**/*.ts',
dest: 'dist',
};
gulp.task('clean', () => {
return gulp.src(`${paths.dest}/**/*.js`, {
read: false
})
.pipe(clean());
});
gulp.task('compile', () => {
return gulp.src(paths.src)
.pipe(tsProject())
.pipe(gulp.dest(paths.dest));
});
//test task depends on clean and compile tasks
gulp.task('run', callback => {
//start with clean, compile and test respectively
runSequence('clean', 'compile', () => {
// exec('node dist/index.js', (error, stdout, stderr) => {
// console.log(stdout);
// console.log(stderr);
// done();
// });
runMainScript()
.then(() => {
callback();
})
.catch(error => {
console.error(error);
})
.done(() => {
console.log("finally");
callback();
});
});
});
function runMainScript() {
let deferred = q.defer();
let arguments = ['./dist/index.js'];
let child = process.spawn('node', arguments);
child.stdout.on("data", data => {
console.log(`stdout: ${data}`);
});
child.stderr.on("data", data => {
console.log(`stderr: ${data}`);
});
child.on('exit', code => {
console.log(`Child exited with code ${code}`);
if (code === 0) {
deferred.resolve(code);
} else {
deferred.reject(`exist with error code ${code}`);
}
});
return deferred.promise;
}
gulp.task('watch', ['compile'], () => {
gulp.watch(paths.src, ['compile']);
});