@tmsfe/tmskit 0.0.12 → 0.0.15-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 +32 -0
- package/README.md +6 -1
- package/dist/index.cjs.js +667 -546
- package/main.js +0 -0
- package/package.json +6 -5
- package/src/compile/compile.js +131 -50
- package/src/compile/dev.js +64 -24
- package/src/compile/watch.js +46 -0
- package/src/core/buildAppJson.js +3 -0
- package/src/core/cloneModules.js +7 -3
- package/src/core/isInIt.js +2 -6
- package/src/core/mpCi.js +1 -1
- package/src/core/npm.js +9 -6
- package/src/core/symbolicLink.js +13 -7
- package/src/core/tmsMpconfig.js +13 -8
- package/src/entry.js +1 -1
- package/src/index.js +1 -4
- package/src/scripts/run/dev/index.js +12 -8
- package/src/scripts/run/index.js +11 -6
- package/src/scripts/run/init/index.js +26 -9
- package/src/scripts/run/install/index.js +2 -9
- package/src/utils/io.js +3 -2
- package/src/utils/log.js +5 -4
- package/src/utils/widgets.js +22 -5
package/src/core/tmsMpconfig.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
const loadash = require('lodash');
|
|
5
5
|
const fs = require('fs');
|
|
6
|
-
const {
|
|
6
|
+
const { TMS_CONFIG_FILENAME, MODULE_CONFIG_FILENAME, TMS_PRIVATE_FILENAME } = require('../config/constant');
|
|
7
7
|
const { resolve, isObject, isArray } = require('../utils/widgets');
|
|
8
8
|
const defaultTmsConfig = require('../config/defaultTmsConfig');
|
|
9
9
|
const { fail } = require('../utils/log');
|
|
@@ -77,15 +77,18 @@ const readTmsPrivateCf = function () {
|
|
|
77
77
|
* @param { array } modules
|
|
78
78
|
* @returns
|
|
79
79
|
*/
|
|
80
|
-
const checkModules = function (tmsConfig, modules) {
|
|
80
|
+
const checkModules = function (tmsConfig, modules, isQuit = false) {
|
|
81
81
|
const targetModules = [];
|
|
82
82
|
modules.forEach((moduleName) => {
|
|
83
83
|
const module = tmsConfig.modules.find(module => module.name === moduleName);
|
|
84
84
|
module && targetModules.push(module);
|
|
85
85
|
});
|
|
86
|
+
|
|
87
|
+
|
|
86
88
|
if (targetModules.length === 0) {
|
|
87
|
-
fail(
|
|
88
|
-
|
|
89
|
+
fail(`你启动的模块无效${modules.join(',')}无效,请检查tms.config.json>modules>${modules.join(',')}
|
|
90
|
+
>name字段与module.config.json的name字段是否一致`);
|
|
91
|
+
isQuit && process.exit(1);
|
|
89
92
|
}
|
|
90
93
|
return targetModules;
|
|
91
94
|
};
|
|
@@ -175,7 +178,7 @@ const tmsModulesMergeLocalModuleCfg = (modules, appName) => {
|
|
|
175
178
|
}
|
|
176
179
|
});
|
|
177
180
|
if (!findModule) {
|
|
178
|
-
fail(`启动模块${moduleName}在${moduleConfigPath}
|
|
181
|
+
fail(`启动模块${moduleName}在${moduleConfigPath}没有找到或pages为空,请检查配置`);
|
|
179
182
|
process.exit(1);
|
|
180
183
|
}
|
|
181
184
|
} catch (e) {
|
|
@@ -213,10 +216,12 @@ const subModulesMergeDepModules = (tmsConfig, modules) => {
|
|
|
213
216
|
// 如果所有模块的dep都在moduleNames内,则所有依赖都齐了
|
|
214
217
|
// 否则递归处理,根据name找到相关配置加到modules里
|
|
215
218
|
if (moduleNames.indexOf(item) === -1) {
|
|
216
|
-
isOver = false;
|
|
217
219
|
const tmpModules = checkModules(tmsConfig, [...new Set([item])]);
|
|
218
|
-
|
|
219
|
-
|
|
220
|
+
if (tmpModules.length > 0) {
|
|
221
|
+
isOver = false;
|
|
222
|
+
mergeModules = [...mergeModules, ...tmpModules];
|
|
223
|
+
mergeModules = tmsModulesMergeLocalModuleCfg(mergeModules, tmsConfig.appName);
|
|
224
|
+
}
|
|
220
225
|
}
|
|
221
226
|
});
|
|
222
227
|
});
|
package/src/entry.js
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = [
|
|
|
28
28
|
options: [
|
|
29
29
|
['-m, --module [moduleName]', '模块名称'],
|
|
30
30
|
['-e, --env [env]', '环境变量'],
|
|
31
|
-
['-
|
|
31
|
+
['-noCache, --noCache', '不使用缓存功能'],
|
|
32
32
|
],
|
|
33
33
|
action: (cmd) => {
|
|
34
34
|
require('./scripts/run/index')('dev', cmd);
|
package/src/index.js
CHANGED
|
@@ -39,9 +39,7 @@ function registerCommand(program, commands) {
|
|
|
39
39
|
registerCommand(program, commands);
|
|
40
40
|
|
|
41
41
|
program.on('--help', () => {
|
|
42
|
-
info();
|
|
43
42
|
info(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
|
|
44
|
-
info();
|
|
45
43
|
});
|
|
46
44
|
|
|
47
45
|
// 捕获未注册的命令
|
|
@@ -49,8 +47,7 @@ program
|
|
|
49
47
|
.arguments('<command>')
|
|
50
48
|
.action((cmd) => {
|
|
51
49
|
program.outputHelp();
|
|
52
|
-
info(`
|
|
53
|
-
info();
|
|
50
|
+
info(` ${chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)}`);
|
|
54
51
|
suggestCommands(cmd);
|
|
55
52
|
process.exitCode = 1;
|
|
56
53
|
});
|
|
@@ -2,10 +2,10 @@ const shelljs = require('shelljs');
|
|
|
2
2
|
const compileDev = require('../../../compile/dev');
|
|
3
3
|
const { resolve } = require('../../../utils/widgets');
|
|
4
4
|
const init = require('../init/index');
|
|
5
|
-
const { isInit } = require('../../../core/isInIt');
|
|
6
5
|
const { tmsModulesMergeLocalModuleCfg } = require('../../../core/tmsMpconfig');
|
|
7
6
|
const { info } = require('../../../utils/log');
|
|
8
7
|
const { global } = require('../../../utils/global');
|
|
8
|
+
const { CACHE_DIR } = require('../../../config/constant');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
// 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
@@ -24,16 +24,20 @@ function delOtherModule(tmsConfig, targetModules) {
|
|
|
24
24
|
|
|
25
25
|
async function dev(tmsConfig, targetModules, env) {
|
|
26
26
|
let newModules = targetModules;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// init函数 下载第三方代码后,会将最新的tms.config.js的modules 合并 module.config.json的配置项返回
|
|
32
|
-
const initData = await init(tmsConfig, newModules);
|
|
33
|
-
newModules = initData.targetModules;
|
|
27
|
+
const { noCache } = global.getData('cmd');
|
|
28
|
+
if (noCache) {
|
|
29
|
+
shelljs.rm('-rf', resolve('dist'));
|
|
30
|
+
shelljs.rm('-rf', CACHE_DIR);
|
|
34
31
|
}
|
|
35
32
|
|
|
33
|
+
// 初始化操作
|
|
34
|
+
const initData = await init(tmsConfig, newModules);
|
|
35
|
+
newModules = initData.targetModules;
|
|
36
|
+
|
|
36
37
|
info('当前dev启动的有效模块', newModules.map(item => item.name).sort());
|
|
38
|
+
if (typeof tmsConfig?.hooks?.beforeCompile === 'function') {
|
|
39
|
+
tmsConfig?.hooks?.beforeCompile({ isDev: true, tmsConfig, modules: newModules });
|
|
40
|
+
};
|
|
37
41
|
delOtherModule(tmsConfig, newModules);
|
|
38
42
|
compileDev(tmsConfig, newModules, env);
|
|
39
43
|
}
|
package/src/scripts/run/index.js
CHANGED
|
@@ -55,12 +55,16 @@ async function run(commandName, cmd) {
|
|
|
55
55
|
tmsConfig.modules,
|
|
56
56
|
);
|
|
57
57
|
|
|
58
|
-
const modules = checkModules(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
...
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
const modules = checkModules(
|
|
59
|
+
tmsConfig,
|
|
60
|
+
[
|
|
61
|
+
...new Set([
|
|
62
|
+
...tmsConfig.mainPackages,
|
|
63
|
+
...specificModules,
|
|
64
|
+
]),
|
|
65
|
+
],
|
|
66
|
+
true,
|
|
67
|
+
);
|
|
64
68
|
|
|
65
69
|
// tms.config.js的modules 合并 module.config.json的配置项
|
|
66
70
|
let newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName);
|
|
@@ -72,6 +76,7 @@ async function run(commandName, cmd) {
|
|
|
72
76
|
env,
|
|
73
77
|
cmd,
|
|
74
78
|
tmsPrivateCf,
|
|
79
|
+
tmsConfig,
|
|
75
80
|
});
|
|
76
81
|
|
|
77
82
|
switch (commandName) {
|
|
@@ -3,12 +3,12 @@ const fs = require('fs');
|
|
|
3
3
|
const io = require('../../../utils/io');
|
|
4
4
|
const { resolve, createTask } = require('../../../utils/widgets');
|
|
5
5
|
const { buildOutputAppJson } = require('../../../core/buildAppJson');
|
|
6
|
-
const { symLink } = require('../../../core/symbolicLink');
|
|
7
6
|
const { MODULE_CODE_DIR, DEFAULT_COPY_CONFIG } = require('../../../config/constant');
|
|
8
7
|
const { cloneModules } = require('../../../core/cloneModules');
|
|
9
8
|
const { tmsModulesMergeLocalModuleCfg, subModulesMergeDepModules } = require('../../../core/tmsMpconfig');
|
|
10
9
|
const { fail, info } = require('../../../utils/log');
|
|
11
10
|
const install = require('../install');
|
|
11
|
+
const { checkDependencies } = require('../../../core/checkDependencies');
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* 拷贝相关配置文件到编译输出目录
|
|
@@ -39,6 +39,25 @@ const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
|
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* 校验相关配置项
|
|
44
|
+
* @param {*} targetModules
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
function checkConfig(targetModules) {
|
|
48
|
+
for (const item of targetModules) {
|
|
49
|
+
if (!item.root) {
|
|
50
|
+
throw new Error(`检查${item.name} module.config.json的root字段`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 判断源码目录是否有该模块
|
|
54
|
+
if (item.path && !fs.existsSync(resolve(item.path))) {
|
|
55
|
+
throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
42
61
|
async function task(tmsConfig, targetModules) {
|
|
43
62
|
// 下载和移动代码
|
|
44
63
|
await createTask(
|
|
@@ -52,6 +71,8 @@ async function task(tmsConfig, targetModules) {
|
|
|
52
71
|
// A分包依赖了B分包的代码, merge B分包进行编译;
|
|
53
72
|
newModules = subModulesMergeDepModules(tmsConfig, newModules);
|
|
54
73
|
|
|
74
|
+
checkConfig(newModules);
|
|
75
|
+
|
|
55
76
|
// 拷贝相关配置文件到输出目录
|
|
56
77
|
await createTask(
|
|
57
78
|
cpFilesToOutput,
|
|
@@ -60,7 +81,9 @@ async function task(tmsConfig, targetModules) {
|
|
|
60
81
|
)(tmsConfig, newModules, DEFAULT_COPY_CONFIG);
|
|
61
82
|
|
|
62
83
|
// install
|
|
63
|
-
|
|
84
|
+
if (checkDependencies(newModules, resolve('./'), tmsConfig.outputDir)) {
|
|
85
|
+
await install(tmsConfig, newModules);
|
|
86
|
+
}
|
|
64
87
|
|
|
65
88
|
// 动态生成编译后的app.json;
|
|
66
89
|
await createTask(
|
|
@@ -69,12 +92,6 @@ async function task(tmsConfig, targetModules) {
|
|
|
69
92
|
'生成编译后的app.json完成',
|
|
70
93
|
)(tmsConfig, newModules);
|
|
71
94
|
|
|
72
|
-
await createTask(
|
|
73
|
-
symLink,
|
|
74
|
-
'开始创建软链接',
|
|
75
|
-
'创建软链接完成',
|
|
76
|
-
)(tmsConfig);
|
|
77
|
-
|
|
78
95
|
return newModules;
|
|
79
96
|
}
|
|
80
97
|
async function init(tmsConfig, targetModules) {
|
|
@@ -86,7 +103,7 @@ async function init(tmsConfig, targetModules) {
|
|
|
86
103
|
};
|
|
87
104
|
} catch (error) {
|
|
88
105
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
89
|
-
fail(
|
|
106
|
+
fail(`初始化流程出现错误${errMsg}`);
|
|
90
107
|
info('详细的错误信息', error);
|
|
91
108
|
process.exit(1);
|
|
92
109
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const { createTask, resolve } = require('../../../utils/widgets');
|
|
2
2
|
const { buildMpNpm } = require('../../../core/mpCi');
|
|
3
3
|
const { CACHE_DIR } = require('../../../config/constant');
|
|
4
|
-
const {
|
|
4
|
+
const { mpNpmInstallAll } = require('../../../core/npm');
|
|
5
5
|
const { global } = require('../../../utils/global');
|
|
6
6
|
|
|
7
|
-
async function install(tmsConfig, modules
|
|
7
|
+
async function install(tmsConfig, modules) {
|
|
8
8
|
// 小程序npm install
|
|
9
9
|
await createTask(
|
|
10
10
|
mpNpmInstallAll,
|
|
@@ -19,13 +19,6 @@ async function install(tmsConfig, modules, isCloud = false) {
|
|
|
19
19
|
'开始构建miniprogram_npm',
|
|
20
20
|
'构建miniprogram_npm 完成',
|
|
21
21
|
)({ appId: tmsConfig.appId, projectPath: resolve('./'), privateKey: tmsPrivateCf.privateKey });
|
|
22
|
-
|
|
23
|
-
// 安装云函数的
|
|
24
|
-
isCloud && createTask(
|
|
25
|
-
cloudNpmInstall,
|
|
26
|
-
'云函数npm install',
|
|
27
|
-
'云函数npm install安装完毕',
|
|
28
|
-
)(resolve(tmsConfig.cloudDir));
|
|
29
22
|
}
|
|
30
23
|
|
|
31
24
|
module.exports = install;
|
package/src/utils/io.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const { info } = require('../utils/log');
|
|
4
|
+
const { relativeCwdPath } = require('../utils/widgets');
|
|
4
5
|
/**
|
|
5
6
|
* 判断目录是否为空
|
|
6
7
|
* @param {string} dirname 目录名
|
|
@@ -44,11 +45,11 @@ function diffContentCopyFile(originFile, destFile) {
|
|
|
44
45
|
const depDestContent = fs.readFileSync(destFile, 'utf8');
|
|
45
46
|
const depOriginContent = fs.readFileSync(originFile, 'utf8');
|
|
46
47
|
if (depDestContent !== depOriginContent) {
|
|
47
|
-
info(`拷贝${originFile}内容到${destFile}`);
|
|
48
|
+
info(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
48
49
|
copyFile(originFile, destFile);
|
|
49
50
|
}
|
|
50
51
|
} else {
|
|
51
|
-
info(`拷贝${originFile}内容到${destFile}`);
|
|
52
|
+
info(`拷贝${relativeCwdPath(originFile)}内容到${relativeCwdPath(destFile)}`);
|
|
52
53
|
copyFile(originFile, destFile);
|
|
53
54
|
}
|
|
54
55
|
}
|
package/src/utils/log.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const chalk = require('chalk');
|
|
2
|
+
const moment = require('moment');
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 本文件提供无依赖的在终端打印彩色文字的方法。
|
|
@@ -13,7 +14,7 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
|
|
|
13
14
|
const fail = (message = '') => {
|
|
14
15
|
const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
|
|
15
16
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
|
|
16
|
-
console.log(`${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
17
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
/**
|
|
@@ -24,7 +25,7 @@ const fail = (message = '') => {
|
|
|
24
25
|
const succeed = (message = '') => {
|
|
25
26
|
const greenStyleConfig = decodeURIComponent('%1B%5B42%3B30m'); // \033[42;30m转义后的字符按,console时输出绿色文字
|
|
26
27
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
|
|
27
|
-
console.log(`${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
28
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
|
|
@@ -34,10 +35,10 @@ const succeed = (message = '') => {
|
|
|
34
35
|
* @returns {undefined} 无
|
|
35
36
|
*/
|
|
36
37
|
const warn = (message) => {
|
|
37
|
-
console.log(chalk.yellow(message));
|
|
38
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk.yellow(message));
|
|
38
39
|
};
|
|
39
40
|
|
|
40
|
-
const info = (...args) => console.log(...args);
|
|
41
|
+
const info = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
|
|
41
42
|
|
|
42
43
|
module.exports = {
|
|
43
44
|
fail,
|
package/src/utils/widgets.js
CHANGED
|
@@ -114,7 +114,7 @@ function pullRepoForGit(dest, branch) {
|
|
|
114
114
|
function npmInstall(dir) {
|
|
115
115
|
return new Promise((resolve, reject) => {
|
|
116
116
|
shelljs.exec(
|
|
117
|
-
'
|
|
117
|
+
'npm install --production --registry http://mirrors.tencent.com/npm/',
|
|
118
118
|
{ cwd: dir, silent: true },
|
|
119
119
|
(code, stdout, stderr) => {
|
|
120
120
|
if (code !== 0) {
|
|
@@ -144,14 +144,13 @@ function createTask(task, startText, endText) {
|
|
|
144
144
|
return async (...args) => {
|
|
145
145
|
const start = Date.now();
|
|
146
146
|
|
|
147
|
-
const spinner = ora(
|
|
148
|
-
|
|
147
|
+
const spinner = ora();
|
|
148
|
+
info(startText);
|
|
149
149
|
spinner.start();
|
|
150
|
-
info('\n');
|
|
151
150
|
|
|
152
151
|
const result = await task(...args);
|
|
153
152
|
|
|
154
|
-
endText && spinner.succeed(`${endText},
|
|
153
|
+
endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
|
|
155
154
|
spinner.stop();
|
|
156
155
|
|
|
157
156
|
return result;
|
|
@@ -165,6 +164,22 @@ function createTask(task, startText, endText) {
|
|
|
165
164
|
*/
|
|
166
165
|
const camelize = str => str.replace(/-(\w)/g, (a, c) => (c ? c.toUpperCase() : ''));
|
|
167
166
|
|
|
167
|
+
const mergeMap = function (obj, src) {
|
|
168
|
+
for (const [k, v] of src) {
|
|
169
|
+
if (obj.has(k)) {
|
|
170
|
+
obj.set(k, obj.get(k) + v);
|
|
171
|
+
} else {
|
|
172
|
+
obj.set(k, v);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return obj;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const relativeCwdPath = function (file) {
|
|
180
|
+
return path.relative(process.cwd(), file);
|
|
181
|
+
};
|
|
182
|
+
|
|
168
183
|
module.exports = {
|
|
169
184
|
resolve,
|
|
170
185
|
isObject,
|
|
@@ -175,4 +190,6 @@ module.exports = {
|
|
|
175
190
|
suggestCommands,
|
|
176
191
|
camelize,
|
|
177
192
|
npmInstall,
|
|
193
|
+
mergeMap,
|
|
194
|
+
relativeCwdPath,
|
|
178
195
|
};
|