1
1
'use strict' ;
2
- const fs = require ( 'fs' ) ;
3
- const glob = require ( 'glob' ) ;
4
2
const path = require ( 'path' ) ;
5
3
6
4
const isProduction = require ( './is-production' ) ;
@@ -26,7 +24,7 @@ class Angular2App extends BroccoliPlugin {
26
24
27
25
this . _options = options ;
28
26
this . _sourceDir = options . sourceDir || 'src/client' ;
29
- this . _inputNode = inputNode || this . _sourceDir ;
27
+ this . _inputNode = inputNode || this . _buildInputTree ( ) ;
30
28
this . _destDir = options . destDir || '' ;
31
29
32
30
// By default, add all spec files to the tsCompiler.
@@ -65,6 +63,15 @@ class Angular2App extends BroccoliPlugin {
65
63
return this . _tree . cleanup ( ) ;
66
64
}
67
65
66
+ _buildInputTree ( ) {
67
+ return new BroccoliMergeTrees ( [
68
+ new BroccoliFunnel ( this . _sourceDir , { destDir : this . _sourceDir } ) ,
69
+ new BroccoliFunnel ( 'typings' , { destDir : 'typings' } ) ,
70
+ new BroccoliFunnel ( 'public' , { destDir : 'public' } ) ,
71
+ this . _getConfigTree ( )
72
+ ] , { overwrite : true } ) ;
73
+ }
74
+
68
75
/**
69
76
* Create and return the app build system tree that:
70
77
* - Get the `assets` tree
@@ -84,27 +91,31 @@ class Angular2App extends BroccoliPlugin {
84
91
var tsTree = this . _getTsTree ( ) ;
85
92
var indexTree = this . _getIndexTree ( ) ;
86
93
var vendorNpmTree = this . _getVendorNpmTree ( ) ;
87
- var excludeDotfilesTree = this . _getPublicTree ( ) ;
88
94
89
95
var buildTrees = [ assetTree , tsTree , indexTree , vendorNpmTree ] ;
90
96
91
- if ( fs . existsSync ( 'public' ) ) {
92
- buildTrees . push ( excludeDotfilesTree ) ;
97
+ for ( const suffix of [ 'sass' , 'less' , 'stylus' , 'compass' ] ) {
98
+ const plugin = require ( `./angular-broccoli-${ suffix } ` ) ;
99
+ const tree = plugin . makeBroccoliTree ( this . _inputNode , this . _options [ `${ suffix } Compiler` ] ) ;
100
+
101
+ if ( ! tree ) {
102
+ continue ;
103
+ }
104
+
105
+ buildTrees . push ( new BroccoliFunnel ( tree , {
106
+ include : [ '**/*' ] ,
107
+ getDestinationPath : ( n ) => {
108
+ if ( n . startsWith ( this . _sourceDir ) ) {
109
+ return n . substr ( this . _sourceDir . length ) ;
110
+ }
111
+ return n ;
112
+ }
113
+ } ) ) ;
93
114
}
94
115
95
- buildTrees = buildTrees . concat (
96
- require ( './angular-broccoli-sass' ) . makeBroccoliTree ( this . _inputNode ,
97
- this . _options . sassCompiler ) ,
98
- require ( './angular-broccoli-less' ) . makeBroccoliTree ( this . _inputNode ,
99
- this . _options . lessCompiler ) ,
100
- require ( './angular-broccoli-stylus' ) . makeBroccoliTree ( this . _inputNode ,
101
- this . _options . stylusCompiler ) ,
102
- require ( './angular-broccoli-compass' ) . makeBroccoliTree ( this . _inputNode ,
103
- this . _options . compassCompiler )
104
- ) . filter ( x => ! ! x ) ;
105
-
106
- var merged = BroccoliMergeTrees ( buildTrees , { overwrite : true } ) ;
107
- return new BroccoliFunnel ( BroccoliMergeTrees ( [ merged , new BroccoliSwManifest ( [ merged ] ) ] ) , {
116
+ var merged = new BroccoliMergeTrees ( buildTrees , { overwrite : true } ) ;
117
+ merged = new BroccoliMergeTrees ( [ merged , new BroccoliSwManifest ( [ merged ] ) ] ) ;
118
+ return new BroccoliFunnel ( merged , {
108
119
destDir : this . _destDir
109
120
} ) ;
110
121
}
@@ -215,19 +226,22 @@ class Angular2App extends BroccoliPlugin {
215
226
* @return {Tree } Tree for app/index.html.
216
227
*/
217
228
_getIndexTree ( ) {
218
- var htmlName = 'index.html' ;
219
229
var files = [
220
230
'index.html'
221
231
] ;
222
232
223
- var index = new BroccoliFunnel ( this . _inputNode , {
224
- files : files ,
225
- description : 'BroccoliFunnel: index.html'
233
+ let indexTree = new BroccoliFunnel ( this . _inputNode , {
234
+ include : files . map ( name => path . join ( this . _sourceDir , name ) ) ,
235
+ getDestinationPath : ( n ) => {
236
+ if ( n . startsWith ( this . _sourceDir ) ) {
237
+ return n . substr ( this . _sourceDir . length ) ;
238
+ }
239
+ return n ;
240
+ }
226
241
} ) ;
227
242
228
-
229
- return BroccoliConfigReplace ( index , {
230
- files : [ htmlName ] ,
243
+ return BroccoliConfigReplace ( indexTree , {
244
+ files : files ,
231
245
patterns : this . _getReplacePatterns ( )
232
246
} ) ;
233
247
}
@@ -268,42 +282,8 @@ class Angular2App extends BroccoliPlugin {
268
282
* @return {Tree } Tree for TypeScript files.
269
283
*/
270
284
_getTsTree ( ) {
271
- var typingsTree = this . _getTypingsTree ( ) ;
272
- var sourceTree = this . _getSourceTree ( ) ;
273
- var configTree = this . _getConfigTree ( ) ;
274
-
275
285
var tsConfigPath = path . join ( this . _sourceDir , 'tsconfig.json' ) ;
276
- var tsconfig = JSON . parse ( fs . readFileSync ( tsConfigPath , 'utf-8' ) ) ;
277
-
278
- // Add all glob files to files. In some cases we don't want to specify
279
- let globFiles = this . _tsCompiler . additionalFiles ;
280
- if ( globFiles ) {
281
- if ( typeof globFiles == 'string' ) {
282
- globFiles = [ globFiles ] ;
283
- }
284
-
285
- for ( const g of globFiles ) {
286
- const files = glob ( g , { sync : true , cwd : this . _sourceDir , root : this . _sourceDir } ) ;
287
- tsconfig . files = tsconfig . files . concat ( files ) ;
288
- }
289
- }
290
-
291
- // Remove dupes in tsconfig.files.
292
- const fileNameMap = { } ;
293
- tsconfig . files = tsconfig . files . filter ( fileName => {
294
- if ( fileNameMap [ fileName ] ) {
295
- return false ;
296
- }
297
- fileNameMap [ fileName ] = true ;
298
- return true ;
299
- } ) ;
300
-
301
- // Because the tsconfig does not include the source directory, add this as the first path
302
- // element.
303
- tsconfig . files = tsconfig . files . map ( name => path . join ( this . _sourceDir , name ) ) ;
304
-
305
- var mergedTree = BroccoliMergeTrees ( [ sourceTree , typingsTree , configTree ] , { overwrite : true } ) ;
306
- var tsTree = new BroccoliTypescript ( mergedTree , tsconfig ) ;
286
+ var tsTree = new BroccoliTypescript ( this . _inputNode , tsConfigPath , this . _tsCompiler ) ;
307
287
308
288
var tsTreeExcludes = [ '*.d.ts' , 'tsconfig.json' ] ;
309
289
var excludeSpecFiles = '**/*.spec.*' ;
@@ -362,6 +342,7 @@ class Angular2App extends BroccoliPlugin {
362
342
*/
363
343
_getAssetsTree ( ) {
364
344
return new BroccoliFunnel ( this . _inputNode , {
345
+ include : [ path . join ( this . _sourceDir , '**/*' ) ] ,
365
346
exclude : [
366
347
'**/*.ts' ,
367
348
'**/*.js' ,
@@ -370,20 +351,12 @@ class Angular2App extends BroccoliPlugin {
370
351
'**/*.less' ,
371
352
'**/*.styl'
372
353
] ,
373
- allowEmpty : true
374
- } ) ;
375
- }
376
-
377
- /**
378
- * Returns the `excludeDotfiles` tree.
379
- *
380
- * @private
381
- * @method _getPublicTree
382
- * @return {Tree } The dotfiles exclusion tree.
383
- */
384
- _getPublicTree ( ) {
385
- return new BroccoliFunnel ( 'public' , {
386
- exclude : [ '**/.*' ] ,
354
+ getDestinationPath : ( n ) => {
355
+ if ( n . startsWith ( this . _sourceDir ) ) {
356
+ return n . substr ( this . _sourceDir . length ) ;
357
+ }
358
+ return n ;
359
+ } ,
387
360
allowEmpty : true
388
361
} ) ;
389
362
}
0 commit comments