From dd4fcb50baea4fef8d714c1a03ee6da125a70907 Mon Sep 17 00:00:00 2001 From: Mike Ryan Date: Fri, 26 Aug 2016 09:02:33 -0500 Subject: [PATCH] chore: Upgrade build process to use ngc and new folder structure --- .gitignore | 1 + circle.yml | 3 +++ karma.conf.js | 16 +++++--------- package.json | 30 +++++++++++++------------ spec/actions.spec.ts | 2 +- spec/connect.spec.ts | 6 ++--- spec/reducer.spec.ts | 4 ++-- spec/tsconfig.json | 26 ---------------------- {lib => src}/actions.ts | 0 {lib => src}/connect.ts | 2 +- {lib => src}/index.ts | 0 {lib => src}/reducer.ts | 0 {lib => src}/router-store-module.ts | 0 tests.js | 23 ------------------- tests.ts | 34 +++++++++++++++++++++++++++++ tsconfig.es5.json | 22 ------------------- tsconfig.esm.json | 22 +++++++++++++++++++ tsconfig.json | 24 ++++++++++---------- typings.json | 7 ------ 19 files changed, 101 insertions(+), 121 deletions(-) create mode 100644 circle.yml delete mode 100644 spec/tsconfig.json rename {lib => src}/actions.ts (100%) rename {lib => src}/connect.ts (96%) rename {lib => src}/index.ts (100%) rename {lib => src}/reducer.ts (100%) rename {lib => src}/router-store-module.ts (100%) delete mode 100644 tests.js create mode 100644 tests.ts delete mode 100644 tsconfig.es5.json create mode 100644 tsconfig.esm.json delete mode 100644 typings.json diff --git a/.gitignore b/.gitignore index d39dd3d..c837656 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,4 @@ __build__/** # Build Artifacts # release +.ngc diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..07e9219 --- /dev/null +++ b/circle.yml @@ -0,0 +1,3 @@ +machine: + node: + version: 6.4.0 diff --git a/karma.conf.js b/karma.conf.js index 3e25d29..dbc1d82 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -9,13 +9,13 @@ module.exports = function(karma) { frameworks: ['jasmine'], files: [ - { pattern: 'tests.js', watched: false } + { pattern: 'tests.ts', watched: false } ], exclude: [], preprocessors: { - 'tests.js': ['coverage', 'webpack', 'sourcemap'] + 'tests.ts': ['coverage', 'webpack', 'sourcemap'] }, reporters: ['mocha', 'coverage'], @@ -50,27 +50,21 @@ module.exports = function(karma) { { test: /\.ts?$/, exclude: /(node_modules)/, - loader: 'ts-loader?target=es5&module=commonjs' + loader: 'awesome-typescript' } ], postLoaders: [ { test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader', - include: path.resolve(__dirname, 'lib'), + include: path.resolve(__dirname, 'src'), exclude: [ /\.(e2e|spec)\.ts$/, + /tests.ts$/, /node_modules/ ] } ] - }, - ts: { - configFileName: './spec/tsconfig.json' } - }, - - webpackServer: { - noInfo: true } }); }; diff --git a/package.json b/package.json index 59dc9f0..2715712 100644 --- a/package.json +++ b/package.json @@ -11,18 +11,16 @@ "lint": "npm-run-all lint:*", "lint:lib": "tslint lib/**.ts", "lint:spec": "tslint spec/**.ts", - "typings": "typings install", "clean": "npm-run-all clean:*", "clean:release": "rm -rf ./release", - "clean:typings": "rm -rf ./typings", - "prebuild": "npm-run-all clean typings karma", - "build": "npm-run-all build:cjs build:es6", - "build:cjs": "tsc --p tsconfig.es5.json --diagnostics --pretty", - "build:es6": "tsc -m es2015 --outDir ./release/es6 --target ES6 -d --diagnostics --pretty", + "prebuild": "npm-run-all clean karma", + "build": "npm-run-all build:cjs build:esm", + "build:cjs": "ngc --p tsconfig.json", + "build:esm": "ngc -p tsconfig.esm.json", "prepare": "npm-run-all prepare:*", - "prepare:es6": "cp -R ./release/es6 ./release/npm", - "prepare:package": "cp ./{package.json,README.md,LICENSE} ./release/npm", - "test": "npm-run-all clean typings karma", + "prepare:ts": "cp -R ./src ./release", + "prepare:package": "cp ./{package.json,README.md,LICENSE} ./release", + "test": "npm-run-all clean karma", "karma": "karma start --single-run", "karma:watch": "karma start", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0", @@ -46,12 +44,17 @@ "devDependencies": { "@angular/common": "^2.0.0-rc.5", "@angular/compiler": "^2.0.0-rc.5", + "@angular/compiler-cli": "^0.5.0", "@angular/core": "^2.0.0-rc.5", "@angular/platform-browser": "^2.0.0-rc.5", "@angular/platform-browser-dynamic": "^2.0.0-rc.5", + "@angular/platform-server": "^2.0.0-rc.5", "@angular/router": "^3.0.0-rc.1", "@ngrx/core": "^1.0.0", "@ngrx/store": "^2.0.0", + "@types/jasmine": "^2.2.33", + "@types/node": "^6.0.38", + "awesome-typescript-loader": "^2.2.1", "conventional-changelog-cli": "^1.1.1", "core-js": "^2.2.2", "istanbul-instrumenter-loader": "^0.2.0", @@ -66,13 +69,12 @@ "karma-webpack": "^1.7.0", "npm-run-all": "^1.7.0", "reflect-metadata": "^0.1.3", - "rxjs": "^5.0.0-beta.6", + "rxjs": "5.0.0-beta.6", "source-map-loader": "^0.1.5", "ts-loader": "^0.8.1", "tslint": "^3.6.0", - "typescript": "^1.8.9", - "typings": "^1.3.0", - "webpack": "^1.12.14", - "zone.js": "0.6.14" + "typescript": "^2.0.0", + "webpack": "^2.1.0-beta.21", + "zone.js": "0.6.12" } } diff --git a/spec/actions.spec.ts b/spec/actions.spec.ts index 418026c..c7f3001 100644 --- a/spec/actions.spec.ts +++ b/spec/actions.spec.ts @@ -1,4 +1,4 @@ -import * as actions from '../lib/actions'; +import * as actions from '../src/actions'; describe('Actions', function() { it('should provide a "go" action creator', function() { diff --git a/spec/connect.spec.ts b/spec/connect.spec.ts index 34c12cc..44d172f 100644 --- a/spec/connect.spec.ts +++ b/spec/connect.spec.ts @@ -4,9 +4,9 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import { Router, NavigationEnd } from '@angular/router'; import { Store } from '@ngrx/store'; -import { RouterState } from '../lib/reducer'; -import * as routerActions from '../lib/actions'; -import { listenForRouterMethodActions, connectRouterActions } from '../lib/connect'; +import { RouterState } from '../src/reducer'; +import * as routerActions from '../src/actions'; +import { listenForRouterMethodActions, connectRouterActions } from '../src/connect'; describe('Router/Store Connectors', function() { describe('listenForRouterMethodActions', function() { diff --git a/spec/reducer.spec.ts b/spec/reducer.spec.ts index 6ff41ea..fef19c4 100644 --- a/spec/reducer.spec.ts +++ b/spec/reducer.spec.ts @@ -1,6 +1,6 @@ -import { routerActions } from '../lib/actions'; -import { routerReducer, RouterState } from '../lib/reducer'; +import { routerActions } from '../src/actions'; +import { routerReducer, RouterState } from '../src/reducer'; describe('routerReducer', function() { diff --git a/spec/tsconfig.json b/spec/tsconfig.json deleted file mode 100644 index b9bd7c0..0000000 --- a/spec/tsconfig.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "compileOnSave": false, - "compilerOptions": { - "target": "es5", - "module": "commonjs", - "sourceMap": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "moduleResolution": "node", - "declaration": false - }, - "filesGlob": [ - "./**/*.ts", - "../typings/index.d.ts" - ], - "files": [ - "./actions.spec.ts", - "./connect.spec.ts", - "./index.spec.ts", - "./reducer.spec.ts", - "../typings/index.d.ts" - ], - "atom": { - "rewriteTsconfig": true - } -} diff --git a/lib/actions.ts b/src/actions.ts similarity index 100% rename from lib/actions.ts rename to src/actions.ts diff --git a/lib/connect.ts b/src/connect.ts similarity index 96% rename from lib/connect.ts rename to src/connect.ts index 7a24526..2f34768 100644 --- a/lib/connect.ts +++ b/src/connect.ts @@ -25,7 +25,7 @@ export function listenForRouterMethodActions(router: Router, location: Location, break; case routerActions.REPLACE: - router.navigate(commands, { queryParams, replaceUrl: true }); + router.navigate(commands, ({ queryParams, replaceUrl: true })); break; case routerActions.SEARCH: diff --git a/lib/index.ts b/src/index.ts similarity index 100% rename from lib/index.ts rename to src/index.ts diff --git a/lib/reducer.ts b/src/reducer.ts similarity index 100% rename from lib/reducer.ts rename to src/reducer.ts diff --git a/lib/router-store-module.ts b/src/router-store-module.ts similarity index 100% rename from lib/router-store-module.ts rename to src/router-store-module.ts diff --git a/tests.js b/tests.js deleted file mode 100644 index 0b21378..0000000 --- a/tests.js +++ /dev/null @@ -1,23 +0,0 @@ -require('core-js'); -require('zone.js/dist/zone.js'); -require('zone.js/dist/long-stack-trace-zone.js'); -require('zone.js/dist/proxy-zone'); -require('zone.js/dist/sync-test.js'); -require('zone.js/dist/async-test.js'); -require('zone.js/dist/jasmine-patch.js'); -require('zone.js/dist/fake-async-test.js'); - -Error.stackTraceLimit = Infinity; - -require('reflect-metadata'); - -const testContext = require.context('./spec', true, /\.spec\.ts/); -testContext.keys().forEach(testContext); - -const testing = require('@angular/core/testing'); -const browser = require('@angular/platform-browser-dynamic/testing'); - -testing.TestBed.initTestEnvironment( - browser.BrowserDynamicTestingModule, - browser.platformBrowserDynamicTesting() -); diff --git a/tests.ts b/tests.ts new file mode 100644 index 0000000..26523ea --- /dev/null +++ b/tests.ts @@ -0,0 +1,34 @@ +import 'core-js'; +import 'core-js/es7/reflect'; +import 'zone.js/dist/zone'; +import 'zone.js/dist/long-stack-trace-zone'; +import 'zone.js/dist/jasmine-patch'; +import 'zone.js/dist/async-test'; +import 'zone.js/dist/fake-async-test'; +import 'zone.js/dist/sync-test'; + +// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. +declare var __karma__: any; +declare var System: any; + +// Prevent Karma from running prematurely. +__karma__.loaded = function () {}; + + +Promise.all([ + System.import('@angular/core/testing'), + System.import('@angular/platform-browser-dynamic/testing') +]) + // First, initialize the Angular testing environment. + .then(([testing, testingBrowser]) => { + testing.getTestBed().initTestEnvironment( + testingBrowser.BrowserDynamicTestingModule, + testingBrowser.platformBrowserDynamicTesting() + ); + }) + // Then we find all the tests. + .then(() => (require).context('./spec', true, /\.spec\.ts/)) + // And load the modules. + .then(context => context.keys().map(context)) + // Finally, start Karma to run the tests. + .then(__karma__.start, __karma__.error); diff --git a/tsconfig.es5.json b/tsconfig.es5.json deleted file mode 100644 index 1874569..0000000 --- a/tsconfig.es5.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "version": "1.8.0", - "compileOnSave": false, - "compilerOptions": { - "outDir": "./release/npm", - "target": "es5", - "module": "commonjs", - "sourceMap": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "removeComments": false, - "moduleResolution": "node", - "declaration": true - }, - "exclude": [ - "node_modules", - "spec", - "release", - "typings/browser", - "typings/browser.d.ts" - ] -} diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..1b67865 --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,22 @@ +{ + "version": "2.0.0", + "compileOnSave": false, + "compilerOptions": { + "outDir": "./release/esm", + "target": "es5", + "module": "es2015", + "sourceMap": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "removeComments": false, + "moduleResolution": "node", + "declaration": true, + "lib": ["dom", "es5", "es2015"] + }, + "include": [ + "src/**/*.ts" + ], + "angularCompilerOptions": { + "genDir": ".ngc" + } +} diff --git a/tsconfig.json b/tsconfig.json index 5716b7b..3175df6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,20 +1,22 @@ { - "version": "1.8.0", + "version": "2.0.0", "compileOnSave": false, "compilerOptions": { - "outDir": "./release/es6", - "target": "es6", - "sourceMap": true, + "outDir": "./release", + "target": "es5", + "module": "commonjs", + "sourceMap": false, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": false, "moduleResolution": "node", - "declaration": true + "declaration": true, + "lib": ["dom", "es5", "es2015"] }, - "exclude": [ - "node_modules", - "spec", - "typings", - "release" - ] + "include": [ + "src/**/*.ts" + ], + "angularCompilerOptions": { + "genDir": ".ngc" + } } diff --git a/typings.json b/typings.json deleted file mode 100644 index c2ad459..0000000 --- a/typings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "globalDependencies": { - "core-js": "registry:dt/core-js#0.0.0+20160725163759", - "jasmine": "registry:dt/jasmine#2.2.0+20160621224255", - "node": "registry:dt/node#6.0.0+20160823142437" - } -}