/
gulpfile.js
189 lines (149 loc) · 5.53 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
'use strict';
var gulp = require('gulp'),
// SASS compiler
sass = require('gulp-sass'),
// Used to automatically add in css browser prefixes so we can just write lovely CSS3 without worrying
autoprefixer = require('gulp-autoprefixer'),
// Used to delete files
del = require('del'),
// Used to replace the output of conditional HTML comments
processhtml = require('gulp-processhtml'),
// Reports the filesize of the latest pipe to the terminal
size = require('gulp-filesize'),
// Used to minify our compiled CSS
mincss = require('gulp-minify-css'),
// Used for minifying javascript
uglify = require('gulp-uglify'),
// Used for linting javascript and checking for issues
jshint = require('gulp-jshint'),
// Used for modular javascript development
browserify = require('browserify'),
// Use conventional text streams at the start of your gulp or vinyl pipelines
source = require('vinyl-source-stream'),
// Converts streaming vinyl files to use buffers
buffer = require('vinyl-buffer'),
// Used for generating sourcemaps of minified javascript files.
sourcemaps = require('gulp-sourcemaps'),
// I'll be honest, I have no idea what this does.
gutil = require('gulp-util'),
// Test-runner
tape = require('gulp-tape'),
// Reporter used by the test runner
tap = require('tap-colorize'),
// Used to output the file sizes
size = require('gulp-size'),
// These are used to perform tasks differently depending on the args
argv = require('yargs').argv,
gulpif = require('gulp-if'),
rename = require('gulp-rename'),
// These are used in the compilation of underscore templates
lodash = require('lodash'),
template = require('gulp-template-compile'),
concat = require('gulp-concat'),
defmod = require('gulp-define-module');
/**
* Polyfill required so the autoprefixer doesn't break.
*/
require('es6-promise').polyfill();
gulp.task('views', function () {
return gulp.src('./src/views/*.html')
.pipe(template({ namespace: 'WAG'}))
.pipe(concat('views.js'))
.pipe(defmod('commonjs'))
.pipe(gulp.dest('./src/scripts'));
});
/**
* Bundle and minify all of the source script files
*/
gulp.task('scripts', ['jshint', 'views'], function () {
return browserify({ entries: './src/scripts/app.js', noParse: ['./src/vendor/pixi.min.js'], debug: true })
.bundle()
.on('error', gutil.log)
.pipe(source('wagamama.js'))
.pipe(buffer())
.pipe(size())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(gulpif(argv.production, uglify()))
.pipe(gulpif(argv.production, rename({suffix: '.min'})))
.pipe(gulpif(argv.production, sourcemaps.write('./')))
.on('error', gutil.log)
.pipe(size())
// .pipe(gulp.dest('../backend/static_assets/scripts'));
.pipe(gulp.dest('../backend/static_assets/scripts'));
});
/**
* Separate gulp task for the competition closed script
*/
gulp.task('closed', ['jshint', 'views'], function () {
return browserify({ entries: './src/scripts/closed.js', noParse: ['./src/vendor/pixi.min.js'], debug: true })
.bundle()
.on('error', gutil.log)
.pipe(source('closed.js'))
.pipe(buffer())
.pipe(size())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(gulpif(argv.production, uglify()))
.pipe(gulpif(argv.production, rename({suffix: '.min'})))
.pipe(gulpif(argv.production, sourcemaps.write('./')))
.on('error', gutil.log)
.pipe(size())
// .pipe(gulp.dest('../backend/static_assets/scripts'));
.pipe(gulp.dest('../backend/static_assets/scripts'));
});
/**
* This task is used to verify that I am not taking crazy pills
* and that my javascript is in fact perfectly formed.
*/
gulp.task('jshint', function() {
return gulp.src([
'./src/scripts/**/*.js',
'!./src/scripts/views/**/*.*',
'!./src/scripts/views.js',
'!./src/scripts/generated/**/*.js',
'!./src/scripts/Social.js',
'!./src/scripts/Tracking.js',
'!./src/scripts/tracking.js'
])
.pipe(jshint(require('./config/jshint.js')))
.pipe(jshint.reporter('default'));
});
/**
* This task compiles, nay transforms my sass into a hard
* shiny peg of truth (CSS). Compiles scss files for dev.
* Minifies if this task is run with the production argument.
*/
gulp.task('sass', function() {
return gulp.src('./src/scss/*.scss')
.pipe(sass())
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulpif(argv.production, mincss()))
.pipe(gulpif(argv.production, rename({suffix: '.min'})))
// .pipe(gulp.dest('../backend/static_assets/css'));
.pipe(gulp.dest('../backend/static_assets/css'));
});
/**
* Run the TAPE tests
*/
gulp.task('test', function() {
return gulp.src('./tests/tape/*.js')
.pipe(tape({
reporter: tap()
}));
});
/**
* EVERYTHING.
*/
gulp.task('build', ['jshint', 'sass', 'scripts']);
/**
* Watch our source files and trigger a build when they change
*/
gulp.task('watch', function() {
gulp.watch([
'./src/scripts/**/*.js',
'./src/views/**/*.html',
'./src/scss/**'
], ['build']);
});