-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
93 lines (81 loc) · 2.84 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
var gulp = require('gulp');
var ts = require('gulp-typescript');
var tsProject = ts.createProject('tsconfig.json');
var closureCompiler = require('gulp-closure-compiler');
var uglify = require('gulp-uglifyjs');
var watch = require('gulp-watch');
var batch = require('gulp-batch');
var runSequence = require('run-sequence');
var header = require('gulp-header');
var fs = require('fs');
var target = 'hidden-blocks.js';
var targetUgly = 'hidden-blocks.ugly.min.js';
var targetUglyReadable = 'hidden-blocks.ugly.readable.js';
var destination = './dist/';
var copyrightStatement = '\/*!\n* Created by Steven Bouma <[email protected]>\n* 2017\n*\/\n\n';
gulp.task('debug', function(callback) {
runSequence('debug-build','copy-debug-build', callback);
});
gulp.task('release', function(callback) {
runSequence('debug-build', 'release-build', 'beautify', 'copy-release-build', callback);
});
// watch changes in TS files and start DEBUG build + copy
gulp.task('watch-debug', function () {
watch('source/**/*.ts', batch(function (events, done) {
gulp.start('debug', done);
}));
});
// watch changes in TS files and start release build + copy
gulp.task('watch-release', function () {
watch('source/**/*.ts', batch(function (events, done) {
gulp.start('release', done);
}));
});
// perform standard Typescript build, based on tsconfig.json
gulp.task('debug-build', function () {
return tsProject.src()
.pipe(tsProject())
// add copyright statement to the compiled js
.pipe(header(copyrightStatement))
.pipe(gulp.dest('./'));
});
// use google closure compiler to obfuscate the result from the Typescript compiler (tsc)
gulp.task('release-build', function() {
return gulp.src('dist/' + target)
.pipe(closureCompiler({
compilerPath: './node_modules/google-closure-compiler/compiler.jar',
fileName: targetUgly,
compilerFlags: {
compilation_level: 'WHITESPACE_ONLY',
language_in: 'ECMASCRIPT6',
language_out: 'ECMASCRIPT6',
externs: [
'./externs/*.js'
],
warning_level: 'QUIET' // QUIET, DEFAULT, VERBOSE
},
continueWithWarning: true
}))
// add copyright statement to the compiled js
.pipe(header(copyrightStatement))
.pipe(gulp.dest('dist'));
});
// beautify the result of google closure compiler, this makes it easier to see what has been renamed
gulp.task('beautify', function() {
// gulp.src(['dist/' + targetUgly])
// .pipe(uglify(targetUglyReadable, {
// mangle: false,
// output: {
// beautify: true
// }
// }))
// .pipe(gulp.dest('dist'))
});
gulp.task('copy-release-build', function() {
gulp.src(['dist/' + targetUgly])
.pipe(gulp.dest(destination));
});
gulp.task('copy-debug-build', function() {
gulp.src(['dist/' + target])
.pipe(gulp.dest(destination));
});