22const path = require ( 'path' ) ;
33const fs = require ( 'fs' ) ;
44
5- const isProduction = require ( './is-production' ) ;
65const BroccoliPlugin = require ( 'broccoli-writer' ) ;
7- const BroccoliConfigReplace = require ( './broccoli-config-replace' ) ;
86const BroccoliTypescript = require ( './broccoli-typescript' ) ;
97const BundlePlugin = require ( './angular-broccoli-bundle' ) ;
108const BroccoliFunnel = require ( 'broccoli-funnel' ) ;
119const BroccoliMergeTrees = require ( 'broccoli-merge-trees' ) ;
1210const BroccoliSource = require ( 'broccoli-source' ) ;
1311const UnwatchedDir = BroccoliSource . UnwatchedDir ;
1412const Project = require ( 'ember-cli/lib/models/project' ) ;
13+ const HandlebarReplace = require ( './broccoli-handlebars' ) ;
1514const config = require ( '../../addon/ng2/models/config' ) ;
15+ const loadEnvironment = require ( './environment' ) ;
1616
1717class Angular2App extends BroccoliPlugin {
1818 constructor ( project , inputNode , options ) {
19- const ngConfig = config . CliConfig . fromProject ( ) ;
19+ super ( ) ;
20+ this . ngConfig = config . CliConfig . fromProject ( ) ;
2021
2122 if ( ! options ) {
2223 options = inputNode ;
2324 inputNode = null ;
2425 }
2526
26- super ( ) ;
2727 options = options || { } ;
2828
2929 this . _options = options ;
3030 this . _sourceDir = options . sourceDir
31- || ( ngConfig . defaults && ngConfig . defaults . sourceDir )
31+ || ( this . ngConfig . defaults && this . ngConfig . defaults . sourceDir )
3232 || 'src' ;
33- this . _inputNode = inputNode || this . _buildInputTree ( ) ;
3433 this . _destDir = options . destDir || '' ;
3534
3635 // By default, add all spec files to the tsCompiler.
@@ -40,6 +39,7 @@ class Angular2App extends BroccoliPlugin {
4039
4140 this . _initProject ( ) ;
4241 this . _notifyAddonIncluded ( ) ;
42+ this . _inputNode = inputNode || this . _buildInputTree ( ) ;
4343
4444 this . _tree = this . _buildTree ( ) ;
4545 }
@@ -135,7 +135,7 @@ class Angular2App extends BroccoliPlugin {
135135
136136 var merged = new BroccoliMergeTrees ( buildTrees , { overwrite : true } ) ;
137137
138- if ( isProduction ) {
138+ if ( loadEnvironment ( this . project ) . production ) {
139139 merged = this . _getBundleTree ( merged ) ;
140140 }
141141
@@ -216,7 +216,6 @@ class Angular2App extends BroccoliPlugin {
216216 case 'config-module': this._contentForConfigModule(content, config); break;
217217 case 'app-boot': this._contentForAppBoot(content, config); break;
218218 }*/
219-
220219 content = this . project . addons . reduce ( function ( content , addon ) {
221220 var addonContent = addon . contentFor ? addon . contentFor ( type ) : null ;
222221 if ( addonContent ) {
@@ -226,22 +225,9 @@ class Angular2App extends BroccoliPlugin {
226225 return content ;
227226 } , content ) ;
228227
229-
230228 return content . join ( '\n' ) ;
231229 }
232230
233- /**
234- * @private
235- * @method _getReplacePatterns
236- * @return Array<Pattern> Replace patterns.
237- */
238- _getReplacePatterns ( ) {
239- return [ {
240- match : / \{ \{ c o n t e n t - f o r [ ' " ] ( .+ ) [ " ' ] \} \} / g,
241- replacement : isProduction ? '' : this . _contentFor . bind ( this )
242- } ] ;
243- }
244-
245231 /**
246232 * Returns the tree for app/index.html.
247233 *
@@ -264,9 +250,26 @@ class Angular2App extends BroccoliPlugin {
264250 }
265251 } ) ;
266252
267- return BroccoliConfigReplace ( indexTree , {
268- files : files ,
269- patterns : this . _getReplacePatterns ( )
253+ return new HandlebarReplace ( indexTree , {
254+ config : this . ngConfig ,
255+ environment : loadEnvironment ( this . project ) ,
256+ scripts : {
257+ polyfills : this . _options . polyfills || [
258+ 'vendor/es6-shim/es6-shim.js' ,
259+ 'vendor/reflect-metadata/Reflect.js' ,
260+ 'vendor/systemjs/dist/system.src.js' ,
261+ 'vendor/zone.js/dist/zone.js'
262+ ]
263+ }
264+ } , {
265+ helpers : {
266+ 'content-for' : ( name ) => {
267+ // TODO: remove content-for.
268+ // eslint-disable-next-line no-console
269+ console . warn ( '"{{content-for}}" has been deprecated and will be removed before RC.' ) ;
270+ return this . _contentFor ( null , name ) ;
271+ }
272+ }
270273 } ) ;
271274 }
272275
@@ -284,7 +287,7 @@ class Angular2App extends BroccoliPlugin {
284287 var tsTreeExcludes = [ '*.d.ts' , 'tsconfig.json' ] ;
285288 var excludeSpecFiles = '**/*.spec.*' ;
286289
287- if ( isProduction ) {
290+ if ( loadEnvironment ( this . project ) . production ) {
288291 tsTreeExcludes . push ( excludeSpecFiles ) ;
289292 }
290293
@@ -350,6 +353,7 @@ class Angular2App extends BroccoliPlugin {
350353 * @return {Tree } The config files tree.
351354 */
352355 _getConfigTree ( ) {
356+ const isProduction = loadEnvironment ( this . project ) . production ;
353357 var envConfigFile = isProduction ? 'environment.prod.ts' : 'environment.dev.ts' ;
354358
355359 return new BroccoliFunnel ( 'config' , {
0 commit comments