Skip to content

Commit 7d2e1d8

Browse files
author
benholloway
committed
changed globbing to avoid all app* folders, tested on mac
1 parent a690814 commit 7d2e1d8

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

lib/config/streams.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
11
'use strict';
22

3-
var gulp = require('gulp'),
4-
path = require('path'),
5-
reduce = require('lodash.reduce'),
6-
slash = require('gulp-slash'),
7-
bowerDir = require('bower-directory');
3+
var gulp = require('gulp'),
4+
path = require('path'),
5+
flatten = require('lodash.flatten'),
6+
reduce = require('lodash.reduce'),
7+
slash = require('gulp-slash'),
8+
bowerDir = require('bower-directory');
89

910
var bowerFiles = require('../inject/bower-files');
1011

1112
var NODE = 'node_modules',
1213
BOWER = path.relative(process.cwd(), bowerDir.sync()),
1314
APP = 'app',
15+
GENERATED = 'app-*',
1416
BUILD = 'app-build',
1517
TEST = 'app-test',
1618
RELEASE_BUNDLE = 'app-release',
1719
RELEASE_VENDOR = 'app-release/vendor',
1820
ROUTES = reduce([ '', BOWER, BUILD ], mapRoutes, { });
1921

2022
/**
21-
* Create a glob with the given pattern elements, and additional directory
22-
* @param {Array|string} pattern One or more glob pattern entries to be included as-in
23-
* @param {Array|string} [additional] Any number of non-library directories to include
24-
* @return {Array} A multi-element glob pattern
23+
* Create a glob generator that features the given additional directories
24+
* @param {...string} [additional] Any number of non-library directories to include
25+
* @return {function({Array})} A multi-element glob pattern
2526
*/
26-
function getGlob(pattern, additional) {
27-
var patternArray = (typeof pattern === 'string') ? [ pattern ] : pattern || [];
28-
var additionalArray = (typeof additional === 'string') ? [ additional ] : additional || [];
29-
return patternArray.concat([NODE, BOWER, APP, BUILD, TEST, RELEASE_BUNDLE, RELEASE_VENDOR]
27+
function getGlob() {
28+
var additional = flatten(Array.prototype.slice.call(arguments));
29+
var excludes = [NODE, BOWER, APP, GENERATED]
3030
.filter(function convertAdditionalToExclude(element) {
31-
return (additionalArray.indexOf(element) < 0);
31+
return (additional.indexOf(element) < 0);
3232
})
33-
.map(function excludeDir(exclude) {
33+
.map(function excludeDirectory(exclude) {
3434
return '!' + exclude + '/**';
35-
}));
35+
});
36+
return function() {
37+
return flatten(Array.prototype.slice.call(arguments))
38+
.concat(excludes); // important - excludes must come after includes
39+
}
3640
}
3741

3842
function mapRoutes(result, path) {
@@ -45,11 +49,11 @@ function jsApp(opts) {
4549
}
4650

4751
function jsLib(opts) {
48-
return gulp.src(getGlob(['**/*.js', '!*.js', '!**/*.spec.js']), opts);
52+
return gulp.src(getGlob()('**/*.js', '!*.js', '!**/*.spec.js'), opts);
4953
}
5054

5155
function jsSpec(opts) {
52-
return gulp.src(getGlob(['**/*.spec.js', '!*.spec.js']), opts);
56+
return gulp.src(getGlob()('**/*.spec.js', '!*.spec.js'), opts);
5357
}
5458

5559
function scssApp(opts) {
@@ -63,7 +67,7 @@ function htmlApp(opts) {
6367
function testDependencies(opts) {
6468
return bowerFiles(80)
6569
.src('js', opts);
66-
};
70+
}
6771

6872
module.exports = {
6973
NODE : NODE,

tasks/watch.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,30 @@ yargs.getInstance('watch')
6565
.wrap(80);
6666

6767
gulp.task('watch', ['server'], function () {
68+
var getGlobAppNodeBower = streams.getGlob(streams.APP, streams.NODE, streams.BOWER);
6869

6970
// enqueue actions to avoid multiple trigger
7071
var queue = watchSequence(500, function () {
7172
console.log(hr('\u2591', 80));
7273
});
7374

7475
// watch statements
75-
watch(streams.getGlob(['**/*.js', '**/*.html', '!*.*', '!**/*.spec.*'], [streams.APP, streams.NODE, streams.BOWER]), {
76+
watch(getGlobAppNodeBower('**/*.js', '**/*.html', '!' + streams.APP + '/**/*.html', '!*.*', '!**/*.spec.*'), {
7677
name : 'JS|HTML',
7778
emitOnGlob: false
78-
}, queue.getHandler('javascript', 'html', 'reload')); // app html will be needed in case previous injection failed
79+
}, queue.getHandler('javascript', 'html', 'reload')); // html will be needed in case previous injection failed
7980

80-
watch(streams.getGlob(['**/*.scss', '!*.scss'], [streams.APP, streams.NODE, streams.BOWER]), {
81+
watch(getGlobAppNodeBower(['**/*.scss', '!*.scss']), {
8182
name : 'CSS',
8283
emitOnGlob: false
8384
}, queue.getHandler('css', 'html', 'reload')); // html will be needed in case previous injection failed
8485

85-
watch([streams.BOWER + '/**/*', '!**/*.js', '!**/*.scss'], { // don't conflict with JS or CSS
86-
name : 'BOWER',
86+
watch([streams.APP + '/**/*.html', streams.BOWER + '/**/*', '!**/*.js', '!**/*.scss'], { // don't conflict JS or CSS
87+
name : 'INJECT',
8788
emitOnGlob: false
8889
}, queue.getHandler('html', 'reload'));
8990

90-
watch(streams.getGlob(['**/*.spec.js', '!*.spec.js']), {
91+
watch(streams.getGlob()(['**/*.spec.js', '!*.spec.js']), {
9192
name : 'TEST',
9293
emitOnGlob: false
9394
}, queue.getHandler('test'));

0 commit comments

Comments
 (0)