@tmsfe/tmskit 0.0.48 → 0.0.52
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/CHANGELOG.md +65 -0
- package/dist/index.cjs.js +938 -475
- package/package.json +2 -2
- package/src/core/buildAppJson.js +5 -0
- package/src/core/handleAgentConfig.js +64 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmsfe/tmskit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.52",
|
|
4
4
|
"description": "tmskit",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"bin": {
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"lodash": "^4.17.21",
|
|
60
60
|
"metalsmith": "^2.3.0",
|
|
61
61
|
"minimatch": "^5.1.0",
|
|
62
|
-
"miniprogram-ci": "
|
|
62
|
+
"miniprogram-ci": "1.8.25",
|
|
63
63
|
"moment": "^2.29.2",
|
|
64
64
|
"object-assign": "^4.0.1",
|
|
65
65
|
"ora": "^5.4.1",
|
package/src/core/buildAppJson.js
CHANGED
|
@@ -10,6 +10,7 @@ const { resolve, filterField } = require('../utils/widgets');
|
|
|
10
10
|
const { handleError } = require('./handleError');
|
|
11
11
|
const { global } = require('../utils/global');
|
|
12
12
|
const report = require('../core/report');
|
|
13
|
+
const { handleAgentConfig, handleProjectConfigInclude } = require('./handleAgentConfig');
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -191,6 +192,10 @@ async function buildOutputAppJson(tmsConfig, modules) {
|
|
|
191
192
|
|
|
192
193
|
// 处理appJson中重复||冲突的地方
|
|
193
194
|
fixAppJson(appJson);
|
|
195
|
+
// 处理 agent 配置:根据是否包含 meta-services 分包来添加或删除
|
|
196
|
+
handleAgentConfig(appJson);
|
|
197
|
+
// 处理 project.config.json 中的 packOptions.include 配置
|
|
198
|
+
handleProjectConfigInclude(appJson, tmsConfig.outputDir);
|
|
194
199
|
// 更新主包,需在subpackages处理完成后执行, pages/
|
|
195
200
|
updateMainPackages(appJson, tmsConfig.mainPackages);
|
|
196
201
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const { resolve } = require('../utils/widgets');
|
|
2
|
+
const { info } = require('../utils/log');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
|
|
5
|
+
/* eslint-disable no-param-reassign */
|
|
6
|
+
/**
|
|
7
|
+
* 检查是否包含 meta-services 分包
|
|
8
|
+
* @param {Object} appJson app.json配置对象
|
|
9
|
+
* @returns {boolean}
|
|
10
|
+
*/
|
|
11
|
+
function hasMetaServicesSubpackage(appJson) {
|
|
12
|
+
return appJson.subpackages.some(s => s.root === 'modules/meta-services' || s.name === 'meta-services');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 处理 agent 配置:根据是否包含 meta-services 分包来添加或删除 agent 配置
|
|
17
|
+
* @param {Object} appJson app.json配置对象
|
|
18
|
+
*/
|
|
19
|
+
export function handleAgentConfig(appJson) {
|
|
20
|
+
const hasMetaServices = hasMetaServicesSubpackage(appJson);
|
|
21
|
+
console.log('🔍', hasMetaServices ? '包含' : '不包含', 'meta-services 分包');
|
|
22
|
+
if (hasMetaServices) {
|
|
23
|
+
if (!appJson.agent) {
|
|
24
|
+
try {
|
|
25
|
+
appJson.agent = require(resolve('./agentConfig.json'));
|
|
26
|
+
info('已从 agentConfig.json 加载 agent 配置');
|
|
27
|
+
} catch (error) {
|
|
28
|
+
info('未找到 agentConfig.json,删除 agent 配置');
|
|
29
|
+
delete appJson.agent;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
} else if (appJson.agent) {
|
|
33
|
+
delete appJson.agent;
|
|
34
|
+
info('已移除 agent 配置');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 处理 project.config.json 中的 packOptions.include 配置
|
|
40
|
+
* @param {Object} appJson app.json配置对象
|
|
41
|
+
* @param {string} outputDir 输出目录
|
|
42
|
+
*/
|
|
43
|
+
export function handleProjectConfigInclude(appJson, outputDir) {
|
|
44
|
+
const projectConfigPath = resolve(outputDir, 'project.config.json');
|
|
45
|
+
if (!fs.existsSync(projectConfigPath)) return;
|
|
46
|
+
|
|
47
|
+
const projectConfig = require(projectConfigPath);
|
|
48
|
+
const hasMetaServices = hasMetaServicesSubpackage(appJson);
|
|
49
|
+
|
|
50
|
+
if (!projectConfig.packOptions) projectConfig.packOptions = {};
|
|
51
|
+
if (!projectConfig.packOptions.include) projectConfig.packOptions.include = [];
|
|
52
|
+
|
|
53
|
+
const existingIndex = projectConfig.packOptions.include.findIndex(item => item.type === 'folder' && item.value === 'modules/meta-services');
|
|
54
|
+
|
|
55
|
+
if (hasMetaServices && existingIndex === -1) {
|
|
56
|
+
projectConfig.packOptions.include.push({ type: 'folder', value: 'modules/meta-services' });
|
|
57
|
+
info('已添加 meta-services 到 project.config.json');
|
|
58
|
+
} else if (!hasMetaServices && existingIndex !== -1) {
|
|
59
|
+
projectConfig.packOptions.include.splice(existingIndex, 1);
|
|
60
|
+
info('已从 project.config.json 移除 meta-services');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fs.writeFileSync(projectConfigPath, JSON.stringify(projectConfig, null, 2));
|
|
64
|
+
}
|