-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (86 loc) · 2.97 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
const beautify = require('gulp-beautify');
const concat = require('gulp-concat');
const compilerPackage = require('google-closure-compiler');
const closureCompiler = compilerPackage.gulp();
const del = require('del');
const gap = require('gulp-append-prepend');
const gitmodified = require('gulp-gitmodified');
const gulp = require('gulp');
const jshint = require('gulp-jshint');
const jsstring = require('gulp-js-string');
const mocha = require('gulp-mocha');
const sourcemaps = require('gulp-sourcemaps');
const paths = {
js: 'src/js/*.js',
glsl: 'src/glsl/*',
tests: 'test/**/*.js'
};
gulp.task('beautify', function() {
return gulp.src(['gulpfile.js', paths.js, paths.tests], {
base: './'
})
.pipe(beautify({
'max_preserve_newlines': 3,
'end_with_newline': true
}))
.pipe(gulp.dest('./'));
});
gulp.task('beautified', gulp.series('beautify', function(done) {
var files = gulp.src(['gulpfile.js', paths.js, paths.tests])
.pipe(gitmodified('modified'));
files.on('data', function(file) {
console.error('Error: Uncommitted changes or beautification needed!');
process.exit(1);
});
done();
}));
gulp.task('clean:build', function() {
return del(['build']);
});
gulp.task('lint', function() {
return gulp.src(['gulpfile.js', paths.js])
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
gulp.task('mocha', function() {
return gulp.src([paths.tests])
.pipe(mocha())
.on('error', console.error);
});
gulp.task('resources', function() {
return gulp.src(paths.glsl)
.pipe(jsstring(function(escapedstring, file) {
var name = file.basename;
return 'resources[\'' + name + '\'] = \'' + escapedstring + '\';';
}))
.pipe(concat('resources.js'))
.pipe(gap.prependText('var resources = {};'))
.pipe(gulp.dest('build/'));
});
gulp.task('js-compile', gulp.series('resources', function compile() {
return gulp.src(['build/resources.js', paths.js], {
base: './'
})
.pipe(sourcemaps.init())
.pipe(closureCompiler({
language_in: 'ECMASCRIPT6_STRICT',
language_out: 'ECMASCRIPT5_STRICT',
dependency_mode: 'LOOSE',
module_resolution: 'NODE',
compilation_level: 'ADVANCED',
warning_level: 'VERBOSE',
jscomp_warning: 'reportUnknownTypes',
rewrite_polyfills: false,
output_wrapper_file: 'src/js/ComplexCurves.js.wrapper',
summary_detail_level: '3',
js_output_file: 'ComplexCurves.js',
process_common_js_modules: true
}).on('error', function(err) {
process.exit(1);
}))
.pipe(sourcemaps.write('/'))
.pipe(gulp.dest('./build/'));
}));
gulp.task('test', gulp.parallel('beautified', 'lint', 'mocha'));
gulp.task('default', gulp.task('js-compile'));