-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
} | ||
} |
This file was deleted.
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; | ||
} | ||
|
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' | ||
}; | ||
|
@@ -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 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normalizing here is redundant with the normalization done with |
||
]; | ||
|
||
|
||
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. | ||
|
@@ -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 { | ||
|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a deprecation warning is missing on |
||
const plugins = <any>gulpLoadPlugins(); | ||
|
||
const processors = [ | ||
|
@@ -47,7 +47,7 @@ function processExternalCss() { | |
} | ||
|
||
function getExternalCss() { | ||
return getEnvDependencies().filter(d => /\.css$/.test(d.src)); | ||
return DEPENDENCIES.filter(d => /\.css$/.test(d.src)); | ||
} | ||
|
||
|
||
|
There was a problem hiding this comment.
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 moveENVIRONMENTS
constant as a class instance member, I suppose. And interface should be moved toseed.config.interfaces
.There was a problem hiding this comment.
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.