-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
55 lines (47 loc) · 1.26 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
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var browserify = require('gulp-browserify');
var jade = require('gulp-jade');
var minifyCSS = require('gulp-minify-css');
var gzip = require('gulp-gzip');
var crypto = require('crypto');
var fs = require('fs');
function generateCacheTag(filename) {
var contents = fs.readFileSync(filename);
var hash = crypto.createHash('md5');
hash.update(contents);
return hash.digest('hex').substring(0, 7);
}
function getApplicationMeta() {
if(fs.existsSync('./app.json')){
return JSON.parse(fs.readFileSync('./app.json'));
}
return {
name: 'Untitled game'
};
}
gulp.task('compile_js_bundle', function() {
return gulp.src('src/main.js')
.pipe(browserify())
.pipe(uglify())
.pipe(gulp.dest('public/js'));
});
gulp.task('compile_html', ['compile_js_bundle'], function() {
return gulp.src('index.jade')
.pipe(jade({
locals: {
cache_tag: generateCacheTag,
app: getApplicationMeta()
}
}))
.pipe(gulp.dest('public'));
});
gulp.task('compress_js_bundle', ['compile_js_bundle'], function() {
return gulp.src('public/js/main.js')
.pipe(gzip())
.pipe(gulp.dest('public/js/'));
});
gulp.task('default', [
'compile_html',
'compress_js_bundle'
]);