@tmsfe/tmskit 0.0.15 → 0.0.16
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/build/publish.sh +34 -0
- package/dist/index.cjs.js +700 -415
- package/main.js +0 -0
- package/package.json +12 -1
- package/src/compile/compile.js +56 -35
- package/src/compile/dev.js +27 -23
- package/src/compile/plugins/gulp-watch/index.js +172 -0
- package/src/compile/watch.js +51 -15
- package/src/core/buildAppJson.js +3 -0
- package/src/entry.js +1 -1
- package/src/scripts/run/dev/index.js +12 -8
- package/src/scripts/run/init/index.js +27 -15
- package/src/scripts/run/install/index.js +18 -9
- package/src/utils/io.js +20 -0
- package/src/utils/log.js +4 -4
- package/src/utils/widgets.js +3 -3
- package/CHANGELOG.md +0 -26
|
@@ -8,6 +8,7 @@ const { cloneModules } = require('../../../core/cloneModules');
|
|
|
8
8
|
const { tmsModulesMergeLocalModuleCfg, subModulesMergeDepModules } = require('../../../core/tmsMpconfig');
|
|
9
9
|
const { fail, info } = require('../../../utils/log');
|
|
10
10
|
const install = require('../install');
|
|
11
|
+
const { checkDependencies } = require('../../../core/checkDependencies');
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* 拷贝相关配置文件到编译输出目录
|
|
@@ -16,7 +17,7 @@ const install = require('../install');
|
|
|
16
17
|
* @param { array } defaultFiles 默认需要拷贝的配置项
|
|
17
18
|
* @returns
|
|
18
19
|
*/
|
|
19
|
-
const cpFilesToOutput = function (tmsConfig,
|
|
20
|
+
const cpFilesToOutput = function (tmsConfig, defaultFiles) {
|
|
20
21
|
const outputDir = resolve(tmsConfig.outputDir);
|
|
21
22
|
io.ensureDirExist(outputDir);
|
|
22
23
|
defaultFiles.forEach((item) => {
|
|
@@ -24,19 +25,26 @@ const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
|
|
|
24
25
|
shelljs.cp('-rf', resolve(item), resolve(tmsConfig.outputDir, item));
|
|
25
26
|
}
|
|
26
27
|
});
|
|
28
|
+
};
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
/**
|
|
31
|
+
* 校验相关配置项
|
|
32
|
+
* @param {*} targetModules
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
function checkConfig(targetModules) {
|
|
36
|
+
for (const item of targetModules) {
|
|
37
|
+
if (!item.root) {
|
|
38
|
+
throw new Error(`检查${item.name} module.config.json的root字段`);
|
|
34
39
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (fs.existsSync(
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
+
|
|
41
|
+
// 判断源码目录是否有该模块
|
|
42
|
+
if (item.path && !fs.existsSync(resolve(item.path))) {
|
|
43
|
+
throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
40
48
|
|
|
41
49
|
async function task(tmsConfig, targetModules) {
|
|
42
50
|
// 下载和移动代码
|
|
@@ -51,15 +59,19 @@ async function task(tmsConfig, targetModules) {
|
|
|
51
59
|
// A分包依赖了B分包的代码, merge B分包进行编译;
|
|
52
60
|
newModules = subModulesMergeDepModules(tmsConfig, newModules);
|
|
53
61
|
|
|
62
|
+
checkConfig(newModules);
|
|
63
|
+
|
|
54
64
|
// 拷贝相关配置文件到输出目录
|
|
55
65
|
await createTask(
|
|
56
66
|
cpFilesToOutput,
|
|
57
67
|
'开始拷贝文件到编译输出目录',
|
|
58
68
|
'拷贝文件到编译输出目录完成',
|
|
59
|
-
)(tmsConfig,
|
|
69
|
+
)(tmsConfig, DEFAULT_COPY_CONFIG);
|
|
60
70
|
|
|
61
71
|
// install
|
|
62
|
-
|
|
72
|
+
if (checkDependencies(newModules, resolve('./'), tmsConfig.outputDir)) {
|
|
73
|
+
await install(tmsConfig, newModules);
|
|
74
|
+
}
|
|
63
75
|
|
|
64
76
|
// 动态生成编译后的app.json;
|
|
65
77
|
await createTask(
|
|
@@ -79,7 +91,7 @@ async function init(tmsConfig, targetModules) {
|
|
|
79
91
|
};
|
|
80
92
|
} catch (error) {
|
|
81
93
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
82
|
-
fail(
|
|
94
|
+
fail(`初始化流程出现错误${errMsg}`);
|
|
83
95
|
info('详细的错误信息', error);
|
|
84
96
|
process.exit(1);
|
|
85
97
|
}
|
|
@@ -1,10 +1,26 @@
|
|
|
1
|
+
const shelljs = require('shelljs');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const io = require('../../../utils/io');
|
|
1
4
|
const { createTask, resolve } = require('../../../utils/widgets');
|
|
2
5
|
const { buildMpNpm } = require('../../../core/mpCi');
|
|
3
6
|
const { CACHE_DIR } = require('../../../config/constant');
|
|
4
|
-
const {
|
|
7
|
+
const { mpNpmInstallAll } = require('../../../core/npm');
|
|
5
8
|
const { global } = require('../../../utils/global');
|
|
9
|
+
const { fail } = require('../../../utils/log');
|
|
10
|
+
|
|
11
|
+
async function install(tmsConfig, modules) {
|
|
12
|
+
// 拷贝模块的package.json到编译输出目录
|
|
13
|
+
modules.forEach((item) => {
|
|
14
|
+
const outputModuleDir = resolve(`${tmsConfig.outputDir}/${item.root}`);
|
|
15
|
+
if (!fs.existsSync(resolve(item.path))) {
|
|
16
|
+
fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
io.ensureDirExist(outputModuleDir);
|
|
20
|
+
const modulePackagePath = resolve(item.path, 'package.json');
|
|
21
|
+
if (fs.existsSync(modulePackagePath)) shelljs.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
22
|
+
});
|
|
6
23
|
|
|
7
|
-
async function install(tmsConfig, modules, isCloud = false) {
|
|
8
24
|
// 小程序npm install
|
|
9
25
|
await createTask(
|
|
10
26
|
mpNpmInstallAll,
|
|
@@ -19,13 +35,6 @@ async function install(tmsConfig, modules, isCloud = false) {
|
|
|
19
35
|
'开始构建miniprogram_npm',
|
|
20
36
|
'构建miniprogram_npm 完成',
|
|
21
37
|
)({ 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
38
|
}
|
|
30
39
|
|
|
31
40
|
module.exports = install;
|
package/src/utils/io.js
CHANGED
|
@@ -97,6 +97,25 @@ const fileInDir = (dir, file) => {
|
|
|
97
97
|
};
|
|
98
98
|
|
|
99
99
|
|
|
100
|
+
function findAllFilesOfDir(dir) {
|
|
101
|
+
const list = [];
|
|
102
|
+
function listFile(dir) {
|
|
103
|
+
const arr = fs.readdirSync(dir);
|
|
104
|
+
arr.forEach((item) => {
|
|
105
|
+
const fullPath = path.join(dir, item);
|
|
106
|
+
const stats = fs.statSync(fullPath);
|
|
107
|
+
if (stats.isDirectory()) {
|
|
108
|
+
listFile(fullPath);
|
|
109
|
+
} else {
|
|
110
|
+
list.push(fullPath);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
return list;
|
|
114
|
+
}
|
|
115
|
+
listFile(dir);
|
|
116
|
+
return list;
|
|
117
|
+
}
|
|
118
|
+
|
|
100
119
|
module.exports = {
|
|
101
120
|
isDirEmpty,
|
|
102
121
|
copyFile,
|
|
@@ -105,4 +124,5 @@ module.exports = {
|
|
|
105
124
|
ext,
|
|
106
125
|
fileInDir,
|
|
107
126
|
isFile,
|
|
127
|
+
findAllFilesOfDir,
|
|
108
128
|
};
|
package/src/utils/log.js
CHANGED
|
@@ -14,7 +14,7 @@ const resetCfg = decodeURIComponent('%1B%5B0m'); // \033[0m转义后的字符按
|
|
|
14
14
|
const fail = (message = '') => {
|
|
15
15
|
const redStyleConfig = decodeURIComponent('%1B%5B41%3B30m'); // \033[41;30m转义后的字符按,console时输出红色文字
|
|
16
16
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B41%3B37m'); // \033[41;30m转义后的字符按,console时输出红底白色文字
|
|
17
|
-
console.log(
|
|
17
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${redStyleConfig} ERROR ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -25,7 +25,7 @@ const fail = (message = '') => {
|
|
|
25
25
|
const succeed = (message = '') => {
|
|
26
26
|
const greenStyleConfig = decodeURIComponent('%1B%5B42%3B30m'); // \033[42;30m转义后的字符按,console时输出绿色文字
|
|
27
27
|
const greenFontStyleConfig = decodeURIComponent('%1B%5B40%3B32m'); // \033[40;32m转义后的字符按,console时输出绿色文字
|
|
28
|
-
console.log(
|
|
28
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, `${greenStyleConfig} Success ${greenFontStyleConfig} ${message}${resetCfg}`); // eslint-disable-line no-console
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
|
|
@@ -35,10 +35,10 @@ const succeed = (message = '') => {
|
|
|
35
35
|
* @returns {undefined} 无
|
|
36
36
|
*/
|
|
37
37
|
const warn = (message) => {
|
|
38
|
-
console.log(
|
|
38
|
+
console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, chalk.yellow(message));
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
const info = (...args) => console.log(
|
|
41
|
+
const info = (...args) => console.log(`${moment().format('YYYY-MM-DD HH:mm:ss')}`, ...args);
|
|
42
42
|
|
|
43
43
|
module.exports = {
|
|
44
44
|
fail,
|
package/src/utils/widgets.js
CHANGED
|
@@ -144,13 +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
150
|
|
|
151
151
|
const result = await task(...args);
|
|
152
152
|
|
|
153
|
-
endText && spinner.succeed(`${endText},
|
|
153
|
+
endText && spinner.succeed(`${endText}, 耗时${cost(start) / 1000}s`);
|
|
154
154
|
spinner.stop();
|
|
155
155
|
|
|
156
156
|
return result;
|
package/CHANGELOG.md
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
##
|
|
2
|
-
1. [0.0.5] 支持创建新的小程序
|
|
3
|
-
2. [0.0.6] 支持编译功能
|
|
4
|
-
3. [0.0.7]
|
|
5
|
-
* 更新切换开发环境需要重启构建工具,调整为改代码直接生效
|
|
6
|
-
* 修复切换第三方代码库分支后,构建工具没有重新拉代码的问题
|
|
7
|
-
* 修复thirdparty代码没有正确构建问题
|
|
8
|
-
* 新增对一个仓库下多个分包的支持
|
|
9
|
-
* 优化代码下载流程,多仓库并行下载,第三方代码下载时间60s->15s
|
|
10
|
-
* 本地private.config.js配置,支持指定屏蔽某些模块,屏蔽所有远程模块的设置
|
|
11
|
-
4. [0.0.10]
|
|
12
|
-
* 优化npm install并行改成串行,60个模块开发第一次启动由100s优化至40s, 第二次启动2s;
|
|
13
|
-
* 添加global全局缓存变量,避免变量层层传递的问题
|
|
14
|
-
* 增加--latest参数,重新初始化操作(拉去第三方模块、npm下载、生成appJson)
|
|
15
|
-
* 修复获取用户指定模块的bug
|
|
16
|
-
5. [0.0.12] 云函数支持创建软连, 支持引入项目外的云函数能力
|
|
17
|
-
|
|
18
|
-
6. [0.0.13]
|
|
19
|
-
* 首次编译完成,提示用户编译完成.
|
|
20
|
-
* 日志添加时间戳
|
|
21
|
-
* 编译代码有更新时,增加提示日志
|
|
22
|
-
* 删除源码文件或文件夹时,支持监听文件变动,删除编译文件
|
|
23
|
-
* fix window中tar命令的兼容性问题
|
|
24
|
-
7. [0.0.14]
|
|
25
|
-
* 删除原函数软连功能
|
|
26
|
-
* fix 修复dist node_module.tar.gz没有删除bug
|