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 , Environments } from './seed.config.interfaces ' ;
5
5
6
- const ENVIRONMENTS = {
6
+ export const ENVIRONMENTS : Environments = {
7
7
DEVELOPMENT : 'dev' ,
8
8
PRODUCTION : 'prod'
9
9
} ;
@@ -50,37 +50,67 @@ export class SeedConfig {
50
50
51
51
NG2LINT_RULES = customRules ( ) ;
52
52
53
-
54
- // Declare NPM dependencies (Note that globs should not be injected).
55
- DEV_NPM_DEPENDENCIES : InjectableDependency [ ] = normalizeDependencies ( [
53
+ NPM_DEPENDENCIES : InjectableDependency [ ] = [
56
54
{ src : 'systemjs/dist/system-polyfills.src.js' , inject : 'shims' } ,
57
55
{ src : 'reflect-metadata/Reflect.js' , inject : 'shims' } ,
58
56
{ src : 'es6-shim/es6-shim.js' , inject : 'shims' } ,
59
57
{ src : 'systemjs/dist/system.src.js' , inject : 'shims' } ,
60
58
{ 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
+ ] ;
74
64
75
65
// Declare local files that needs to be injected
76
66
APP_ASSETS : InjectableDependency [ ] = [
77
67
{ src : `${ this . ASSETS_SRC } /main.css` , inject : true , vendor : false }
78
68
] ;
79
69
80
70
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
+ }
83
109
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
+ }
84
114
85
115
// ----------------
86
116
// SystemsJS Configuration.
@@ -123,6 +153,7 @@ export class SeedConfig {
123
153
'bb >= 10'
124
154
] ;
125
155
getEnvDependencies ( ) {
156
+ console . warn ( 'The "getEnvDependencies" method is deprecated. Consider using "DEPENDENCIES" instead.' ) ;
126
157
if ( this . ENV === 'prod' ) {
127
158
return this . PROD_DEPENDENCIES ;
128
159
} else {
@@ -137,6 +168,16 @@ export class SeedConfig {
137
168
// --------------
138
169
// Utils.
139
170
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
+
140
181
export function normalizeDependencies ( deps : InjectableDependency [ ] ) {
141
182
deps
142
183
. filter ( ( d :InjectableDependency ) => ! / \* / . test ( d . src ) ) // Skip globs
0 commit comments