Change build to use gulp instead of tsc so that route-recognizer can be bundled

This commit is contained in:
Matt Mazzola 2016-06-06 14:38:57 -07:00
Родитель c13f76df90
Коммит 2b67e074d5
8 изменённых файлов: 93 добавлений и 31 удалений

26
.vscode/tasks.json поставляемый
Просмотреть файл

@ -2,9 +2,27 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558 // See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format // for the documentation about the tasks.json format
"version": "0.1.0", "version": "0.1.0",
"command": "tsc", "command": "gulp",
"isShellCommand": true, "isShellCommand": true,
"args": ["-p", "."], "args": [
"showOutput": "silent", "--no-color"
"problemMatcher": "$tsc" ],
"tasks": [
{
"taskName": "build",
"args": [],
"isBuildCommand": true,
"isWatching": false,
"problemMatcher": [
"$lessCompile",
"$tsc",
"$jshint"
]
},
{
"taskName": "test",
"args": [],
"isTestCommand": true
}
]
} }

Просмотреть файл

@ -1,11 +1,39 @@
var gulp = require('gulp-help')(require('gulp')); var gulp = require('gulp-help')(require('gulp'));
var karma = require('karma'), var del = require('del'),
karma = require('karma'),
webpack = require('webpack-stream'), webpack = require('webpack-stream'),
webpackConfig = require('./webpack.config'), webpackConfig = require('./webpack.config'),
webpackE2eConfig = require('./webpack.e2e.config'),
runSequence = require('run-sequence'), runSequence = require('run-sequence'),
argv = require('yargs').argv argv = require('yargs').argv
; ;
gulp.task('build', 'Build library', function (done) {
return runSequence(
'build:src',
'copydts',
'removedts',
done
)
});
gulp.task('copydts', 'Copy .d.ts to dist', function() {
return gulp.src('./src/*.d.ts')
.pipe(gulp.dest('./dist'))
});
gulp.task('removedts', 'Clean .d.ts from src', function () {
return del([
'./src/*.d.ts'
]);
})
gulp.task('build:src', 'Compile source files', function () {
return gulp.src(['typings/**/*.d.ts', './src/**/*.ts'])
.pipe(webpack(webpackConfig))
.pipe(gulp.dest('./dist'));
});
gulp.task('test', 'Run unit tests', function (done) { gulp.task('test', 'Run unit tests', function (done) {
return runSequence( return runSequence(
'compile:spec', 'compile:spec',
@ -16,7 +44,7 @@ gulp.task('test', 'Run unit tests', function (done) {
gulp.task('compile:spec', 'Compile typescript for tests', function () { gulp.task('compile:spec', 'Compile typescript for tests', function () {
return gulp.src(['typings/**/*.d.ts', './src/**/*.ts', './test/**/*.spec.ts']) return gulp.src(['typings/**/*.d.ts', './src/**/*.ts', './test/**/*.spec.ts'])
.pipe(webpack(webpackConfig)) .pipe(webpack(webpackE2eConfig))
.pipe(gulp.dest('./tmp')); .pipe(gulp.dest('./tmp'));
}); });

Просмотреть файл

@ -6,7 +6,7 @@
"typings": "dist/router.d.ts", "typings": "dist/router.d.ts",
"scripts": { "scripts": {
"test": "gulp test --chrome", "test": "gulp test --chrome",
"prepublish": "tsc -p ." "prepublish": "gulp build"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -20,6 +20,7 @@
"author": "Microsoft Power BI Team", "author": "Microsoft Power BI Team",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"del": "^2.2.0",
"gulp": "^3.9.1", "gulp": "^3.9.1",
"gulp-help": "^1.6.1", "gulp-help": "^1.6.1",
"jasmine-core": "^2.4.1", "jasmine-core": "^2.4.1",

Просмотреть файл

@ -1,4 +1,4 @@
import * as RouteRecognizer from 'route-recognizer'; import RouteRecognizer = require('route-recognizer');
export interface IAddHandler { export interface IAddHandler {
addHandler(handler: any): void; addHandler(handler: any): void;
@ -10,11 +10,11 @@ export interface IRouterHandler {
export class Router { export class Router {
private handlers: IAddHandler; private handlers: IAddHandler;
private getRouteRecognizer: RouteRecognizer.RouteRecognizer; private getRouteRecognizer: RouteRecognizer<any>;
private patchRouteRecognizer: RouteRecognizer.RouteRecognizer; private patchRouteRecognizer: RouteRecognizer<any>;
private postRouteRecognizer: RouteRecognizer.RouteRecognizer; private postRouteRecognizer: RouteRecognizer<any>;
private putRouteRecognizer: RouteRecognizer.RouteRecognizer; private putRouteRecognizer: RouteRecognizer<any>;
private deleteRouteRecognizer: RouteRecognizer.RouteRecognizer; private deleteRouteRecognizer: RouteRecognizer<any>;
constructor(handlers: IAddHandler) { constructor(handlers: IAddHandler) {
this.handlers = handlers; this.handlers = handlers;
@ -23,11 +23,11 @@ export class Router {
* TODO: look at generating the router dynamically based on list of supported http methods * TODO: look at generating the router dynamically based on list of supported http methods
* instead of hardcoding the creation of these and the methods. * instead of hardcoding the creation of these and the methods.
*/ */
this.getRouteRecognizer = new RouteRecognizer.RouteRecognizer(); this.getRouteRecognizer = new RouteRecognizer();
this.patchRouteRecognizer = new RouteRecognizer.RouteRecognizer(); this.patchRouteRecognizer = new RouteRecognizer();
this.postRouteRecognizer = new RouteRecognizer.RouteRecognizer(); this.postRouteRecognizer = new RouteRecognizer();
this.putRouteRecognizer = new RouteRecognizer.RouteRecognizer(); this.putRouteRecognizer = new RouteRecognizer();
this.deleteRouteRecognizer = new RouteRecognizer.RouteRecognizer(); this.deleteRouteRecognizer = new RouteRecognizer();
} }
get(url: string, handler: IRouterHandler): this { get(url: string, handler: IRouterHandler): this {
@ -55,7 +55,7 @@ export class Router {
return this; return this;
} }
private registerHandler(routeRecognizer: RouteRecognizer.RouteRecognizer, method: string, url: string, handler: IRouterHandler) { private registerHandler(routeRecognizer: RouteRecognizer<any>, method: string, url: string, handler: IRouterHandler) {
routeRecognizer.add([ routeRecognizer.add([
{ path: url, handler: () => {} } { path: url, handler: () => {} }
]); ]);
@ -79,7 +79,7 @@ export class Router {
*/ */
const route = matchingRoutes[0]; const route = matchingRoutes[0];
(<IExtendedRequest>request).params = route.params; (<IExtendedRequest>request).params = route.params;
(<IExtendedRequest>request).queryParams = matchingRoutes.queryParams; (<IExtendedRequest>request).queryParams = (<any>matchingRoutes).queryParams;
return true; return true;
}, },

Просмотреть файл

@ -1,6 +1,5 @@
{ {
"compilerOptions": { "compilerOptions": {
"moduleResolution": "node",
"target": "es5", "target": "es5",
"module": "umd", "module": "umd",
"declaration": true, "declaration": true,

Просмотреть файл

@ -1,14 +1,11 @@
module.exports = { module.exports = {
entry: './test/router.spec.ts', entry: './src/router.ts',
output: { output: {
path: __dirname + "/tmp", path: __dirname + "/dist",
filename: 'router.spec.js' filename: 'router.js',
library: 'powerbi-router',
libraryTarget: 'umd'
}, },
externals: [
{
"route-recognizer": "RouteRecognizer"
}
],
devtool: 'source-map', devtool: 'source-map',
resolve: { resolve: {
extensions: ['', '.webpack.js', '.web.js', '.ts', '.js'] extensions: ['', '.webpack.js', '.web.js', '.ts', '.js']

19
webpack.e2e.config.js Normal file
Просмотреть файл

@ -0,0 +1,19 @@
module.exports = {
entry: './test/router.spec.ts',
output: {
path: __dirname + "/tmp",
filename: 'router.spec.js'
},
devtool: 'source-map',
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.ts', '.js']
},
module: {
loaders: [
{ test: /\.ts$/, loader: 'ts-loader' }
]
},
ts: {
configFileName: "webpack.tsconfig.json"
}
}

Просмотреть файл

@ -1,7 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es5", "target": "es5",
"declaration": false, "declaration": true,
"noImplicitAny": true, "noImplicitAny": true,
"sourceMap": true "sourceMap": true
}, },