-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
147 lines (126 loc) · 4.07 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
var fs = require('fs');
var gulp = require('gulp');
var closureCompiler = require('gulp-closure-compiler');
var concat = require('gulp-concat');
var del = require('del');
var zip = require('gulp-zip');
var cleanCSS = require('gulp-clean-css');
var imageOptim = require('gulp-imageoptim');
var inline = require('gulp-inline');
var inlineBase64 = require('gulp-inline-base64');
var htmlmin = require('gulp-htmlmin');
var inject = require('gulp-js-base64-inject');
var concatOrder = [
'src/config.js',
'src/util.js',
'src/sound.js',
'src/graphics.js',
'src/pixeldisplay.js',
'src/text.js',
'src/food.js',
'src/pet.js',
'src/printer.js',
'src/screen-manager.js',
'src/screens/*.js',
'src/game.js',
];
gulp.task('copy:html',function() {
return gulp.src('src/index.html')
.pipe(gulp.dest('build'));
});
gulp.task('copy:png',function() {
return gulp.src('src/*.png')
.pipe(gulp.dest('build'));
});
gulp.task('inject:images', function() {
return gulp.src('build/game.js')
.pipe(inject({ basepath: 'build'}))
.pipe(gulp.dest('build'));
});
gulp.task('packhtml', function() {
return gulp.src('build/index.html')
.pipe(inline())
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('dist'));
});
gulp.task('zip', function() {
return gulp.src('dist/index.html')
.pipe(zip('game.zip'))
.pipe(gulp.dest('dist'));
});
gulp.task('concat', function() {
return gulp.src(concatOrder)
.pipe(concat('game.js'))
.pipe(gulp.dest('build'));
});
gulp.task('minify:js', function() {
return gulp.src('build/game.js')
.pipe(closureCompiler({
fileName: 'game.js',
compilerFlags: {
language_in: 'ECMASCRIPT6',
language_out: 'ES5',
compilation_level: 'ADVANCED_OPTIMIZATIONS',
// .call is super important, otherwise Closure Library will not work in strict mode.
output_wrapper: '(function(){%output%}).call(window);',
warning_level: 'VERBOSE'
}
}))
.pipe(gulp.dest('build'));
});
gulp.task('minify:css', function() {
return gulp.src('src/*.css')
.pipe(inlineBase64({baseDir: 'src/'}))
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(gulp.dest('build'));
});
gulp.task('minify:png', function() {
return gulp.src('src/*.png*')
.pipe(imageOptim.optimize())
.pipe(gulp.dest('build'));
});
gulp.task('report', function(done) {
var stat = fs.statSync('dist/game.zip'),
limit = 1024 * 13,
size = stat.size,
remaining = limit - size,
percentage = (remaining / limit) * 100;
percentage = Math.round(percentage * 100) / 100;
console.log('\n\n-------------');
console.log('BYTES USED: ' + stat.size);
console.log('BYTES REMAINING: ' + remaining);
console.log(percentage + '%');
console.log('-------------\n\n');
done();
});
gulp.task('clean:dist', function () {
return del(['dist/**/*']);
});
gulp.task('clean:build', function () {
return del(['build/**/*']);
});
gulp.task('build:dev', function() {
return gulp.src(concatOrder)
.pipe(concat('game.js'))
.pipe(inject({ basepath: 'src' }))
.pipe(gulp.dest('dev'));
});
gulp.task('css:dev', function() {
return gulp.src('src/*.css')
.pipe(inlineBase64({baseDir: 'src/'}))
.pipe(gulp.dest('dev'));
});
gulp.task('copy:dev', function() {
return gulp.src('src/*.html')
.pipe(gulp.dest('dev'));
});
gulp.task('watch', function() {
gulp.watch('src/**/*.js', gulp.series('build:dev'));
gulp.watch('src/*.html', gulp.series('copy:dev'));
gulp.watch('src/*.css', gulp.series('css:dev'));;
});
gulp.task('clean:all', gulp.parallel('clean:build', 'clean:dist'));
gulp.task('minify', gulp.parallel( gulp.series('concat', 'minify:png', 'inject:images', 'minify:js'), 'minify:css'));
gulp.task('minify:codeonly', gulp.parallel( gulp.series('concat', 'copy:png', 'inject:images', 'minify:js'), 'minify:css'));
gulp.task('build', gulp.series('clean:all', 'minify', 'copy:html', 'packhtml', 'zip', 'clean:build', 'report'));
gulp.task('build:quick', gulp.series('clean:all', 'minify:codeonly', 'copy:html', 'packhtml', 'zip', 'clean:build', 'report'));