Skip to content

chore: simplify config, deprecates npm_deps #644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ Forks of this project demonstrate how to extend and integrate with other librari

# Contributors

[<img alt="mgechev" src="https://avatars.githubusercontent.com/u/455023?v=3&s=117" width="117">](https://github.com/mgechev) |[<img alt="ludohenin" src="https://avatars.githubusercontent.com/u/1011516?v=3&s=117" width="117">](https://github.com/ludohenin) |[<img alt="tarlepp" src="https://avatars.githubusercontent.com/u/595561?v=3&s=117" width="117">](https://github.com/tarlepp) |[<img alt="d3viant0ne" src="https://avatars.githubusercontent.com/u/8420490?v=3&s=117" width="117">](https://github.com/d3viant0ne) |[<img alt="NathanWalker" src="https://avatars.githubusercontent.com/u/457187?v=3&s=117" width="117">](https://github.com/NathanWalker) |[<img alt="nareshbhatia" src="https://avatars.githubusercontent.com/u/1220198?v=3&s=117" width="117">](https://github.com/nareshbhatia) |
[<img alt="mgechev" src="https://avatars.githubusercontent.com/u/455023?v=3&s=117" width="117">](https://github.com/mgechev) |[<img alt="ludohenin" src="https://avatars.githubusercontent.com/u/1011516?v=3&s=117" width="117">](https://github.com/ludohenin) |[<img alt="d3viant0ne" src="https://avatars.githubusercontent.com/u/8420490?v=3&s=117" width="117">](https://github.com/d3viant0ne) |[<img alt="tarlepp" src="https://avatars.githubusercontent.com/u/595561?v=3&s=117" width="117">](https://github.com/tarlepp) |[<img alt="NathanWalker" src="https://avatars.githubusercontent.com/u/457187?v=3&s=117" width="117">](https://github.com/NathanWalker) |[<img alt="nareshbhatia" src="https://avatars.githubusercontent.com/u/1220198?v=3&s=117" width="117">](https://github.com/nareshbhatia) |
:---: |:---: |:---: |:---: |:---: |:---: |
[mgechev](https://github.com/mgechev) |[ludohenin](https://github.com/ludohenin) |[tarlepp](https://github.com/tarlepp) |[d3viant0ne](https://github.com/d3viant0ne) |[NathanWalker](https://github.com/NathanWalker) |[nareshbhatia](https://github.com/nareshbhatia) |
[mgechev](https://github.com/mgechev) |[ludohenin](https://github.com/ludohenin) |[d3viant0ne](https://github.com/d3viant0ne) |[tarlepp](https://github.com/tarlepp) |[NathanWalker](https://github.com/NathanWalker) |[nareshbhatia](https://github.com/nareshbhatia) |

[<img alt="jesperronn" src="https://avatars.githubusercontent.com/u/6267?v=3&s=117" width="117">](https://github.com/jesperronn) |[<img alt="aboeglin" src="https://avatars.githubusercontent.com/u/8297302?v=3&s=117" width="117">](https://github.com/aboeglin) |[<img alt="the-ult" src="https://avatars.githubusercontent.com/u/4863062?v=3&s=117" width="117">](https://github.com/the-ult) |[<img alt="ryzy" src="https://avatars.githubusercontent.com/u/994940?v=3&s=117" width="117">](https://github.com/ryzy) |[<img alt="pgrzeszczak" src="https://avatars.githubusercontent.com/u/3300099?v=3&s=117" width="117">](https://github.com/pgrzeszczak) |[<img alt="natarajanmca11" src="https://avatars.githubusercontent.com/u/9244766?v=3&s=117" width="117">](https://github.com/natarajanmca11) |
:---: |:---: |:---: |:---: |:---: |:---: |
Expand Down
13 changes: 6 additions & 7 deletions tools/config/project.config.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import {join} from 'path';
import {SeedConfig, normalizeDependencies} from './seed.config';
import {SeedConfig} from './seed.config';
import {InjectableDependency} from './seed.config.interfaces';

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

constructor() {
super();
// this.APP_TITLE = 'Put name of your app here';
let additional_deps: Array<any> = [
let additional_deps: InjectableDependency[] = [
// {src: 'jquery/dist/jquery.min.js', inject: 'libs'},
// {src: 'lodash/lodash.min.js', inject: 'libs'},
];

this.DEV_NPM_DEPENDENCIES = this.DEV_DEPENDENCIES.concat(normalizeDependencies(additional_deps));
this.PROD_NPM_DEPENDENCIES = this.PROD_NPM_DEPENDENCIES.concat(normalizeDependencies(additional_deps));
const seedDependencies = this.NPM_DEPENDENCIES;

this.NPM_DEPENDENCIES = seedDependencies.concat(additional_deps);

this.APP_ASSETS = [
// {src: `${this.ASSETS_SRC}/css/toastr.min.css`, inject: true},
// {src: `${this.APP_DEST}/assets/scss/global.css`, inject: true},
{ src: `${this.ASSETS_SRC}/main.css`, inject: true },
];

this.DEV_DEPENDENCIES = this.DEV_NPM_DEPENDENCIES.concat(this.APP_ASSETS);
this.PROD_DEPENDENCIES = this.PROD_NPM_DEPENDENCIES.concat(this.APP_ASSETS);
}
}
5 changes: 0 additions & 5 deletions tools/config/seed.config.interface.ts

This file was deleted.

13 changes: 13 additions & 0 deletions tools/config/seed.config.interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export interface InjectableDependency {
src: string;
inject: string | boolean;
vendor?: boolean;
env?: string[] | string;
}

export interface Environments {
DEVELOPMENT: string;
PRODUCTION: string;
[key: string]: string;
}

81 changes: 61 additions & 20 deletions tools/config/seed.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {readFileSync} from 'fs';
import {argv} from 'yargs';
import {normalize, join} from 'path';
import {InjectableDependency} from './seed.config.interface';
import {InjectableDependency, Environments} from './seed.config.interfaces';

const ENVIRONMENTS = {
export const ENVIRONMENTS: Environments = {
DEVELOPMENT: 'dev',
PRODUCTION: 'prod'
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make ENVIRONMENTS interface "usefull", we may have to move ENVIRONMENTS constant as a class instance member, I suppose. And interface should be moved to seed.config.interfaces.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving ENVIRONMENTS will allow extensibility.

Expand Down Expand Up @@ -50,37 +50,67 @@ export class SeedConfig {

NG2LINT_RULES = customRules();


// Declare NPM dependencies (Note that globs should not be injected).
DEV_NPM_DEPENDENCIES: InjectableDependency[] = normalizeDependencies([
NPM_DEPENDENCIES: InjectableDependency[] = [
{ src: 'systemjs/dist/system-polyfills.src.js', inject: 'shims' },
{ src: 'reflect-metadata/Reflect.js', inject: 'shims' },
{ src: 'es6-shim/es6-shim.js', inject: 'shims' },
{ src: 'systemjs/dist/system.src.js', inject: 'shims' },
{ src: 'angular2/bundles/angular2-polyfills.js', inject: 'shims' },
{ src: 'rxjs/bundles/Rx.js', inject: 'libs' },
{ src: 'angular2/bundles/angular2.js', inject: 'libs' },
{ src: 'angular2/bundles/router.js', inject: 'libs' },
{ src: 'angular2/bundles/http.js', inject: 'libs' }
]);

PROD_NPM_DEPENDENCIES: InjectableDependency[] = normalizeDependencies([
{ src: 'systemjs/dist/system-polyfills.src.js', inject: 'shims' },
{ src: 'reflect-metadata/Reflect.js', inject: 'shims' },
{ src: 'es6-shim/es6-shim.min.js', inject: 'shims' },
{ src: 'systemjs/dist/system.js', inject: 'shims' },
{ src: 'angular2/bundles/angular2-polyfills.min.js', inject: 'libs' }
]);
{ src: 'rxjs/bundles/Rx.js', inject: 'libs', env: ENVIRONMENTS.DEVELOPMENT },
{ src: 'angular2/bundles/angular2.js', inject: 'libs', env: ENVIRONMENTS.DEVELOPMENT },
{ src: 'angular2/bundles/router.js', inject: 'libs', env: ENVIRONMENTS.DEVELOPMENT },
{ src: 'angular2/bundles/http.js', inject: 'libs', env: ENVIRONMENTS.DEVELOPMENT }
];

// Declare local files that needs to be injected
APP_ASSETS: InjectableDependency[] = [
{ src: `${this.ASSETS_SRC}/main.css`, inject: true, vendor: false }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normalizing here is redundant with the normalization done with get DEPENDENCIES()

];


DEV_DEPENDENCIES = this.DEV_NPM_DEPENDENCIES.concat(this.APP_ASSETS);
PROD_DEPENDENCIES = this.PROD_NPM_DEPENDENCIES.concat(this.APP_ASSETS);
get PROD_DEPENDENCIES(): InjectableDependency[] {
console.warn('The property "PROD_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.');
return normalizeDependencies(this.NPM_DEPENDENCIES.filter(filterDependency.bind(null, ENVIRONMENTS.PRODUCTION)))
.concat(this.APP_ASSETS.filter(filterDependency.bind(null, ENVIRONMENTS.PRODUCTION)));
}

get DEV_DEPENDENCIES(): InjectableDependency[] {
console.warn('The property "DEV_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.');
return normalizeDependencies(this.NPM_DEPENDENCIES.filter(filterDependency.bind(null, ENVIRONMENTS.DEVELOPMENT)))
.concat(this.APP_ASSETS.filter(filterDependency.bind(null, ENVIRONMENTS.DEVELOPMENT)));
}

set DEV_DEPENDENCIES(val: InjectableDependency[]) {
console.warn('The property "DEV_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.');
}

set PROD_DEPENDENCIES(val: InjectableDependency[]) {
console.warn('The property "PROD_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.');
}

get DEV_NPM_DEPENDENCIES(): InjectableDependency[] {
console.warn('The property "DEV_NPM_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.');
return normalizeDependencies(this.NPM_DEPENDENCIES.filter(filterDependency.bind(null, ENVIRONMENTS.DEVELOPMENT)));
}
get PROD_NPM_DEPENDENCIES(): InjectableDependency[] {
console.warn('The property "PROD_NPM_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.');
return normalizeDependencies(this.NPM_DEPENDENCIES.filter(filterDependency.bind(null, ENVIRONMENTS.PRODUCTION)));
}
set DEV_NPM_DEPENDENCIES(value: InjectableDependency[]) {
console.warn('The property "DEV_NPM_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.');
const notDev = this.NPM_DEPENDENCIES.filter(d => !filterDependency(ENVIRONMENTS.DEVELOPMENT, d));
this.NPM_DEPENDENCIES = notDev.concat(value);
}
set PROD_NPM_DEPENDENCIES(value: InjectableDependency[]) {
console.warn('The property "PROD_NPM_DEPENDENCIES" is deprecated. Consider using "DEPENDENCIES" instead.');
const notProd = this.NPM_DEPENDENCIES.filter(d => !filterDependency(ENVIRONMENTS.PRODUCTION, d));
this.NPM_DEPENDENCIES = notProd.concat(value);
}

get DEPENDENCIES(): InjectableDependency[] {
return normalizeDependencies(this.NPM_DEPENDENCIES.filter(filterDependency.bind(null, this.ENV)))
.concat(this.APP_ASSETS.filter(filterDependency.bind(null, this.ENV)));
}

// ----------------
// SystemsJS Configuration.
Expand Down Expand Up @@ -123,6 +153,7 @@ export class SeedConfig {
'bb >= 10'
];
getEnvDependencies() {
console.warn('The "getEnvDependencies" method is deprecated. Consider using "DEPENDENCIES" instead.');
if (this.ENV === 'prod') {
return this.PROD_DEPENDENCIES;
} else {
Expand All @@ -137,6 +168,16 @@ export class SeedConfig {
// --------------
// Utils.

function filterDependency(env: string, d: InjectableDependency): boolean {
if (!d.env) {
d.env = Object.keys(ENVIRONMENTS).map(k => ENVIRONMENTS[k]);
}
if (!(d.env instanceof Array)) {
(<any>d).env = [d.env];
}
return d.env.indexOf(env) >= 0;
}

export function normalizeDependencies(deps: InjectableDependency[]) {
deps
.filter((d:InjectableDependency) => !/\*/.test(d.src)) // Skip globs
Expand Down
4 changes: 2 additions & 2 deletions tools/tasks/seed/build.bundles.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as gulp from 'gulp';
import * as gulpLoadPlugins from 'gulp-load-plugins';
import * as merge from 'merge-stream';
import {PROD_DEPENDENCIES, JS_PROD_SHIMS_BUNDLE, JS_DEST} from '../../config';
import {DEPENDENCIES, JS_PROD_SHIMS_BUNDLE, JS_DEST} from '../../config';
const plugins = <any>gulpLoadPlugins();

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

function getShims() {
let libs = PROD_DEPENDENCIES
let libs = DEPENDENCIES
.filter(d => /\.js$/.test(d.src));

return libs.filter(l => l.inject === 'shims')
Expand Down
4 changes: 2 additions & 2 deletions tools/tasks/seed/build.html_css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as merge from 'merge-stream';
import * as autoprefixer from 'autoprefixer';
import * as cssnano from 'cssnano';
import {join} from 'path';
import {APP_SRC, TMP_DIR, CSS_PROD_BUNDLE, CSS_DEST, APP_DEST, BROWSER_LIST, ENV, getEnvDependencies} from '../../config';
import {APP_SRC, TMP_DIR, CSS_PROD_BUNDLE, CSS_DEST, APP_DEST, BROWSER_LIST, ENV, DEPENDENCIES} from '../../config';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a deprecation warning is missing on getEnvDependencies method of SeedConfig class.

const plugins = <any>gulpLoadPlugins();

const processors = [
Expand Down Expand Up @@ -47,7 +47,7 @@ function processExternalCss() {
}

function getExternalCss() {
return getEnvDependencies().filter(d => /\.css$/.test(d.src));
return DEPENDENCIES.filter(d => /\.css$/.test(d.src));
}


Expand Down
4 changes: 2 additions & 2 deletions tools/tasks/seed/build.index.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as gulp from 'gulp';
import * as gulpLoadPlugins from 'gulp-load-plugins';
import {join} from 'path';
import * as slash from 'slash';
import {APP_SRC, APP_DEST, APP_BASE, DEV_DEPENDENCIES} from '../../config';
import {APP_SRC, APP_DEST, APP_BASE, DEPENDENCIES} from '../../config';
import {templateLocals} from '../../utils';
const plugins = <any>gulpLoadPlugins();

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

function getInjectablesDependenciesRef(name?: string) {
return DEV_DEPENDENCIES
return DEPENDENCIES
.filter(dep => dep['inject'] && dep['inject'] === (name || true))
.map(mapPath);
}
Expand Down