1
1
'use strict' ;
2
2
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' ) ;
8
9
9
10
var bowerFiles = require ( '../inject/bower-files' ) ;
10
11
11
12
var NODE = 'node_modules' ,
12
13
BOWER = path . relative ( process . cwd ( ) , bowerDir . sync ( ) ) ,
13
14
APP = 'app' ,
15
+ GENERATED = 'app-*' ,
14
16
BUILD = 'app-build' ,
15
17
TEST = 'app-test' ,
16
18
RELEASE_BUNDLE = 'app-release' ,
17
19
RELEASE_VENDOR = 'app-release/vendor' ,
18
20
ROUTES = reduce ( [ '' , BOWER , BUILD ] , mapRoutes , { } ) ;
19
21
20
22
/**
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
25
26
*/
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 ]
30
30
. filter ( function convertAdditionalToExclude ( element ) {
31
- return ( additionalArray . indexOf ( element ) < 0 ) ;
31
+ return ( additional . indexOf ( element ) < 0 ) ;
32
32
} )
33
- . map ( function excludeDir ( exclude ) {
33
+ . map ( function excludeDirectory ( exclude ) {
34
34
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
+ }
36
40
}
37
41
38
42
function mapRoutes ( result , path ) {
@@ -45,11 +49,11 @@ function jsApp(opts) {
45
49
}
46
50
47
51
function jsLib ( opts ) {
48
- return gulp . src ( getGlob ( [ '**/*.js' , '!*.js' , '!**/*.spec.js' ] ) , opts ) ;
52
+ return gulp . src ( getGlob ( ) ( '**/*.js' , '!*.js' , '!**/*.spec.js' ) , opts ) ;
49
53
}
50
54
51
55
function jsSpec ( opts ) {
52
- return gulp . src ( getGlob ( [ '**/*.spec.js' , '!*.spec.js' ] ) , opts ) ;
56
+ return gulp . src ( getGlob ( ) ( '**/*.spec.js' , '!*.spec.js' ) , opts ) ;
53
57
}
54
58
55
59
function scssApp ( opts ) {
@@ -63,7 +67,7 @@ function htmlApp(opts) {
63
67
function testDependencies ( opts ) {
64
68
return bowerFiles ( 80 )
65
69
. src ( 'js' , opts ) ;
66
- } ;
70
+ }
67
71
68
72
module . exports = {
69
73
NODE : NODE ,
0 commit comments