Skip to content

Commit c5f1bcc

Browse files
committed
chore: make Angular2App a full broccoli plugin.
`toTree()` is always called and nothing else is ever done anyway.
1 parent 0b69491 commit c5f1bcc

File tree

2 files changed

+58
-32
lines changed

2 files changed

+58
-32
lines changed

addon/ng2/blueprints/ng2/files/angular-cli-build.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
44

55
module.exports = function(defaults) {
6-
var app = new Angular2App(defaults, {
6+
return new Angular2App(defaults, {
77
vendorNpmFiles: []
88
});
9-
return app.toTree();
109
};

lib/broccoli/angular2-app.js

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
'use strict';
2+
const fs = require('fs');
3+
const glob = require('glob');
24
const path = require('path');
5+
36
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');
1114
const Project = require('ember-cli/lib/models/project');
12-
const glob = require('glob');
1315

1416

15-
class Angular2App {
17+
class Angular2App extends BroccoliPlugin {
1618
constructor(defaults, options) {
19+
super();
1720
options = options || {};
1821

1922
this._options = options;
@@ -27,6 +30,32 @@ class Angular2App {
2730

2831
this._initProject();
2932
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();
3059
}
3160

3261
/**
@@ -39,11 +68,11 @@ class Angular2App {
3968
* - Apply/remove stuff based on the environment (dev|prod)
4069
* - Return the app trees to be extended
4170
*
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.
4574
*/
46-
toTree() {
75+
_buildTree() {
4776
var assetTree = this._getAssetsTree();
4877
var tsTree = this._getTsTree();
4978
var indexTree = this._getIndexTree();
@@ -67,8 +96,8 @@ class Angular2App {
6796
this._options.compassCompiler)
6897
).filter(x => !!x);
6998

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])]), {
72101
destDir: this._destDir
73102
});
74103
}
@@ -184,13 +213,13 @@ class Angular2App {
184213
'index.html'
185214
];
186215

187-
var index = new Funnel(this._sourceDir, {
216+
var index = new BroccoliFunnel(this._sourceDir, {
188217
files: files,
189-
description: 'Funnel: index.html'
218+
description: 'BroccoliFunnel: index.html'
190219
});
191220

192221

193-
return configReplace(index, {
222+
return BroccoliConfigReplace(index, {
194223
files: [htmlName],
195224
patterns: this._getReplacePatterns()
196225
});
@@ -204,7 +233,7 @@ class Angular2App {
204233
* @return {Tree} Tree for the src dir.
205234
*/
206235
_getSourceTree() {
207-
return new Funnel(this._sourceDir, {
236+
return new BroccoliFunnel(this._sourceDir, {
208237
include: ['*.ts', '**/*.ts', '**/*.d.ts'],
209238
destDir: this._sourceDir
210239
});
@@ -218,7 +247,7 @@ class Angular2App {
218247
* @return {Tree} Tree for the src dir.
219248
*/
220249
_getTypingsTree() {
221-
return new Funnel('typings', {
250+
return new BroccoliFunnel('typings', {
222251
include: ['browser.d.ts', 'browser/**'],
223252
destDir: 'typings'
224253
});
@@ -266,18 +295,18 @@ class Angular2App {
266295
// element.
267296
tsconfig.files = tsconfig.files.map(name => path.join(this._sourceDir, name));
268297

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);
271300

272301
var tsTreeExcludes = ['*.d.ts', 'tsconfig.json'];
273302
var excludeSpecFiles = '**/*.spec.*';
274303

275304
if (isProduction) {
276305
tsTreeExcludes.push(excludeSpecFiles);
277-
tsTree = uglify(tsTree);
306+
tsTree = BroccoliUglify(tsTree);
278307
}
279308

280-
tsTree = new Funnel(tsTree, {
309+
tsTree = new BroccoliFunnel(tsTree, {
281310
srcDir: this._sourceDir,
282311
exclude: tsTreeExcludes
283312
});
@@ -311,12 +340,10 @@ class Angular2App {
311340
vendorNpmFiles = vendorNpmFiles.concat(this._options.vendorNpmFiles);
312341
}
313342

314-
var vendorNpmTree = new Funnel('node_modules', {
343+
return new BroccoliFunnel('node_modules', {
315344
include: vendorNpmFiles,
316345
destDir: 'vendor'
317346
});
318-
319-
return vendorNpmTree;
320347
}
321348

322349
/**
@@ -327,7 +354,7 @@ class Angular2App {
327354
* @return {Tree} The assets tree.
328355
*/
329356
_getAssetsTree() {
330-
return new Funnel(this._sourceDir, {
357+
return new BroccoliFunnel(this._sourceDir, {
331358
include: ['**/*.*'],
332359
exclude: [
333360
'**/*.ts',
@@ -349,7 +376,7 @@ class Angular2App {
349376
* @return {Tree} The dotfiles exclusion tree.
350377
*/
351378
_getPublicTree() {
352-
return new Funnel('public', {
379+
return new BroccoliFunnel('public', {
353380
exclude: ['**/.*'],
354381
allowEmpty: true
355382
});
@@ -365,7 +392,7 @@ class Angular2App {
365392
_getConfigTree() {
366393
var envConfigFile = isProduction ? 'environment.prod.ts' : 'environment.dev.ts';
367394
// console.log(envConfigFile);
368-
return new Funnel('config', {
395+
return new BroccoliFunnel('config', {
369396
include: [envConfigFile],
370397
destDir: 'src/client/app',
371398
getDestinationPath: () => 'environment.ts'

0 commit comments

Comments
 (0)