@tmsfe/tmskit 0.0.23 → 0.0.24-beta.0
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 +1 -1
- package/dist/index.cjs.js +739 -390
- package/package.json +2 -2
- package/src/.DS_Store +0 -0
- package/src/compile/dev.js +4 -2
- package/src/compile/watch.js +1 -0
- package/src/config/defaultTmsConfig.js +24 -0
- package/src/core/buildAppJson.js +1 -0
- package/src/core/cache.js +36 -0
- package/src/core/cloneModules.js +3 -3
- package/src/core/mpCi.js +62 -14
- package/src/core/report.js +2 -7
- package/src/core/tmsMpconfig.js +4 -19
- package/src/entry.js +35 -10
- package/src/scripts/.DS_Store +0 -0
- package/src/scripts/run/build/index.js +8 -3
- package/src/scripts/run/cloud/index.js +1 -1
- package/src/scripts/run/dev/index.js +4 -3
- package/src/scripts/run/index.js +18 -8
- package/src/scripts/run/preview/index.js +70 -0
- package/src/scripts/run/preview/utils.js +43 -0
- package/src/scripts/run/upload/index.js +65 -0
- package/src/utils/widgets.js +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmsfe/tmskit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24-beta.0",
|
|
4
4
|
"description": "tmskit",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"bin": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"lodash": "^4.17.21",
|
|
56
56
|
"metalsmith": "^2.3.0",
|
|
57
57
|
"minimatch": "^5.1.0",
|
|
58
|
-
"miniprogram-ci": "1.
|
|
58
|
+
"miniprogram-ci": "1.8.25",
|
|
59
59
|
"moment": "^2.29.2",
|
|
60
60
|
"object-assign": "^4.0.1",
|
|
61
61
|
"ora": "^5.1.0",
|
package/src/.DS_Store
ADDED
|
Binary file
|
package/src/compile/dev.js
CHANGED
|
@@ -10,6 +10,7 @@ const compile = require('./compile');
|
|
|
10
10
|
const watch = require('./watch');
|
|
11
11
|
const { info } = require('../utils/log');
|
|
12
12
|
const report = require('../core/report');
|
|
13
|
+
const { global } = require('../utils/global');
|
|
13
14
|
|
|
14
15
|
const watchEvents = ['add', 'change', 'unlink', 'addDir', 'unlinkDir'];
|
|
15
16
|
|
|
@@ -113,11 +114,12 @@ module.exports = async (tmsConfig, modules, isDev = true) => {
|
|
|
113
114
|
buildOutputAppJson(tmsConfig, modules, isDev);
|
|
114
115
|
}
|
|
115
116
|
eTime = new Date().getTime() - sTime;
|
|
116
|
-
if (typeof tmsConfig?.hooks?.
|
|
117
|
-
await tmsConfig?.hooks?.
|
|
117
|
+
if (typeof tmsConfig?.hooks?.afterFirstCompile === 'function') {
|
|
118
|
+
await tmsConfig?.hooks?.afterFirstCompile({
|
|
118
119
|
isDev,
|
|
119
120
|
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
120
121
|
modules,
|
|
122
|
+
cmdOptions: global.getData('cmdOptions'),
|
|
121
123
|
});
|
|
122
124
|
report('hooks:afterCompile');
|
|
123
125
|
}
|
package/src/compile/watch.js
CHANGED
|
@@ -107,6 +107,7 @@ async function updateFileHook(tmsConfig, sourceFile, targetFile, type) {
|
|
|
107
107
|
if (typeof tmsConfig?.hooks?.updateFile === 'function') {
|
|
108
108
|
await tmsConfig.hooks.updateFile({
|
|
109
109
|
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
110
|
+
cmdOptions: global.getData('cmdOptions'),
|
|
110
111
|
sourceFile,
|
|
111
112
|
targetFile,
|
|
112
113
|
type,
|
|
@@ -13,4 +13,28 @@ module.exports = {
|
|
|
13
13
|
sourceDir: './',
|
|
14
14
|
/** 静态资源目录 */
|
|
15
15
|
static: [],
|
|
16
|
+
/** 上传是的配置 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E7%BC%96%E8%AF%91%E8%AE%BE%E7%BD%AE */
|
|
17
|
+
upload: {
|
|
18
|
+
setting: {
|
|
19
|
+
es6: true,
|
|
20
|
+
es7: true,
|
|
21
|
+
minify: true,
|
|
22
|
+
minifyJS: true,
|
|
23
|
+
minifyWXML: true,
|
|
24
|
+
minifyWXSS: true,
|
|
25
|
+
autoPrefixWXSS: true,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
/** 预览的配置 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E9%A2%84%E8%A7%88 */
|
|
29
|
+
preview: {
|
|
30
|
+
setting: {
|
|
31
|
+
es6: true,
|
|
32
|
+
es7: true,
|
|
33
|
+
minify: true,
|
|
34
|
+
minifyJS: true,
|
|
35
|
+
minifyWXML: true,
|
|
36
|
+
minifyWXSS: true,
|
|
37
|
+
autoPrefixWXSS: true,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
16
40
|
};
|
package/src/core/buildAppJson.js
CHANGED
|
@@ -143,6 +143,7 @@ function buildOutputAppJson(tmsConfig, modules) {
|
|
|
143
143
|
if (typeof tmsConfig?.hooks?.updateAppJson === 'function') {
|
|
144
144
|
tmsConfig?.hooks?.updateAppJson({
|
|
145
145
|
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
146
|
+
cmdOptions: global.getData('cmdOptions'),
|
|
146
147
|
modules,
|
|
147
148
|
appJson,
|
|
148
149
|
isDev: global.getData('isDev'),
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { CACHE_FILE, CACHE_DIR } = require('../config/constant');
|
|
4
|
+
const { ensureDirExist } = require('../utils/io');
|
|
5
|
+
|
|
6
|
+
function getCache(projectDir, type) {
|
|
7
|
+
const filePath = `${CACHE_DIR}/${CACHE_FILE}`;
|
|
8
|
+
if (!fs.existsSync(filePath)) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const content = require(filePath);
|
|
12
|
+
return content?.[projectDir]?.[type];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
function setCache(projectDir, type = 'miniprogram_npm', data) {
|
|
17
|
+
const filePath = `${CACHE_DIR}/${CACHE_FILE}`;
|
|
18
|
+
if (!fs.existsSync(filePath)) {
|
|
19
|
+
const dir = path.dirname(filePath);
|
|
20
|
+
ensureDirExist(dir);
|
|
21
|
+
fs.writeFileSync(filePath, '{}');
|
|
22
|
+
}
|
|
23
|
+
const content = require(filePath);
|
|
24
|
+
if (!content[projectDir]) {
|
|
25
|
+
content[projectDir] = {};
|
|
26
|
+
}
|
|
27
|
+
content[projectDir] = {
|
|
28
|
+
[type]: data,
|
|
29
|
+
};
|
|
30
|
+
fs.writeFileSync(filePath, JSON.stringify(content, null, 2));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = {
|
|
34
|
+
setCache,
|
|
35
|
+
getCache,
|
|
36
|
+
};
|
package/src/core/cloneModules.js
CHANGED
|
@@ -21,7 +21,8 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
|
|
|
21
21
|
const tmsConfig = global.getData('tmsConfig');
|
|
22
22
|
|
|
23
23
|
let gitUrl = httpRepoUrl;
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
const { username = '', pass = '' } = tmsConfig?.gitAccount?.[moduleName] || tmsConfig?.gitAccount?.[httpRepoUrl] || {};
|
|
25
26
|
|
|
26
27
|
const urlPrefixReg = /http(s)?:\/\//;
|
|
27
28
|
if (username && pass && urlPrefixReg.test(gitUrl)) {
|
|
@@ -150,7 +151,6 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
150
151
|
]);
|
|
151
152
|
},
|
|
152
153
|
};
|
|
153
|
-
|
|
154
154
|
if (downloadTasksMap.has(sourcePath)) {
|
|
155
155
|
const task = downloadTasksMap.get(sourcePath);
|
|
156
156
|
task.callbacks.push(callback);
|
|
@@ -159,7 +159,7 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
|
|
|
159
159
|
let promiseTask;
|
|
160
160
|
if (fs.existsSync(sourcePath) && fs.existsSync(`${sourcePath}/.git`)) {
|
|
161
161
|
promiseTask = (gitUrl, sourcePath, branch, httpRepoUrl) => {
|
|
162
|
-
info(`git pull:${httpRepoUrl}`);
|
|
162
|
+
info(`git pull:${httpRepoUrl} --branch: ${branch}`);
|
|
163
163
|
return pullRepoForGit(sourcePath, branch);
|
|
164
164
|
};
|
|
165
165
|
} else {
|
package/src/core/mpCi.js
CHANGED
|
@@ -6,8 +6,8 @@ const path = require('path');
|
|
|
6
6
|
* @returns {Object} 小程序ci对象
|
|
7
7
|
*/
|
|
8
8
|
const getMpCi = ({ appId, projectPath, type = 'miniProgram', privateKey = 'TODO' }) => {
|
|
9
|
-
const
|
|
10
|
-
const ignores =
|
|
9
|
+
const projectCg = require(path.join(projectPath, 'project.config.json'));
|
|
10
|
+
const ignores = projectCg?.packOptions?.ignore?.map(({ value }) => value) || [];
|
|
11
11
|
|
|
12
12
|
return new ci.Project({
|
|
13
13
|
appid: appId,
|
|
@@ -18,14 +18,6 @@ const getMpCi = ({ appId, projectPath, type = 'miniProgram', privateKey = 'TODO'
|
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
// 用小程序ci工具构建小程序
|
|
23
|
-
const packMpProject = async (project) => {
|
|
24
|
-
await ci.packNpm(project, {
|
|
25
|
-
ignores: ['cloud/**/*'],
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
|
|
29
21
|
/**
|
|
30
22
|
* 格式化构建npm结果信息
|
|
31
23
|
* @param {Array<String>} warning 构建时的告警信息
|
|
@@ -43,21 +35,27 @@ const formatPackNpmWarning = (warning) => {
|
|
|
43
35
|
};
|
|
44
36
|
|
|
45
37
|
/**
|
|
46
|
-
* 构建miniprogram_npm
|
|
47
|
-
*
|
|
38
|
+
* 构建miniprogram_npm https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E6%9E%84%E5%BB%BAnpm
|
|
39
|
+
* * @param {object} {
|
|
40
|
+
* appId,
|
|
41
|
+
* peojectPath,
|
|
42
|
+
* privateKey,
|
|
43
|
+
* }
|
|
48
44
|
*/
|
|
49
45
|
const buildMpNpm = async ({
|
|
50
46
|
appId,
|
|
51
47
|
projectPath,
|
|
52
48
|
privateKey,
|
|
53
49
|
}) => {
|
|
54
|
-
const mpCi =
|
|
50
|
+
const mpCi = getMpCi({
|
|
55
51
|
appId,
|
|
56
52
|
projectPath,
|
|
57
53
|
privateKey,
|
|
58
54
|
});
|
|
59
55
|
|
|
60
|
-
const packNpmWarning = await
|
|
56
|
+
const packNpmWarning = await ci.packNpm(mpCi, {
|
|
57
|
+
ignores: ['cloud/**/*'],
|
|
58
|
+
});
|
|
61
59
|
|
|
62
60
|
const packNpmMsg = formatPackNpmWarning(packNpmWarning);
|
|
63
61
|
if (packNpmMsg) {
|
|
@@ -67,7 +65,57 @@ const buildMpNpm = async ({
|
|
|
67
65
|
return Promise.resolve();
|
|
68
66
|
};
|
|
69
67
|
|
|
68
|
+
/**
|
|
69
|
+
* 预览小程序码 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E9%A2%84%E8%A7%88
|
|
70
|
+
* @param {object} {
|
|
71
|
+
* appId,
|
|
72
|
+
* peojectPath,
|
|
73
|
+
* privateKey,
|
|
74
|
+
* desc
|
|
75
|
+
* robot
|
|
76
|
+
* }
|
|
77
|
+
*/
|
|
78
|
+
const previewMp = async (params = {}) => {
|
|
79
|
+
const { appId, projectPath, privateKey, ...resetParams } = params;
|
|
80
|
+
const mpCi = await getMpCi({
|
|
81
|
+
appId,
|
|
82
|
+
projectPath,
|
|
83
|
+
privateKey,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return await ci.preview({
|
|
87
|
+
project: mpCi,
|
|
88
|
+
...resetParams,
|
|
89
|
+
onProgressUpdate: () => {},
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 上传小程序 https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html#%E4%B8%8A%E4%BC%A0
|
|
95
|
+
* @param {object} {
|
|
96
|
+
* appId,
|
|
97
|
+
* peojectPath,
|
|
98
|
+
* privateKey,
|
|
99
|
+
* version,
|
|
100
|
+
* desc
|
|
101
|
+
* }
|
|
102
|
+
*/
|
|
103
|
+
const uploadMp = async (params = {}) => {
|
|
104
|
+
const { appId, projectPath, privateKey, ...resetParams } = params;
|
|
105
|
+
const mpCi = await getMpCi({
|
|
106
|
+
appId,
|
|
107
|
+
projectPath,
|
|
108
|
+
privateKey,
|
|
109
|
+
});
|
|
110
|
+
return await ci.upload({
|
|
111
|
+
project: mpCi,
|
|
112
|
+
...resetParams,
|
|
113
|
+
onProgressUpdate: () => {},
|
|
114
|
+
});
|
|
115
|
+
};
|
|
70
116
|
|
|
71
117
|
module.exports = {
|
|
72
118
|
buildMpNpm,
|
|
119
|
+
previewMp,
|
|
120
|
+
uploadMp,
|
|
73
121
|
};
|
package/src/core/report.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
const request = require('request');
|
|
2
|
-
const
|
|
2
|
+
const { getGitUser } = require('../utils/widgets');
|
|
3
3
|
const apiUrl = 'https://tim.map.qq.com/basic/tmskit/upload';
|
|
4
4
|
|
|
5
|
-
function getGitUser() {
|
|
6
|
-
const res = shelljs.exec('git config user.name', { async: false, silent: true });
|
|
7
|
-
return res.stdout;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
5
|
const report = (name, attrs = {}) => {
|
|
11
6
|
try {
|
|
12
7
|
const param = [];
|
|
@@ -19,7 +14,7 @@ const report = (name, attrs = {}) => {
|
|
|
19
14
|
if (!param[i]) param[i] = null;
|
|
20
15
|
};
|
|
21
16
|
|
|
22
|
-
request.post({ url: apiUrl, json: { param } });
|
|
17
|
+
request.post({ url: apiUrl, json: { param } }, () => {});
|
|
23
18
|
// (error, response, body) => {
|
|
24
19
|
// console.log('body:', body);
|
|
25
20
|
// }
|
package/src/core/tmsMpconfig.js
CHANGED
|
@@ -118,20 +118,8 @@ function adaptMpCgContent(fileContent, appName) {
|
|
|
118
118
|
return content;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
const adaptDependencies = function (dependencies, subPackages) {
|
|
122
|
-
const newDependencies = dependencies || [];
|
|
123
|
-
subPackages.forEach((item) => {
|
|
124
|
-
if (item.dependencies) {
|
|
125
|
-
dependencies = newDependencies.concat(item.dependencies);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
return newDependencies;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
121
|
const adaptSubPackages = function (moduleConfig, appName) {
|
|
132
|
-
const subPackages =
|
|
133
|
-
? moduleConfig.subPackages
|
|
134
|
-
: isObject(moduleConfig) ? [moduleConfig] : moduleConfig;
|
|
122
|
+
const { subPackages } = moduleConfig;
|
|
135
123
|
return adaptMpCgContent(subPackages, appName);
|
|
136
124
|
};
|
|
137
125
|
|
|
@@ -153,11 +141,9 @@ function getModulesConfig(modules = [], appName) {
|
|
|
153
141
|
|
|
154
142
|
// 兼容历史逻辑,后续可删除--- start
|
|
155
143
|
const subPackages = adaptSubPackages(moduleConfig, appName);
|
|
156
|
-
const dependencies = adaptDependencies(moduleConfig.dependencies, subPackages);
|
|
157
144
|
moduleConfig = {
|
|
158
145
|
...(isObject(moduleConfig) ? moduleConfig : {}),
|
|
159
146
|
subPackages,
|
|
160
|
-
dependencies,
|
|
161
147
|
};
|
|
162
148
|
// 兼容逻辑--- end
|
|
163
149
|
modulesConfig.push(moduleConfig);
|
|
@@ -210,10 +196,6 @@ const getSubPackageSrcPath = function (tmsConfig, module, subPackage) {
|
|
|
210
196
|
const checkModuleItem = (tmsConfig, tmsModuleItem, moduleConfig) => {
|
|
211
197
|
const newModuleItem = { ...tmsModuleItem, ...moduleConfig };
|
|
212
198
|
|
|
213
|
-
// 兼容逻辑
|
|
214
|
-
if (!newModuleItem.moduleName) newModuleItem.moduleName = newModuleItem.name;
|
|
215
|
-
delete newModuleItem.name;
|
|
216
|
-
|
|
217
199
|
// 参数校验-模块源码路径
|
|
218
200
|
if (!newModuleItem.path) {
|
|
219
201
|
throw new Error(`${newModuleItem.moduleName}模块没有找到path字段,请检查tms.config.js的modules.all>module>path路径`);
|
|
@@ -250,6 +232,9 @@ const getModulesByMergeDepModules = (tmsConfig, modules, errorIsQuit = false) =>
|
|
|
250
232
|
const allModules = new Map();
|
|
251
233
|
function dfs(tmsConfig, modules) {
|
|
252
234
|
modules.forEach((moduleItem) => {
|
|
235
|
+
if (!moduleItem.path) {
|
|
236
|
+
throw new Error(`${moduleItem.moduleName}模块没有找到path字段,请检查tms.config.js的modules.all>module>path路径`);
|
|
237
|
+
}
|
|
253
238
|
const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
|
|
254
239
|
if (!fs.existsSync(moduleConfigPath)) {
|
|
255
240
|
if (!allModules.has(moduleItem.moduleName)) {
|
package/src/entry.js
CHANGED
|
@@ -12,9 +12,9 @@ module.exports = [
|
|
|
12
12
|
options: [
|
|
13
13
|
['--registry [registry]', 'npm源'],
|
|
14
14
|
],
|
|
15
|
-
action: (npmName,
|
|
15
|
+
action: (npmName, cmdOptions) => {
|
|
16
16
|
const res = require('./scripts/extend-cmd');
|
|
17
|
-
res.installCmd(npmName,
|
|
17
|
+
res.installCmd(npmName, cmdOptions);
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
{
|
|
@@ -29,8 +29,8 @@ module.exports = [
|
|
|
29
29
|
['-m, --module [moduleName]', '模块名称'],
|
|
30
30
|
['-e, --env [env]', '环境变量'],
|
|
31
31
|
],
|
|
32
|
-
action: (
|
|
33
|
-
require('./scripts/run/index')('install',
|
|
32
|
+
action: (cmdOptions) => {
|
|
33
|
+
require('./scripts/run/index')('install', cmdOptions);
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
36
|
{
|
|
@@ -41,8 +41,8 @@ module.exports = [
|
|
|
41
41
|
['-e, --env [env]', '环境变量'],
|
|
42
42
|
['-noCache, --noCache', '不使用缓存功能'],
|
|
43
43
|
],
|
|
44
|
-
action: (
|
|
45
|
-
require('./scripts/run/index')('dev',
|
|
44
|
+
action: (cmdOptions) => {
|
|
45
|
+
require('./scripts/run/index')('dev', cmdOptions);
|
|
46
46
|
},
|
|
47
47
|
},
|
|
48
48
|
{
|
|
@@ -52,8 +52,8 @@ module.exports = [
|
|
|
52
52
|
['-m, --module [moduleName]', '模块名称'],
|
|
53
53
|
['-e, --env [env]', '环境变量'],
|
|
54
54
|
],
|
|
55
|
-
action: (
|
|
56
|
-
require('./scripts/run/index')('cloud',
|
|
55
|
+
action: (cmdOptions) => {
|
|
56
|
+
require('./scripts/run/index')('cloud', cmdOptions);
|
|
57
57
|
},
|
|
58
58
|
},
|
|
59
59
|
{
|
|
@@ -63,8 +63,33 @@ module.exports = [
|
|
|
63
63
|
['-m, --module [moduleName]', '模块名称'],
|
|
64
64
|
['-e, --env [env]', '环境变量'],
|
|
65
65
|
],
|
|
66
|
-
action: (
|
|
67
|
-
require('./scripts/run/index')('build',
|
|
66
|
+
action: (cmdOptions) => {
|
|
67
|
+
require('./scripts/run/index')('build', cmdOptions);
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
command: 'preview',
|
|
72
|
+
description: '小程序预览',
|
|
73
|
+
options: [
|
|
74
|
+
['-f, --qrcodeFormat [qrcodeFormat]', '二维码的格式,选项terminal, image, base64。默认terminal'],
|
|
75
|
+
['-o, --qrcodeOutputDest [qrcodeOutputDest]', '二维码会被输出到给定路径'],
|
|
76
|
+
['-i, --info-output [infoOutput]', '相关信息会被输出到给定路径'],
|
|
77
|
+
],
|
|
78
|
+
action: (cmdOptions) => {
|
|
79
|
+
require('./scripts/run/index')('preview', cmdOptions);
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
command: 'upload',
|
|
84
|
+
description: '小程序上传',
|
|
85
|
+
options: [
|
|
86
|
+
['-version, --version [version]', '上传代码版本,version 指定版本号'],
|
|
87
|
+
['-d, --desc [desc]', '上传代码时的备注'],
|
|
88
|
+
['-i, --info-output [infoOutput]', '相关信息会被输出到给定路径'],
|
|
89
|
+
['-r, --robot [robot]', '指定使用哪一个 ci 机器人,可选值:1 ~ 30'],
|
|
90
|
+
],
|
|
91
|
+
action: (cmdOptions) => {
|
|
92
|
+
require('./scripts/run/index')('upload', cmdOptions);
|
|
68
93
|
},
|
|
69
94
|
},
|
|
70
95
|
],
|
|
Binary file
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
const shelljs = require('shelljs');
|
|
2
2
|
const { resolve, filterField } = require('../../../utils/widgets');
|
|
3
3
|
const init = require('../init/index');
|
|
4
|
+
const { info } = require('../../../utils/log');
|
|
4
5
|
const compileBuild = require('../../../compile/build');
|
|
5
6
|
const report = require('../../../core/report');
|
|
7
|
+
const { global } = require('../../../utils/global');
|
|
6
8
|
|
|
7
9
|
async function build(tmsConfig, targetModules) {
|
|
8
10
|
// 开始构建前,清理输出目录
|
|
9
11
|
await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
|
|
10
12
|
|
|
11
13
|
const { modules: newModules } = await init(tmsConfig, targetModules);
|
|
14
|
+
info('当前build有效模块', newModules.map(item => item.moduleName).sort());
|
|
12
15
|
|
|
13
16
|
const isDev = false;
|
|
14
|
-
if (typeof tmsConfig?.hooks?.
|
|
15
|
-
await tmsConfig?.hooks?.
|
|
17
|
+
if (typeof tmsConfig?.hooks?.beforeFirstCompile === 'function') {
|
|
18
|
+
await tmsConfig?.hooks?.beforeFirstCompile({
|
|
16
19
|
isDev,
|
|
17
20
|
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
18
|
-
modules: newModules
|
|
21
|
+
modules: newModules,
|
|
22
|
+
cmdOptions: global.getData('cmdOptions'),
|
|
23
|
+
});
|
|
19
24
|
report('hooks:beforeCompile');
|
|
20
25
|
};
|
|
21
26
|
compileBuild(tmsConfig, newModules, isDev);
|
|
@@ -28,7 +28,7 @@ function delOtherPackages(tmsConfig, targetSubPackages) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
async function dev(tmsConfig, targetModules) {
|
|
31
|
-
const { noCache } = global.getData('
|
|
31
|
+
const { noCache } = global.getData('cmdOptions');
|
|
32
32
|
if (noCache) {
|
|
33
33
|
shelljs.rm('-rf', resolve(tmsConfig.outputDir));
|
|
34
34
|
shelljs.rm('-rf', MODULE_CODE_DIR);
|
|
@@ -41,11 +41,12 @@ async function dev(tmsConfig, targetModules) {
|
|
|
41
41
|
const { subPackages, modules: newModules } = await init(tmsConfig, targetModules);
|
|
42
42
|
|
|
43
43
|
info('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
|
|
44
|
-
if (typeof tmsConfig?.hooks?.
|
|
45
|
-
await tmsConfig?.hooks?.
|
|
44
|
+
if (typeof tmsConfig?.hooks?.beforeFirstCompile === 'function') {
|
|
45
|
+
await tmsConfig?.hooks?.beforeFirstCompile({
|
|
46
46
|
isDev: true,
|
|
47
47
|
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
48
48
|
modules: newModules,
|
|
49
|
+
cmdOptions: global.getData('cmdOptions'),
|
|
49
50
|
});
|
|
50
51
|
report('hooks:beforeCompile');
|
|
51
52
|
};
|
package/src/scripts/run/index.js
CHANGED
|
@@ -3,6 +3,8 @@ const init = require('./init/index');
|
|
|
3
3
|
const dev = require('./dev/index');
|
|
4
4
|
const build = require('./build/index');
|
|
5
5
|
const install = require('./install/index');
|
|
6
|
+
const preview = require('./preview/index');
|
|
7
|
+
const upload = require('./upload/index');
|
|
6
8
|
const cloud = require('./cloud/index');
|
|
7
9
|
const { fail, info } = require('../../utils/log');
|
|
8
10
|
const { global } = require('../../utils/global');
|
|
@@ -14,10 +16,10 @@ const {
|
|
|
14
16
|
getModulesByModuleNames,
|
|
15
17
|
} = require('../../core/tmsMpconfig');
|
|
16
18
|
|
|
17
|
-
const handleModuleArg = (
|
|
19
|
+
const handleModuleArg = (cmdOptions) => {
|
|
18
20
|
// 单模块或多模块开发-用户通过脚手架参数指定的模块
|
|
19
|
-
if (typeof
|
|
20
|
-
return
|
|
21
|
+
if (typeof cmdOptions.module === 'string') {
|
|
22
|
+
return cmdOptions.module.split(',');
|
|
21
23
|
}
|
|
22
24
|
return [];
|
|
23
25
|
};
|
|
@@ -45,13 +47,13 @@ const getSpecificModuleNames = (moduleArg, modules) => {
|
|
|
45
47
|
return all.map(item => item.moduleName);
|
|
46
48
|
};
|
|
47
49
|
|
|
48
|
-
async function run(commandName,
|
|
50
|
+
async function run(commandName, cmdOptions) {
|
|
49
51
|
// 用户本地的配置
|
|
50
52
|
const tmsConfig = getTmsConfig();
|
|
51
53
|
try {
|
|
52
54
|
// 缓存数据
|
|
53
55
|
global.setData({
|
|
54
|
-
|
|
56
|
+
cmdOptions,
|
|
55
57
|
tmsConfig,
|
|
56
58
|
});
|
|
57
59
|
|
|
@@ -60,7 +62,7 @@ async function run(commandName, cmd) {
|
|
|
60
62
|
report('run:cloud', { appName: tmsConfig?.appName });
|
|
61
63
|
return;
|
|
62
64
|
}
|
|
63
|
-
otherCommands(tmsConfig, commandName,
|
|
65
|
+
otherCommands(tmsConfig, commandName, cmdOptions);
|
|
64
66
|
} catch (error) {
|
|
65
67
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
66
68
|
report('run', { errMsg, appName: tmsConfig?.appName });
|
|
@@ -70,10 +72,10 @@ async function run(commandName, cmd) {
|
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
function otherCommands(tmsConfig, commandName,
|
|
75
|
+
function otherCommands(tmsConfig, commandName, cmdOptions) {
|
|
74
76
|
// 处理module参数
|
|
75
77
|
const specificModuleNames = getSpecificModuleNames(
|
|
76
|
-
handleModuleArg(
|
|
78
|
+
handleModuleArg(cmdOptions),
|
|
77
79
|
tmsConfig.modules,
|
|
78
80
|
);
|
|
79
81
|
|
|
@@ -105,6 +107,14 @@ function otherCommands(tmsConfig, commandName, cmd) {
|
|
|
105
107
|
build(tmsConfig, newModules);
|
|
106
108
|
report('run:build', { appName: tmsConfig?.appName });
|
|
107
109
|
return;
|
|
110
|
+
case 'preview':
|
|
111
|
+
preview(tmsConfig, cmdOptions);
|
|
112
|
+
report('run:preview', { appName: tmsConfig?.appName });
|
|
113
|
+
return;
|
|
114
|
+
case 'upload':
|
|
115
|
+
upload(tmsConfig, cmdOptions);
|
|
116
|
+
report('run:upload', { appName: tmsConfig?.appName });
|
|
117
|
+
return;
|
|
108
118
|
default:
|
|
109
119
|
return;
|
|
110
120
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const mpCi = require('../../../core/mpCi');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const { resolve, createTask, getAbsolutePath, filterField } = require('../../../utils/widgets');
|
|
4
|
+
const { handleError } = require('../../../core/handleError');
|
|
5
|
+
const { info } = require('../../../utils/log');
|
|
6
|
+
const { global } = require('../../../utils/global');
|
|
7
|
+
const { getAllSize, outputInfo, getDefaultDesc } = require('./utils');
|
|
8
|
+
const report = require('../../../core/report');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const handleParams = (tmsConfig, cmdOptions) => {
|
|
12
|
+
const params = {
|
|
13
|
+
...(tmsConfig.preview ? tmsConfig.preview : {}),
|
|
14
|
+
...cmdOptions,
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
...params,
|
|
18
|
+
appId: params.appId || tmsConfig.appId,
|
|
19
|
+
projectPath: resolve(tmsConfig.outputDir),
|
|
20
|
+
privateKey: params.privateKey || tmsConfig.privateKey,
|
|
21
|
+
robot: params.robot || 30,
|
|
22
|
+
desc: params.desc || getDefaultDesc(),
|
|
23
|
+
qrcodeOutputDest: getAbsolutePath(params.qrcodeOutputDest || ''),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 预览
|
|
29
|
+
* @params {object} tmsConfig
|
|
30
|
+
* @param {object} cmdOptions {qrcodeFormat: 'base64', qrcodeOutputDest: './a.txt', robot: 2, infoOutput: './a.txt' }
|
|
31
|
+
*/
|
|
32
|
+
async function preview(tmsConfig, cmdOptions) {
|
|
33
|
+
try {
|
|
34
|
+
const params = handleParams(tmsConfig, cmdOptions);
|
|
35
|
+
if (typeof tmsConfig?.hooks?.beforePreview === 'function') {
|
|
36
|
+
await tmsConfig?.hooks?.beforePreview({
|
|
37
|
+
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
38
|
+
cmdOptions: global.getData('cmdOptions'),
|
|
39
|
+
params,
|
|
40
|
+
});
|
|
41
|
+
report('hooks:beforePreview');
|
|
42
|
+
};
|
|
43
|
+
const previewRes = await createTask(
|
|
44
|
+
mpCi.previewMp,
|
|
45
|
+
'正在构建预览码',
|
|
46
|
+
'构建预览码完成',
|
|
47
|
+
)({
|
|
48
|
+
...params,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const allSize = getAllSize(previewRes);
|
|
52
|
+
if (params.infoOutput) {
|
|
53
|
+
let qrcodeBase64 = '';
|
|
54
|
+
if (params.qrcodeFormat === 'base64' && fs.existsSync(params.qrcodeOutputDest)) {
|
|
55
|
+
qrcodeBase64 = fs.readFileSync(params.qrcodeOutputDest, 'utf8');
|
|
56
|
+
}
|
|
57
|
+
outputInfo(params.infoOutput, {
|
|
58
|
+
sourceCode: params.projectPath,
|
|
59
|
+
qrcodeBase64,
|
|
60
|
+
...previewRes,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
info('预览包大小:', `${allSize}k`);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
console.log('详细错误:', e);
|
|
66
|
+
handleError(`预览错误: ${e.message}`, true);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = preview;
|