Skip to content

Commit c4aeb80

Browse files
committed
Merge pull request #644 from mgechev/simplify-config
chore: simplify config, deprecates npm_deps
2 parents 387c260 + 3b20c26 commit c4aeb80

7 files changed

+86
-38
lines changed

tools/config/project.config.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
import {join} from 'path';
2-
import {SeedConfig, normalizeDependencies} from './seed.config';
2+
import {SeedConfig} from './seed.config';
3+
import {InjectableDependency} from './seed.config.interfaces';
34

45
export class ProjectConfig extends SeedConfig {
56
PROJECT_TASKS_DIR = join(process.cwd(), this.TOOLS_DIR, 'tasks', 'project');
67

78
constructor() {
89
super();
910
// this.APP_TITLE = 'Put name of your app here';
10-
let additional_deps: Array<any> = [
11+
let additional_deps: InjectableDependency[] = [
1112
// {src: 'jquery/dist/jquery.min.js', inject: 'libs'},
1213
// {src: 'lodash/lodash.min.js', inject: 'libs'},
1314
];
1415

15-
this.DEV_NPM_DEPENDENCIES = this.DEV_DEPENDENCIES.concat(normalizeDependencies(additional_deps));
16-
this.PROD_NPM_DEPENDENCIES = this.PROD_NPM_DEPENDENCIES.concat(normalizeDependencies(additional_deps));
16+
const seedDependencies = this.NPM_DEPENDENCIES;
17+
18+
this.NPM_DEPENDENCIES = seedDependencies.concat(additional_deps);
1719

1820
this.APP_ASSETS = [
1921
// {src: `${this.ASSETS_SRC}/css/toastr.min.css`, inject: true},
2022
// {src: `${this.APP_DEST}/assets/scss/global.css`, inject: true},
2123
{ src: `${this.ASSETS_SRC}/main.css`, inject: true },
2224
];
23-
24-
this.DEV_DEPENDENCIES = this.DEV_NPM_DEPENDENCIES.concat(this.APP_ASSETS);
25-
this.PROD_DEPENDENCIES = this.PROD_NPM_DEPENDENCIES.concat(this.APP_ASSETS);
2625
}
2726
}

tools/config/seed.config.interface.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export interface InjectableDependency {
2+
src: string;
3+
inject: string | boolean;
4+
vendor?: boolean;
5+
env?: string[] | string;
6+
}
7+
8+
export interface Environments {
9+
DEVELOPMENT: string;
10+
PRODUCTION: string;
11+
[key: string]: string;
12+
}
13+

tools/config/seed.config.ts

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {readFileSync} from 'fs';
22
import {argv} from 'yargs';
33
import {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+
140181
export function normalizeDependencies(deps: InjectableDependency[]) {
141182
deps
142183
.filter((d:InjectableDependency) => !/\*/.test(d.src)) // Skip globs

tools/tasks/seed/build.bundles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as gulp from 'gulp';
22
import * as gulpLoadPlugins from 'gulp-load-plugins';
33
import * as merge from 'merge-stream';
4-
import {PROD_DEPENDENCIES, JS_PROD_SHIMS_BUNDLE, JS_DEST} from '../../config';
4+
import {DEPENDENCIES, JS_PROD_SHIMS_BUNDLE, JS_DEST} from '../../config';
55
const plugins = <any>gulpLoadPlugins();
66

77
export = () => merge(bundleShims());
88

99
function getShims() {
10-
let libs = PROD_DEPENDENCIES
10+
let libs = DEPENDENCIES
1111
.filter(d => /\.js$/.test(d.src));
1212

1313
return libs.filter(l => l.inject === 'shims')

tools/tasks/seed/build.html_css.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as merge from 'merge-stream';
44
import * as autoprefixer from 'autoprefixer';
55
import * as cssnano from 'cssnano';
66
import {join} from 'path';
7-
import {APP_SRC, TMP_DIR, CSS_PROD_BUNDLE, CSS_DEST, APP_DEST, BROWSER_LIST, ENV, getEnvDependencies} from '../../config';
7+
import {APP_SRC, TMP_DIR, CSS_PROD_BUNDLE, CSS_DEST, APP_DEST, BROWSER_LIST, ENV, DEPENDENCIES} from '../../config';
88
const plugins = <any>gulpLoadPlugins();
99

1010
const processors = [
@@ -47,7 +47,7 @@ function processExternalCss() {
4747
}
4848

4949
function getExternalCss() {
50-
return getEnvDependencies().filter(d => /\.css$/.test(d.src));
50+
return DEPENDENCIES.filter(d => /\.css$/.test(d.src));
5151
}
5252

5353

tools/tasks/seed/build.index.dev.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as gulp from 'gulp';
22
import * as gulpLoadPlugins from 'gulp-load-plugins';
33
import {join} from 'path';
44
import * as slash from 'slash';
5-
import {APP_SRC, APP_DEST, APP_BASE, DEV_DEPENDENCIES} from '../../config';
5+
import {APP_SRC, APP_DEST, APP_BASE, DEPENDENCIES} from '../../config';
66
import {templateLocals} from '../../utils';
77
const plugins = <any>gulpLoadPlugins();
88

@@ -24,7 +24,7 @@ function inject(name?: string) {
2424
}
2525

2626
function getInjectablesDependenciesRef(name?: string) {
27-
return DEV_DEPENDENCIES
27+
return DEPENDENCIES
2828
.filter(dep => dep['inject'] && dep['inject'] === (name || true))
2929
.map(mapPath);
3030
}

0 commit comments

Comments
 (0)