Repository navigation
Expand file tree
/
Copy pathgulpfile.js
More file actions
112 lines (92 loc) · 3.4 KB
/
Copy pathgulpfile.js
File metadata and controls
112 lines (92 loc) · 3.4 KB
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
var gulp = require('gulp');
var tsc = require('gulp-typescript');
var tsd = require('gulp-tsd');
var tslint = require('gulp-tslint');
var browserify = require('browserify');
var gutil = require('gulp-util');
var stringify = require('stringify');
var source = require('vinyl-source-stream');
var path = require('path');
var _ = require('lodash');
function makeBundle(options) {
var bundle = browserify(_.merge({ debug: true }, options))
.plugin('tsify', { noImplicitAny: true })
.transform(stringify())
.add([path.resolve('./src/client/app.ts')]);
var errors = [];
var errorHandler = function (error) {
if (error.fileName) {
gutil.log(gutil.colors.red('TS Error') + ':', error.message, gutil.colors.magenta(error.fileName) + ':' + gutil.colors.cyan(error.line) + ':' + gutil.colors.cyan(error.column));
}
errors.push(error);
};
bundle.on('bundle', function (pipeline) {
pipeline.on('error', errorHandler);
pipeline.once('end', function () {
pipeline.removeListener('error', errorHandler);
if (errors.length) {
bundle.emit('error', new Error('browserify failed'));
}
errors = [];
});
});
bundle.name = 'bundle.js';
return bundle;
}
function runBundle(bundle) {
return bundle.bundle().pipe(source(bundle.name)).pipe(gulp.dest('./dist/web/res'));
}
function watchBundle(bundle, path) {
gutil.log('Change detected in ' + path);
bundle.on('error', function (err) { console.log(err); });
gutil.log('Rebundling', gutil.colors.magenta(bundle.name));
var start = Date.now();
var stream = runBundle(bundle);
stream.on('end', function() {
gutil.log(gutil.colors.magenta(bundle.name), 'generated in', gutil.colors.cyan(Date.now() - start), gutil.colors.cyan('ms'));
});
}
gulp.task('browserify', ['tsd'], function () {
return runBundle(makeBundle());
});
gulp.task('bootstrap', function() {
return gulp.src('node_modules/bootstrap/dist/**/*.*')
.pipe(gulp.dest('dist/web/res/bootstrap'));
});
gulp.task('fontawesome', function() {
return gulp.src('node_modules/font-awesome/*(fonts|css)/*.*')
.pipe(gulp.dest('dist/web/res/font-awesome'));
});
gulp.task('res', function() {
return gulp.src('src/web/res/**/*.*')
.pipe(gulp.dest('dist/web/res/'));
});
gulp.task('tsd', function (callback) {
tsd({
command: 'reinstall',
config: 'tsd.json'
}, callback);
});
gulp.task('tsc', ['tsd'], function () {
var options = {
module: 'commonjs',
target: 'es5'
};
return gulp.src(['src/!(client)/**/*.ts'])
.pipe(tsc(options))
.pipe(gulp.dest('dist'));
});
gulp.task('tslint', ['tsc'], function () {
return gulp.src(['src/**/*.ts'])
.pipe(tslint({ configuration: require('./tslint.json') }))
.pipe(tslint.report('verbose'));
});
gulp.task('watch', ['default'], function () {
gulp.watch(['src/!(client)/**/*.ts'], ['tsc']);
gulp.watch(['src/web/res/**/*.*'], ['res']);
return gulp.watch('src/client/**/*.ts', function(event) {
watchBundle(makeBundle(), event.path);
});
});
gulp.task('build', ['tsc', 'tslint', 'res', 'browserify', 'bootstrap', 'fontawesome']);
gulp.task('default', ['build']);