11import { readFileSync } from 'fs' ;
22import { argv } from 'yargs' ;
33import { normalize , join } from 'path' ;
4- import { InjectableDependency } from './seed.config.interface ' ;
4+ import { InjectableDependency , Environments } from './seed.config.interfaces ' ;
55
6- const ENVIRONMENTS = {
6+ export const ENVIRONMENTS : Environments = {
77 DEVELOPMENT : 'dev' ,
88 PRODUCTION : 'prod'
99} ;
@@ -50,37 +50,67 @@ export class SeedConfig {
5050
5151 NG2LINT_RULES = customRules ( ) ;
5252
53-
54- // Declare NPM dependencies (Note that globs should not be injected).
55- DEV_NPM_DEPENDENCIES : InjectableDependency [ ] = normalizeDependencies ( [
53+ NPM_DEPENDENCIES : InjectableDependency [ ] = [
5654 { src : 'systemjs/dist/system-polyfills.src.js' , inject : 'shims' } ,
5755 { src : 'reflect-metadata/Reflect.js' , inject : 'shims' } ,
5856 { src : 'es6-shim/es6-shim.js' , inject : 'shims' } ,
5957 { src : 'systemjs/dist/system.src.js' , inject : 'shims' } ,
6058 { src : 'angular2/bundles/angular2-polyfills.js' , inject : 'shims' } ,
61- { src : 'rxjs/bundles/Rx.js' , inject : 'libs' } ,
62- { src : 'angular2/bundles/angular2.js' , inject : 'libs' } ,
63- { src : 'angular2/bundles/router.js' , inject : 'libs' } ,
64- { src : 'angular2/bundles/http.js' , inject : 'libs' }
65- ] ) ;
66-
67- PROD_NPM_DEPENDENCIES : InjectableDependency [ ] = normalizeDependencies ( [
68- { src : 'systemjs/dist/system-polyfills.src.js' , inject : 'shims' } ,
69- { src : 'reflect-metadata/Reflect.js' , inject : 'shims' } ,
70- { src : 'es6-shim/es6-shim.min.js' , inject : 'shims' } ,
71- { src : 'systemjs/dist/system.js' , inject : 'shims' } ,
72- { src : 'angular2/bundles/angular2-polyfills.min.js' , inject : 'libs' }
73- ] ) ;
59+ { src : 'rxjs/bundles/Rx.js' , inject : 'libs' , env : ENVIRONMENTS . DEVELOPMENT } ,
60+ { src : 'angular2/bundles/angular2.js' , inject : 'libs' , env : ENVIRONMENTS . DEVELOPMENT } ,
61+ { src : 'angular2/bundles/router.js' , inject : 'libs' , env : ENVIRONMENTS . DEVELOPMENT } ,
62+ { src : 'angular2/bundles/http.js' , inject : 'libs' , env : ENVIRONMENTS . DEVELOPMENT }
63+ ] ;
7464
7565 // Declare local files that needs to be injected
7666 APP_ASSETS : InjectableDependency [ ] = [
7767 { src : `${ this . ASSETS_SRC } /main.css` , inject : true , vendor : false }
7868 ] ;
7969
8070
81- DEV_DEPENDENCIES = this . DEV_NPM_DEPENDENCIES . concat ( this . APP_ASSETS ) ;
82- PROD_DEPENDENCIES = this . PROD_NPM_DEPENDENCIES . concat ( this . APP_ASSETS ) ;
71+ get PROD_DEPENDENCIES ( ) : InjectableDependency [ ] {
72+ console . warn ( 'The property "PROD_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.' ) ;
73+ return normalizeDependencies ( this . NPM_DEPENDENCIES . filter ( filterDependency . bind ( null , ENVIRONMENTS . PRODUCTION ) ) )
74+ . concat ( this . APP_ASSETS . filter ( filterDependency . bind ( null , ENVIRONMENTS . PRODUCTION ) ) ) ;
75+ }
76+
77+ get DEV_DEPENDENCIES ( ) : InjectableDependency [ ] {
78+ console . warn ( 'The property "DEV_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.' ) ;
79+ return normalizeDependencies ( this . NPM_DEPENDENCIES . filter ( filterDependency . bind ( null , ENVIRONMENTS . DEVELOPMENT ) ) )
80+ . concat ( this . APP_ASSETS . filter ( filterDependency . bind ( null , ENVIRONMENTS . DEVELOPMENT ) ) ) ;
81+ }
82+
83+ set DEV_DEPENDENCIES ( val : InjectableDependency [ ] ) {
84+ console . warn ( 'The property "DEV_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.' ) ;
85+ }
86+
87+ set PROD_DEPENDENCIES ( val : InjectableDependency [ ] ) {
88+ console . warn ( 'The property "PROD_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.' ) ;
89+ }
90+
91+ get DEV_NPM_DEPENDENCIES ( ) : InjectableDependency [ ] {
92+ console . warn ( 'The property "DEV_NPM_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.' ) ;
93+ return normalizeDependencies ( this . NPM_DEPENDENCIES . filter ( filterDependency . bind ( null , ENVIRONMENTS . DEVELOPMENT ) ) ) ;
94+ }
95+ get PROD_NPM_DEPENDENCIES ( ) : InjectableDependency [ ] {
96+ console . warn ( 'The property "PROD_NPM_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.' ) ;
97+ return normalizeDependencies ( this . NPM_DEPENDENCIES . filter ( filterDependency . bind ( null , ENVIRONMENTS . PRODUCTION ) ) ) ;
98+ }
99+ set DEV_NPM_DEPENDENCIES ( value : InjectableDependency [ ] ) {
100+ console . warn ( 'The property "DEV_NPM_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.' ) ;
101+ const notDev = this . NPM_DEPENDENCIES . filter ( d => ! filterDependency ( ENVIRONMENTS . DEVELOPMENT , d ) ) ;
102+ this . NPM_DEPENDENCIES = notDev . concat ( value ) ;
103+ }
104+ set PROD_NPM_DEPENDENCIES ( value : InjectableDependency [ ] ) {
105+ console . warn ( 'The property "PROD_NPM_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.' ) ;
106+ const notProd = this . NPM_DEPENDENCIES . filter ( d => ! filterDependency ( ENVIRONMENTS . PRODUCTION , d ) ) ;
107+ this . NPM_DEPENDENCIES = notProd . concat ( value ) ;
108+ }
83109
110+ get DEPENDENCIES ( ) : InjectableDependency [ ] {
111+ return normalizeDependencies ( this . NPM_DEPENDENCIES . filter ( filterDependency . bind ( null , this . ENV ) ) )
112+ . concat ( this . APP_ASSETS . filter ( filterDependency . bind ( null , this . ENV ) ) ) ;
113+ }
84114
85115 // ----------------
86116 // SystemsJS Configuration.
@@ -123,6 +153,7 @@ export class SeedConfig {
123153 'bb >= 10'
124154 ] ;
125155 getEnvDependencies ( ) {
156+ console . warn ( 'The "getEnvDependencies" method is deprecated. Consider using "DEPENDENCIES" instead.' ) ;
126157 if ( this . ENV === 'prod' ) {
127158 return this . PROD_DEPENDENCIES ;
128159 } else {
@@ -137,6 +168,16 @@ export class SeedConfig {
137168// --------------
138169// Utils.
139170
171+ function filterDependency ( env : string , d : InjectableDependency ) : boolean {
172+ if ( ! d . env ) {
173+ d . env = Object . keys ( ENVIRONMENTS ) . map ( k => ENVIRONMENTS [ k ] ) ;
174+ }
175+ if ( ! ( d . env instanceof Array ) ) {
176+ ( < any > d ) . env = [ d . env ] ;
177+ }
178+ return d . env . indexOf ( env ) >= 0 ;
179+ }
180+
140181export function normalizeDependencies ( deps : InjectableDependency [ ] ) {
141182 deps
142183 . filter ( ( d :InjectableDependency ) => ! / \* / . test ( d . src ) ) // Skip globs
0 commit comments