@tmsfe/tmskit 0.0.20 → 0.0.23
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 +7 -1
- package/dist/index.cjs.js +1632 -1868
- package/package.json +4 -7
- package/src/{init.js → check.js} +2 -3
- package/src/compile/build.js +2 -2
- package/src/compile/compile.js +53 -155
- package/src/compile/dev.js +25 -69
- package/src/compile/plugins/mpProjectJson.js +13 -0
- package/src/compile/plugins/replaceEnv.js +7 -14
- package/src/compile/watch.js +49 -17
- package/src/config/constant.js +29 -8
- package/src/core/buildAppJson.js +3 -0
- package/src/core/checkDependencies.js +11 -8
- package/src/core/cloneModules.js +3 -0
- package/src/core/npm.js +6 -25
- package/src/core/recommendVersion.js +118 -0
- package/src/core/report.js +30 -0
- package/src/core/symbolicLink.js +17 -19
- package/src/core/tmsMpconfig.js +148 -69
- package/src/entry.js +13 -14
- package/src/index.js +61 -20
- package/src/scripts/create/index.js +3 -1
- package/src/scripts/extend-cmd/index.js +74 -0
- package/src/scripts/run/build/index.js +4 -2
- package/src/scripts/run/cloud/index.js +0 -2
- package/src/scripts/run/dev/index.js +9 -3
- package/src/scripts/run/index.js +52 -76
- package/src/scripts/run/init/index.js +2 -24
- package/src/{core → scripts/run/install}/cache.js +4 -4
- package/src/scripts/run/install/index.js +15 -19
- package/src/utils/log.js +3 -0
- package/src/utils/widgets.js +58 -34
package/src/utils/log.js
CHANGED
|
@@ -40,9 +40,12 @@ const warn = (message) => {
|
|
|
40
40
|
|
|
41
41
|
const info = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
|
|
42
42
|
|
|
43
|
+
const infoNoTime = (...args) => console.log(...args);
|
|
44
|
+
|
|
43
45
|
module.exports = {
|
|
44
46
|
fail,
|
|
45
47
|
succeed,
|
|
46
48
|
warn,
|
|
47
49
|
info,
|
|
50
|
+
infoNoTime,
|
|
48
51
|
};
|
package/src/utils/widgets.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
|
|
2
|
-
const program = require('commander');
|
|
3
|
-
const leven = require('leven');
|
|
4
2
|
const ora = require('ora');
|
|
5
3
|
const path = require('path');
|
|
6
4
|
const fs = require('fs');
|
|
7
5
|
const shelljs = require('shelljs');
|
|
8
6
|
const glob = require('glob-ignore');
|
|
9
7
|
const { info } = require('./log');
|
|
10
|
-
const chalk = require('chalk');
|
|
11
8
|
const shelljsOptions = { slient: true, async: false };
|
|
12
9
|
|
|
13
10
|
// 获取当前目录
|
|
@@ -16,28 +13,6 @@ function resolve(...args) {
|
|
|
16
13
|
return path.resolve(cwd, ...args);
|
|
17
14
|
};
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 用户输入命令时,进行提示
|
|
22
|
-
* @param {String} unknownCommand 非预期的命令
|
|
23
|
-
* @returns {Undefined} 无需返回值
|
|
24
|
-
*/
|
|
25
|
-
const suggestCommands = (unknownCommand) => {
|
|
26
|
-
const availableCommands = program.commands.map(cmd => cmd._name);
|
|
27
|
-
|
|
28
|
-
let suggestion;
|
|
29
|
-
availableCommands.forEach((cmd) => {
|
|
30
|
-
const isBestMatch = leven(cmd, unknownCommand) < leven(suggestion || '', unknownCommand);
|
|
31
|
-
if (leven(cmd, unknownCommand) < 3 && isBestMatch) {
|
|
32
|
-
suggestion = cmd;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
if (suggestion) {
|
|
37
|
-
info(` ${chalk.red(`Did you mean ${chalk.yellow(suggestion)}?`)}`);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
16
|
/**
|
|
42
17
|
* 判断变量是否是一个数组
|
|
43
18
|
* @param { unknown } obj 变量
|
|
@@ -109,13 +84,15 @@ function pullRepoForGit(dest, branch) {
|
|
|
109
84
|
|
|
110
85
|
/**
|
|
111
86
|
* npm 下载依赖
|
|
112
|
-
* @param {
|
|
87
|
+
* @param {string} dir 下载npm的目录
|
|
88
|
+
* @param {object} npm npm的配置 (见下获取npm源入参)
|
|
113
89
|
* @returns
|
|
114
90
|
*/
|
|
115
|
-
function npmInstall(dir) {
|
|
91
|
+
function npmInstall(dir, npmConfig) {
|
|
116
92
|
return new Promise((resolve, reject) => {
|
|
93
|
+
const registry = getNpmRegistry(npmConfig);
|
|
117
94
|
shelljs.exec(
|
|
118
|
-
|
|
95
|
+
`npm install --production ${registry}`,
|
|
119
96
|
{ cwd: dir, silent: true },
|
|
120
97
|
(code, stdout, stderr) => {
|
|
121
98
|
if (code !== 0) {
|
|
@@ -127,6 +104,28 @@ function npmInstall(dir) {
|
|
|
127
104
|
});
|
|
128
105
|
}
|
|
129
106
|
|
|
107
|
+
// 获取npm源
|
|
108
|
+
// 入参:{
|
|
109
|
+
// registry: "https://registry.npmjs.org/",
|
|
110
|
+
// scope: {
|
|
111
|
+
// "@tencent": "http://mirrors.tencent.com/npm/"
|
|
112
|
+
// }
|
|
113
|
+
// }
|
|
114
|
+
// 出参: --@tencent:registry=http://mirrors.tencent.com/npm/ --registry=https://registry.npmjs.org/
|
|
115
|
+
function getNpmRegistry(npmConfig = {}) {
|
|
116
|
+
let resRegistry = '';
|
|
117
|
+
if (npmConfig.registry) {
|
|
118
|
+
resRegistry = ` --registry=${npmConfig.registry}`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (isObject(npmConfig.scope)) {
|
|
122
|
+
Object.keys(npmConfig.scope).forEach((key) => {
|
|
123
|
+
resRegistry += ` --${key}:registry=${npmConfig.scope[key]}`;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return resRegistry;
|
|
127
|
+
}
|
|
128
|
+
|
|
130
129
|
/**
|
|
131
130
|
* 计算各项任务耗时
|
|
132
131
|
* @param {Number} start 任务开始时间
|
|
@@ -167,11 +166,7 @@ const camelize = str => str.replace(/-(\w)/g, (a, c) => (c ? c.toUpperCase() : '
|
|
|
167
166
|
|
|
168
167
|
const mergeMap = function (obj, src) {
|
|
169
168
|
for (const [k, v] of src) {
|
|
170
|
-
|
|
171
|
-
obj.set(k, obj.get(k) + v);
|
|
172
|
-
} else {
|
|
173
|
-
obj.set(k, v);
|
|
174
|
-
}
|
|
169
|
+
obj.set(k, v);
|
|
175
170
|
}
|
|
176
171
|
|
|
177
172
|
return obj;
|
|
@@ -209,6 +204,33 @@ function findFiles(globPath, filter = []) {
|
|
|
209
204
|
});
|
|
210
205
|
}
|
|
211
206
|
|
|
207
|
+
// 获取绝对路径
|
|
208
|
+
function getAbsolutePath(pathDir, cwd = '') {
|
|
209
|
+
let newPath = pathDir;
|
|
210
|
+
newPath = newPath.startsWith('/') ? newPath : resolve(cwd, newPath);
|
|
211
|
+
newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
|
|
212
|
+
return newPath;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 版本比较 => 1(大于), 0(等于), -1(小于)
|
|
216
|
+
function versionCompare(v1, v2) {
|
|
217
|
+
// 将两个版本号拆成数组
|
|
218
|
+
const arr1 = v1.split('.');
|
|
219
|
+
const arr2 = v2.split('.');
|
|
220
|
+
const minLength = Math.min(arr1.length, arr2.length);
|
|
221
|
+
// 依次比较版本号每一位大小
|
|
222
|
+
for (let i = 0; i < minLength; i++) {
|
|
223
|
+
if (parseInt(arr1[i], 10) !== parseInt(arr2[i], 10)) {
|
|
224
|
+
return (parseInt(arr1[i], 10) > parseInt(arr2[i], 10)) ? 1 : -1;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// 若前几位分隔相同,则按分隔数比较。
|
|
228
|
+
if (arr1.length === arr2.length) {
|
|
229
|
+
return 0;
|
|
230
|
+
}
|
|
231
|
+
return (arr1.length > arr2.length) ? 1 : -1;
|
|
232
|
+
}
|
|
233
|
+
|
|
212
234
|
module.exports = {
|
|
213
235
|
resolve,
|
|
214
236
|
isObject,
|
|
@@ -216,11 +238,13 @@ module.exports = {
|
|
|
216
238
|
createTask,
|
|
217
239
|
downloadRepoForGit,
|
|
218
240
|
pullRepoForGit,
|
|
219
|
-
suggestCommands,
|
|
220
241
|
camelize,
|
|
221
242
|
npmInstall,
|
|
222
243
|
mergeMap,
|
|
223
244
|
relativeCwdPath,
|
|
224
245
|
filterField,
|
|
225
246
|
findFiles,
|
|
247
|
+
getAbsolutePath,
|
|
248
|
+
getNpmRegistry,
|
|
249
|
+
versionCompare,
|
|
226
250
|
};
|