@tmsfe/tmskit 0.0.16 → 0.0.17
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 +40 -0
- package/README.md +2 -3
- package/dist/index.cjs.js +412 -315
- package/main.js +0 -0
- package/package.json +2 -2
- package/src/compile/dev.js +13 -12
- package/src/compile/plugins/mpJsonDep.js +1 -1
- package/src/core/buildAppJson.js +14 -17
- package/src/core/tmsMpconfig.js +22 -25
- package/src/entry.js +11 -0
- package/src/scripts/run/build/index.js +3 -0
- package/src/scripts/run/cloud/index.js +12 -0
- package/src/scripts/run/index.js +4 -0
package/main.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmsfe/tmskit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "tmskit",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"bin": {
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"lodash": "^4.17.21",
|
|
65
65
|
"metalsmith": "^2.3.0",
|
|
66
66
|
"miniprogram-ci": "1.4.13",
|
|
67
|
-
"moment": "^2.29.
|
|
67
|
+
"moment": "^2.29.2",
|
|
68
68
|
"object-assign": "^4.0.1",
|
|
69
69
|
"ora": "^5.1.0",
|
|
70
70
|
"plugin-error": "^1.0.0",
|
package/src/compile/dev.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const ora = require('ora');
|
|
4
|
+
const chalk = require('chalk');
|
|
4
5
|
const { parallel, series } = require('gulp');
|
|
5
6
|
const { resolve, mergeMap } = require('../utils/widgets');
|
|
6
7
|
const { buildOutputAppJson } = require('../core/buildAppJson');
|
|
@@ -37,17 +38,6 @@ function adaptPath(pathDir) {
|
|
|
37
38
|
}
|
|
38
39
|
module.exports = async (tmsConfig, newModules, isDev = true) => {
|
|
39
40
|
const compileTasksMap = new Map();
|
|
40
|
-
// 监听app.json
|
|
41
|
-
if (isDev) {
|
|
42
|
-
watch(
|
|
43
|
-
[resolve('app.json')],
|
|
44
|
-
{ ignoreInitial: false, events: watchEvents },
|
|
45
|
-
() => buildOutputAppJson(tmsConfig, newModules, isDev),
|
|
46
|
-
{ from: resolve(), to: resolve(tmsConfig.outputDir) },
|
|
47
|
-
);
|
|
48
|
-
} else {
|
|
49
|
-
buildOutputAppJson(tmsConfig, newModules, isDev);
|
|
50
|
-
}
|
|
51
41
|
|
|
52
42
|
// 监听根目录的文件
|
|
53
43
|
mergeMap(compileTasksMap, compile(tmsConfig, {
|
|
@@ -148,15 +138,25 @@ module.exports = async (tmsConfig, newModules, isDev = true) => {
|
|
|
148
138
|
}
|
|
149
139
|
async function end(cb) {
|
|
150
140
|
if (isDev) {
|
|
141
|
+
// 监听app.json
|
|
142
|
+
watch(
|
|
143
|
+
[resolve('app.json')],
|
|
144
|
+
{ ignoreInitial: false, events: watchEvents },
|
|
145
|
+
() => buildOutputAppJson(tmsConfig, newModules, isDev),
|
|
146
|
+
{ from: resolve(), to: resolve(tmsConfig.outputDir) },
|
|
147
|
+
);
|
|
148
|
+
// 监听其他文件
|
|
151
149
|
compileTasksMap.forEach(({ taskFn, module }, globValue) => {
|
|
152
150
|
watch(globValue, { ignoreInitial: true, events: watchEvents }, taskFn, module);
|
|
153
151
|
});
|
|
152
|
+
} else {
|
|
153
|
+
buildOutputAppJson(tmsConfig, newModules, isDev);
|
|
154
154
|
}
|
|
155
155
|
eTime = new Date().getTime() - sTime;
|
|
156
156
|
if (typeof tmsConfig?.hooks?.afterCompile === 'function') {
|
|
157
157
|
await tmsConfig?.hooks?.afterCompile({ isDev, tmsConfig, modules: newModules });
|
|
158
158
|
}
|
|
159
|
-
spinner.succeed(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`);
|
|
159
|
+
spinner.succeed(chalk.green(`首次编译完成, 耗时${eTime / 1000}s, 微信开发者工具打开项目即可预览。`));
|
|
160
160
|
spinner.stop();
|
|
161
161
|
cb();
|
|
162
162
|
}
|
|
@@ -165,5 +165,6 @@ module.exports = async (tmsConfig, newModules, isDev = true) => {
|
|
|
165
165
|
compileTasksMap.forEach(({ taskFn }) => {
|
|
166
166
|
compileTasks.push(taskFn);
|
|
167
167
|
});
|
|
168
|
+
// 一次性完成编译任务(编译完成后再添加watch任务-封装到end函数里面)
|
|
168
169
|
series(start, parallel(...compileTasks), end)();
|
|
169
170
|
};
|
|
@@ -49,7 +49,7 @@ function mpJsonDep(
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
// eslint-disable-next-line
|
|
52
|
-
const reg = new RegExp(`^(
|
|
52
|
+
const reg = new RegExp(`^(\./|\.\.\/)+.*\/${includeName}\/(.*)`);
|
|
53
53
|
const regRes = componentPath.match(reg) || [];
|
|
54
54
|
if (regRes[2]) {
|
|
55
55
|
const depDestPath = resolve(tmsConfig.outputDir, module.to, includeName, regRes[2]);
|
package/src/core/buildAppJson.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 生成编译后的app.json
|
|
3
3
|
*/
|
|
4
|
+
/* eslint-disable no-param-reassign */
|
|
4
5
|
const fs = require('fs');
|
|
5
6
|
const { MODULE_CONFIG_FILENAME, MODULE_CONFIG_INVALID_KEY } = require('../config/constant');
|
|
6
|
-
const { getModuleConfig
|
|
7
|
+
const { getModuleConfig } = require('./tmsMpconfig');
|
|
7
8
|
const { fail } = require('../utils/log');
|
|
8
9
|
const { resolve, isObject } = require('../utils/widgets');
|
|
9
10
|
const { handleError } = require('./handleError');
|
|
11
|
+
const { global } = require('../utils/global');
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* 更新appJson里面的主包配置
|
|
@@ -36,7 +38,6 @@ function updateMainPackages(appJson, mainPackages = []) {
|
|
|
36
38
|
|
|
37
39
|
// 去掉 subpackages 中的主包配置
|
|
38
40
|
const foundMainPackageNames = foundMainPackages.map(item => item.name);
|
|
39
|
-
// eslint-disable-next-line
|
|
40
41
|
appJson.subpackages = appJson.subpackages.filter(subpackage => !foundMainPackageNames.includes(subpackage.name));
|
|
41
42
|
|
|
42
43
|
return appJson;
|
|
@@ -62,17 +63,15 @@ const getAppJsonContent = (sourceAppJsonPath) => {
|
|
|
62
63
|
/**
|
|
63
64
|
* 更新app.json中的subpackages
|
|
64
65
|
* @param {Object} appJson
|
|
65
|
-
* @param {Object}
|
|
66
|
+
* @param {Object} modulesConfigs
|
|
66
67
|
*/
|
|
67
|
-
const updateSubpackages = (appJson,
|
|
68
|
+
const updateSubpackages = (appJson, modulesConfigs) => {
|
|
68
69
|
// eslint-disable-next-line
|
|
69
|
-
for (const
|
|
70
|
-
const moduleInfo = isObject(
|
|
71
|
-
|
|
72
|
-
const validModules = getValidModules(moduleInfo);
|
|
73
|
-
// eslint-disable-next-line
|
|
74
|
-
appJson.subpackages = appJson.subpackages.concat(validModules);
|
|
70
|
+
for (const modulePath in modulesConfigs) {
|
|
71
|
+
const moduleInfo = isObject(modulesConfigs[modulePath]) ? [modulesConfigs[modulePath]] : modulesConfigs[modulePath];
|
|
72
|
+
appJson.subpackages = appJson.subpackages.concat(moduleInfo);
|
|
75
73
|
}
|
|
74
|
+
appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name));
|
|
76
75
|
};
|
|
77
76
|
|
|
78
77
|
/**
|
|
@@ -105,9 +104,7 @@ const fixAppJson = (appJson) => {
|
|
|
105
104
|
if (['requiredBackgroundModes', 'embeddedAppIdList'].indexOf(key) > -1) {
|
|
106
105
|
// 提到appjson最上层处理
|
|
107
106
|
const preVal = appJson[key];
|
|
108
|
-
// eslint-disable-next-line
|
|
109
107
|
preVal ? appJson[key] = Array.from(new Set(preVal
|
|
110
|
-
// eslint-disable-next-line
|
|
111
108
|
.slice(0).concat(subp[key]))) : appJson[key] = subp[key].slice(0);
|
|
112
109
|
return;
|
|
113
110
|
}
|
|
@@ -115,7 +112,6 @@ const fixAppJson = (appJson) => {
|
|
|
115
112
|
if (invalidKeys.length) {
|
|
116
113
|
fail(`不支持分包${subp?.name}配置${invalidKeys.join(',')}\n`);
|
|
117
114
|
}
|
|
118
|
-
// eslint-disable-next-line
|
|
119
115
|
invalidKeys.concat(['requiredBackgroundModes', 'embeddedAppIdList']).forEach(k => delete subp[k]);
|
|
120
116
|
return subp;
|
|
121
117
|
});
|
|
@@ -130,7 +126,6 @@ const fixAppJson = (appJson) => {
|
|
|
130
126
|
if (pluginsErrMsg) {
|
|
131
127
|
fail(`plugins配置出现错误:${pluginsErrMsg}`);
|
|
132
128
|
}
|
|
133
|
-
// eslint-disable-next-line
|
|
134
129
|
appJson.subpackages = subps;
|
|
135
130
|
};
|
|
136
131
|
|
|
@@ -143,11 +138,11 @@ const fixAppJson = (appJson) => {
|
|
|
143
138
|
function buildOutputAppJson(tmsConfig, modules) {
|
|
144
139
|
try {
|
|
145
140
|
// 获取当前 modules 下的所有子模块的配置内容
|
|
146
|
-
const
|
|
141
|
+
const modulesConfigs = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME);
|
|
147
142
|
// 获取app.json的配置
|
|
148
143
|
const appJson = getAppJsonContent(resolve('./app.json'));
|
|
149
144
|
// 更新app.json中的subpackages
|
|
150
|
-
updateSubpackages(appJson,
|
|
145
|
+
updateSubpackages(appJson, modulesConfigs);
|
|
151
146
|
// 处理appJson中重复||冲突的地方
|
|
152
147
|
fixAppJson(appJson);
|
|
153
148
|
// 更新主包,需在subpackages处理完成后执行, pages/
|
|
@@ -155,7 +150,9 @@ function buildOutputAppJson(tmsConfig, modules) {
|
|
|
155
150
|
|
|
156
151
|
fs.writeFileSync(resolve(`${tmsConfig.outputDir}/app.json`), JSON.stringify(appJson, null, 2), 'utf8');
|
|
157
152
|
if (typeof tmsConfig?.hooks?.updateAppJson === 'function') {
|
|
158
|
-
tmsConfig?.hooks?.updateAppJson(
|
|
153
|
+
tmsConfig?.hooks?.updateAppJson({
|
|
154
|
+
tmsConfig, module, appJson, isDev: global.getData('isDev'),
|
|
155
|
+
});
|
|
159
156
|
}
|
|
160
157
|
|
|
161
158
|
return appJson;
|
package/src/core/tmsMpconfig.js
CHANGED
|
@@ -93,40 +93,38 @@ const checkModules = function (tmsConfig, modules, isQuit = false) {
|
|
|
93
93
|
return targetModules;
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
-
/**
|
|
97
|
-
* 过滤页面为空的分包
|
|
98
|
-
* @param {Array} moduleCfg 模块配置内容
|
|
99
|
-
* @returns pages不为空的分包
|
|
100
|
-
*/
|
|
101
|
-
const getValidModules = (moduleCfg) => {
|
|
102
|
-
// 过滤 pages 为空的情况
|
|
103
|
-
const validModules = moduleCfg.filter(item => item.pages.length > 0);
|
|
104
|
-
return validModules;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
96
|
/**
|
|
108
97
|
* 适配处理module.config.json的字段
|
|
109
98
|
* @param { object } fileContent module.config.json的内容
|
|
110
99
|
* @param { string } appName 小程序的名称
|
|
111
100
|
*/
|
|
112
101
|
function adaptMpCgContent(fileContent, appName) {
|
|
113
|
-
const
|
|
102
|
+
const handleContent = function (appName, current) {
|
|
103
|
+
let res = current;
|
|
104
|
+
if (appName && current.mpConfig && current.mpConfig[appName]) {
|
|
105
|
+
res = { ...current, ...current.mpConfig[appName] };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
delete res.mpConfig;
|
|
109
|
+
delete res.isSubpackages;
|
|
110
|
+
return res;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
let content = JSON.parse(fileContent);
|
|
114
114
|
|
|
115
115
|
if (isArray(content)) {
|
|
116
116
|
let i = content.length - 1;
|
|
117
117
|
while (i >= 0) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (appName && current.mpConfig && current.mpConfig[appName]) {
|
|
121
|
-
current = { ...current, ...current.mpConfig[appName] };
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
delete current.mpConfig;
|
|
125
|
-
delete current.isSubpackages;
|
|
126
|
-
|
|
127
|
-
content[i] = current;
|
|
118
|
+
content[i] = handleContent(appName, content[i]);
|
|
128
119
|
i--; // eslint-disable-line
|
|
129
120
|
}
|
|
121
|
+
} else {
|
|
122
|
+
if (appName && content.mpConfig && content.mpConfig[appName]) {
|
|
123
|
+
content = { ...content, ...content.mpConfig[appName] };
|
|
124
|
+
delete content.mpConfig;
|
|
125
|
+
delete content.isSubpackages;
|
|
126
|
+
}
|
|
127
|
+
content = handleContent(appName, content);
|
|
130
128
|
}
|
|
131
129
|
return content;
|
|
132
130
|
}
|
|
@@ -168,7 +166,7 @@ const tmsModulesMergeLocalModuleCfg = (modules, appName) => {
|
|
|
168
166
|
let moduleConfigContent = fs.readFileSync(moduleConfigPath, 'utf-8');
|
|
169
167
|
moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
|
|
170
168
|
const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
171
|
-
|
|
169
|
+
moduleContentArr.forEach(({ name }, moduleContentArrIndex) => {
|
|
172
170
|
if (name === moduleName) {
|
|
173
171
|
findModule = true;
|
|
174
172
|
newModules.push({
|
|
@@ -178,7 +176,7 @@ const tmsModulesMergeLocalModuleCfg = (modules, appName) => {
|
|
|
178
176
|
}
|
|
179
177
|
});
|
|
180
178
|
if (!findModule) {
|
|
181
|
-
fail(`启动模块${moduleName}在${moduleConfigPath}
|
|
179
|
+
fail(`启动模块${moduleName}在${moduleConfigPath}没有找到,请检查配置`);
|
|
182
180
|
process.exit(1);
|
|
183
181
|
}
|
|
184
182
|
} catch (e) {
|
|
@@ -232,7 +230,6 @@ module.exports = {
|
|
|
232
230
|
readTmsConfig,
|
|
233
231
|
readTmsPrivateCf,
|
|
234
232
|
getModuleConfig,
|
|
235
|
-
getValidModules,
|
|
236
233
|
checkModules,
|
|
237
234
|
tmsModulesMergeLocalModuleCfg,
|
|
238
235
|
subModulesMergeDepModules,
|
package/src/entry.js
CHANGED
|
@@ -34,6 +34,17 @@ module.exports = [
|
|
|
34
34
|
require('./scripts/run/index')('dev', cmd);
|
|
35
35
|
},
|
|
36
36
|
},
|
|
37
|
+
{
|
|
38
|
+
command: 'cloud',
|
|
39
|
+
description: '云函数开发',
|
|
40
|
+
options: [
|
|
41
|
+
['-m, --module [moduleName]', '模块名称'],
|
|
42
|
+
['-e, --env [env]', '环境变量'],
|
|
43
|
+
],
|
|
44
|
+
action: (cmd) => {
|
|
45
|
+
require('./scripts/run/index')('cloud', cmd);
|
|
46
|
+
},
|
|
47
|
+
},
|
|
37
48
|
{
|
|
38
49
|
command: 'build',
|
|
39
50
|
description: 'prod 打包编译',
|
|
@@ -9,6 +9,9 @@ async function build(tmsConfig, targetModules, env) {
|
|
|
9
9
|
|
|
10
10
|
const { targetModules: newModules } = await init(tmsConfig, targetModules);
|
|
11
11
|
|
|
12
|
+
if (typeof tmsConfig?.hooks?.beforeCompile === 'function') {
|
|
13
|
+
await tmsConfig?.hooks?.beforeCompile({ isDev: false, tmsConfig, modules: newModules });
|
|
14
|
+
};
|
|
12
15
|
compileBuild(tmsConfig, newModules, env);
|
|
13
16
|
}
|
|
14
17
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const { symLink } = require('../../../core/symbolicLink');
|
|
2
|
+
const { handleError } = require('../../../core/handleError');
|
|
3
|
+
const { succeed } = require('../../../utils/log');
|
|
4
|
+
|
|
5
|
+
module.exports = async (tmsConfig) => {
|
|
6
|
+
try {
|
|
7
|
+
await symLink(tmsConfig);
|
|
8
|
+
succeed('云函数创建软链成功');
|
|
9
|
+
} catch (e) {
|
|
10
|
+
handleError(`创建软链错误: ${e}`);
|
|
11
|
+
}
|
|
12
|
+
};
|
package/src/scripts/run/index.js
CHANGED
|
@@ -2,6 +2,7 @@ const init = require('./init/index');
|
|
|
2
2
|
const dev = require('./dev/index');
|
|
3
3
|
const build = require('./build/index');
|
|
4
4
|
const install = require('./install/index');
|
|
5
|
+
const cloud = require('./cloud/index');
|
|
5
6
|
const { global } = require('../../utils/global');
|
|
6
7
|
const {
|
|
7
8
|
readTmsConfig,
|
|
@@ -87,6 +88,9 @@ async function run(commandName, cmd) {
|
|
|
87
88
|
global.setData('isDev', true);
|
|
88
89
|
dev(tmsConfig, newModules, env);
|
|
89
90
|
return;
|
|
91
|
+
case 'cloud':
|
|
92
|
+
cloud(tmsConfig, env);
|
|
93
|
+
return;
|
|
90
94
|
case 'install':
|
|
91
95
|
install(tmsConfig, newModules, env);
|
|
92
96
|
return;
|