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
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "tsc",
"command": "gulp",
"isShellCommand": true,
"args": ["-p", "."],
"showOutput": "silent",
"problemMatcher": "$tsc"
"args": [
"--no-color"
],
"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 karma = require('karma'),
var del = require('del'),
karma = require('karma'),
webpack = require('webpack-stream'),
webpackConfig = require('./webpack.config'),
webpackE2eConfig = require('./webpack.e2e.config'),
runSequence = require('run-sequence'),
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) {
return runSequence(
'compile:spec',
@ -16,7 +44,7 @@ gulp.task('test', 'Run unit tests', function (done) {
gulp.task('compile:spec', 'Compile typescript for tests', function () {
return gulp.src(['typings/**/*.d.ts', './src/**/*.ts', './test/**/*.spec.ts'])
.pipe(webpack(webpackConfig))
.pipe(webpack(webpackE2eConfig))
.pipe(gulp.dest('./tmp'));
});

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

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

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

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

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

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

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

@ -1,14 +1,11 @@
module.exports = {
entry: './test/router.spec.ts',
module.exports = {
entry: './src/router.ts',
output: {
path: __dirname + "/tmp",
filename: 'router.spec.js'
path: __dirname + "/dist",
filename: 'router.js',
library: 'powerbi-router',
libraryTarget: 'umd'
},
externals: [
{
"route-recognizer": "RouteRecognizer"
}
],
devtool: 'source-map',
resolve: {
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": {
"target": "es5",
"declaration": false,
"declaration": true,
"noImplicitAny": true,
"sourceMap": true
},