@tmsfe/tmskit 0.0.24 → 0.0.27
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 +4 -2
- package/dist/index.cjs.js +1307 -789
- package/package.json +6 -6
- package/src/.DS_Store +0 -0
- package/src/compile/dev.js +2 -0
- package/src/compile/watch.js +1 -0
- package/src/config/defaultTmsConfig.js +27 -0
- package/src/core/buildAppJson.js +1 -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 +50 -16
- package/src/scripts/.DS_Store +0 -0
- package/src/scripts/run/build/index.js +6 -1
- package/src/scripts/run/cloud/check.js +34 -0
- package/src/scripts/run/cloud/dev.js +146 -0
- package/src/scripts/run/cloud/getClouds.js +46 -0
- package/src/scripts/run/cloud/install.js +31 -0
- package/src/scripts/run/cloud/link.js +37 -0
- package/src/scripts/run/dev/index.js +4 -3
- package/src/scripts/run/index.js +32 -16
- 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/src/core/cache.js +0 -36
- package/src/core/symbolicLink.js +0 -33
- package/src/scripts/run/cloud/index.js +0 -10
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const { resolve, getAbsolutePath } = require('../../../utils/widgets');
|
|
2
|
+
|
|
3
|
+
// 处理tms.config.cloudModules的兼容数据
|
|
4
|
+
function getTmsCloudModules(tmsConfig) {
|
|
5
|
+
const { cloudModules } = tmsConfig;
|
|
6
|
+
if (Array.isArray(tmsConfig.cloudModules)) {
|
|
7
|
+
return {
|
|
8
|
+
all: [...tmsConfig.cloudModules],
|
|
9
|
+
include: [],
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return cloudModules;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 获取需要监听的云函数
|
|
17
|
+
* @param {*} tmsConfig {}
|
|
18
|
+
* @param {*} cmdOptions eg:{clouds: 'aggrecarshop,car'}
|
|
19
|
+
* @returns
|
|
20
|
+
* [{ name: '', sourcePath: '', targetPath: ''}]
|
|
21
|
+
*/
|
|
22
|
+
function getCloudsOfListen(tmsConfig, cmdOptions) {
|
|
23
|
+
// 获取tmsconfig配置的云函数的配置项
|
|
24
|
+
const cloudModules = getTmsCloudModules(tmsConfig);
|
|
25
|
+
|
|
26
|
+
let includeClouds = cmdOptions?.cloud?.split(',') || cloudModules.include || [];
|
|
27
|
+
|
|
28
|
+
// 如果没有配置include, 默认使用所有的数据云函数列表
|
|
29
|
+
if (includeClouds.length === 0) {
|
|
30
|
+
includeClouds = cloudModules.all.map(item => item.name);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const result = [];
|
|
34
|
+
for (const item of cloudModules.all) {
|
|
35
|
+
if (includeClouds.includes(item.name)) {
|
|
36
|
+
result.push({
|
|
37
|
+
name: item.name,
|
|
38
|
+
sourcePath: `${getAbsolutePath(item.path)}`,
|
|
39
|
+
targetPath: resolve(tmsConfig.cloudDir, item.name),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = getCloudsOfListen;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const shellJs = require('shelljs');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const { resolve, npmInstall } = require('../../../utils/widgets');
|
|
4
|
+
const { ensureDirExist } = require('../../../utils/io');
|
|
5
|
+
const { info } = require('../../../utils/log');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* npm install
|
|
9
|
+
* @param {array} clouds [{name: '', sourcePath: '', targetPath: ''}]
|
|
10
|
+
*/
|
|
11
|
+
const runInstall = async (clouds, tmsConfig) => {
|
|
12
|
+
const promises = [];
|
|
13
|
+
|
|
14
|
+
for (const item of clouds) {
|
|
15
|
+
ensureDirExist(item.targetPath);
|
|
16
|
+
const packageFilePath = resolve(item.sourcePath, 'package.json');
|
|
17
|
+
if (fs.existsSync(packageFilePath)) {
|
|
18
|
+
shellJs.cp('-Rf', resolve(packageFilePath), item.targetPath);
|
|
19
|
+
promises.push(() => {
|
|
20
|
+
info(`云函数${item.name}: npm install`);
|
|
21
|
+
return npmInstall(item.targetPath, tmsConfig.npm);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
await Promise.all(promises.map(item => item()));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
module.exports = {
|
|
30
|
+
runInstall,
|
|
31
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const { info } = require('../../../utils/log');
|
|
3
|
+
const { resolve } = require('../../../utils/widgets');
|
|
4
|
+
const { ensureDirExist } = require('../../../utils/io');
|
|
5
|
+
const { warn, succeed } = require('../../../utils/log');
|
|
6
|
+
const getCloudsOfListen = require('./getClouds');
|
|
7
|
+
const { handleError } = require('../../../core/handleError');
|
|
8
|
+
const { checkCloudConfig } = require('./check');
|
|
9
|
+
|
|
10
|
+
module.exports = async (tmsConfig, cmdOptions) => {
|
|
11
|
+
try {
|
|
12
|
+
ensureDirExist(resolve(tmsConfig.cloudDir));
|
|
13
|
+
checkCloudConfig(tmsConfig);
|
|
14
|
+
|
|
15
|
+
// 获取需要监听的云函数列表
|
|
16
|
+
const clouds = getCloudsOfListen(tmsConfig, cmdOptions);
|
|
17
|
+
// 打印启动云函数列表
|
|
18
|
+
info('当前启动云函数列表:', clouds.map(item => item.name).sort());
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
clouds.forEach((item) => {
|
|
22
|
+
if (!fs.existsSync(item.sourcePath)) {
|
|
23
|
+
warn(`云函数${item.sourcePath}不存在`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const stat = fs.lstatSync(item.targetPath);
|
|
27
|
+
if (!stat.isSymbolicLink()) {
|
|
28
|
+
fs.symlinkSync(item.sourcePath, item.targetPath);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
succeed('云函数创建软链成功');
|
|
33
|
+
} catch (e) {
|
|
34
|
+
info('创建软链详细错误', e);
|
|
35
|
+
handleError(`创建软链错误: ${e}`, true);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
@@ -7,7 +7,7 @@ const { info } = require('../../../utils/log');
|
|
|
7
7
|
const { global } = require('../../../utils/global');
|
|
8
8
|
const { MODULE_CODE_DIR, NODE_MODULES_DIR } = require('../../../config/constant');
|
|
9
9
|
const report = require('../../../core/report');
|
|
10
|
-
const { recommendVersion } = require('../../../core/recommendVersion');
|
|
10
|
+
// const { recommendVersion } = require('../../../core/recommendVersion');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
// 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
@@ -28,14 +28,14 @@ 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);
|
|
35
35
|
shelljs.rm('-rf', NODE_MODULES_DIR);
|
|
36
36
|
}
|
|
37
37
|
// 推荐tmskit的版本
|
|
38
|
-
await recommendVersion();
|
|
38
|
+
// await recommendVersion();
|
|
39
39
|
|
|
40
40
|
// 初始化操作
|
|
41
41
|
const { subPackages, modules: newModules } = await init(tmsConfig, targetModules);
|
|
@@ -46,6 +46,7 @@ async function dev(tmsConfig, targetModules) {
|
|
|
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,7 +3,10 @@ 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
|
|
6
|
+
const preview = require('./preview/index');
|
|
7
|
+
const upload = require('./upload/index');
|
|
8
|
+
const cloudLink = require('./cloud/link');
|
|
9
|
+
const cloudDev = require('./cloud/dev');
|
|
7
10
|
const { fail, info } = require('../../utils/log');
|
|
8
11
|
const { global } = require('../../utils/global');
|
|
9
12
|
const report = require('../../core/report');
|
|
@@ -14,10 +17,10 @@ const {
|
|
|
14
17
|
getModulesByModuleNames,
|
|
15
18
|
} = require('../../core/tmsMpconfig');
|
|
16
19
|
|
|
17
|
-
const handleModuleArg = (
|
|
20
|
+
const handleModuleArg = (cmdOptions) => {
|
|
18
21
|
// 单模块或多模块开发-用户通过脚手架参数指定的模块
|
|
19
|
-
if (typeof
|
|
20
|
-
return
|
|
22
|
+
if (typeof cmdOptions.module === 'string') {
|
|
23
|
+
return cmdOptions.module.split(',');
|
|
21
24
|
}
|
|
22
25
|
return [];
|
|
23
26
|
};
|
|
@@ -45,22 +48,27 @@ const getSpecificModuleNames = (moduleArg, modules) => {
|
|
|
45
48
|
return all.map(item => item.moduleName);
|
|
46
49
|
};
|
|
47
50
|
|
|
48
|
-
async function run(commandName,
|
|
51
|
+
async function run(commandName, cmdOptions) {
|
|
49
52
|
// 用户本地的配置
|
|
50
53
|
const tmsConfig = getTmsConfig();
|
|
51
54
|
try {
|
|
52
55
|
// 缓存数据
|
|
53
56
|
global.setData({
|
|
54
|
-
|
|
57
|
+
cmdOptions,
|
|
55
58
|
tmsConfig,
|
|
56
59
|
});
|
|
57
60
|
|
|
58
|
-
if (commandName === 'cloud') {
|
|
59
|
-
|
|
60
|
-
report('run:cloud', { appName: tmsConfig?.appName });
|
|
61
|
+
if (commandName === 'cloud-link') {
|
|
62
|
+
cloudLink(tmsConfig, cmdOptions);
|
|
63
|
+
report('run:cloud-link', { appName: tmsConfig?.appName });
|
|
61
64
|
return;
|
|
62
65
|
}
|
|
63
|
-
|
|
66
|
+
if (commandName === 'cloud-dev') {
|
|
67
|
+
cloudDev(tmsConfig, cmdOptions);
|
|
68
|
+
report('run:cloud-dev', { appName: tmsConfig?.appName });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
otherCommands(tmsConfig, commandName, cmdOptions);
|
|
64
72
|
} catch (error) {
|
|
65
73
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
66
74
|
report('run', { errMsg, appName: tmsConfig?.appName });
|
|
@@ -70,10 +78,10 @@ async function run(commandName, cmd) {
|
|
|
70
78
|
}
|
|
71
79
|
}
|
|
72
80
|
|
|
73
|
-
function otherCommands(tmsConfig, commandName,
|
|
81
|
+
function otherCommands(tmsConfig, commandName, cmdOptions) {
|
|
74
82
|
// 处理module参数
|
|
75
83
|
const specificModuleNames = getSpecificModuleNames(
|
|
76
|
-
handleModuleArg(
|
|
84
|
+
handleModuleArg(cmdOptions),
|
|
77
85
|
tmsConfig.modules,
|
|
78
86
|
);
|
|
79
87
|
|
|
@@ -89,21 +97,29 @@ function otherCommands(tmsConfig, commandName, cmd) {
|
|
|
89
97
|
switch (commandName) {
|
|
90
98
|
case 'init':
|
|
91
99
|
init(tmsConfig, newModules);
|
|
92
|
-
report('run:init', { appName: tmsConfig
|
|
100
|
+
report('run:init', { appName: tmsConfig.appName });
|
|
93
101
|
return;
|
|
94
102
|
case 'dev':
|
|
95
103
|
global.setData('isDev', true);
|
|
96
104
|
dev(tmsConfig, newModules);
|
|
97
|
-
report('run:dev', { appName: tmsConfig
|
|
105
|
+
report('run:dev', { appName: tmsConfig.appName });
|
|
98
106
|
return;
|
|
99
107
|
case 'install':
|
|
100
108
|
install(tmsConfig, subPackages, false);
|
|
101
|
-
report('run:install', { appName: tmsConfig
|
|
109
|
+
report('run:install', { appName: tmsConfig.appName });
|
|
102
110
|
return;
|
|
103
111
|
case 'build':
|
|
104
112
|
global.setData('isDev', false);
|
|
105
113
|
build(tmsConfig, newModules);
|
|
106
|
-
report('run:build', { appName: tmsConfig
|
|
114
|
+
report('run:build', { appName: tmsConfig.appName });
|
|
115
|
+
return;
|
|
116
|
+
case 'preview':
|
|
117
|
+
preview(tmsConfig, cmdOptions);
|
|
118
|
+
report('run:preview', { appName: tmsConfig.appName });
|
|
119
|
+
return;
|
|
120
|
+
case 'upload':
|
|
121
|
+
upload(tmsConfig, cmdOptions);
|
|
122
|
+
report('run:upload', { appName: tmsConfig.appName });
|
|
107
123
|
return;
|
|
108
124
|
default:
|
|
109
125
|
return;
|
|
@@ -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, getDesc } = 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 || getDesc(params.desc),
|
|
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;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const moment = require('moment');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const { getGitUser, getAbsolutePath } = require('../../../utils/widgets');
|
|
5
|
+
const { ensureDirExist } = require('../../../utils/io');
|
|
6
|
+
|
|
7
|
+
function getAllSize(data = {}) {
|
|
8
|
+
let allSize;
|
|
9
|
+
for (const item of data?.subPackageInfo) {
|
|
10
|
+
if (item.name === '__FULL__') {
|
|
11
|
+
allSize = item.size;
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return allSize;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const getDesc = (desc = '') => {
|
|
19
|
+
const user = getGitUser();
|
|
20
|
+
const date = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
21
|
+
return `构建描述:${desc}; 构建人: ${user}; 构建时间:${date}`;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const outputInfo = (infoOutput, data) => {
|
|
25
|
+
const outPath = getAbsolutePath(infoOutput);
|
|
26
|
+
const dir = path.dirname(outPath);
|
|
27
|
+
ensureDirExist(dir);
|
|
28
|
+
fs.writeFileSync(outPath, JSON.stringify(data, null, 2));
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const getDetaultVersion = () => {
|
|
32
|
+
const version = moment().format('gggg,mm')
|
|
33
|
+
.split(',');
|
|
34
|
+
version.push('0');
|
|
35
|
+
return version.join('.');
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
module.exports = {
|
|
39
|
+
getAllSize,
|
|
40
|
+
getDesc,
|
|
41
|
+
outputInfo,
|
|
42
|
+
getDetaultVersion,
|
|
43
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const mpCi = require('../../../core/mpCi');
|
|
2
|
+
const { resolve, createTask, filterField } = require('../../../utils/widgets');
|
|
3
|
+
const { handleError } = require('../../../core/handleError');
|
|
4
|
+
const { info } = require('../../../utils/log');
|
|
5
|
+
const { global } = require('../../../utils/global');
|
|
6
|
+
const { getAllSize, outputInfo, getDesc } = require('../preview/utils');
|
|
7
|
+
const report = require('../../../core/report');
|
|
8
|
+
|
|
9
|
+
const handleParams = (tmsConfig, cmdOptions) => {
|
|
10
|
+
const params = {
|
|
11
|
+
...(tmsConfig.upload ? tmsConfig.upload : {}),
|
|
12
|
+
...cmdOptions,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
if (!params.version) {
|
|
16
|
+
throw new Error('请指定传入版本号 eg: tmskit run upload --version 2022.28.5');
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
...params,
|
|
20
|
+
appId: params.appId || tmsConfig.appId,
|
|
21
|
+
projectPath: resolve(tmsConfig.outputDir),
|
|
22
|
+
privateKey: params.privateKey || tmsConfig.privateKey,
|
|
23
|
+
robot: params.robot || 30,
|
|
24
|
+
desc: params.desc || getDesc(params.desc),
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 上传
|
|
30
|
+
* @param {object} tmsConfig
|
|
31
|
+
* @param {object} cmdOptions {version: '2022.28.5', desc: '', robot: 2, infoOutput: './a.txt' }
|
|
32
|
+
*/
|
|
33
|
+
async function upload(tmsConfig, cmdOptions) {
|
|
34
|
+
try {
|
|
35
|
+
const params = handleParams(tmsConfig, cmdOptions);
|
|
36
|
+
if (typeof tmsConfig?.hooks?.beforeUpload === 'function') {
|
|
37
|
+
await tmsConfig?.hooks?.beforeUpload({
|
|
38
|
+
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
39
|
+
cmdOptions: global.getData('cmdOptions'),
|
|
40
|
+
params,
|
|
41
|
+
});
|
|
42
|
+
report('hooks:beforeUpload');
|
|
43
|
+
};
|
|
44
|
+
const uploadRes = await createTask(
|
|
45
|
+
mpCi.uploadMp,
|
|
46
|
+
'正在上传小程序代码',
|
|
47
|
+
'上传小程序代码完成',
|
|
48
|
+
)({
|
|
49
|
+
...params,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const allSize = getAllSize(uploadRes);
|
|
53
|
+
if (params.infoOutput) {
|
|
54
|
+
outputInfo(params.infoOutput, {
|
|
55
|
+
sourceCode: params.projectPath,
|
|
56
|
+
...uploadRes,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
info(`上传包大小: ${allSize}k; 上传包版本: ${params.version}`);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.log('详细错误:', e);
|
|
62
|
+
handleError(`上传错误: ${e.message}`, true);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
module.exports = upload;
|
package/src/utils/widgets.js
CHANGED
|
@@ -231,6 +231,11 @@ function versionCompare(v1, v2) {
|
|
|
231
231
|
return (arr1.length > arr2.length) ? 1 : -1;
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
+
function getGitUser() {
|
|
235
|
+
const res = shelljs.exec('git config user.name', { async: false, silent: true });
|
|
236
|
+
return res.stdout;
|
|
237
|
+
}
|
|
238
|
+
|
|
234
239
|
module.exports = {
|
|
235
240
|
resolve,
|
|
236
241
|
isObject,
|
|
@@ -247,4 +252,5 @@ module.exports = {
|
|
|
247
252
|
getAbsolutePath,
|
|
248
253
|
getNpmRegistry,
|
|
249
254
|
versionCompare,
|
|
255
|
+
getGitUser,
|
|
250
256
|
};
|
package/src/core/cache.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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/symbolicLink.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const { resolve } = require('../utils/widgets');
|
|
3
|
-
const { ensureDirExist } = require('../utils/io');
|
|
4
|
-
const { warn, succeed } = require('../utils/log');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 根据相关配置创建软链接
|
|
8
|
-
* @param { object } tmsConfig
|
|
9
|
-
*/
|
|
10
|
-
const symLink = (tmsConfig) => {
|
|
11
|
-
ensureDirExist(resolve(tmsConfig.cloudDir));
|
|
12
|
-
if (tmsConfig.cloudModules) {
|
|
13
|
-
tmsConfig.cloudModules.forEach((item) => {
|
|
14
|
-
const sourcePath = resolve(item.path);
|
|
15
|
-
const targetPath = resolve(tmsConfig.cloudDir, item.name);
|
|
16
|
-
|
|
17
|
-
if (!fs.existsSync(sourcePath)) {
|
|
18
|
-
warn(`云函数${sourcePath}不存在`);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (!fs.existsSync(targetPath)) {
|
|
22
|
-
fs.symlinkSync(sourcePath, targetPath);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
succeed('云函数创建软链成功');
|
|
26
|
-
} else {
|
|
27
|
-
warn('你没有在tms.config.js的cloudModules注册云函数');
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
module.exports = {
|
|
32
|
-
symLink,
|
|
33
|
-
};
|