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