1
1
import { readFileSync } from 'fs' ;
2
2
import { argv } from 'yargs' ;
3
3
import { normalize , join } from 'path' ;
4
- import { InjectableDependency } from './seed.config.interface ' ;
4
+ import { InjectableDependency } from './seed.config.interfaces ' ;
5
5
6
- const ENVIRONMENTS = {
6
+ interface Environments {
7
+ DEVELOPMENT : string ;
8
+ PRODUCTION : string ;
9
+ [ key : string ] : string ;
10
+ }
11
+
12
+ const ENVIRONMENTS : Environments = {
7
13
DEVELOPMENT : 'dev' ,
8
14
PRODUCTION : 'prod'
9
15
} ;
@@ -50,26 +56,16 @@ export class SeedConfig {
50
56
51
57
NG2LINT_RULES = customRules ( ) ;
52
58
53
-
54
- // Declare NPM dependencies (Note that globs should not be injected).
55
- DEV_NPM_DEPENDENCIES : InjectableDependency [ ] = normalizeDependencies ( [
59
+ NPM_DEPENDENCIES : InjectableDependency [ ] = normalizeDependencies ( [
56
60
{ src : 'systemjs/dist/system-polyfills.src.js' , inject : 'shims' } ,
57
61
{ src : 'reflect-metadata/Reflect.js' , inject : 'shims' } ,
58
62
{ src : 'es6-shim/es6-shim.js' , inject : 'shims' } ,
59
63
{ src : 'systemjs/dist/system.src.js' , inject : 'shims' } ,
60
64
{ 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' }
65
+ { src : 'rxjs/bundles/Rx.js' , inject : 'libs' , env : ENVIRONMENTS . DEVELOPMENT } ,
66
+ { src : 'angular2/bundles/angular2.js' , inject : 'libs' , env : ENVIRONMENTS . DEVELOPMENT } ,
67
+ { src : 'angular2/bundles/router.js' , inject : 'libs' , env : ENVIRONMENTS . DEVELOPMENT } ,
68
+ { src : 'angular2/bundles/http.js' , inject : 'libs' , env : ENVIRONMENTS . DEVELOPMENT }
73
69
] ) ;
74
70
75
71
// Declare local files that needs to be injected
@@ -78,9 +74,33 @@ export class SeedConfig {
78
74
] ;
79
75
80
76
81
- DEV_DEPENDENCIES = this . DEV_NPM_DEPENDENCIES . concat ( this . APP_ASSETS ) ;
82
- PROD_DEPENDENCIES = this . PROD_NPM_DEPENDENCIES . concat ( this . APP_ASSETS ) ;
77
+ get PROD_DEPENDENCIES ( ) : InjectableDependency [ ] {
78
+ console . warn ( 'The property "PROD_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.' ) ;
79
+ return normalizeDependencies ( this . NPM_DEPENDENCIES . filter ( filterDependency . bind ( null , ENVIRONMENTS . PRODUCTION ) ) )
80
+ . concat ( this . APP_ASSETS . filter ( filterDependency . bind ( null , ENVIRONMENTS . PRODUCTION ) ) ) ;
81
+ }
82
+
83
+ get DEV_DEPENDENCIES ( ) : InjectableDependency [ ] {
84
+ console . warn ( 'The property "DEV_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.' ) ;
85
+ return normalizeDependencies ( this . NPM_DEPENDENCIES . filter ( filterDependency . bind ( null , ENVIRONMENTS . DEVELOPMENT ) ) )
86
+ . concat ( this . APP_ASSETS . filter ( filterDependency . bind ( null , ENVIRONMENTS . DEVELOPMENT ) ) ) ;
87
+ }
88
+
89
+ set DEV_DEPENDENCIES ( val : InjectableDependency [ ] ) {
90
+ console . warn ( 'The property "DEV_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.' ) ;
91
+ }
92
+
93
+ set PROD_DEPENDENCIES ( val : InjectableDependency [ ] ) {
94
+ console . warn ( 'The property "PROD_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.' ) ;
95
+ }
96
+
97
+ DEV_NPM_DEPENDENCIES : InjectableDependency [ ] = null ;
98
+ PROD_NPM_DEPENDENCIES : InjectableDependency [ ] = null ;
83
99
100
+ get DEPENDENCIES ( ) : InjectableDependency [ ] {
101
+ return normalizeDependencies ( this . NPM_DEPENDENCIES . filter ( filterDependency . bind ( null , this . ENV ) ) )
102
+ . concat ( this . APP_ASSETS . filter ( filterDependency . bind ( null , this . ENV ) ) ) ;
103
+ }
84
104
85
105
// ----------------
86
106
// SystemsJS Configuration.
@@ -137,6 +157,16 @@ export class SeedConfig {
137
157
// --------------
138
158
// Utils.
139
159
160
+ function filterDependency ( env : string , d : InjectableDependency ) : boolean {
161
+ if ( ! d . env ) {
162
+ d . env = Object . keys ( ENVIRONMENTS ) . map ( k => ENVIRONMENTS [ k ] ) ;
163
+ }
164
+ if ( ! ( d . env instanceof Array ) ) {
165
+ ( < any > d ) . env = [ d . env ] ;
166
+ }
167
+ return d . env . indexOf ( env ) >= 0 ;
168
+ }
169
+
140
170
export function normalizeDependencies ( deps : InjectableDependency [ ] ) {
141
171
deps
142
172
. filter ( ( d :InjectableDependency ) => ! / \* / . test ( d . src ) ) // Skip globs
0 commit comments