-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
89 lines (80 loc) · 2.2 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
'use strict';
var gulp = require('gulp'),
browserify = require('browserify'),
del = require('del'),
exec = require('child_process').exec,
source = require('vinyl-source-stream'),
uglify = require('gulp-uglify'),
buffer = require('vinyl-buffer'),
sourcemaps = require('gulp-sourcemaps'),
gutil = require('gulp-util'),
glob = require('glob'),
es = require('event-stream'),
fs = require('fs'),
path = require('path'),
nodemon = require('gulp-nodemon');
gulp.task('default', ['watch', 'nodemon']);
gulp.task('build', ['bundle-js', 'bundle-css']);
// compile the typescript source
gulp.task('ts', function(cb) {
exec(path.normalize('node_modules/.bin/tsc') + ' -p src', function(err, stdout, stderr) {
if (stdout) {
console.log(stdout);
}
if (stderr) {
console.error(stderr);
}
cb(err);
});
});
// clean up the generated javascript files
gulp.task('clean:ts', function() {
var files = [
'./src/**/*.js',
'./analysis/**/*.js'
]
del(files);
return gulp;
});
// watch typescript files for changes and recompile
gulp.task('watch', function() {
gulp.watch(
[
'./src/*.ts',
'./src/**/*.ts',
],
['bundle-js']
);
});
// start the node server
gulp.task('nodemon', function() {
nodemon({ script: './src/server.js' });
});
gulp.task('bundle-js', ['ts'], function(done) {
var files = glob.sync('./src/client/script/**/*.js'),
tasks = [];
for (var f in files) {
var file_path = files[f].split('/'),
file = file_path[ file_path.length -1 ];
var b = browserify({
entries: file_path.slice(0, file_path.length-1).join('/') + '/' + file,
debug: true
});
tasks.push(b.bundle()
.pipe(source(file))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.on('error', gutil.log)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./public/script/')));
}
return es.merge(tasks);
});
gulp.task('bundle-css', function() {
var files = fs.readFileSync('./src/client/style/dependencies', 'utf8')
.split('\n');
return gulp
.src(files, { base: './node_modules/' })
.pipe(gulp.dest('./public/style/'));
});