-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
85 lines (71 loc) · 2.42 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
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var minifyCSS = require('gulp-clean-css');
var rm = require('gulp-rimraf');
var editorJS = ['client/editor/*.js', 'client/services/*.js', 'client/editor/components/*/*.js'];
var editorCSS = ['client/editor/*.css', 'client/editor/components/*/*.css'];
var gameJS = ['client/game/app.js', 'client/services/*.js', 'client/game/*.js'];
// lint checks for syntax and JS best practices
gulp.task('lint', function() {
return gulp.src(editorJS)
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('game-lint', function() {
return gulp.src(gameJS)
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// clean previously built JS files
gulp.task('cleanJS', function() {
return gulp.src('client/editor/dist/*.js')
.pipe(rm());
});
gulp.task('game-cleanJS', function() {
return gulp.src('client/game/dist/*.js')
.pipe(rm());
})
// clean CSS
gulp.task('cleanCSS', function() {
return gulp.src('client/editor/dist/*.css')
.pipe(rm());
});
// minify and concat css
gulp.task('css', function() {
return gulp.src(editorCSS)
.pipe(concat('all.min.css'))
.pipe(minifyCSS())
.pipe(gulp.dest('./client/editor/dist'));
});
// concat and minify JS
gulp.task('scripts', function() {
return gulp.src(editorJS)
.pipe(concat('all.js'))
.pipe(gulp.dest('client/editor/dist'))
.pipe(rename('all.min.js'))
.pipe(uglify({ mangle: false }))
.pipe(gulp.dest('client/editor/dist'));
});
gulp.task('game-scripts', function() {
return gulp.src(gameJS)
.pipe(concat('all.js'))
.pipe(gulp.dest('client/game/dist'))
.pipe(rename('all.min.js'))
.pipe(uglify({ mangle: false }))
.pipe(gulp.dest('client/game/dist'));
});
// watch for file changes
gulp.task('watch', function() {
gulp.watch(editorJS,['lint', 'cleanJS', 'scripts']);
gulp.watch(editorCSS, ['cleanCSS', 'css']);
gulp.watch(gameJS, ['game-lint', 'game-cleanJS', 'game-scripts']);
});
// clean all built files
gulp.task('clean', ['cleanJS', 'cleanCSS', 'game-cleanJS']);
// default task builds and watches
gulp.task('default', ['lint', 'game-lint', 'clean', 'game-cleanJS', 'css', 'scripts', 'game-scripts', 'watch']);
// build without watching
gulp.task('build', ['lint', 'game-lint', 'clean', 'game-cleanJS', 'css', 'scripts', 'game-scripts']);