1
1
'use strict' ;
2
+ const fs = require ( 'fs' ) ;
3
+ const glob = require ( 'glob' ) ;
2
4
const path = require ( 'path' ) ;
5
+
3
6
const isProduction = require ( './is-production' ) ;
4
- const configReplace = require ( './ broccoli-config-replace ' ) ;
5
- const compileWithTypescript = require ( './broccoli-typescript ' ) ;
6
- const SwManifest = require ( './service-worker-manifest' ) . default ;
7
- const fs = require ( 'fs' ) ;
8
- const Funnel = require ( 'broccoli-funnel' ) ;
9
- const mergeTrees = require ( 'broccoli-merge-trees' ) ;
10
- const uglify = require ( 'broccoli-uglify-js' ) ;
7
+ const BroccoliPlugin = require ( 'broccoli-writer ' ) ;
8
+ const BroccoliConfigReplace = require ( './broccoli-config-replace ' ) ;
9
+ const BroccoliTypescript = require ( './broccoli-typescript' ) ;
10
+ const BroccoliSwManifest = require ( './service-worker-manifest' ) . default ;
11
+ const BroccoliFunnel = require ( 'broccoli-funnel' ) ;
12
+ const BroccoliMergeTrees = require ( 'broccoli-merge-trees' ) ;
13
+ const BroccoliUglify = require ( 'broccoli-uglify-js' ) ;
11
14
const Project = require ( 'ember-cli/lib/models/project' ) ;
12
- const glob = require ( 'glob' ) ;
13
15
14
16
15
- class Angular2App {
17
+ class Angular2App extends BroccoliPlugin {
16
18
constructor ( defaults , options ) {
19
+ super ( ) ;
17
20
options = options || { } ;
18
21
19
22
this . _options = options ;
@@ -27,6 +30,32 @@ class Angular2App {
27
30
28
31
this . _initProject ( ) ;
29
32
this . _notifyAddonIncluded ( ) ;
33
+
34
+ this . _tree = this . _buildTree ( ) ;
35
+ }
36
+
37
+ /**
38
+ * For backward compatibility.
39
+ * @public
40
+ * @method toTree
41
+ * @return {BroccoliPlugin } A broccoli plugin.
42
+ */
43
+ toTree ( ) {
44
+ console . warn ( 'Angular2App is now a broccoli plugin. Calling toTree() is deprecated.' ) ;
45
+ return this ;
46
+ }
47
+
48
+ /**
49
+ * @override
50
+ */
51
+ read ( readTree ) {
52
+ return this . _tree . read ( readTree ) ;
53
+ }
54
+ /**
55
+ * @override
56
+ */
57
+ cleanup ( ) {
58
+ return this . _tree . cleanup ( ) ;
30
59
}
31
60
32
61
/**
@@ -39,11 +68,11 @@ class Angular2App {
39
68
* - Apply/remove stuff based on the environment (dev|prod)
40
69
* - Return the app trees to be extended
41
70
*
42
- * @public
43
- * @method toTree
44
- * @return {Array<Tree> } The app trees that can be used to extend the build.
71
+ * @private
72
+ * @method _buildTree
73
+ * @return {BroccoliFunnel } The app trees that can be used to extend the build.
45
74
*/
46
- toTree ( ) {
75
+ _buildTree ( ) {
47
76
var assetTree = this . _getAssetsTree ( ) ;
48
77
var tsTree = this . _getTsTree ( ) ;
49
78
var indexTree = this . _getIndexTree ( ) ;
@@ -67,8 +96,8 @@ class Angular2App {
67
96
this . _options . compassCompiler )
68
97
) . filter ( x => ! ! x ) ;
69
98
70
- var merged = mergeTrees ( buildTrees , { overwrite : true } ) ;
71
- return new Funnel ( mergeTrees ( [ merged , new SwManifest ( [ merged ] ) ] ) , {
99
+ var merged = BroccoliMergeTrees ( buildTrees , { overwrite : true } ) ;
100
+ return new BroccoliFunnel ( BroccoliMergeTrees ( [ merged , new BroccoliSwManifest ( [ merged ] ) ] ) , {
72
101
destDir : this . _destDir
73
102
} ) ;
74
103
}
@@ -184,13 +213,13 @@ class Angular2App {
184
213
'index.html'
185
214
] ;
186
215
187
- var index = new Funnel ( this . _sourceDir , {
216
+ var index = new BroccoliFunnel ( this . _sourceDir , {
188
217
files : files ,
189
- description : 'Funnel : index.html'
218
+ description : 'BroccoliFunnel : index.html'
190
219
} ) ;
191
220
192
221
193
- return configReplace ( index , {
222
+ return BroccoliConfigReplace ( index , {
194
223
files : [ htmlName ] ,
195
224
patterns : this . _getReplacePatterns ( )
196
225
} ) ;
@@ -204,7 +233,7 @@ class Angular2App {
204
233
* @return {Tree } Tree for the src dir.
205
234
*/
206
235
_getSourceTree ( ) {
207
- return new Funnel ( this . _sourceDir , {
236
+ return new BroccoliFunnel ( this . _sourceDir , {
208
237
include : [ '*.ts' , '**/*.ts' , '**/*.d.ts' ] ,
209
238
destDir : this . _sourceDir
210
239
} ) ;
@@ -218,7 +247,7 @@ class Angular2App {
218
247
* @return {Tree } Tree for the src dir.
219
248
*/
220
249
_getTypingsTree ( ) {
221
- return new Funnel ( 'typings' , {
250
+ return new BroccoliFunnel ( 'typings' , {
222
251
include : [ 'browser.d.ts' , 'browser/**' ] ,
223
252
destDir : 'typings'
224
253
} ) ;
@@ -266,18 +295,18 @@ class Angular2App {
266
295
// element.
267
296
tsconfig . files = tsconfig . files . map ( name => path . join ( this . _sourceDir , name ) ) ;
268
297
269
- var mergedTree = mergeTrees ( [ sourceTree , typingsTree , configTree ] , { overwrite : true } ) ;
270
- var tsTree = new compileWithTypescript ( mergedTree , tsconfig ) ;
298
+ var mergedTree = BroccoliMergeTrees ( [ sourceTree , typingsTree , configTree ] , { overwrite : true } ) ;
299
+ var tsTree = new BroccoliTypescript ( mergedTree , tsconfig ) ;
271
300
272
301
var tsTreeExcludes = [ '*.d.ts' , 'tsconfig.json' ] ;
273
302
var excludeSpecFiles = '**/*.spec.*' ;
274
303
275
304
if ( isProduction ) {
276
305
tsTreeExcludes . push ( excludeSpecFiles ) ;
277
- tsTree = uglify ( tsTree ) ;
306
+ tsTree = BroccoliUglify ( tsTree ) ;
278
307
}
279
308
280
- tsTree = new Funnel ( tsTree , {
309
+ tsTree = new BroccoliFunnel ( tsTree , {
281
310
srcDir : this . _sourceDir ,
282
311
exclude : tsTreeExcludes
283
312
} ) ;
@@ -311,12 +340,10 @@ class Angular2App {
311
340
vendorNpmFiles = vendorNpmFiles . concat ( this . _options . vendorNpmFiles ) ;
312
341
}
313
342
314
- var vendorNpmTree = new Funnel ( 'node_modules' , {
343
+ return new BroccoliFunnel ( 'node_modules' , {
315
344
include : vendorNpmFiles ,
316
345
destDir : 'vendor'
317
346
} ) ;
318
-
319
- return vendorNpmTree ;
320
347
}
321
348
322
349
/**
@@ -327,7 +354,7 @@ class Angular2App {
327
354
* @return {Tree } The assets tree.
328
355
*/
329
356
_getAssetsTree ( ) {
330
- return new Funnel ( this . _sourceDir , {
357
+ return new BroccoliFunnel ( this . _sourceDir , {
331
358
include : [ '**/*.*' ] ,
332
359
exclude : [
333
360
'**/*.ts' ,
@@ -349,7 +376,7 @@ class Angular2App {
349
376
* @return {Tree } The dotfiles exclusion tree.
350
377
*/
351
378
_getPublicTree ( ) {
352
- return new Funnel ( 'public' , {
379
+ return new BroccoliFunnel ( 'public' , {
353
380
exclude : [ '**/.*' ] ,
354
381
allowEmpty : true
355
382
} ) ;
@@ -365,7 +392,7 @@ class Angular2App {
365
392
_getConfigTree ( ) {
366
393
var envConfigFile = isProduction ? 'environment.prod.ts' : 'environment.dev.ts' ;
367
394
// console.log(envConfigFile);
368
- return new Funnel ( 'config' , {
395
+ return new BroccoliFunnel ( 'config' , {
369
396
include : [ envConfigFile ] ,
370
397
destDir : 'src/client/app' ,
371
398
getDestinationPath : ( ) => 'environment.ts'
0 commit comments