Skip to content

Commit d78e0f6

Browse files
committed
refactor(gulp): Use arrow functions in a bunch of places
[ci skip]
1 parent 58bafcd commit d78e0f6

1 file changed

Lines changed: 49 additions & 58 deletions

File tree

app/templates/gulpfile.babel.js

Lines changed: 49 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,24 @@ function checkAppReady(cb) {
6868
host: 'localhost',
6969
port: config.port,
7070
};
71-
http.get(options, function() {
72-
cb(true);
73-
}).on('error', function() {
74-
cb(false);
75-
});
71+
http
72+
.get(options, () => cb(true))
73+
.on('error', () => cb(false));
7674
}
7775

7876
// Call page until first success
7977
function whenServerReady(cb) {
8078
var serverReady = false;
81-
var appReadyInterval = setInterval(function() {
82-
checkAppReady(function(ready) {
79+
var appReadyInterval = setInterval(() =>
80+
checkAppReady((ready) => {
8381
if(!ready || serverReady) {
8482
return;
8583
}
8684
clearInterval(appReadyInterval);
8785
serverReady = true;
8886
cb();
89-
});
90-
}, 100);
87+
}),
88+
100);
9189
}
9290

9391
////////////////////////
@@ -113,41 +111,34 @@ var styles = lazypipe()<% if(filters.stylus) { %>
113111
// Tasks //
114112
///////////
115113

116-
gulp.task('styles', function () {
117-
return styles();
118-
});<% if(filters.coffee) { %>
114+
gulp.task('styles', () => styles());<% if(filters.coffee) { %>
119115

120-
gulp.task('coffee', function() {
121-
return gulp.src(paths.client.scripts)
116+
gulp.task('coffee', () =>
117+
gulp.src(paths.client.scripts)
122118
.pipe(lintScripts())
123119
.pipe(plugins.coffee({bare: true}).on('error', plugins.util.log))
124120
.pipe(gulp.dest('.tmp/scripts'));
125-
});<% } %>
121+
);<% } %>
126122

127-
gulp.task('lint:scripts', function () {
128-
var scripts = paths.client.scripts.concat(paths.server.scripts);
129-
return gulp.src(scripts).pipe(lintScripts());
130-
});
123+
gulp.task('lint:scripts', () => gulp.src(paths.client.scripts.concat(paths.server.scripts)).pipe(lintScripts()));
131124

132-
gulp.task('clean:tmp', function () {
133-
return gulp.src('.tmp', {read: false}).pipe(plugins.clean());
134-
});
125+
gulp.task('clean:tmp', () => gulp.src('.tmp', {read: false}).pipe(plugins.clean()));
135126

136-
gulp.task('start:client', [<% if(filters.coffee) { %>'coffee', <% } %>'styles'], function (callback) {
137-
whenServerReady(function () {
127+
gulp.task('start:client', [<% if(filters.coffee) { %>'coffee', <% } %>'styles'], (callback) => {
128+
whenServerReady(() => {
138129
open('http://localhost:' + config.port);
139130
callback();
140131
});
141132
});
142133

143-
gulp.task('start:server', function () {
134+
gulp.task('start:server', () => {
144135
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
145136
config = require('./server/config/environment');
146137
nodemon('-w lib server/app.js')
147138
.on('log', onServerLog);
148139
});
149140

150-
gulp.task('watch', function () {
141+
gulp.task('watch', () => {
151142
var testFiles = paths.client.test.concat(paths.server.test);
152143

153144
plugins.watch(paths.client.styles)
@@ -173,53 +164,52 @@ gulp.task('watch', function () {
173164
gulp.watch('bower.json', ['bower']);
174165
});
175166

176-
gulp.task('serve', function (callback) {
167+
gulp.task('serve', (callback) =>
177168
runSequence('clean:tmp',
178169
['lint:scripts'],
179170
'bower',
180171
['start:server', 'start:client'],
181-
'watch', callback);
182-
});
172+
'watch',
173+
callback);
174+
);
183175

184-
gulp.task('test:server', function () {
176+
gulp.task('test:server', () => {
185177
process.env.NODE_ENV = 'test';
186178
return gulp.src(paths.server.test)
187179
.pipe(plugins.mocha({reporter: 'spec'}));
188180
});
189181

190-
gulp.task('test:client', function () {
182+
gulp.task('test:client', () => {
191183
var testFiles = paths.client.testRequire.concat(paths.client.test)
192-
gulp.src(testFiles)
184+
return gulp.src(testFiles)
193185
.pipe(plugins.karma({
194186
configFile: paths.karma,
195187
action: 'watch'
196188
}));
197189
});
198190

199191
// inject bower components
200-
gulp.task('bower', function () {
201-
return gulp.src(paths.views.main)
192+
gulp.task('bower', () =>
193+
gulp.src(paths.views.main)
202194
.pipe(wiredep({
203195
exclude: [/bootstrap-sass-official/, /bootstrap.js/, '/json3/', '/es5-shim/', /bootstrap.css/, /font-awesome.css/ ]
204196
}))
205-
.pipe(gulp.dest('client/'));
206-
});
197+
.pipe(gulp.dest('client/'));
198+
);
207199

208200
///////////
209201
// Build //
210202
///////////
211203

212-
gulp.task('build', function (callback) {
204+
gulp.task('build', (callback) =>
213205
runSequence('clean:dist',
214206
['images', 'copy:extras', 'copy:fonts', 'copy:server', 'client:build'],
215207
callback);
216-
});
208+
);
217209

218-
gulp.task('clean:dist', function () {
219-
return gulp.src('dist', {read: false}).pipe(plugins.clean());
220-
});
210+
gulp.task('clean:dist', () => gulp.src('dist', {read: false}).pipe(plugins.clean()));
221211

222-
gulp.task('client:build', ['html'], function () {
212+
gulp.task('client:build', ['html'], () => {
223213
var jsFilter = plugins.filter('**/*.js');
224214
var cssFilter = plugins.filter('**/*.css');<% if(filters.jade) { %>
225215
var assets = plugins.filter('**/*.{js,css}');<% } %>
@@ -242,35 +232,36 @@ gulp.task('client:build', ['html'], function () {
242232
.pipe(gulp.dest(paths.dist + '/public'));
243233
});
244234

245-
gulp.task('html', function () {
246-
return gulp.src(yeoman.app + '/views/**/*')
235+
gulp.task('html', () =>
236+
gulp.src(yeoman.app + '/views/**/*')
247237
.pipe(gulp.dest(paths.dist + '/public/views'));
248-
});
238+
);
249239

250-
gulp.task('images', function () {
251-
return gulp.src(yeoman.app + '/images/**/*')
240+
gulp.task('images', () =>
241+
gulp.src(yeoman.app + '/images/**/*')
252242
.pipe(plugins.cache(plugins.imagemin({
253243
optimizationLevel: 5,
254244
progressive: true,
255245
interlaced: true
256246
})))
257247
.pipe(gulp.dest(paths.dist + '/public/images'));
258-
});
248+
);
259249

260-
gulp.task('copy:extras', function () {
261-
return gulp.src(yeoman.app + '/*.*', { dot: true })
250+
gulp.task('copy:extras', () =>
251+
gulp.src(yeoman.app + '/*.*', { dot: true })
262252
.pipe(gulp.dest(paths.dist + '/public'));
263-
});
253+
);
264254

265-
gulp.task('copy:fonts', function () {
266-
return gulp.src(yeoman.app + '/fonts/**/*')
255+
gulp.task('copy:fonts', () =>
256+
gulp.src(yeoman.app + '/fonts/**/*')
267257
.pipe(gulp.dest(paths.dist + '/fonts'));
268-
});
258+
);
269259

270-
gulp.task('copy:server', function(){
271-
return gulp.src([
260+
gulp.task('copy:server', () =>
261+
gulp.src([
272262
'package.json',
273263
'server.js',
274264
'lib/**/*'
275-
], {cwdbase: true}).pipe(gulp.dest(paths.dist));
276-
});
265+
], {cwdbase: true})
266+
.pipe(gulp.dest(paths.dist));
267+
);

0 commit comments

Comments
 (0)