-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGulpfile.js
120 lines (103 loc) · 3.26 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
var gulp = require('gulp');
var gutil = require('gulp-util');
var map = require('map-stream');
var es = require('event-stream');
var ts = require('gulp-typescript');
var sourcemaps = require('gulp-sourcemaps');
var replace = require('gulp-replace');
var nodemon = require('gulp-nodemon')
var ext = require('./tools/gulp/extensions');
var paths = {
ts: ['src/**/*.ts', 'extern/lodash.d.ts'],
outputDir: 'output/',
deployDir: 'deploy/'
};
var tsProject = ts.createProject({
target: 'es5',
module: 'commonjs',
declarationFiles: false,
noExternalResolve: false,
sortOutput: true,
sourceRoot: '../src'
});
gulp.task('watch', function () {
gulp.watch(paths.ts, ['build'])
});
gulp.task('default', ['build']);
gulp.task('build', ['compile']);
gulp.task('compile', function() {
var hasCompileError = false;
var tsResult = gulp.src(paths.ts)
.pipe(sourcemaps.init())
.pipe(ts(tsProject, undefined, { error: function(error) {
ts.reporter.defaultReporter().error(error);
// Sometimes the errors get swallowed and don't trigger a task error.
hasCompileError = true;
}}));
var jsSaved = tsResult.js
.pipe(ext.concatReferences())
.pipe(replace('this.__extends || function', 'function'))
.pipe(sourcemaps.write({
includeContent: false,
sourceRoot: function(file) {
return '../src';
},
sourceMappingURLPrefix: ''
}))
.pipe(gulp.dest(paths.outputDir));
var dtsSaved = tsResult.dts
.pipe(gulp.dest(paths.outputDir));
return es.merge(jsSaved, dtsSaved)
.on('end', function() {
if (hasCompileError) {
var err = new gutil.PluginError('compile', 'Compilation failed');
err.toString = function() { return ''; };
this.emit('error', err);
}
});
});
gulp.task('deploy', function() {
return gulp
.src(paths.outputDir + '**/*.*')
.pipe(gulp.dest(paths.deployDir));
});
/* Sync from the deploy dir*/
gulp.task('sync', function() {
nodemon({
script: 'tools/sync/sync.js',
watch: 'tools/sync/',
env: { 'syncArgs': '--beautify' }
});
});
/* Sync from the deploy dir (with remote debugging) */
gulp.task('syncDebug', function() {
nodemon({
script: 'tools/sync/sync.js',
watch: 'tools/sync/',
env: { 'syncArgs': '--beautify --debug' }
});
});
/* Sync directly from the compile/output dir */
gulp.task('syncDeploy', function() {
nodemon({
script: 'tools/sync/sync.js',
watch: 'tools/sync/',
env: { 'syncArgs': '--beautify --deployDir ../../output' }
});
});
/* Sync directly from the compile/output dir */
gulp.task('syncDeployDual', function() {
nodemon({
script: 'tools/sync/sync.js',
watch: 'tools/sync/',
env: { 'syncArgs': '--beautify --deployDir ../../output --deploy2Dir ../../output' }
});
});
/* Sync directly from the compile/output dir (with remote debugging) */
gulp.task('syncDeployDebug', function() {
nodemon({
script: 'tools/sync/sync.js',
watch: 'tools/sync/',
env: { 'syncArgs': '--beautify --debug --deployDir ../../output' }
});
});