Skip to content

Commit 9ec1007

Browse files
committed
chore(config): introduce computed properties
Fix #823
1 parent a26180d commit 9ec1007

File tree

1 file changed

+147
-111
lines changed

1 file changed

+147
-111
lines changed

tools/config/seed.config.ts

Lines changed: 147 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ export class SeedConfig {
115115
* `hot_loader_main.ts` file will be used.
116116
* @type {string}
117117
*/
118-
BOOTSTRAP_MODULE = `${this.BOOTSTRAP_DIR}/` + (this.ENABLE_HOT_LOADING ? 'hot_loader_main' : 'main');
118+
get BOOTSTRAP_MODULE() {
119+
return `${this.BOOTSTRAP_DIR}/` + (this.ENABLE_HOT_LOADING ? 'hot_loader_main' : 'main');
120+
}
119121

120122
/**
121123
* The default title of the application as used in the `<title>` tag of the
@@ -128,19 +130,25 @@ export class SeedConfig {
128130
* The base folder of the applications source files.
129131
* @type {string}
130132
*/
131-
APP_SRC = `src/${this.APP_CLIENT}`;
133+
get APP_SRC() {
134+
return `src/${this.APP_CLIENT}`;
135+
}
132136

133137
/**
134138
* The folder of the applications asset files.
135139
* @type {string}
136140
*/
137-
ASSETS_SRC = `${this.APP_SRC}/assets`;
141+
get ASSETS_SRC() {
142+
return `${this.APP_SRC}/assets`;
143+
}
138144

139145
/**
140146
* The folder of the applications css files.
141147
* @type {string}
142148
*/
143-
CSS_SRC = `${this.APP_SRC}/css`;
149+
get CSS_SRC() {
150+
return `${this.APP_SRC}/css`;
151+
}
144152

145153
/**
146154
* The directory of the applications tools
@@ -151,7 +159,9 @@ export class SeedConfig {
151159
/**
152160
* The directory of the tasks provided by the seed.
153161
*/
154-
SEED_TASKS_DIR = join(process.cwd(), this.TOOLS_DIR, 'tasks', 'seed');
162+
get SEED_TASKS_DIR() {
163+
return join(process.cwd(), this.TOOLS_DIR, 'tasks', 'seed');
164+
}
155165

156166
/**
157167
* The destination folder for the generated documentation.
@@ -169,42 +179,56 @@ export class SeedConfig {
169179
* The folder for built files in the `dev` environment.
170180
* @type {string}
171181
*/
172-
DEV_DEST = `${this.DIST_DIR}/dev`;
182+
get DEV_DEST() {
183+
return `${this.DIST_DIR}/dev`;
184+
}
173185

174186
/**
175187
* The folder for the built files in the `prod` environment.
176188
* @type {string}
177189
*/
178-
PROD_DEST = `${this.DIST_DIR}/prod`;
190+
get PROD_DEST() {
191+
return `${this.DIST_DIR}/prod`;
192+
}
179193

180194
/**
181195
* The folder for temporary files.
182196
* @type {string}
183197
*/
184-
TMP_DIR = `${this.DIST_DIR}/tmp`;
198+
get TMP_DIR() {
199+
return `${this.DIST_DIR}/tmp`;
200+
}
185201

186202
/**
187203
* The folder for the built files, corresponding to the current environment.
188204
* @type {string}
189205
*/
190-
APP_DEST = this.ENV === ENVIRONMENTS.DEVELOPMENT ? this.DEV_DEST : this.PROD_DEST;
206+
get APP_DEST() {
207+
return this.ENV === ENVIRONMENTS.DEVELOPMENT ? this.DEV_DEST : this.PROD_DEST;
208+
}
191209

192210
/**
193211
* The folder for the built CSS files.
194212
* @type {strings}
195213
*/
196-
CSS_DEST = `${this.APP_DEST}/css`;
214+
get CSS_DEST() {
215+
return `${this.APP_DEST}/css`;
216+
}
197217

198218
/**
199219
* The folder for the built JavaScript files.
200220
* @type {string}
201221
*/
202-
JS_DEST = `${this.APP_DEST}/js`;
222+
get JS_DEST() {
223+
return `${this.APP_DEST}/js`;
224+
}
203225

204226
/**
205227
* The version of the application as defined in the `package.json`.
206228
*/
207-
VERSION = appVersion();
229+
get VERSION() {
230+
return appVersion();
231+
}
208232

209233
/**
210234
* The name of the bundle file to includes all CSS files.
@@ -252,21 +276,25 @@ export class SeedConfig {
252276
* The list of NPM dependcies to be injected in the `index.html`.
253277
* @type {InjectableDependency[]}
254278
*/
255-
NPM_DEPENDENCIES: InjectableDependency[] = [
256-
{ src: 'systemjs/dist/system-polyfills.src.js', inject: 'shims', env: ENVIRONMENTS.DEVELOPMENT },
257-
{ src: 'zone.js/dist/zone.js', inject: 'libs' },
258-
{ src: 'core-js/client/shim.min.js', inject: 'shims' },
259-
{ src: 'systemjs/dist/system.src.js', inject: 'shims', env: ENVIRONMENTS.DEVELOPMENT },
260-
{ src: 'rxjs/bundles/Rx.js', inject: 'libs', env: ENVIRONMENTS.DEVELOPMENT }
261-
];
279+
get NPM_DEPENDENCIES(): InjectableDependency[] {
280+
return [
281+
{ src: 'systemjs/dist/system-polyfills.src.js', inject: 'shims', env: ENVIRONMENTS.DEVELOPMENT },
282+
{ src: 'zone.js/dist/zone.js', inject: 'libs' },
283+
{ src: 'core-js/client/shim.min.js', inject: 'shims' },
284+
{ src: 'systemjs/dist/system.src.js', inject: 'shims', env: ENVIRONMENTS.DEVELOPMENT },
285+
{ src: 'rxjs/bundles/Rx.js', inject: 'libs', env: ENVIRONMENTS.DEVELOPMENT }
286+
];
287+
}
262288

263289
/**
264290
* The list of local files to be injected in the `index.html`.
265291
* @type {InjectableDependency[]}
266292
*/
267-
APP_ASSETS: InjectableDependency[] = [
268-
{ src: `${this.CSS_SRC}/main.${ this.getInjectableStyleExtension() }`, inject: true, vendor: false },
269-
];
293+
get APP_ASSETS(): InjectableDependency[] {
294+
return [
295+
{ src: `${this.CSS_SRC}/main.${this.getInjectableStyleExtension()}`, inject: true, vendor: false },
296+
];
297+
}
270298

271299
/**
272300
* The list of editor temporary files to ignore in watcher and asset builder.
@@ -290,86 +318,92 @@ export class SeedConfig {
290318
* The configuration of SystemJS for the `dev` environment.
291319
* @type {any}
292320
*/
293-
protected SYSTEM_CONFIG_DEV: any = {
294-
defaultJSExtensions: true,
295-
packageConfigPaths: [
296-
`${this.APP_BASE}node_modules/*/package.json`,
297-
`${this.APP_BASE}node_modules/**/package.json`,
298-
`${this.APP_BASE}node_modules/@angular/*/package.json`
299-
],
300-
paths: {
301-
[this.BOOTSTRAP_MODULE]: `${this.APP_BASE}${this.BOOTSTRAP_MODULE}`,
302-
'@angular/core': `${this.APP_BASE}node_modules/@angular/core/core.umd.js`,
303-
'@angular/common': `${this.APP_BASE}node_modules/@angular/common/common.umd.js`,
304-
'@angular/compiler': `${this.APP_BASE}node_modules/@angular/compiler/compiler.umd.js`,
305-
'@angular/http': `${this.APP_BASE}node_modules/@angular/http/http.umd.js`,
306-
'@angular/router': `${this.APP_BASE}node_modules/@angular/router/router.umd.js`,
307-
'@angular/platform-browser': `${this.APP_BASE}node_modules/@angular/platform-browser/platform-browser.umd.js`,
308-
'@angular/platform-browser-dynamic': `${this.APP_BASE}node_modules/@angular/platform-browser-dynamic/platform-browser-dynamic.umd.js`,
309-
'rxjs/*': `${this.APP_BASE}node_modules/rxjs/*`,
310-
'app/*': `/app/*`,
311-
'*': `${this.APP_BASE}node_modules/*`
312-
},
313-
packages: {
314-
rxjs: { defaultExtension: false }
315-
}
316-
};
321+
protected get SYSTEM_CONFIG_DEV(): any {
322+
return {
323+
defaultJSExtensions: true,
324+
packageConfigPaths: [
325+
`${this.APP_BASE}node_modules/*/package.json`,
326+
`${this.APP_BASE}node_modules/**/package.json`,
327+
`${this.APP_BASE}node_modules/@angular/*/package.json`
328+
],
329+
paths: {
330+
[this.BOOTSTRAP_MODULE]: `${this.APP_BASE}${this.BOOTSTRAP_MODULE}`,
331+
'@angular/core': `${this.APP_BASE}node_modules/@angular/core/core.umd.js`,
332+
'@angular/common': `${this.APP_BASE}node_modules/@angular/common/common.umd.js`,
333+
'@angular/compiler': `${this.APP_BASE}node_modules/@angular/compiler/compiler.umd.js`,
334+
'@angular/http': `${this.APP_BASE}node_modules/@angular/http/http.umd.js`,
335+
'@angular/router': `${this.APP_BASE}node_modules/@angular/router/router.umd.js`,
336+
'@angular/platform-browser': `${this.APP_BASE}node_modules/@angular/platform-browser/platform-browser.umd.js`,
337+
'@angular/platform-browser-dynamic': `${this.APP_BASE}node_modules/@angular/platform-browser-dynamic/platform-browser-dynamic.umd.js`,
338+
'rxjs/*': `${this.APP_BASE}node_modules/rxjs/*`,
339+
'app/*': `/app/*`,
340+
'*': `${this.APP_BASE}node_modules/*`
341+
},
342+
packages: {
343+
rxjs: { defaultExtension: false }
344+
}
345+
};
346+
}
317347

318348
/**
319349
* The configuration of SystemJS of the application.
320350
* Per default, the configuration of the `dev` environment will be used.
321351
* @type {any}
322352
*/
323-
SYSTEM_CONFIG: any = this.SYSTEM_CONFIG_DEV;
353+
get SYSTEM_CONFIG(): any {
354+
return this.SYSTEM_CONFIG_DEV;
355+
}
324356

325357
/**
326358
* The system builder configuration of the application.
327359
* @type {any}
328360
*/
329-
SYSTEM_BUILDER_CONFIG: any = {
330-
defaultJSExtensions: true,
331-
packageConfigPaths: [
332-
join(this.PROJECT_ROOT, 'node_modules', '*', 'package.json'),
333-
join(this.PROJECT_ROOT, 'node_modules', '@angular', '*', 'package.json')
334-
],
335-
paths: {
336-
[`${this.TMP_DIR}/*`]: `${this.TMP_DIR}/*`,
337-
'*': 'node_modules/*'
338-
},
339-
packages: {
340-
'@angular/core': {
341-
main: 'index.js',
342-
defaultExtension: 'js'
343-
},
344-
'@angular/compiler': {
345-
main: 'index.js',
346-
defaultExtension: 'js'
347-
},
348-
'@angular/common': {
349-
main: 'index.js',
350-
defaultExtension: 'js'
351-
},
352-
'@angular/http': {
353-
main: 'index.js',
354-
defaultExtension: 'js'
361+
get SYSTEM_BUILDER_CONFIG(): any {
362+
return {
363+
defaultJSExtensions: true,
364+
packageConfigPaths: [
365+
join(this.PROJECT_ROOT, 'node_modules', '*', 'package.json'),
366+
join(this.PROJECT_ROOT, 'node_modules', '@angular', '*', 'package.json')
367+
],
368+
paths: {
369+
[`${this.TMP_DIR}/*`]: `${this.TMP_DIR}/*`,
370+
'*': 'node_modules/*'
355371
},
356-
'@angular/platform-browser': {
357-
main: 'index.js',
358-
defaultExtension: 'js'
359-
},
360-
'@angular/platform-browser-dynamic': {
361-
main: 'index.js',
362-
defaultExtension: 'js'
363-
},
364-
'@angular/router': {
365-
main: 'index.js',
366-
defaultExtension: 'js'
367-
},
368-
'rxjs': {
369-
defaultExtension: 'js'
372+
packages: {
373+
'@angular/core': {
374+
main: 'index.js',
375+
defaultExtension: 'js'
376+
},
377+
'@angular/compiler': {
378+
main: 'index.js',
379+
defaultExtension: 'js'
380+
},
381+
'@angular/common': {
382+
main: 'index.js',
383+
defaultExtension: 'js'
384+
},
385+
'@angular/http': {
386+
main: 'index.js',
387+
defaultExtension: 'js'
388+
},
389+
'@angular/platform-browser': {
390+
main: 'index.js',
391+
defaultExtension: 'js'
392+
},
393+
'@angular/platform-browser-dynamic': {
394+
main: 'index.js',
395+
defaultExtension: 'js'
396+
},
397+
'@angular/router': {
398+
main: 'index.js',
399+
defaultExtension: 'js'
400+
},
401+
'rxjs': {
402+
defaultExtension: 'js'
403+
}
370404
}
371-
}
372-
};
405+
};
406+
}
373407

374408
/**
375409
* The Autoprefixer configuration for the application.
@@ -391,30 +425,32 @@ export class SeedConfig {
391425
* Configurations for NPM module configurations. Add to or override in project.config.ts.
392426
* If you like, use the mergeObject() method to assist with this.
393427
*/
394-
PLUGIN_CONFIGS: any = {
395-
/**
396-
* The BrowserSync configuration of the application.
397-
* The default open behavior is to open the browser. To prevent the browser from opening use the `--b` flag when
398-
* running `npm start` (tested with serve.dev).
399-
* Example: `npm start -- --b`
400-
* @type {any}
401-
*/
402-
'browser-sync': {
403-
middleware: [require('connect-history-api-fallback')({ index: `${this.APP_BASE}index.html` })],
404-
port: this.PORT,
405-
startPath: this.APP_BASE,
406-
open: argv['b'] ? false : true,
407-
injectChanges: false,
408-
server: {
409-
baseDir: `${this.DIST_DIR}/empty/`,
410-
routes: {
411-
[`${this.APP_BASE}${this.APP_DEST}`]: this.APP_DEST,
412-
[`${this.APP_BASE}node_modules`]: 'node_modules',
413-
[`${this.APP_BASE.replace(/\/$/, '')}`]: this.APP_DEST
428+
get PLUGIN_CONFIGS(): any {
429+
return {
430+
/**
431+
* The BrowserSync configuration of the application.
432+
* The default open behavior is to open the browser. To prevent the browser from opening use the `--b` flag when
433+
* running `npm start` (tested with serve.dev).
434+
* Example: `npm start -- --b`
435+
* @type {any}
436+
*/
437+
'browser-sync': {
438+
middleware: [require('connect-history-api-fallback')({ index: `${this.APP_BASE}index.html` })],
439+
port: this.PORT,
440+
startPath: this.APP_BASE,
441+
open: argv['b'] ? false : true,
442+
injectChanges: false,
443+
server: {
444+
baseDir: `${this.DIST_DIR}/empty/`,
445+
routes: {
446+
[`${this.APP_BASE}${this.APP_DEST}`]: this.APP_DEST,
447+
[`${this.APP_BASE}node_modules`]: 'node_modules',
448+
[`${this.APP_BASE.replace(/\/$/, '')}`]: this.APP_DEST
449+
}
414450
}
415451
}
416-
}
417-
};
452+
};
453+
}
418454

419455
/**
420456
* Recursively merge source onto target.

0 commit comments

Comments
 (0)