Skip to content
This repository was archived by the owner on Oct 12, 2020. It is now read-only.

Commit 3c01dad

Browse files
author
linjianghe
committed
refactor: 将项目的根目录命名由 basePath 修改为 rootPath,这样更容易识别
1 parent b65e63a commit 3c01dad

10 files changed

Lines changed: 23 additions & 45 deletions

File tree

business/e2e-build/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const matman = require('../matman');
22

3-
function getClientScriptHandler(basePath, buildPath, regMatch) {
3+
function getClientScriptHandler(rootPath, buildPath, regMatch) {
44
const clientScript = new matman.ClientScript({
5-
basePath: basePath,
5+
rootPath: rootPath,
66
buildPath: buildPath,
77
regMatch: regMatch
88
});

business/local-server/config/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const path = require('path');
44
/**
55
* 获取最终的配置数据
66
* @param {Object | String} opts 用户传递过来的参数
7-
* @param {String} [opts.basePath] 项目根目录
7+
* @param {String} [opts.rootPath] 项目根目录
88
* @returns {Object}
99
*/
1010
function getConfigOpts(opts) {
@@ -29,9 +29,9 @@ function getConfigOpts(opts) {
2929
return null;
3030
}
3131

32-
// 如果没有 basePath,则将无法启动成功
33-
if (!configOpts.basePath) {
34-
console.error('Should define basePath!', opts, configOpts);
32+
// 如果没有 rootPath,则将无法启动成功
33+
if (!configOpts.rootPath) {
34+
console.error('Should define rootPath!', opts, configOpts);
3535
return null;
3636
}
3737

@@ -43,8 +43,8 @@ function getConfigOpts(opts) {
4343
}, configOpts.mocker);
4444
}
4545

46-
// 日志文件存储的路径,默认值为 ${basePath}/logs
47-
configOpts.LOG_PATH = configOpts.LOG_PATH || path.join(configOpts.basePath, 'logs');
46+
// 日志文件存储的路径,默认值为 ${rootPath}/logs
47+
configOpts.LOG_PATH = configOpts.LOG_PATH || path.join(configOpts.rootPath, 'logs');
4848

4949
// matman 启动之后的服务端口号,默认为 9527
5050
configOpts.port = configOpts.port || 9527;

business/local-server/plugins/mocker/router.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const HANDLER_NAME_FIELD = 'mockerName';
1313
module.exports = (router, entry) => {
1414
// 创建 MockerParser 对象
1515
const mockerParser = new MockerParser({
16-
basePath: matman.mockerUtil.getMockServerBasePath(entry.basePath, entry.mockServerPath),
17-
buildPath: matman.mockerUtil.getMockServerBuildPath(entry.basePath, entry.buildPath)
16+
basePath: matman.mockerUtil.getMockServerBasePath(entry.rootPath, entry.mockServerPath),
17+
buildPath: matman.mockerUtil.getMockServerBuildPath(entry.rootPath, entry.buildPath)
1818
});
1919

2020
// 获取所有的 mocker 列表

lib/internal/build/builder-webpack3/builder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ class Builder {
1818
* @desc 创建用于生产环境中的webpack打包配置
1919
*
2020
* @param {Object} params
21-
* @param {RegExp} params.basePath 项目根目录
21+
* @param {RegExp} params.rootPath 项目根目录
2222
* @param {RegExp} params.clientScriptMatch 正则表达式,用于匹配路径中那些文件是 client script
2323
* @param {Object} params.entry 传递给webpack 的 entry属性属性
2424
* @param {String} params.clientScriptBuildPath 输出打包后的 client script 的路径
2525
* @param {Object} opts
2626
* @example
2727
*/
2828
static createProdConfig(params = {}, opts = {}) {
29-
const clientScriptHandler = e2eBuild.getClientScriptHandler(params.basePath, params.clientScriptBuildPath, params.clientScriptMatch);
29+
const clientScriptHandler = e2eBuild.getClientScriptHandler(params.rootPath, params.clientScriptBuildPath, params.clientScriptMatch);
3030

3131
// 设置打包规则
3232
const prodRules = [];

lib/internal/build/utils/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ function getConfig(targetPath) {
5757
return fsHandler.handle.getModuleResult(configFile)
5858
.then((config) => {
5959

60-
// basePath 默认值为 matman.config.js 当前目录
61-
if (!config.basePath) {
62-
config.basePath = path.dirname(configFile);
60+
// rootPath 默认值为 matman.config.js 当前目录
61+
if (!config.rootPath) {
62+
config.rootPath = path.dirname(configFile);
6363
}
6464

6565
return config;

lib/internal/start/start.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ module.exports = function (args) {
2828

2929
let matmanConfig = require(configAbsolutePath);
3030

31-
// 如果不定义 basePath,则默认取 process.cwd()
32-
if (!matmanConfig.basePath) {
33-
matmanConfig.basePath = cwd;
34-
}
35-
36-
if (!matmanConfig.buildPath) {
37-
matmanConfig.buildPath = path.resolve(matmanConfig.basePath, './build');
31+
// 如果不定义 rootPath,则默认取 process.cwd()
32+
if (!matmanConfig.rootPath) {
33+
matmanConfig.rootPath = cwd;
3834
}
3935

4036
// 启动本地服务
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

test/data/demo_03/matman.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const path = require('path');
22

33
module.exports = {
4-
// basePath: __dirname,
5-
// dataPath: path.resolve(__dirname, './build'),
4+
// rootPath: __dirname,
5+
// buildPath: path.resolve(__dirname, './build'),
66
// mockServerPath: path.resolve(__dirname, '../../../../matman/test/data/fixtures/mock_server/mockers'),
77
mockServerPath: path.resolve(__dirname, '../../../../now-h5-weishi-redpacket/matman-app/src/mock_server/mockers'),
88
// clientScriptBuildPath: path.join(__dirname, 'dist-client-script'),

test/data/demo_99/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path');
22
const localServer = require('../../../business/local-server');
33

44
localServer.startServer({
5-
basePath: __dirname,
6-
dataPath: path.resolve(__dirname, './app'),
5+
rootPath: __dirname,
6+
buildPath: path.resolve(__dirname, './app'),
77
mockServerPath: path.resolve(__dirname, '../../../../matman/test/data/fixtures/mock_service/mockers'),
88
});

test/data/demo_99/pfork-script.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)