-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
120 lines (101 loc) · 3.32 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
/**
* @fileoverview This is the file that determines the behavior of the Gulp task
* runner.
* @author [email protected] (Alvin Lin)
*/
var gulp = require('gulp');
var compilerPackage = require('google-closure-compiler');
var gjslint = require('gulp-gjslint');
var less = require('gulp-less');
var plumber = require('gulp-plumber');
var rename = require('gulp-rename');
var lessAutoprefix = require('less-plugin-autoprefix');
var lessCleancss = require('less-plugin-clean-css');
var merge = require('merge-stream');
var path = require('path');
var getClosureCompilerConfiguration = function(outputFile) {
var basePath = path.dirname(__filename);
var closureCompiler = compilerPackage.gulp();
return closureCompiler({
externs: [
compilerPackage.compiler.CONTRIB_PATH + '/externs/jquery-1.9.js',
basePath + '/extern/extern.js'
],
warning_level: 'VERBOSE',
compilation_level: 'ADVANCED_OPTIMIZATIONS',
js_output_file: outputFile
});
};
var getLessConfiguration = function() {
var autoprefix = new lessAutoprefix({
browsers: ["last 2 versions"]
});
var cleancss = new lessCleancss({
advanced: true
});
return less({
plugins: [autoprefix, cleancss]
});
};
gulp.task('default', ['js-lint', 'js-compile', 'less']);
gulp.task('js', ['js-lint', 'js-compile']);
gulp.task('lint', ['js-lint']);
gulp.task('js-lint', function() {
return gulp.src(['./extern/*.js',
'./lib/**/*.js',
'./public/js/**/*.js',
'./shared/*.js' ])
.pipe(gjslint({
flags: ['--jslint_error indentation',
'--jslint_error well_formed_author',
'--jslint_error braces_around_type',
'--jslint_error unused_private_members',
'--jsdoc',
'--max_line_length 80',
'--error_trace'
]
}))
.pipe(gjslint.reporter('console'));
});
gulp.task('js-compile', function() {
var indexJs = gulp.src(['./public/js/index.js'])
.pipe(plumber())
.pipe(getClosureCompilerConfiguration('index.min.js'))
.pipe(gulp.dest('./public/dist'));
var gameJs = gulp.src(['./shared/*.js',
'./public/js/game/game.js',
'./public/js/game/*.js' ])
.pipe(plumber())
.pipe(getClosureCompilerConfiguration('game.min.js'))
.pipe(gulp.dest('./public/dist'));
return merge(indexJs, gameJs);
});
gulp.task('less', function() {
var indexCss = gulp.src('./public/less/index.less')
.pipe(plumber())
.pipe(getLessConfiguration())
.pipe(rename('index.min.css'))
.pipe(gulp.dest('./public/dist'));
var gameCss = gulp.src('./public/less/game.less')
.pipe(plumber())
.pipe(getLessConfiguration())
.pipe(rename('game.min.css'))
.pipe(gulp.dest('./public/dist'));
return merge(indexCss, gameCss);
});
gulp.task('watch-js', function() {
gulp.watch(['./extern/*.js',
'./lib/**/*.js',
'./public/js/**/*.js',
'./shared/*.js' ], ['js-compile']);
});
gulp.task('watch-less', function() {
gulp.watch('./public/less/*.less', ['less']);
});
gulp.task('watch', function() {
gulp.watch(['./extern/*.js',
'./lib/**/*.js',
'./public/js/**/*.js',
'./shared/*.js' ], ['js-compile']);
gulp.watch('./public/less/*.less', ['less']);
});