@tmsfe/tmskit 0.0.18 → 0.0.21
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 +1440 -1045
- package/package.json +10 -8
- package/src/{init.js → check.js} +2 -3
- package/src/compile/build.js +2 -2
- package/src/compile/dev.js +32 -33
- package/src/compile/watch.js +31 -12
- package/src/config/constant.js +29 -3
- package/src/core/buildAppJson.js +14 -21
- package/src/core/cache.js +36 -0
- package/src/core/checkDependencies.js +38 -21
- package/src/core/cloneModules.js +5 -7
- package/src/core/handleError.js +7 -1
- package/src/core/npm.js +12 -9
- package/src/core/symbolicLink.js +17 -19
- package/src/core/tmsMpconfig.js +183 -94
- package/src/entry.js +4 -4
- package/src/index.js +18 -4
- package/src/scripts/create/generator.js +1 -2
- package/src/scripts/create/index.js +73 -32
- package/src/scripts/run/build/index.js +5 -4
- package/src/scripts/run/cloud/index.js +0 -2
- package/src/scripts/run/dev/index.js +15 -14
- package/src/scripts/run/index.js +43 -59
- package/src/scripts/run/init/index.js +13 -36
- package/src/scripts/run/install/index.js +113 -23
- package/src/utils/md5.js +25 -0
- package/src/utils/widgets.js +23 -0
- package/src/core/isInIt.js +0 -65
|
@@ -2,19 +2,22 @@ const shelljs = require('shelljs');
|
|
|
2
2
|
const compileDev = require('../../../compile/dev');
|
|
3
3
|
const { resolve, filterField } = require('../../../utils/widgets');
|
|
4
4
|
const init = require('../init/index');
|
|
5
|
-
const {
|
|
5
|
+
const { getModulesByMergeDepModules, getSubPackages } = require('../../../core/tmsMpconfig');
|
|
6
6
|
const { info } = require('../../../utils/log');
|
|
7
7
|
const { global } = require('../../../utils/global');
|
|
8
8
|
const { CACHE_DIR } = require('../../../config/constant');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
// 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
function delOtherPackages(tmsConfig, targetSubPackages) {
|
|
13
|
+
// 获取所有模块,合并模块依赖的模块
|
|
14
|
+
const allModules = getModulesByMergeDepModules(tmsConfig, tmsConfig.modules.all);
|
|
15
|
+
// 获取所有的分包
|
|
16
|
+
const allSubPackages = getSubPackages(allModules);
|
|
17
|
+
const targetSubPackagesName = targetSubPackages.map(item => item.name);
|
|
18
|
+
allSubPackages.forEach((item) => {
|
|
19
|
+
if (item.root && targetSubPackagesName.indexOf(item.name) === -1) {
|
|
20
|
+
const moduleRootDir = resolve(`${tmsConfig.outputDir}/${item.root}`);
|
|
18
21
|
shelljs.rm('-rf', `${moduleRootDir}/*`, { silent: true });
|
|
19
22
|
// 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
|
|
20
23
|
// io.ensureDirExist(moduleRootDir);
|
|
@@ -22,8 +25,7 @@ function delOtherModule(tmsConfig, targetModules) {
|
|
|
22
25
|
});
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
async function dev(tmsConfig, targetModules
|
|
26
|
-
let newModules = targetModules;
|
|
28
|
+
async function dev(tmsConfig, targetModules) {
|
|
27
29
|
const { noCache } = global.getData('cmd');
|
|
28
30
|
if (noCache) {
|
|
29
31
|
shelljs.rm('-rf', resolve(tmsConfig.outputDir));
|
|
@@ -31,10 +33,9 @@ async function dev(tmsConfig, targetModules, env) {
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
// 初始化操作
|
|
34
|
-
const
|
|
35
|
-
newModules = initData.targetModules;
|
|
36
|
+
const { subPackages, modules: newModules } = await init(tmsConfig, targetModules);
|
|
36
37
|
|
|
37
|
-
info('当前dev启动的有效模块', newModules.map(item => item.
|
|
38
|
+
info('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
|
|
38
39
|
if (typeof tmsConfig?.hooks?.beforeCompile === 'function') {
|
|
39
40
|
await tmsConfig?.hooks?.beforeCompile({
|
|
40
41
|
isDev: true,
|
|
@@ -42,8 +43,8 @@ async function dev(tmsConfig, targetModules, env) {
|
|
|
42
43
|
modules: newModules,
|
|
43
44
|
});
|
|
44
45
|
};
|
|
45
|
-
|
|
46
|
-
compileDev(tmsConfig, newModules,
|
|
46
|
+
delOtherPackages(tmsConfig, subPackages);
|
|
47
|
+
compileDev(tmsConfig, newModules, true);
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
module.exports = dev;
|
package/src/scripts/run/index.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */
|
|
2
|
-
const loadash = require('lodash');
|
|
3
2
|
const init = require('./init/index');
|
|
4
3
|
const dev = require('./dev/index');
|
|
5
4
|
const build = require('./build/index');
|
|
6
5
|
const install = require('./install/index');
|
|
7
6
|
const cloud = require('./cloud/index');
|
|
7
|
+
const { fail, info } = require('../../utils/log');
|
|
8
8
|
const { global } = require('../../utils/global');
|
|
9
9
|
const {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
subModulesMergeDepModules,
|
|
10
|
+
getTmsConfig,
|
|
11
|
+
getModulesByMergeDepModules,
|
|
12
|
+
getSubPackages,
|
|
13
|
+
getModulesByModuleNames,
|
|
15
14
|
} = require('../../core/tmsMpconfig');
|
|
16
15
|
|
|
17
16
|
const handleModuleArg = (cmd) => {
|
|
@@ -27,7 +26,7 @@ const handleModuleArg = (cmd) => {
|
|
|
27
26
|
* @param {Object} modulePrivateCfg 私有配置里的模块
|
|
28
27
|
* @param {Array} moduleAll 当前小程序全部模块
|
|
29
28
|
*/
|
|
30
|
-
const
|
|
29
|
+
const getSpecificModuleNames = (moduleArg, modules) => {
|
|
31
30
|
if (moduleArg.length > 0) {
|
|
32
31
|
return moduleArg;
|
|
33
32
|
}
|
|
@@ -37,83 +36,68 @@ const getSpecificModules = (moduleArg, modules) => {
|
|
|
37
36
|
return include;
|
|
38
37
|
}
|
|
39
38
|
if (exclude?.length > 0) {
|
|
40
|
-
return all.filter(module => !exclude.includes(module.
|
|
39
|
+
return all.filter(module => !exclude.includes(module.moduleName)).map(item => item.moduleName);
|
|
41
40
|
}
|
|
42
41
|
if (blockRemote === true) {
|
|
43
|
-
return all.filter(module => module.repoInfo === undefined).map(item => item.
|
|
42
|
+
return all.filter(module => module.repoInfo === undefined).map(item => item.moduleName);
|
|
44
43
|
}
|
|
45
|
-
return all.map(item => item.
|
|
44
|
+
return all.map(item => item.moduleName);
|
|
46
45
|
};
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
tmsConfig.modules = modules;
|
|
53
|
-
}
|
|
54
|
-
// 合并默认值
|
|
55
|
-
const res = loadash.mergeWith(tmsConfig, tmsPrivateCf, (objValue, srcValue) => {
|
|
56
|
-
if (loadash.isArray(objValue) && objValue[0] && loadash.isObject(objValue[0])) {
|
|
57
|
-
return objValue.concat(srcValue);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
47
|
+
async function run(commandName, cmd) {
|
|
48
|
+
try {
|
|
49
|
+
// 用户本地的配置
|
|
50
|
+
const tmsConfig = getTmsConfig();
|
|
60
51
|
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
// 缓存数据
|
|
53
|
+
global.setData({
|
|
54
|
+
cmd,
|
|
55
|
+
tmsConfig,
|
|
56
|
+
});
|
|
63
57
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
58
|
+
if (commandName === 'cloud') {
|
|
59
|
+
cloud(tmsConfig);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
otherCommands(tmsConfig, commandName, cmd);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
const errMsg = typeof error === 'object' ? error.message : error;
|
|
65
|
+
fail(`构建出现错误: ${errMsg}`);
|
|
66
|
+
info('详细错误信息', error);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
70
|
|
|
71
|
+
function otherCommands(tmsConfig, commandName, cmd) {
|
|
71
72
|
// 处理module参数
|
|
72
|
-
const
|
|
73
|
+
const specificModuleNames = getSpecificModuleNames(
|
|
73
74
|
handleModuleArg(cmd),
|
|
74
75
|
tmsConfig.modules,
|
|
75
76
|
);
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
...new Set([
|
|
81
|
-
...tmsConfig.mainPackages,
|
|
82
|
-
...specificModules,
|
|
83
|
-
]),
|
|
84
|
-
],
|
|
85
|
-
true,
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
// tms.config.js的modules 合并 module.config.json的配置项
|
|
89
|
-
let newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName);
|
|
90
|
-
// A分包依赖了B分包的代码, merge B分包进行编译;
|
|
91
|
-
newModules = subModulesMergeDepModules(tmsConfig, newModules);
|
|
78
|
+
// moduleNames => ['home', 'car']
|
|
79
|
+
const moduleNames = [...new Set([...specificModuleNames])];
|
|
80
|
+
const modules = getModulesByModuleNames(tmsConfig, moduleNames, false);
|
|
92
81
|
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
tmsConfig,
|
|
98
|
-
});
|
|
82
|
+
// 获取所有模块,合并模块依赖的模块
|
|
83
|
+
const newModules = getModulesByMergeDepModules(tmsConfig, modules, false);
|
|
84
|
+
// 获取所有的分包
|
|
85
|
+
const subPackages = getSubPackages(newModules);
|
|
99
86
|
|
|
100
87
|
switch (commandName) {
|
|
101
88
|
case 'init':
|
|
102
|
-
init(tmsConfig, newModules
|
|
89
|
+
init(tmsConfig, newModules);
|
|
103
90
|
return;
|
|
104
91
|
case 'dev':
|
|
105
92
|
global.setData('isDev', true);
|
|
106
|
-
dev(tmsConfig, newModules
|
|
107
|
-
return;
|
|
108
|
-
case 'cloud':
|
|
109
|
-
cloud(tmsConfig, env);
|
|
93
|
+
dev(tmsConfig, newModules);
|
|
110
94
|
return;
|
|
111
95
|
case 'install':
|
|
112
|
-
install(tmsConfig,
|
|
96
|
+
install(tmsConfig, subPackages, false);
|
|
113
97
|
return;
|
|
114
98
|
case 'build':
|
|
115
99
|
global.setData('isDev', false);
|
|
116
|
-
build(tmsConfig, newModules
|
|
100
|
+
build(tmsConfig, newModules);
|
|
117
101
|
return;
|
|
118
102
|
default:
|
|
119
103
|
return;
|
|
@@ -5,10 +5,9 @@ const { resolve, createTask } = require('../../../utils/widgets');
|
|
|
5
5
|
const { buildOutputAppJson } = require('../../../core/buildAppJson');
|
|
6
6
|
const { MODULE_CODE_DIR, DEFAULT_COPY_CONFIG } = require('../../../config/constant');
|
|
7
7
|
const { cloneModules } = require('../../../core/cloneModules');
|
|
8
|
-
const {
|
|
8
|
+
const { getModulesByMergeDepModules, getSubPackages } = require('../../../core/tmsMpconfig');
|
|
9
9
|
const { fail, info } = require('../../../utils/log');
|
|
10
10
|
const install = require('../install');
|
|
11
|
-
const { checkDependencies } = require('../../../core/checkDependencies');
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* 拷贝相关配置文件到编译输出目录
|
|
@@ -27,25 +26,6 @@ const cpFilesToOutput = function (tmsConfig, defaultFiles) {
|
|
|
27
26
|
});
|
|
28
27
|
};
|
|
29
28
|
|
|
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字段`);
|
|
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
|
-
}
|
|
48
|
-
|
|
49
29
|
async function task(tmsConfig, targetModules) {
|
|
50
30
|
// 下载和移动代码
|
|
51
31
|
await createTask(
|
|
@@ -54,12 +34,10 @@ async function task(tmsConfig, targetModules) {
|
|
|
54
34
|
'下载模块代码码完成',
|
|
55
35
|
)(MODULE_CODE_DIR, resolve('./'), targetModules);
|
|
56
36
|
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
checkConfig(newModules);
|
|
37
|
+
// 获取所有模块,合并模块依赖的模块
|
|
38
|
+
const newModules = getModulesByMergeDepModules(tmsConfig, targetModules, true);
|
|
39
|
+
// 获取所有的分包
|
|
40
|
+
const newSubPackages = getSubPackages(newModules);
|
|
63
41
|
|
|
64
42
|
// 拷贝相关配置文件到输出目录
|
|
65
43
|
await createTask(
|
|
@@ -69,9 +47,7 @@ async function task(tmsConfig, targetModules) {
|
|
|
69
47
|
)(tmsConfig, DEFAULT_COPY_CONFIG);
|
|
70
48
|
|
|
71
49
|
// install
|
|
72
|
-
|
|
73
|
-
await install(tmsConfig, newModules);
|
|
74
|
-
}
|
|
50
|
+
await install(tmsConfig, newSubPackages, true);
|
|
75
51
|
|
|
76
52
|
// 动态生成编译后的app.json;
|
|
77
53
|
await createTask(
|
|
@@ -80,18 +56,19 @@ async function task(tmsConfig, targetModules) {
|
|
|
80
56
|
'生成编译后的app.json完成',
|
|
81
57
|
)(tmsConfig, newModules);
|
|
82
58
|
|
|
83
|
-
return
|
|
59
|
+
return {
|
|
60
|
+
modules: newModules,
|
|
61
|
+
subPackages: newSubPackages,
|
|
62
|
+
};
|
|
84
63
|
}
|
|
85
64
|
async function init(tmsConfig, targetModules) {
|
|
86
65
|
try {
|
|
87
|
-
const
|
|
66
|
+
const taskRes = await task(tmsConfig, targetModules);
|
|
88
67
|
|
|
89
|
-
return
|
|
90
|
-
targetModules: newModules,
|
|
91
|
-
};
|
|
68
|
+
return taskRes;
|
|
92
69
|
} catch (error) {
|
|
93
70
|
const errMsg = typeof error === 'object' ? error.message : error;
|
|
94
|
-
fail(
|
|
71
|
+
fail(`初始化流程出现错误: ${errMsg}`);
|
|
95
72
|
info('详细的错误信息', error);
|
|
96
73
|
process.exit(1);
|
|
97
74
|
}
|
|
@@ -1,38 +1,128 @@
|
|
|
1
1
|
const shelljs = require('shelljs');
|
|
2
2
|
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
3
4
|
const io = require('../../../utils/io');
|
|
4
|
-
const { createTask, resolve } = require('../../../utils/widgets');
|
|
5
|
+
const { createTask, resolve, getAbsolutePath } = require('../../../utils/widgets');
|
|
5
6
|
const { buildMpNpm } = require('../../../core/mpCi');
|
|
7
|
+
const { setCache, getCache } = require('../../../core/cache');
|
|
6
8
|
const { CACHE_DIR } = require('../../../config/constant');
|
|
7
|
-
const {
|
|
8
|
-
const {
|
|
9
|
+
const { npmInstallAll } = require('../../../core/npm');
|
|
10
|
+
const { info } = require('../../../utils/log');
|
|
11
|
+
const { fileMd5 } = require('../../../utils/md5');
|
|
12
|
+
const { isDependenciesUpdate } = require('../../../core/checkDependencies');
|
|
9
13
|
|
|
10
|
-
async function install(tmsConfig,
|
|
14
|
+
async function install(tmsConfig, subPackages, useCache = true) {
|
|
15
|
+
const cwd = process.cwd();
|
|
16
|
+
const npmInstallRes = await createTask(
|
|
17
|
+
npmInstall,
|
|
18
|
+
'小程序 开始npm install',
|
|
19
|
+
'小程序npm install 完成',
|
|
20
|
+
)(tmsConfig, subPackages, useCache);
|
|
21
|
+
|
|
22
|
+
// 如果npm install 没有命中缓存,则说明node_module有更新,此时必须构建miniprogram_npm
|
|
23
|
+
if (!npmInstallRes.isCache) {
|
|
24
|
+
// 构建miniprogram_npm, 不使用缓存
|
|
25
|
+
await createTask(
|
|
26
|
+
mpCiInstall,
|
|
27
|
+
'开始构建miniprogram_npm',
|
|
28
|
+
'构建miniprogram_npm 完成',
|
|
29
|
+
)(tmsConfig, subPackages, false);
|
|
30
|
+
} else {
|
|
31
|
+
// 构建miniprogram_npm
|
|
32
|
+
await createTask(
|
|
33
|
+
mpCiInstall,
|
|
34
|
+
'开始构建miniprogram_npm',
|
|
35
|
+
'构建miniprogram_npm 完成',
|
|
36
|
+
)(tmsConfig, subPackages, useCache);
|
|
37
|
+
}
|
|
38
|
+
shelljs.cd(cwd);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function npmInstall(tmsConfig, subPackages, useCache) {
|
|
42
|
+
// 如果依赖没有更新和使用缓存数据(则命中缓存)
|
|
43
|
+
if (!isDependenciesUpdate(subPackages, resolve('./'), tmsConfig.outputDir) && useCache) {
|
|
44
|
+
info('node_modules命中缓存');
|
|
45
|
+
return { isCache: true };
|
|
46
|
+
}
|
|
11
47
|
// 拷贝模块的package.json到编译输出目录
|
|
12
|
-
|
|
48
|
+
subPackages.forEach((item) => {
|
|
13
49
|
const outputModuleDir = resolve(`${tmsConfig.outputDir}/${item.root}`);
|
|
14
|
-
if (!fs.existsSync(resolve(item.path))) {
|
|
15
|
-
fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
18
50
|
io.ensureDirExist(outputModuleDir);
|
|
19
|
-
const modulePackagePath =
|
|
51
|
+
const modulePackagePath = `${getAbsolutePath(item.path)}/package.json`;
|
|
20
52
|
if (fs.existsSync(modulePackagePath)) shelljs.cp('-Rf', modulePackagePath, outputModuleDir);
|
|
21
53
|
});
|
|
22
54
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
55
|
+
await npmInstallAll(subPackages, resolve(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`);
|
|
56
|
+
return { isCache: false };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 构建miniprogram_npm
|
|
60
|
+
async function mpCiInstall(tmsConfig, subPackages, useCache) {
|
|
61
|
+
const packageJsonFiles = [];
|
|
62
|
+
const rootPackFile = resolve(`${tmsConfig.outputDir}/package.json`);
|
|
63
|
+
if (fs.existsSync(rootPackFile)) {
|
|
64
|
+
packageJsonFiles.push(rootPackFile);
|
|
65
|
+
}
|
|
66
|
+
subPackages.forEach((item) => {
|
|
67
|
+
const packageJsonFile = resolve(`${tmsConfig.outputDir}/${item.root}/package.json`);
|
|
68
|
+
if (fs.existsSync(packageJsonFile)) {
|
|
69
|
+
packageJsonFiles.push(packageJsonFile);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
let isCache = false;
|
|
74
|
+
const statusMap = { success: 1, doing: 2 };
|
|
75
|
+
if (useCache) {
|
|
76
|
+
let flag = true;
|
|
77
|
+
await Promise.all(packageJsonFiles.map(async (item) => {
|
|
78
|
+
const packageDir = path.dirname(item);
|
|
79
|
+
const mpDir = resolve(`${packageDir}/miniprogram_npm`);
|
|
80
|
+
const md5Value = await getMNPMd5(packageDir);
|
|
81
|
+
const preCache = getCache(mpDir, 'miniprogram_npm');
|
|
82
|
+
// console.log('miniprogram_npm', preCache, md5Value);
|
|
83
|
+
// 上一次构建成功 && 上次md5与当前本地的miniprogram_npm的md5 一致,才可以进入缓存
|
|
84
|
+
if (preCache?.status !== statusMap.success || preCache?.md5 !== md5Value) {
|
|
85
|
+
flag = false;
|
|
86
|
+
}
|
|
87
|
+
}));
|
|
88
|
+
isCache = flag;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (isCache) {
|
|
92
|
+
info('miniprogram_npm命中缓存');
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 即将构建,在cache中标记开始
|
|
97
|
+
await Promise.all(packageJsonFiles.map(async (item) => {
|
|
98
|
+
const packageDir = path.dirname(item);
|
|
99
|
+
const mpDir = resolve(`${packageDir}/miniprogram_npm`);
|
|
100
|
+
setCache(mpDir, 'miniprogram_npm', { md5: '', status: statusMap.doing });
|
|
101
|
+
}));
|
|
102
|
+
|
|
103
|
+
await buildMpNpm({ appId: tmsConfig.appId, projectPath: resolve('./'), privateKey: tmsConfig.privateKey });
|
|
104
|
+
|
|
105
|
+
// 构建成功后,计算md5写入cache
|
|
106
|
+
await Promise.all(packageJsonFiles.map(async (item) => {
|
|
107
|
+
const packageDir = path.dirname(item);
|
|
108
|
+
const mpDir = resolve(`${packageDir}/miniprogram_npm`);
|
|
109
|
+
const md5Value = await getMNPMd5(packageDir);
|
|
110
|
+
setCache(mpDir, 'miniprogram_npm', { md5: md5Value, status: statusMap.success });
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 计算miniprogram_npm压缩文件的md5值
|
|
115
|
+
async function getMNPMd5(cwd) {
|
|
116
|
+
const shellJsOption = { async: false, silent: true };
|
|
117
|
+
shelljs.cd(cwd);
|
|
118
|
+
if (fs.existsSync('miniprogram_npm')) {
|
|
119
|
+
shelljs.exec('tar -cvf ./miniprogram_npm.tar.gz ./miniprogram_npm', { cwd, ...shellJsOption });
|
|
120
|
+
const tarDir = path.join(cwd, './miniprogram_npm.tar.gz');
|
|
121
|
+
const md5Value = await fileMd5(tarDir);
|
|
122
|
+
shelljs.rm('-rf', tarDir);
|
|
123
|
+
return md5Value;
|
|
124
|
+
}
|
|
125
|
+
return '';
|
|
36
126
|
}
|
|
37
127
|
|
|
38
128
|
module.exports = install;
|
package/src/utils/md5.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
|
|
4
|
+
function fileMd5(filePath) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const md5sum = crypto.createHash('md5');
|
|
7
|
+
const stream = fs.ReadStream(filePath);
|
|
8
|
+
stream.on('data', (d) => {
|
|
9
|
+
md5sum.update(d);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
stream.on('error', (err) => {
|
|
13
|
+
reject(err);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
stream.on('end', () => {
|
|
17
|
+
const hash = md5sum.digest('hex');
|
|
18
|
+
resolve(hash);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
fileMd5,
|
|
25
|
+
};
|
package/src/utils/widgets.js
CHANGED
|
@@ -5,6 +5,7 @@ const ora = require('ora');
|
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const fs = require('fs');
|
|
7
7
|
const shelljs = require('shelljs');
|
|
8
|
+
const glob = require('glob-ignore');
|
|
8
9
|
const { info } = require('./log');
|
|
9
10
|
const chalk = require('chalk');
|
|
10
11
|
const shelljsOptions = { slient: true, async: false };
|
|
@@ -196,6 +197,26 @@ const filterField = (obj, filterNames = []) => {
|
|
|
196
197
|
return newObj;
|
|
197
198
|
};
|
|
198
199
|
|
|
200
|
+
// 检索出文件列表
|
|
201
|
+
function findFiles(globPath, filter = []) {
|
|
202
|
+
return new Promise((resolve, reject) => {
|
|
203
|
+
glob(globPath, filter, (err, files) => {
|
|
204
|
+
if (err) {
|
|
205
|
+
reject(err);
|
|
206
|
+
}
|
|
207
|
+
resolve(files);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 获取绝对路径
|
|
213
|
+
function getAbsolutePath(pathDir, cwd = '') {
|
|
214
|
+
let newPath = pathDir;
|
|
215
|
+
newPath = newPath.startsWith('/') ? newPath : resolve(cwd, newPath);
|
|
216
|
+
newPath = newPath.endsWith('/') ? newPath.slice(0, newPath.length - 1) : newPath;
|
|
217
|
+
return newPath;
|
|
218
|
+
}
|
|
219
|
+
|
|
199
220
|
module.exports = {
|
|
200
221
|
resolve,
|
|
201
222
|
isObject,
|
|
@@ -209,4 +230,6 @@ module.exports = {
|
|
|
209
230
|
mergeMap,
|
|
210
231
|
relativeCwdPath,
|
|
211
232
|
filterField,
|
|
233
|
+
findFiles,
|
|
234
|
+
getAbsolutePath,
|
|
212
235
|
};
|
package/src/core/isInIt.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const { resolve } = require('../utils/widgets');
|
|
3
|
-
const { MODULE_CODE_DIR } = require('../config/constant');
|
|
4
|
-
const { checkRemoteModGitUrlBranch } = require('./cloneModules');
|
|
5
|
-
const { checkDependencies } = require('./checkDependencies');
|
|
6
|
-
const { fail } = require('../utils/log');
|
|
7
|
-
|
|
8
|
-
function checkModule(targetModules) {
|
|
9
|
-
// 判断\源码\dist\是否存在用户指定的模块
|
|
10
|
-
for (const item of targetModules) {
|
|
11
|
-
// 此模块没有root字段(原因:没有merge到module.config.json的配置项。第三方模块的代码可能还没有下载)
|
|
12
|
-
if (!item.root) {
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// 判断第三方远程模块git地址与branch是否有更新
|
|
17
|
-
if (checkRemoteModGitUrlBranch(MODULE_CODE_DIR, item)) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// 判断源码目录是否有该模块
|
|
22
|
-
if (item.path && !fs.existsSync(resolve(item.path))) {
|
|
23
|
-
fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
|
|
24
|
-
process.exit(1);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function isInit(tmsConfig, targetModules, contextDir) {
|
|
31
|
-
// 判断是否存在dist目录
|
|
32
|
-
if (!fs.existsSync(contextDir)) {
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
// 判断dist是否存在node_modules
|
|
36
|
-
if (!fs.existsSync(`${contextDir}/node_modules`)) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 判断dist是否存在miniprogram_npm
|
|
41
|
-
if (!fs.existsSync(`${contextDir}/miniprogram_npm`)) {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// 判断dist是否存在app.json
|
|
46
|
-
if (!fs.existsSync(`${contextDir}/app.json`)) {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// 判断模块信息
|
|
51
|
-
if (checkModule(targetModules, contextDir)) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// 判断package.json的版本是否有新的版本
|
|
56
|
-
if (checkDependencies(targetModules, resolve('./'), tmsConfig.outputDir)) {
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
module.exports = {
|
|
64
|
-
isInit,
|
|
65
|
-
};
|