-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
86 lines (72 loc) · 2.25 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
var gulp = require('gulp');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var htmlmin = require('gulp-htmlmin');
var cssmin = require('gulp-cssmin');
var concat = require('gulp-concat');
var htmlreplace = require('gulp-html-replace');
var zip = require('gulp-zip');
var fs = require('fs');
var mkdirp = require('mkdirp');
var chalk = require('chalk');
var watch = require('gulp-watch');
//
// Chalk colours.
var error = chalk.bold.red;
var success = chalk.green;
var regular = chalk.white;
//
gulp.task('watch', function() {
gulp.watch('./src/index.html', gulp.series('build-html', 'html-replace', 'zip', 'check'));
gulp.watch('./src/scss/**/*.scss', gulp.series('compile-sass', 'build-css', 'zip', 'check'));
gulp.watch('./src/js/**/*.js', gulp.series('build-js', 'zip', 'check'));
});
//
gulp.task('html-replace', function() {
return gulp.src('./build/**/*.html')
.pipe(htmlreplace({
'css': 'app.css',
'game': 'game.js'
}))
.pipe(gulp.dest('./build'));
});
gulp.task('zip', function() {
return gulp.src('./build/**/*')
.pipe(zip('entry.zip'))
.pipe(gulp.dest('dist'));
});
gulp.task('check', gulp.series('zip', function(done) {
var stats = fs.statSync("./dist/entry.zip")
var fileSize = stats.size;
if (fileSize > 13312) {
console.log(error("Your zip compressed game is larger than 13kb (13312 bytes)!"))
console.log(regular("Your zip compressed game is " + fileSize + " bytes"));
} else {
console.log(success("Your zip compressed game is " + fileSize + " bytes."));
}
done();
}));
//
gulp.task('build-html', function() {
return gulp.src('./src/**/*.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('./build/'));
});
gulp.task('compile-sass', function() {
return gulp.src('./src/scss/app.scss')
.pipe(sass())
.pipe(gulp.dest('./src/css'));
});
gulp.task('build-css', function() {
return gulp.src('./src/css/**/*.css')
.pipe(cssmin())
.pipe(gulp.dest('./build/'));
});
gulp.task('build-js', function() {
return gulp.src('./src/js/**/*.js')
.pipe(uglify())
.pipe(gulp.dest('./build/'));
});
gulp.task('build', gulp.series('build-html', 'compile-sass', 'build-css', 'build-js', 'html-replace', 'check', function(done) {
done();
}));