-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
67 lines (60 loc) · 1.85 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
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var ts = require('gulp-typescript');
var merge = require('merge2');
var spawn = require('child_process').spawn;
var iojsInstance = null;
var notifier = require('node-notifier');
var sourcemaps = require('gulp-sourcemaps');
var typescript15 = require('typescript');
gulp.task('jshint', function () {
return gulp.src('./src/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'));
});
var tsProjectTripl = ts.createProject({
declarationFiles: true,
noExternalResolve: false,
module: 'commonjs',
target: 'ES5',
noEmitOnError: false,
typescript: typescript15
});
gulp.task('ts', function () {
var tsResult = gulp.src('src/**/*.ts')
.pipe(sourcemaps.init())
.pipe(ts(tsProjectTripl));
tsResult._events.error[0] = function (error) {
if(!error || !error.__safety || !error.__safety.toString) {
return;
}
notifier.notify({
'title': 'Compilation error',
'message': error.__safety.toString(),
sound: true
});
};
return merge([
tsResult.dts.pipe(gulp.dest('build/definitions')),
tsResult.js.pipe(gulp.dest('build/js'))
]);
});
gulp.task('start', ['ts'], function () {
if (iojsInstance) {
iojsInstance.kill();
}
iojsInstance = spawn('iojs', ['build/js/main.js'], {stdio: 'inherit'});
iojsInstance.on('close', function (code) {
if (code === 8) {
notifier.notify({
'title': 'Restart error',
'message': 'Error detected, waiting for changes...',
sound: true
});
gulp.log('Error detected, waiting for changes...');
}
});
});
gulp.task('default', ['start'], function () {
gulp.watch(['./src/**/*.ts'], ['start']);
});