diff --git a/packages/af-webpack/package.json b/packages/af-webpack/package.json index 45bf2cd29ffe..1857166c24e4 100644 --- a/packages/af-webpack/package.json +++ b/packages/af-webpack/package.json @@ -73,11 +73,6 @@ "bugs": { "url": "https://github.com/umijs/umi/issues" }, - "scripts": { - "test": "ruban test --timeout 200000", - "debug": "ruban debug --timeout 200000", - "coveralls": "ruban coveralls" - }, "devDependencies": { "glob": "^7.1.2", "node-sass": "^4.7.2", diff --git a/packages/babel-preset-umi/package.json b/packages/babel-preset-umi/package.json index d069063c1174..1a51ad9fc367 100644 --- a/packages/babel-preset-umi/package.json +++ b/packages/babel-preset-umi/package.json @@ -13,11 +13,6 @@ "bugs": { "url": "https://github.com/umijs/umi/issues" }, - "scripts": { - "test": "ruban test", - "debug": "ruban debug", - "coveralls": "ruban coveralls" - }, "dependencies": { "@babel/plugin-proposal-async-generator-functions": "^7.0.0-beta.31", "@babel/plugin-proposal-class-properties": "^7.0.0-beta.31", diff --git a/packages/eslint-config-umi/package.json b/packages/eslint-config-umi/package.json index 726214b4e504..fe5451fabb7f 100644 --- a/packages/eslint-config-umi/package.json +++ b/packages/eslint-config-umi/package.json @@ -12,11 +12,6 @@ "bugs": { "url": "https://github.com/umijs/umi/issues" }, - "scripts": { - "test": "ruban test", - "debug": "ruban debug", - "coveralls": "ruban coveralls" - }, "dependencies": { "eslint-config-react-app": "^2.0.0" }, diff --git a/packages/umi-build-dev/package.json b/packages/umi-build-dev/package.json index 088f842b732d..08ebc1eae9fd 100644 --- a/packages/umi-build-dev/package.json +++ b/packages/umi-build-dev/package.json @@ -42,11 +42,6 @@ "bugs": { "url": "http://github.com/umijs/umi/issues" }, - "scripts": { - "test": "ruban test", - "debug": "ruban debug", - "coveralls": "ruban coveralls" - }, "devDependencies": { "glob": "^7.1.2" }, diff --git a/packages/umi-build-dev/src/FilesGenerator.js b/packages/umi-build-dev/src/FilesGenerator.js index 33eee1e4738c..4e810a6cd1c0 100644 --- a/packages/umi-build-dev/src/FilesGenerator.js +++ b/packages/umi-build-dev/src/FilesGenerator.js @@ -152,7 +152,9 @@ if (process.env.NODE_ENV === 'production') { generateRouterJS() { const { paths, config } = this.service; const { absRouterJSPath } = paths; - const routes = getRouteConfig(paths, config); + const routes = this.service.applyPlugins('modifyRoutes', { + initialValue: getRouteConfig(paths, config), + }); this.service.setRoutes(routes); diff --git a/packages/umi-plugin-dva/package.json b/packages/umi-plugin-dva/package.json index 2257871e7eb4..806d9e9a8739 100644 --- a/packages/umi-plugin-dva/package.json +++ b/packages/umi-plugin-dva/package.json @@ -2,10 +2,6 @@ "name": "umi-plugin-dva", "version": "0.3.3", "main": "./lib/index.js", - "scripts": { - "test": "ruban test", - "debug": "ruban debug" - }, "dependencies": { "dva": "^2.1.0", "dva-loading": "^1.0.4", @@ -14,9 +10,9 @@ }, "repository": { "type": "git", - "url": "https://github.com/umijs/umi/tree/master/packages/umi-plugin-yunfengdie" + "url": "https://github.com/umijs/umi/tree/master/packages/umi-plugin-dva" }, - "homepage": "https://github.com/umijs/umi/tree/master/packages/umi-plugin-yunfengdie", + "homepage": "https://github.com/umijs/umi/tree/master/packages/umi-plugin-dva", "authors": [ "chencheng (https://github.com/sorrycc)" ], diff --git a/packages/umi-plugin-routes/package.json b/packages/umi-plugin-routes/package.json new file mode 100644 index 000000000000..2d1a6b77d6d3 --- /dev/null +++ b/packages/umi-plugin-routes/package.json @@ -0,0 +1,23 @@ +{ + "name": "umi-plugin-routes", + "version": "0.1.0", + "main": "./lib/index.js", + "repository": { + "type": "git", + "url": "https://github.com/umijs/umi/tree/master/packages/umi-plugin-routes" + }, + "homepage": "https://github.com/umijs/umi/tree/master/packages/umi-plugin-routes", + "authors": [ + "chencheng (https://github.com/sorrycc)" + ], + "bugs": { + "url": "https://github.com/umijs/umi/issues" + }, + "files": [ + "lib", + "src" + ], + "dependencies": { + "is-plain-object": "^2.0.4" + } +} diff --git a/packages/umi-plugin-routes/src/index.js b/packages/umi-plugin-routes/src/index.js new file mode 100644 index 000000000000..e74f7de6b7ef --- /dev/null +++ b/packages/umi-plugin-routes/src/index.js @@ -0,0 +1,51 @@ +import assert from 'assert'; +import isPlainObject from 'is-plain-object'; + +function optsToArray(item) { + if (!item) return []; + if (Array.isArray(item)) { + return item; + } else { + return [item]; + } +} + +export default function(api, opts) { + api.register('modifyRoutes', ({ memo }) => { + // opts.exclude + memo = memo.filter(route => { + for (const exclude of optsToArray(opts.exclude)) { + if (typeof exclude === 'function' && exclude(route)) { + return false; + } + if (exclude instanceof RegExp && exclude.test(route.component)) { + return false; + } + } + return true; + }); + + // opts.include + for (const include of optsToArray(opts.include)) { + if (isPlainObject(include)) { + memo = [...memo, include]; + } + if (typeof include === 'string') { + throw new Error( + 'opts.include with string not support, please wait for next version.', + ); + } + } + + // opts.update + if (opts.update) { + assert( + typeof opts.update === 'function', + `opts.update should be function, but got ${opts.update}`, + ); + memo = opts.update(memo); + } + + return memo; + }); +} diff --git a/packages/umi-plugin-yunfengdie/package.json b/packages/umi-plugin-yunfengdie/package.json index 1082682e0f56..59d2e7318caf 100644 --- a/packages/umi-plugin-yunfengdie/package.json +++ b/packages/umi-plugin-yunfengdie/package.json @@ -2,10 +2,6 @@ "name": "umi-plugin-yunfengdie", "version": "0.4.1", "main": "./lib/index.js", - "scripts": { - "test": "ruban test", - "debug": "ruban debug" - }, "dependencies": { "debug": "^3.1.0" }, diff --git a/packages/umi/package.json b/packages/umi/package.json index f220e43fe781..77456cc9ae0c 100644 --- a/packages/umi/package.json +++ b/packages/umi/package.json @@ -33,11 +33,6 @@ "bugs": { "url": "https://github.com/umijs/umi/issues" }, - "scripts": { - "test": "ruban test --timeout 200000", - "debug": "DISABLE_TRANSFORM_RUNTIME=1 ruban debug --timeout 200000", - "coveralls": "ruban coveralls" - }, "files": [ "lib", "src",