Skip to content

Commit 9010ffd

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

File tree

2 files changed

+60
-33
lines changed

2 files changed

+60
-33
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: 59 additions & 31 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,33 @@ 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+
// 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();
3060
}
3161

3262
/**
@@ -39,11 +69,11 @@ class Angular2App {
3969
* - Apply/remove stuff based on the environment (dev|prod)
4070
* - Return the app trees to be extended
4171
*
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.
4575
*/
46-
toTree() {
76+
_buildTree() {
4777
var assetTree = this._getAssetsTree();
4878
var tsTree = this._getTsTree();
4979
var indexTree = this._getIndexTree();
@@ -67,8 +97,8 @@ class Angular2App {
6797
this._options.compassCompiler)
6898
).filter(x => !!x);
6999

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])]), {
72102
destDir: this._destDir
73103
});
74104
}
@@ -184,13 +214,13 @@ class Angular2App {
184214
'index.html'
185215
];
186216

187-
var index = new Funnel(this._sourceDir, {
217+
var index = new BroccoliFunnel(this._sourceDir, {
188218
files: files,
189-
description: 'Funnel: index.html'
219+
description: 'BroccoliFunnel: index.html'
190220
});
191221

192222

193-
return configReplace(index, {
223+
return BroccoliConfigReplace(index, {
194224
files: [htmlName],
195225
patterns: this._getReplacePatterns()
196226
});
@@ -204,7 +234,7 @@ class Angular2App {
204234
* @return {Tree} Tree for the src dir.
205235
*/
206236
_getSourceTree() {
207-
return new Funnel(this._sourceDir, {
237+
return new BroccoliFunnel(this._sourceDir, {
208238
include: ['*.ts', '**/*.ts', '**/*.d.ts'],
209239
destDir: this._sourceDir
210240
});
@@ -218,7 +248,7 @@ class Angular2App {
218248
* @return {Tree} Tree for the src dir.
219249
*/
220250
_getTypingsTree() {
221-
return new Funnel('typings', {
251+
return new BroccoliFunnel('typings', {
222252
include: ['browser.d.ts', 'browser/**'],
223253
destDir: 'typings'
224254
});
@@ -266,18 +296,18 @@ class Angular2App {
266296
// element.
267297
tsconfig.files = tsconfig.files.map(name => path.join(this._sourceDir, name));
268298

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

272302
var tsTreeExcludes = ['*.d.ts', 'tsconfig.json'];
273303
var excludeSpecFiles = '**/*.spec.*';
274304

275305
if (isProduction) {
276306
tsTreeExcludes.push(excludeSpecFiles);
277-
tsTree = uglify(tsTree);
307+
tsTree = BroccoliUglify(tsTree);
278308
}
279309

280-
tsTree = new Funnel(tsTree, {
310+
tsTree = new BroccoliFunnel(tsTree, {
281311
srcDir: this._sourceDir,
282312
exclude: tsTreeExcludes
283313
});
@@ -311,12 +341,10 @@ class Angular2App {
311341
vendorNpmFiles = vendorNpmFiles.concat(this._options.vendorNpmFiles);
312342
}
313343

314-
var vendorNpmTree = new Funnel('node_modules', {
344+
return new BroccoliFunnel('node_modules', {
315345
include: vendorNpmFiles,
316346
destDir: 'vendor'
317347
});
318-
319-
return vendorNpmTree;
320348
}
321349

322350
/**
@@ -327,7 +355,7 @@ class Angular2App {
327355
* @return {Tree} The assets tree.
328356
*/
329357
_getAssetsTree() {
330-
return new Funnel(this._sourceDir, {
358+
return new BroccoliFunnel(this._sourceDir, {
331359
include: ['**/*.*'],
332360
exclude: [
333361
'**/*.ts',
@@ -349,7 +377,7 @@ class Angular2App {
349377
* @return {Tree} The dotfiles exclusion tree.
350378
*/
351379
_getPublicTree() {
352-
return new Funnel('public', {
380+
return new BroccoliFunnel('public', {
353381
exclude: ['**/.*'],
354382
allowEmpty: true
355383
});
@@ -364,8 +392,8 @@ class Angular2App {
364392
*/
365393
_getConfigTree() {
366394
var envConfigFile = isProduction ? 'environment.prod.ts' : 'environment.dev.ts';
367-
// console.log(envConfigFile);
368-
return new Funnel('config', {
395+
396+
return new BroccoliFunnel('config', {
369397
include: [envConfigFile],
370398
destDir: 'src/client/app',
371399
getDestinationPath: () => 'environment.ts'

0 commit comments

Comments
 (0)