Skip to content

Commit 77b7be6

Browse files
committed
refactor(gulp): update path globs and references
use template strings to turn all references to `dist/`, `client/` and `server/` into variables. update some path globs to more accurately match target files (aiming for grunt parity)
1 parent c0d5a14 commit 77b7be6

File tree

1 file changed

+55
-54
lines changed

1 file changed

+55
-54
lines changed

Diff for: app/templates/gulpfile.babel(gulp).js

+55-54
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,39 @@ import nib from 'nib';<% } %>
1717
var plugins = gulpLoadPlugins();
1818
var config;
1919

20+
const clientPath = require('./bower.json').appPath || 'client';
21+
const serverPath = 'server';
2022
const paths = {
21-
appPath: require('./bower.json').appPath || 'client',
2223
client: {
23-
assets: 'client/assets/**/*',
24-
images: 'client/assets/images/*',
24+
assets: `${clientPath}/assets/**/*`,
25+
images: `${clientPath}/assets/images/**/*`,
2526
scripts: [
26-
'client/**/*.<%= scriptExt %>',
27-
'!client/bower_components/**/*.js'
27+
`${clientPath}/**/*.<%= scriptExt %>`,
28+
`!${clientPath}/bower_components/**/*.js`
2829
],
29-
styles: ['client/{app,components}/**/*.<%= styleExt %>'],
30-
mainStyle: 'client/app/app.<%= styleExt %>',
31-
views: 'client/{app,components}/**/*.<%= templateExt %>',
32-
mainView: 'client/index.html',
33-
test: ['client/**/*.spec.<%= scriptExt %>'],
30+
styles: [`${clientPath}/{app,components}/**/*.<%= styleExt %>`],
31+
mainStyle: `${clientPath}/app/app.<%= styleExt %>`,
32+
views: `${clientPath}/{app,components}/**/*.<%= templateExt %>`,
33+
mainView: `${clientPath}/index.html`,
34+
test: [`${clientPath}/{app,components}/**/*.spec.<%= scriptExt %>`],
3435
testRequire: [
35-
'client/bower_components/angular/angular.js',
36-
'client/bower_components/angular-mocks/angular-mocks.js',
37-
'client/bower_components/angular-resource/angular-resource.js',
38-
'client/bower_components/angular-cookies/angular-cookies.js',
39-
'client/bower_components/angular-sanitize/angular-sanitize.js',
40-
'client/bower_components/angular-route/angular-route.js',
41-
'client/**/*.spec.<%= scriptExt %>'
36+
`${clientPath}/bower_components/angular/angular.js`,
37+
`${clientPath}/bower_components/angular-mocks/angular-mocks.js`,
38+
`${clientPath}/bower_components/angular-resource/angular-resource.js`,
39+
`${clientPath}/bower_components/angular-cookies/angular-cookies.js`,
40+
`${clientPath}/bower_components/angular-sanitize/angular-sanitize.js`,
41+
`${clientPath}/bower_components/angular-route/angular-route.js`,
42+
`${clientPath}/**/*.spec.<%= scriptExt %>`
4243
],
43-
bower: 'client/bower_components/'
44+
bower: `${clientPath}/bower_components/`
4445
},
4546
server: {
46-
scripts: ['server/**/*.<%= scriptExt %>'],
47-
json: ['server/**/*.json'],
47+
scripts: [`${serverPath}/**/*.<%= scriptExt %>`],
48+
json: [`${serverPath}/**/*.json`],
4849
test: [
49-
'server/**/*.spec.js',
50-
'server/**/*.mock.js',
51-
'server/**/*.integration.js'
50+
`${serverPath}/**/*.spec.js`,
51+
`${serverPath}/**/*.mock.js`,
52+
`${serverPath}/**/*.integration.js`
5253
]
5354
},
5455
karma: 'karma.conf.js',
@@ -117,13 +118,13 @@ function sortModulesFirst(a, b) {
117118
let lintClientScripts = lazypipe()<% if(filters.coffee) { %>
118119
.pipe(plugins.coffeelint)
119120
.pipe(plugins.coffeelint.reporter);<% } else { %>
120-
.pipe(plugins.jshint, 'client/.jshintrc')
121+
.pipe(plugins.jshint, `${clientPath}/.jshintrc`)
121122
.pipe(plugins.jshint.reporter, 'jshint-stylish');<% } %>
122123

123124
let lintServerScripts = lazypipe()<% if(filters.coffee) { %>
124125
.pipe(plugins.coffeelint)
125126
.pipe(plugins.coffeelint.reporter);<% } else { %>
126-
.pipe(plugins.jshint, 'server/.jshintrc')
127+
.pipe(plugins.jshint, `${serverPath}/.jshintrc`)
127128
.pipe(plugins.jshint.reporter, 'jshint-stylish');<% } %>
128129

129130
let styles = lazypipe()
@@ -152,7 +153,7 @@ let transpile = lazypipe()
152153
gulp.task('env:all', () => {
153154
let localConfig;
154155
try {
155-
localConfig = require('./server/config/local.env');
156+
localConfig = require(`./${serverPath}/config/local.env`);
156157
} catch (e) {
157158
localConfig = {};
158159
}
@@ -182,31 +183,31 @@ gulp.task('inject', cb => {
182183
gulp.task('inject:js', () => {
183184
return gulp.src(paths.client.mainView)
184185
.pipe(plugins.inject(
185-
gulp.src(_.union(paths.client.scripts, ['!client/**/*.spec.<%= scriptExt %>']), {read: false})
186+
gulp.src(_.union(paths.client.scripts, [`!${clientPath}/**/*.spec.<%= scriptExt %>`]), {read: false})
186187
.pipe(plugins.sort(sortModulesFirst)),
187188
{
188189
starttag: '<!-- injector:js -->',
189190
endtag: '<!-- endinjector -->',
190-
transform: (filepath) => '<script src="' + filepath.replace('/client/', '') + '"></script>'
191+
transform: (filepath) => '<script src="' + filepath.replace(`/${clientPath}/`, '') + '"></script>'
191192
}))
192-
.pipe(gulp.dest('client'));
193+
.pipe(gulp.dest(clientPath));
193194
});
194195

195196
gulp.task('inject:css', () => {
196197
return gulp.src(paths.client.mainView)
197198
.pipe(plugins.inject(
198-
gulp.src('/client/**/*.css', {read: false})
199+
gulp.src('/${clientPath}/{app,components}/**/*.css', {read: false})
199200
.pipe(plugins.sort()),
200201
{
201202
starttag: '<!-- injector:css -->',
202203
endtag: '<!-- endinjector -->',
203-
transform: (filepath) => '<link rel="stylesheet" href="' + filepath.replace('/client/', '').replace('/.tmp/', '') + '">'
204+
transform: (filepath) => '<link rel="stylesheet" href="' + filepath.replace(`/${clientPath}/`, '').replace('/.tmp/', '') + '">'
204205
}))
205-
.pipe(gulp.dest('client'));
206+
.pipe(gulp.dest(clientPath));
206207
});
207208

208209
gulp.task('inject:<%= styleExt %>', () => {
209-
return gulp.src('client/app/app.<%= styleExt %>')
210+
return gulp.src(paths.client.mainStyle)
210211
.pipe(plugins.inject(
211212
gulp.src(_.union(paths.client.styles, ['!' + paths.client.mainStyle]), {read: false})
212213
.pipe(plugins.sort()),
@@ -215,14 +216,14 @@ gulp.task('inject:<%= styleExt %>', () => {
215216
endtag: '// endinjector',
216217
transform: (filepath) => {
217218
let newPath = filepath
218-
.replace('/client/app/', '')
219-
.replace('/client/components/', '../components/')
219+
.replace(`/${clientPath}/app/`, '')
220+
.replace(`/${clientPath}/components/`, '../components/')
220221
.replace(/_(.*).<%= styleExt %>/, (match, p1, offset, string) => p1)
221222
.replace('.<%= styleExt %>', '');
222-
return '@import \'' + newPath + '\';';
223+
return `@import '${newPath}';`;
223224
}
224225
}))
225-
.pipe(gulp.dest('client/app'));
226+
.pipe(gulp.dest(`${clientPath}/app`));
226227
});
227228

228229
gulp.task('styles', () => {
@@ -240,7 +241,7 @@ gulp.task('transpile:client', () => {
240241
gulp.task('transpile:server', () => {
241242
return gulp.src(_.union(paths.server.scripts, paths.server.json))
242243
.pipe(transpile())
243-
.pipe(gulp.dest(paths.dist + '/server'));
244+
.pipe(gulp.dest(`${paths.dist}/${serverPath}`));
244245
});
245246

246247
gulp.task('lint:scripts', cb => runSequence(['lint:scripts:client', 'lint:scripts:server'], cb));
@@ -266,8 +267,8 @@ gulp.task('start:client', cb => {
266267

267268
gulp.task('start:server', () => {
268269
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
269-
config = require('./server/config/environment');
270-
nodemon('-w server server')
270+
config = require(`./${serverPath}/config/environment`);
271+
nodemon(`-w ${serverPath} ${serverPath}`)
271272
.on('log', onServerLog);
272273
});
273274

@@ -360,9 +361,9 @@ gulp.task('wiredep:client', () => {
360361
/bootstrap.css/,
361362
/font-awesome.css/
362363
],
363-
ignorePath: paths.appPath
364+
ignorePath: clientPath
364365
}))
365-
.pipe(gulp.dest('client/'));
366+
.pipe(gulp.dest(`${clientPath}/`));
366367
});
367368

368369
gulp.task('wiredep:test', () => {
@@ -402,7 +403,7 @@ gulp.task('build', cb => {
402403
cb);
403404
});
404405

405-
gulp.task('clean:dist', () => del(['dist/**/*']));
406+
gulp.task('clean:dist', () => del([`${paths.dist}/**/*`]));
406407

407408
gulp.task('build:client', ['transpile:client', 'styles', 'html'], () => {
408409
var appFilter = plugins.filter('**/app.js');
@@ -411,7 +412,7 @@ gulp.task('build:client', ['transpile:client', 'styles', 'html'], () => {
411412
var htmlFilter = plugins.filter('**/*.html');<% if(filters.jade) { %>
412413
var assetsFilter = plugins.filter('**/*.{js,css}');<% } %>
413414

414-
let assets = plugins.useref.assets({searchPath: ['client', '.tmp']});
415+
let assets = plugins.useref.assets({searchPath: [clientPath, '.tmp']});
415416

416417
return gulp.src(paths.client.mainView)<% if(filters.jade) { %>
417418
.pipe(plugins.jade({pretty: true}))<% } %>
@@ -435,11 +436,11 @@ gulp.task('build:client', ['transpile:client', 'styles', 'html'], () => {
435436
.pipe(plugins.revReplace())
436437
.pipe(plugins.useref())<% if(filters.jade) { %>
437438
.pipe(assetsFilter)<% } %>
438-
.pipe(gulp.dest(paths.dist + '/client'));
439+
.pipe(gulp.dest(`${paths.dist}/${clientPath}`));
439440
});
440441

441442
gulp.task('html', function() {
442-
return gulp.src('client/{app,components}/**/*.html')
443+
return gulp.src(`${clientPath}/{app,components}/**/*.html`)
443444
.pipe(plugins.angularTemplatecache({
444445
module: '<%= scriptAppName %>'
445446
}))
@@ -452,7 +453,7 @@ gulp.task('jade', function() {
452453
});<% } %>
453454

454455
gulp.task('constant', function() {
455-
let sharedConfig = require('./server/config/environment/shared');
456+
let sharedConfig = require(`./${serverPath}/config/environment/shared`);
456457
plugins.ngConstant({
457458
name: '<%= scriptAppName %>.constants',
458459
deps: [],
@@ -463,30 +464,30 @@ gulp.task('constant', function() {
463464
.pipe(plugins.rename({
464465
basename: 'app.constant'
465466
}))
466-
.pipe(gulp.dest('client/app/'))
467+
.pipe(gulp.dest(`${clientPath}/app/`))
467468
})
468469

469470
gulp.task('build:images', () => {
470-
return gulp.src('client/assets/images/**/*')
471+
return gulp.src(paths.client.images)
471472
.pipe(plugins.imagemin({
472473
optimizationLevel: 5,
473474
progressive: true,
474475
interlaced: true
475476
}))
476-
.pipe(gulp.dest(paths.dist + '/client/assets/images'));
477+
.pipe(gulp.dest(`${paths.dist}/${clientPath}/assets/images`));
477478
});
478479

479480
gulp.task('copy:extras', () => {
480481
return gulp.src([
481-
'client/favicon.ico',
482-
'client/robots.txt'
482+
`${clientPath}/favicon.ico`,
483+
`${clientPath}/robots.txt`
483484
], { dot: true })
484-
.pipe(gulp.dest(paths.dist + '/client'));
485+
.pipe(gulp.dest(`${paths.dist}/${clientPath}`));
485486
});
486487

487488
gulp.task('copy:assets', () => {
488489
return gulp.src([paths.client.assets, '!' + paths.client.images])
489-
.pipe(gulp.dest(paths.dist + '/client/assets'));
490+
.pipe(gulp.dest(`${paths.dist}/${clientPath}/assets`));
490491
});
491492

492493
gulp.task('copy:server', () => {

0 commit comments

Comments
 (0)