@zgfe/business-lib 1.1.45 → 1.1.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config.js +27 -7
- package/package.json +2 -2
package/config.js
CHANGED
|
@@ -6,14 +6,34 @@ const path = require('path');
|
|
|
6
6
|
* @param defaultConfig
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
|
-
function getConfig(defaultConfig) {
|
|
10
|
-
const configPath = path.resolve(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
function getConfig(defaultConfig, basePath) {
|
|
10
|
+
const configPath = path.resolve(basePath, '.config.json');
|
|
11
|
+
let resConfig = defaultConfig;
|
|
12
|
+
try {
|
|
13
|
+
if (fs.existsSync(configPath)) {
|
|
14
|
+
const config = fs.readFileSync(configPath, 'utf-8');
|
|
15
|
+
if (!config || config === '{}') {
|
|
16
|
+
throw new Error('配置文件为空');
|
|
17
|
+
}
|
|
18
|
+
const configObj = JSON.parse(config);
|
|
19
|
+
// 如果读取的配置文件,数据结构与默认配置不一致,则更新配置文件,更新规则:以默认配置为准,保留用户自定义配置
|
|
20
|
+
const isSame = Object.keys(defaultConfig).every((key) => {
|
|
21
|
+
return configObj.hasOwnProperty(key);
|
|
22
|
+
});
|
|
23
|
+
if (!isSame) {
|
|
24
|
+
resConfig = Object.assign({}, defaultConfig, configObj);
|
|
25
|
+
throw new Error('配置文件数据结构不一致');
|
|
26
|
+
}
|
|
27
|
+
resConfig = configObj;
|
|
28
|
+
} else {
|
|
29
|
+
throw new Error('配置文件不存在');
|
|
30
|
+
}
|
|
31
|
+
} catch (e) {
|
|
32
|
+
console.log(e.message);
|
|
33
|
+
fs.writeFileSync(configPath, JSON.stringify(resConfig, null, 2));
|
|
14
34
|
}
|
|
15
|
-
|
|
16
|
-
return
|
|
35
|
+
console.log('配置详情', resConfig);
|
|
36
|
+
return resConfig;
|
|
17
37
|
}
|
|
18
38
|
|
|
19
39
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgfe/business-lib",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.47",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"start": "dumi dev",
|
|
6
6
|
"docs:build": "dumi build",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"react": "^16.12.0 || ^17.0.0",
|
|
61
61
|
"yorkie": "^2.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "6a4976b13f69cc950fcfe71b494c1fde7499ac63"
|
|
64
64
|
}
|