Skip to content

Commit 234d565

Browse files
committed
🎨 去除 micro-app.config.js 的强依赖性.
1 parent 8365028 commit 234d565

19 files changed

Lines changed: 167 additions & 125 deletions

File tree

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ jobs:
2323
paths:
2424
- ./node_modules
2525
- run: yarn run test --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
26+
- run: rm -rf ./micro-app.config.js
27+
- run: yarn run test --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
2628

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019-present, Zyao89
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

config/default.js

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

libs/Config/base/BaseConfig.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ const fs = require('fs-extra');
55
const tryRequire = require('try-require');
66
const _ = require('lodash');
77

8-
const symbols = require('../../../config/symbols');
9-
const CONSTANTS = require('../../../config/constants');
8+
const symbols = require('../../Constants/symbols');
9+
const CONSTANTS = require('../../Constants');
1010
const logger = require('../../../src/utils/logger');
1111
const getPadLength = require('../../../src/utils/getPadLength');
1212

1313
// 默认配置
14-
const DEFAULT_CONFIG = require('../../../config/default');
14+
const DEFAULT_CONFIG = require('../../Constants/default');
1515

1616
const validate = require('../schema');
1717
const SCHEMA = require('../schema/configSchema');
@@ -50,9 +50,10 @@ class BaseConfig {
5050
this._package = require(packagePath);
5151
}
5252
} catch (error) {
53+
console.warn(config, error);
5354
this._packagePath = '';
5455
this._package = {};
55-
logger.warn('Not Fount "package.json" !');
56+
logger.warn(`Not Fount "${CONSTANTS.PACKAGE_JSON}" !`);
5657
}
5758
}
5859
}

libs/Config/base/BaseConfig.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* global expect */
44

55
const BaseConfig = require('./BaseConfig');
6-
const defaultConfig = require('../../../micro-app.config');
6+
const loadFile = require('../../../src/utils/loadFile');
77

88
const testConfig = {
99
shared: {
@@ -28,7 +28,8 @@ const testConfig = {
2828
describe('BaseConfig', () => {
2929

3030
it('new constructor', () => {
31-
const config = new BaseConfig(Object.assign({}, defaultConfig, testConfig));
31+
const defaultConfig = loadFile(__dirname, '../../Constants/default.js');
32+
const config = new BaseConfig(Object.assign(defaultConfig, testConfig));
3233

3334
expect(config.config).not.toBeNull();
3435
expect(config.root).not.toBeUndefined();
@@ -52,7 +53,8 @@ describe('BaseConfig', () => {
5253
});
5354

5455
it('config inspect', () => {
55-
const config = new BaseConfig(Object.assign({}, defaultConfig, testConfig));
56+
const defaultConfig = loadFile(__dirname, '../../Constants/default.js');
57+
const config = new BaseConfig(Object.assign(defaultConfig, testConfig));
5658

5759
expect(config.inspect).not.toBeNull();
5860
expect(config.inspect).not.toBeUndefined();

libs/Config/index.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
/* global expect */
44

55
const MicroAppConfig = require('./index');
6-
const defaultConfig = require('../../micro-app.config');
6+
const loadFile = require('../../src/utils/loadFile');
77

88
describe('MicroAppConfig', () => {
99

1010
it('new constructor', () => {
11+
const defaultConfig = loadFile(__dirname, '../Constants/default.js');
1112
const config = new MicroAppConfig(Object.assign({}, defaultConfig, {
1213

1314
}));
@@ -34,6 +35,7 @@ describe('MicroAppConfig', () => {
3435
});
3536

3637
it('new constructor Config', () => {
38+
const defaultConfig = loadFile(__dirname, '../Constants/default.js');
3739
const config = new MicroAppConfig(Object.assign({}, defaultConfig, {
3840

3941
}));
@@ -55,6 +57,7 @@ describe('MicroAppConfig', () => {
5557
});
5658

5759
it('new constructor others', () => {
60+
const defaultConfig = loadFile(__dirname, '../Constants/default.js');
5861
const config = new MicroAppConfig(Object.assign({}, defaultConfig, {
5962
entry: {
6063
main: [ './test/index.js' ],

libs/Constants/default.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
'use strict';
2+
3+
module.exports = {
4+
name: '', // 名称, 为空则使用 package.json 中的 name
5+
description: '', // 描述
6+
version: '0.0.1', // 版本
7+
type: '', // types 类型
8+
strict: true, // 是否为严格模式? 默认为 true - 强依赖
9+
10+
// entry: { // 入口
11+
// },
12+
13+
// htmls: [
14+
// {
15+
// template: '',
16+
// },
17+
// ], // 模版
18+
19+
// staticPath: [], // String | Array
20+
21+
// dlls: [
22+
// { // dll 基本配置, [ 只支持子模块中使用 ]
23+
// disabled: false,
24+
// context: '',
25+
// manifest: '',
26+
// filepath: '',
27+
// },
28+
// ],
29+
30+
alias: { // 共享别名
31+
// api: './client/api.js', // 默认为前后端通用
32+
// service: {
33+
// link: './server/service.js',
34+
// type: 'server', // 只支持后端
35+
// },
36+
},
37+
38+
// micros: [ // 需要注入的子模块
39+
// 'test'
40+
// ],
41+
42+
// 服务端配置
43+
// server: {
44+
// hooks: '', // 服务端 hook 路径
45+
// entry: '', // 服务端入口
46+
// host: ‘’, // 服务 IP
47+
// port: 8888, // 服务端口号
48+
// options: { }, // 服务端注入附加参数
49+
50+
// proxy: { // 服务代理
51+
// '/api': {
52+
// target: 'http://127.0.0.1', // target host
53+
// changeOrigin: true, // needed for virtual hosted sites
54+
// ws: true, // proxy websockets
55+
// },
56+
// },
57+
// },
58+
59+
// 一些插件配置项 (弃用)
60+
// plugin: {
61+
// ReplaceFileNotExists: {
62+
// debug: false, // 开启log
63+
// warnHint: 'Not Found',
64+
// loader: '', // 路径
65+
// resource: '', // 路径
66+
// test: /^@micros\//i, // 匹配规则
67+
// },
68+
// SpeedMeasurePlugin: {
69+
// disabled: true,
70+
// },
71+
// HappyPack: {
72+
// disabled: true,
73+
// },
74+
// },
75+
76+
// plugins: [ // 插件集
77+
// [
78+
// '', {},
79+
// ],
80+
// ],
81+
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const pkg = require('../package.json');
3+
const pkg = require('../../package.json');
44

55
module.exports = {
66
NAME: 'Micro App',

libs/Service/base/BaseAPI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const semver = require('semver');
44
const logger = require('../../../src/utils/logger');
5-
const CONSTANTS = require('../../../config/constants');
5+
const CONSTANTS = require('../../../libs/Constants');
66

77
class BaseAPI {
88

0 commit comments

Comments
 (0)