import { readFileSync } from 'fs' ; import { argv } from 'yargs' ; import { normalize , join } from 'path' ; const ENVIRONMENTS = { DEVELOPMENT : 'dev' , PRODUCTION : 'prod' } ; export const PROJECT_ROOT = normalize ( join ( __dirname , '..' ) ) ; export const ENV = getEnvironment ( ) ; export const DEBUG = argv [ 'debug' ] || false ; export const PORT = argv [ 'port' ] || 5555 ; export const LIVE_RELOAD_PORT = argv [ 'reload-port' ] || 4002 ; export const DOCS_PORT = argv [ 'docs-port' ] || 4003 ; export const APP_BASE = argv [ 'base' ] || '/' ; export const ENABLE_HOT_LOADING = ! ! argv [ 'hot-loader' ] ; export const HOT_LOADER_PORT = 5578 ; export const BOOTSTRAP_MODULE = ENABLE_HOT_LOADING ? 'hot_loader_bootstrap' : 'bootstrap' ; export const APP_TITLE = 'My Angular2 App' ; export const APP_SRC = 'app' ; export const ASSETS_SRC = `${ APP_SRC }/assets` ; export const TOOLS_DIR = 'tools' ; export const TMP_DIR = 'tmp' ; export const TEST_DEST = 'test' ; export const DOCS_DEST = 'docs' ; export const APP_DEST = ENV === 'dev' ? `dist/${ ENV }` : 'add_angular2' ; export const ASSETS_DEST = `${ APP_DEST }/assets` ; export const CSS_DEST = `${ APP_DEST }/css` ; export const JS_DEST = `${ APP_DEST }/js` ; export const APP_ROOT = ENV === 'dev' ? `${ APP_BASE }${ APP_DEST }/` : `${ APP_BASE }` ; export const VERSION = appVersion ( ) ; export const CSS_PROD_BUNDLE = 'all.css' ; export const JS_PROD_SHIMS_BUNDLE = 'shims.js' ; export const JS_PROD_APP_BUNDLE = 'app.js' ; export const VERSION_NPM = '2.14.2' ; export const VERSION_NODE = '4.0.0' ; interface InjectableDependency { src : string ; inject : string | boolean ; dest ? : string ; } export const DEV_NPM_DEPENDENCIES = normalizeDependencies ( [ { src : 'systemjs/dist/system-polyfills.src.js' , inject : 'shims' , dest : JS_DEST } , { src : 'reflect-metadata/Reflect.js' , inject : 'shims' , dest : JS_DEST } , { src : 'es6-shim/es6-shim.js' , inject : 'shims' , dest : JS_DEST } , { src : 'systemjs/dist/system.src.js' , inject : 'shims' , dest : JS_DEST } , { src : 'angular2/bundles/angular2-polyfills.js' , inject : 'shims' , dest : JS_DEST } , { src : 'rxjs/bundles/Rx.js' , inject : 'libs' , dest : JS_DEST } , { src : 'angular2/bundles/angular2.js' , inject : 'libs' , dest : JS_DEST } , { src : 'angular2/bundles/router.js' , inject : 'libs' , dest : JS_DEST } , { src : 'angular2/bundles/http.js' , inject : 'libs' , dest : JS_DEST } , { src : 'bootstrap/dist/css/bootstrap.css' , inject : true , dest : CSS_DEST } ] ) ; export const PROD_NPM_DEPENDENCIES = normalizeDependencies ( [ { src : 'reflect-metadata/Reflect.js' , inject : 'shims' } , { src : 'es6-shim/es6-shim.min.js' , inject : 'shims' } , { src : 'angular2/bundles/angular2-polyfills.min.js' , inject : 'libs' } , { src : 'bootstrap/dist/css/bootstrap.min.css' , inject : true } ] ) ; export const APP_ASSETS = [ ] ; export const DEV_DEPENDENCIES = DEV_NPM_DEPENDENCIES . concat ( APP_ASSETS ) ; export const PROD_DEPENDENCIES = PROD_NPM_DEPENDENCIES . concat ( APP_ASSETS ) ; const SYSTEM_CONFIG_DEV = { defaultJSExtensions : true , paths : { 'bootstrap' : `${ APP_ROOT }bootstrap` , 'hot_loader_bootstrap' : `${ APP_ROOT }hot_loader_bootstrap` , '*' : `${ APP_BASE }node_modules/*` } } ; export const SYSTEM_CONFIG = SYSTEM_CONFIG_DEV ; function normalizeDependencies ( deps ) { deps . filter ( d => ! /\*/ . test ( d . src ) ) . forEach ( d => d . src = require . resolve ( d . src ) ) ; return deps ; } function appVersion ( ) { var pkg = JSON . parse ( readFileSync ( 'package.json' ) . toString ( ) ) ; return pkg . version ; } function getEnvironment ( ) { let base = argv [ '_' ] ; let prodKeyword = ! ! base . filter ( o => o . indexOf ( ENVIRONMENTS . PRODUCTION ) >= 0 ) . pop ( ) ; if ( base && prodKeyword || argv [ 'env' ] === ENVIRONMENTS . PRODUCTION ) { return ENVIRONMENTS . PRODUCTION ; } else { return ENVIRONMENTS . DEVELOPMENT ; } }