@tmsfe/tmskit 0.0.19 → 0.0.20
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 +6 -1
- package/dist/index.cjs.js +963 -812
- package/package.json +10 -8
- package/src/compile/build.js +2 -2
- package/src/compile/dev.js +30 -25
- package/src/compile/watch.js +31 -12
- package/src/config/constant.js +24 -3
- package/src/core/buildAppJson.js +14 -21
- package/src/core/checkDependencies.js +34 -17
- package/src/core/cloneModules.js +5 -7
- package/src/core/handleError.js +7 -1
- package/src/core/npm.js +7 -2
- package/src/core/tmsMpconfig.js +87 -74
- package/src/entry.js +3 -3
- 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/dev/index.js +14 -13
- package/src/scripts/run/index.js +68 -54
- package/src/scripts/run/init/index.js +13 -12
- package/src/scripts/run/install/index.js +4 -3
package/src/core/tmsMpconfig.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 用来读取处理tms.config.js与module.config.json字段
|
|
3
3
|
*/
|
|
4
|
+
/* eslint-disable no-param-reassign, no-nested-ternary */
|
|
4
5
|
const loadash = require('lodash');
|
|
5
6
|
const fs = require('fs');
|
|
6
7
|
const { TMS_CONFIG_FILENAME, MODULE_CONFIG_FILENAME, TMS_PRIVATE_FILENAME } = require('../config/constant');
|
|
@@ -50,7 +51,7 @@ const readTmsPrivateCf = function () {
|
|
|
50
51
|
const checkModules = function (tmsConfig, modules, isQuit = false) {
|
|
51
52
|
const targetModules = [];
|
|
52
53
|
modules.forEach((moduleName) => {
|
|
53
|
-
const module = tmsConfig.modules.all.find(module => module.
|
|
54
|
+
const module = tmsConfig.modules.all.find(module => module.moduleName === moduleName);
|
|
54
55
|
module && targetModules.push(module);
|
|
55
56
|
});
|
|
56
57
|
|
|
@@ -79,7 +80,7 @@ function adaptMpCgContent(fileContent, appName) {
|
|
|
79
80
|
return res;
|
|
80
81
|
};
|
|
81
82
|
|
|
82
|
-
let content =
|
|
83
|
+
let content = fileContent;
|
|
83
84
|
|
|
84
85
|
if (isArray(content)) {
|
|
85
86
|
let i = content.length - 1;
|
|
@@ -94,107 +95,119 @@ function adaptMpCgContent(fileContent, appName) {
|
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
/**
|
|
97
|
-
*
|
|
98
|
+
* 获取模块module.config.json中的配置信息
|
|
98
99
|
* @param {array} modules 用户要编译的模块列表
|
|
99
100
|
* @param { string } appName 小程序的名称
|
|
100
|
-
* @param {
|
|
101
|
+
* @param {boolean} notFindIsQuit 找不到配置文件是否退出
|
|
101
102
|
*/
|
|
102
|
-
function
|
|
103
|
-
const modulesConfig =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (fs.existsSync(moduleConfigPath)) {
|
|
108
|
-
const content = fs.readFileSync(moduleConfigPath, 'utf-8');
|
|
109
|
-
modulesConfig[moduleConfigPath] = adaptMpCgContent(content, appName);
|
|
103
|
+
function getModulesConfig(modules = [], appName, notFindIsQuit) {
|
|
104
|
+
const modulesConfig = [];
|
|
105
|
+
modules.forEach((moduleItem) => {
|
|
106
|
+
if (!moduleItem.path) {
|
|
107
|
+
throw new Error(`${moduleItem.moduleName}模块路径配置没有找到`);
|
|
110
108
|
}
|
|
109
|
+
const moduleConfigPath = resolve(moduleItem.path, MODULE_CONFIG_FILENAME);
|
|
110
|
+
if (!fs.existsSync(moduleConfigPath)) {
|
|
111
|
+
if (notFindIsQuit) {
|
|
112
|
+
throw new Error(`${moduleItem.moduleName}模块的配置文件module.config.json在${moduleItem.path}目录下没有找到`);
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
let moduleConfig;
|
|
117
|
+
try {
|
|
118
|
+
moduleConfig = JSON.parse(fs.readFileSync(moduleConfigPath, 'utf-8'));
|
|
119
|
+
} catch (e) {
|
|
120
|
+
throw new Error(`${moduleConfigPath}json解析报错: ${e}`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 兼容历史逻辑,后续可删除--- start
|
|
124
|
+
if (!moduleItem.moduleName) moduleItem.moduleName = moduleItem.name;
|
|
125
|
+
delete moduleItem.name;
|
|
126
|
+
|
|
127
|
+
let subPackages = isObject(moduleConfig) && moduleConfig.subPackages
|
|
128
|
+
? moduleConfig.subPackages
|
|
129
|
+
: isObject(moduleConfig) ? [moduleConfig] : moduleConfig;
|
|
130
|
+
|
|
131
|
+
subPackages = adaptMpCgContent(subPackages, appName);
|
|
132
|
+
let dependencies = moduleConfig.dependencies || [];
|
|
133
|
+
subPackages.forEach((item) => {
|
|
134
|
+
item.path = moduleItem.path;
|
|
135
|
+
if (item.dependencies) {
|
|
136
|
+
dependencies = dependencies.concat(item.dependencies);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
moduleItem.subPackages = subPackages;
|
|
140
|
+
moduleItem.dependencies = dependencies;
|
|
141
|
+
// 兼容逻辑--- end
|
|
142
|
+
|
|
143
|
+
modulesConfig.push(moduleItem);
|
|
111
144
|
});
|
|
112
145
|
|
|
113
146
|
return modulesConfig;
|
|
114
147
|
}
|
|
115
148
|
|
|
116
149
|
/**
|
|
117
|
-
*
|
|
150
|
+
* 获取分包内容 (读取module.config.json的配置项)
|
|
118
151
|
* @param {array} modules
|
|
119
|
-
* @param {string} appName
|
|
120
|
-
* @param {string} moduleDir
|
|
121
152
|
* @returns
|
|
122
153
|
*/
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
modules.forEach((
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
let moduleConfigContent = fs.readFileSync(moduleConfigPath, 'utf-8');
|
|
131
|
-
moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
|
|
132
|
-
const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
|
|
133
|
-
moduleContentArr.forEach(({ name }, moduleContentArrIndex) => {
|
|
134
|
-
if (name === moduleName) {
|
|
135
|
-
findModule = true;
|
|
136
|
-
newModules.push({
|
|
137
|
-
...modules[moduleIndex],
|
|
138
|
-
...moduleContentArr[moduleContentArrIndex],
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
if (!findModule) {
|
|
143
|
-
fail(`启动模块${moduleName}在${moduleConfigPath}没有找到,请检查配置`);
|
|
144
|
-
process.exit(1);
|
|
145
|
-
}
|
|
146
|
-
} catch (e) {
|
|
147
|
-
fail(`${moduleConfigPath}配置错误: ${e}`);
|
|
148
|
-
newModules.push({
|
|
149
|
-
...modules[moduleIndex],
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
} else {
|
|
153
|
-
newModules.push({
|
|
154
|
-
...modules[moduleIndex],
|
|
154
|
+
const getSubPackages = (modules) => {
|
|
155
|
+
const newSubPackages = [];
|
|
156
|
+
modules.forEach((module) => {
|
|
157
|
+
(module.subPackages || []).forEach((item) => {
|
|
158
|
+
newSubPackages.push({
|
|
159
|
+
path: module.path,
|
|
160
|
+
...item,
|
|
155
161
|
});
|
|
156
|
-
}
|
|
162
|
+
});
|
|
157
163
|
});
|
|
158
|
-
return
|
|
164
|
+
return newSubPackages;
|
|
159
165
|
};
|
|
160
166
|
|
|
161
167
|
/**
|
|
162
|
-
*
|
|
168
|
+
* 获取所有的模块,合并模块的依赖模块
|
|
163
169
|
* @param { object } tmsConfig
|
|
164
170
|
* @param {array} modules
|
|
165
|
-
* @param {
|
|
171
|
+
* @param {boolean} notFindIsQuit 找不到配置文件是否退出
|
|
166
172
|
* @returns
|
|
167
173
|
*/
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
174
|
+
const getModulesByMergeDepModules = (tmsConfig, modules, notFindIsQuit = false) => {
|
|
175
|
+
const allModules = new Map();
|
|
176
|
+
function dfs(tmsConfig, modules) {
|
|
177
|
+
modules.forEach((moduleItem) => {
|
|
178
|
+
const [moduleConfig = {}] = getModulesConfig([moduleItem], tmsConfig.appName, notFindIsQuit);
|
|
179
|
+
|
|
180
|
+
if (!allModules.has(moduleItem.moduleName)) {
|
|
181
|
+
allModules.set(moduleItem.moduleName, { ...moduleItem, ...moduleConfig });
|
|
182
|
+
|
|
183
|
+
const dependenciesModules = [];
|
|
184
|
+
(moduleConfig?.dependencies || []).forEach((dependenciesModule) => {
|
|
185
|
+
tmsConfig.modules.all.forEach((module) => {
|
|
186
|
+
if (dependenciesModule === module.moduleName) {
|
|
187
|
+
dependenciesModules.push({ ...module });
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
if (dependenciesModules.length) {
|
|
192
|
+
dfs(tmsConfig, dependenciesModules);
|
|
186
193
|
}
|
|
187
194
|
}
|
|
188
195
|
});
|
|
189
|
-
}
|
|
190
|
-
|
|
196
|
+
}
|
|
197
|
+
dfs(tmsConfig, modules);
|
|
198
|
+
|
|
199
|
+
const modulesArr = [];
|
|
200
|
+
for (const module of allModules.values()) {
|
|
201
|
+
modulesArr.push(module);
|
|
202
|
+
}
|
|
203
|
+
return modulesArr;
|
|
191
204
|
};
|
|
192
205
|
|
|
193
206
|
module.exports = {
|
|
194
207
|
readTmsConfig,
|
|
195
208
|
readTmsPrivateCf,
|
|
196
|
-
|
|
209
|
+
getModulesConfig,
|
|
197
210
|
checkModules,
|
|
198
|
-
|
|
199
|
-
|
|
211
|
+
getSubPackages,
|
|
212
|
+
getModulesByMergeDepModules,
|
|
200
213
|
};
|
package/src/entry.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
module.exports = [
|
|
2
2
|
{
|
|
3
|
-
command: 'create <
|
|
3
|
+
command: 'create <project-name>',
|
|
4
4
|
description: '创建新的应用',
|
|
5
|
-
action: (
|
|
6
|
-
require('./scripts/create')(
|
|
5
|
+
action: (projectName) => {
|
|
6
|
+
require('./scripts/create')(projectName);
|
|
7
7
|
},
|
|
8
8
|
},
|
|
9
9
|
{
|
|
@@ -3,8 +3,7 @@ const render = require('./render');
|
|
|
3
3
|
const ask = require('./ask');
|
|
4
4
|
const FILES_TO_IGNORE = require('./ignoreFiles');
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
const generator = (buildDir, distDir, preMetadata) => new Promise((resolve, reject) => {
|
|
6
|
+
const generator = (buildDir, distDir, preMetadata = {}) => new Promise((resolve, reject) => {
|
|
8
7
|
Metalsmith(buildDir)
|
|
9
8
|
.metadata(preMetadata)
|
|
10
9
|
.ignore(FILES_TO_IGNORE)
|
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const shelljs = require('shelljs');
|
|
4
|
-
const
|
|
5
|
-
const {
|
|
4
|
+
const inquirer = require('inquirer');
|
|
5
|
+
const {
|
|
6
|
+
TEMPLATE_DIR,
|
|
7
|
+
TEMPLATE_URL,
|
|
8
|
+
TEMPLATE_NAME,
|
|
9
|
+
TEMPLATE_TKIT_DIR,
|
|
10
|
+
CREATE_TEMPLATE_QUESTION,
|
|
11
|
+
} = require('../../config/constant.js');
|
|
12
|
+
const { resolve } = require('../../utils/widgets');
|
|
6
13
|
const io = require('../../utils/io');
|
|
7
14
|
const { fail, succeed, info } = require('../../utils/log');
|
|
8
15
|
const generator = require('./generator');
|
|
16
|
+
const request = require('request');
|
|
17
|
+
const unzip = require('unzipper');
|
|
9
18
|
|
|
10
19
|
/**
|
|
11
20
|
* 如果该目录下面存在文件,换个名字
|
|
12
21
|
* @param { string } targetDir 当前文件夹
|
|
13
22
|
* @returns { undefined }
|
|
14
23
|
*/
|
|
15
|
-
async function
|
|
24
|
+
async function createProjectDir(targetDir) {
|
|
16
25
|
// 如果目录非空或者已经存在,提示用户,做选择
|
|
17
26
|
if (fs.existsSync(targetDir)) {
|
|
18
27
|
if (!await io.isDirEmpty(targetDir)) {
|
|
@@ -24,43 +33,75 @@ async function createAppDir(targetDir) {
|
|
|
24
33
|
}
|
|
25
34
|
}
|
|
26
35
|
|
|
36
|
+
/**
|
|
37
|
+
* 下载和解压远程的小程序模板
|
|
38
|
+
* @param {string} templateDir
|
|
39
|
+
* @param {string} templateUrl
|
|
40
|
+
* @param {string} templateName
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
const localZipPath = `${templateDir}/${templateName}.zip`;
|
|
46
|
+
const stream = fs.createWriteStream(localZipPath);
|
|
47
|
+
request(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream)
|
|
48
|
+
.on('close', (err) => {
|
|
49
|
+
if (err) {
|
|
50
|
+
reject(err);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
fs.createReadStream(localZipPath).pipe(unzip.Extract({ path: templateDir }))
|
|
54
|
+
.on('close', (err) => {
|
|
55
|
+
if (err) {
|
|
56
|
+
reject(err);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
resolve();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
27
65
|
/**
|
|
28
66
|
* 创建本地小程序运行环境
|
|
29
|
-
* @param { string }
|
|
30
|
-
* @param { string }
|
|
67
|
+
* @param { string } projectType 项目类型
|
|
68
|
+
* @param { string } projectName 项目名称
|
|
31
69
|
*/
|
|
32
|
-
async function create(
|
|
70
|
+
async function create(projectName) {
|
|
33
71
|
const cwd = process.cwd();
|
|
34
|
-
const targetDir = path.resolve(cwd,
|
|
35
|
-
const
|
|
36
|
-
await createAppDir(targetDir);
|
|
72
|
+
const targetDir = path.resolve(cwd, projectName);
|
|
73
|
+
const { projectType } = await inquirer.prompt(CREATE_TEMPLATE_QUESTION);
|
|
37
74
|
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
TEMPLATE_DIR
|
|
44
|
-
|
|
45
|
-
);
|
|
75
|
+
// 创建项目目录
|
|
76
|
+
await createProjectDir(targetDir);
|
|
77
|
+
|
|
78
|
+
// 新创建缓存目录
|
|
79
|
+
if (fs.existsSync(TEMPLATE_DIR)) {
|
|
80
|
+
shelljs.rm('-rf', TEMPLATE_DIR);
|
|
81
|
+
}
|
|
82
|
+
fs.mkdirSync(TEMPLATE_DIR, { recursive: true });
|
|
83
|
+
|
|
84
|
+
// 下载和解压模板
|
|
85
|
+
await downloadAndUnZipTemplate(TEMPLATE_DIR, TEMPLATE_URL, TEMPLATE_NAME);
|
|
46
86
|
|
|
47
87
|
// 生成模板(1. 询问问题, 2. ejs生成模板 3.生成到目标目录)
|
|
48
|
-
generator(path.join(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
}
|
|
88
|
+
generator(path.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
|
|
89
|
+
shelljs.cd(projectName);
|
|
90
|
+
const hookFilePath = resolve(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
|
|
91
|
+
if (fs.existsSync(hookFilePath)) {
|
|
92
|
+
const hooks = require(hookFilePath);
|
|
93
|
+
if (hooks.afterCreate) {
|
|
94
|
+
hooks.afterCreate.forEach((item) => {
|
|
95
|
+
if (typeof item === 'function') {
|
|
96
|
+
item.call(null, shelljs, { projectName });
|
|
97
|
+
} else {
|
|
98
|
+
shelljs.exec(item);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
shelljs.rm('-rf', resolve(projectName, TEMPLATE_TKIT_DIR));
|
|
62
103
|
}
|
|
63
|
-
|
|
104
|
+
|
|
64
105
|
succeed('项目创建完成.');
|
|
65
106
|
})
|
|
66
107
|
.catch((err) => {
|
|
@@ -3,19 +3,20 @@ const { resolve, filterField } = require('../../../utils/widgets');
|
|
|
3
3
|
const init = require('../init/index');
|
|
4
4
|
const compileBuild = require('../../../compile/build');
|
|
5
5
|
|
|
6
|
-
async function build(tmsConfig, targetModules
|
|
6
|
+
async function build(tmsConfig, targetModules) {
|
|
7
7
|
// 开始构建前,清理输出目录
|
|
8
8
|
await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
|
|
9
9
|
|
|
10
|
-
const {
|
|
10
|
+
const { modules: newModules, subPackages } = await init(tmsConfig, targetModules);
|
|
11
11
|
|
|
12
|
+
const isDev = false;
|
|
12
13
|
if (typeof tmsConfig?.hooks?.beforeCompile === 'function') {
|
|
13
14
|
await tmsConfig?.hooks?.beforeCompile({
|
|
14
|
-
isDev
|
|
15
|
+
isDev,
|
|
15
16
|
tmsConfig: filterField(tmsConfig, ['gitAccount']),
|
|
16
17
|
modules: newModules });
|
|
17
18
|
};
|
|
18
|
-
compileBuild(tmsConfig, newModules,
|
|
19
|
+
compileBuild(tmsConfig, newModules, subPackages, isDev);
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
module.exports = build;
|
|
@@ -2,18 +2,21 @@ 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
|
-
|
|
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) {
|
|
17
20
|
const moduleRootDir = resolve(`${tmsConfig.outputDir}/${item.root}`);
|
|
18
21
|
shelljs.rm('-rf', `${moduleRootDir}/*`, { silent: true });
|
|
19
22
|
// 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
|
|
@@ -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, subPackages, true);
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
module.exports = dev;
|
package/src/scripts/run/index.js
CHANGED
|
@@ -5,13 +5,14 @@ const dev = require('./dev/index');
|
|
|
5
5
|
const build = require('./build/index');
|
|
6
6
|
const install = require('./install/index');
|
|
7
7
|
const cloud = require('./cloud/index');
|
|
8
|
+
const { fail, info } = require('../../utils/log');
|
|
8
9
|
const { global } = require('../../utils/global');
|
|
9
10
|
const {
|
|
10
11
|
readTmsConfig,
|
|
11
12
|
readTmsPrivateCf,
|
|
12
13
|
checkModules,
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
getModulesByMergeDepModules,
|
|
15
|
+
getSubPackages,
|
|
15
16
|
} = require('../../core/tmsMpconfig');
|
|
16
17
|
|
|
17
18
|
const handleModuleArg = (cmd) => {
|
|
@@ -37,14 +38,20 @@ const getSpecificModules = (moduleArg, modules) => {
|
|
|
37
38
|
return include;
|
|
38
39
|
}
|
|
39
40
|
if (exclude?.length > 0) {
|
|
40
|
-
return all.filter(module => !exclude.includes(module.
|
|
41
|
+
return all.filter(module => !exclude.includes(module.moduleName)).map(item => item.moduleName);
|
|
41
42
|
}
|
|
42
43
|
if (blockRemote === true) {
|
|
43
|
-
return all.filter(module => module.repoInfo === undefined).map(item => item.
|
|
44
|
+
return all.filter(module => module.repoInfo === undefined).map(item => item.moduleName);
|
|
44
45
|
}
|
|
45
|
-
return all.map(item => item.
|
|
46
|
+
return all.map(item => item.moduleName);
|
|
46
47
|
};
|
|
47
48
|
|
|
49
|
+
/**
|
|
50
|
+
* 合并tms.config.js 与 tms.private.config.js的配置项
|
|
51
|
+
* @param {*} tmsConfig
|
|
52
|
+
* @param {*} tmsPrivateCf
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
48
55
|
const mergeConfig = (tmsConfig, tmsPrivateCf) => {
|
|
49
56
|
const modules = {};
|
|
50
57
|
if (Array.isArray(tmsConfig.modules)) {
|
|
@@ -62,61 +69,68 @@ const mergeConfig = (tmsConfig, tmsPrivateCf) => {
|
|
|
62
69
|
};
|
|
63
70
|
|
|
64
71
|
async function run(commandName, cmd) {
|
|
72
|
+
try {
|
|
65
73
|
// 用户本地的私有项目配置
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
const tmsPrivateCf = readTmsPrivateCf();
|
|
75
|
+
const { env = tmsPrivateCf?.env } = cmd;
|
|
76
|
+
let tmsConfig = readTmsConfig(env);
|
|
77
|
+
tmsConfig = mergeConfig(tmsConfig, tmsPrivateCf);
|
|
70
78
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
// 处理module参数
|
|
80
|
+
const specificModules = getSpecificModules(
|
|
81
|
+
handleModuleArg(cmd),
|
|
82
|
+
tmsConfig.modules,
|
|
83
|
+
);
|
|
76
84
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
const modules = checkModules(
|
|
86
|
+
tmsConfig,
|
|
87
|
+
[
|
|
88
|
+
...new Set([
|
|
89
|
+
...tmsConfig.mainPackages,
|
|
90
|
+
...specificModules,
|
|
91
|
+
]),
|
|
92
|
+
],
|
|
93
|
+
true,
|
|
94
|
+
);
|
|
87
95
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
// 获取所有模块,合并模块依赖的模块
|
|
97
|
+
const newModules = getModulesByMergeDepModules(tmsConfig, modules);
|
|
98
|
+
// 获取所有的分包
|
|
99
|
+
const subPackages = getSubPackages(newModules);
|
|
92
100
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
101
|
+
// 缓存数据
|
|
102
|
+
global.setData({
|
|
103
|
+
env,
|
|
104
|
+
cmd,
|
|
105
|
+
tmsConfig,
|
|
106
|
+
});
|
|
99
107
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
108
|
+
switch (commandName) {
|
|
109
|
+
case 'init':
|
|
110
|
+
init(tmsConfig, newModules);
|
|
111
|
+
return;
|
|
112
|
+
case 'dev':
|
|
113
|
+
global.setData('isDev', true);
|
|
114
|
+
dev(tmsConfig, newModules);
|
|
115
|
+
return;
|
|
116
|
+
case 'cloud':
|
|
117
|
+
cloud(tmsConfig);
|
|
118
|
+
return;
|
|
119
|
+
case 'install':
|
|
120
|
+
install(tmsConfig, subPackages, false);
|
|
121
|
+
return;
|
|
122
|
+
case 'build':
|
|
123
|
+
global.setData('isDev', false);
|
|
124
|
+
build(tmsConfig, newModules);
|
|
125
|
+
return;
|
|
126
|
+
default:
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
} catch (error) {
|
|
130
|
+
const errMsg = typeof error === 'object' ? error.message : error;
|
|
131
|
+
fail(`构建出现错误: ${errMsg}`);
|
|
132
|
+
info('详细错误信息', error);
|
|
133
|
+
process.exit(1);
|
|
120
134
|
}
|
|
121
135
|
}
|
|
122
136
|
|