@tmsfe/tmskit 0.0.17 → 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/src/core/npm.js CHANGED
@@ -30,7 +30,12 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
30
30
  const npmTasksMap = new Map();
31
31
  for (const packageJsonPath of packageJsonFiles) {
32
32
  const packageContent = fs.readFileSync(packageJsonPath);
33
- const packageJson = JSON.parse(packageContent);
33
+ let packageJson;
34
+ try {
35
+ packageJson = JSON.parse(packageContent);
36
+ } catch (e) {
37
+ throw new Error(`${packageJsonPath}json解析出现错误:${e}`);
38
+ }
34
39
  const md5Obj = {
35
40
  dependencies: packageJson.dependencies || {},
36
41
  };
@@ -99,7 +104,7 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
99
104
 
100
105
 
101
106
  // 遍历安装指定目录下所有项目的npm依赖
102
- const mpNpmInstallAll = async (modules, contextDir, cacheDir) => {
107
+ const npmInstallAll = async (modules, contextDir, cacheDir) => {
103
108
  const cwd = process.cwd();
104
109
  const packageJsonFiles = await findAllPackageJson(modules, contextDir);
105
110
 
@@ -118,12 +123,13 @@ const mpNpmInstallAll = async (modules, contextDir, cacheDir) => {
118
123
  return Promise.all(callArr);
119
124
  })
120
125
  .catch((e) => {
121
- handleError(`npm install ${params.packageJsonPath}出现错误:${e}`);
126
+ handleError(`npm install ${params.packageJsonPath}出现错误:${e}`, true);
122
127
  }));
123
128
  });
124
129
 
125
130
  await Promise.all(arrPromises);
126
131
  shell.cd(cwd);
132
+ return packageJsonFiles;
127
133
  };
128
134
 
129
135
  /**
@@ -215,7 +221,7 @@ function cloudNpmInstall(contextDir) {
215
221
 
216
222
  module.exports = {
217
223
  cloudNpmInstall,
218
- mpNpmInstallAll,
224
+ npmInstallAll,
219
225
  findAllPackageJson,
220
226
  };
221
227
 
@@ -1,13 +1,13 @@
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');
7
8
  const { resolve, isObject, isArray } = require('../utils/widgets');
8
9
  const defaultTmsConfig = require('../config/defaultTmsConfig');
9
10
  const { fail } = require('../utils/log');
10
- const path = require('path');
11
11
 
12
12
  /**
13
13
  * 读取tms.config.js
@@ -23,35 +23,11 @@ const readTmsConfig = function (env) {
23
23
  const tmsConfig = tmsConfigFn({
24
24
  env,
25
25
  });
26
- // 合并默认值
27
- loadash.mergeWith(tmsConfig, defaultTmsConfig);
28
26
 
29
- // modules兼容处理
30
- tmsConfig.modules = convertModules(tmsConfig.modules);
31
- return tmsConfig;
27
+ // 合并默认值
28
+ return loadash.mergeWith(defaultTmsConfig, tmsConfig);
32
29
  };
33
30
 
34
- // convertModules 处理默认值
35
- const convertModules = (modules) => {
36
- const newModules = [];
37
- modules.forEach((module) => {
38
- const newModule = {};
39
- if (typeof module === 'string') {
40
- // 路径字符串
41
- Object.assign(newModule, {
42
- name: path.basename(module),
43
- path: module,
44
- });
45
- } else if (typeof module === 'object') {
46
- Object.assign(newModule, module);
47
- if (module.name === undefined) {
48
- newModule.name = path.basename(module.path);
49
- }
50
- }
51
- newModules.push(newModule);
52
- });
53
- return newModules;
54
- };
55
31
 
56
32
  /**
57
33
  * 读取tms.private.config.js
@@ -62,12 +38,7 @@ const readTmsPrivateCf = function () {
62
38
  if (fs.existsSync(tmsPrivatePath)) {
63
39
  tmsPrivateCf = require(tmsPrivatePath);
64
40
  }
65
- // 处理modules字段
66
- if (tmsPrivateCf.modules instanceof Array) {
67
- Object.assign(tmsPrivateCf.modules, {
68
- include: tmsPrivateCf.modules,
69
- });
70
- }
41
+
71
42
  return tmsPrivateCf;
72
43
  };
73
44
 
@@ -80,11 +51,10 @@ const readTmsPrivateCf = function () {
80
51
  const checkModules = function (tmsConfig, modules, isQuit = false) {
81
52
  const targetModules = [];
82
53
  modules.forEach((moduleName) => {
83
- const module = tmsConfig.modules.find(module => module.name === moduleName);
54
+ const module = tmsConfig.modules.all.find(module => module.moduleName === moduleName);
84
55
  module && targetModules.push(module);
85
56
  });
86
57
 
87
-
88
58
  if (targetModules.length === 0) {
89
59
  fail(`你启动的模块无效${modules.join(',')}无效,请检查tms.config.json>modules>${modules.join(',')}
90
60
  >name字段与module.config.json的name字段是否一致`);
@@ -110,7 +80,7 @@ function adaptMpCgContent(fileContent, appName) {
110
80
  return res;
111
81
  };
112
82
 
113
- let content = JSON.parse(fileContent);
83
+ let content = fileContent;
114
84
 
115
85
  if (isArray(content)) {
116
86
  let i = content.length - 1;
@@ -119,118 +89,125 @@ function adaptMpCgContent(fileContent, appName) {
119
89
  i--; // eslint-disable-line
120
90
  }
121
91
  } else {
122
- if (appName && content.mpConfig && content.mpConfig[appName]) {
123
- content = { ...content, ...content.mpConfig[appName] };
124
- delete content.mpConfig;
125
- delete content.isSubpackages;
126
- }
127
92
  content = handleContent(appName, content);
128
93
  }
129
94
  return content;
130
95
  }
131
96
 
132
97
  /**
133
- * 递归获取本地所有模块的配置信息
98
+ * 获取模块module.config.json中的配置信息
134
99
  * @param {array} modules 用户要编译的模块列表
135
100
  * @param { string } appName 小程序的名称
136
- * @param { string } moduleConfigFilename moduleConfig的文件名
101
+ * @param {boolean} notFindIsQuit 找不到配置文件是否退出
137
102
  */
138
- function getModuleConfig(modules = [], appName, moduleConfigFilename) {
139
- const modulesConfig = {};
140
-
141
- modules.forEach(({ path }) => {
142
- const moduleConfigPath = resolve(path, moduleConfigFilename);
143
- if (fs.existsSync(moduleConfigPath)) {
144
- const content = fs.readFileSync(moduleConfigPath, 'utf-8');
145
- 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}模块路径配置没有找到`);
146
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);
147
144
  });
148
145
 
149
146
  return modulesConfig;
150
147
  }
151
148
 
152
149
  /**
153
- * tms.config.js的modules 合并 module.config.json的配置项
150
+ * 获取分包内容 (读取module.config.json的配置项)
154
151
  * @param {array} modules
155
- * @param {string} appName
156
- * @param {string} moduleDir
157
152
  * @returns
158
153
  */
159
- const tmsModulesMergeLocalModuleCfg = (modules, appName) => {
160
- const newModules = [];
161
- modules.forEach(({ path: relativePath, name: moduleName }, moduleIndex) => {
162
- const moduleConfigPath = resolve(relativePath, MODULE_CONFIG_FILENAME);
163
- if (fs.existsSync(moduleConfigPath)) {
164
- try {
165
- let findModule = false;
166
- let moduleConfigContent = fs.readFileSync(moduleConfigPath, 'utf-8');
167
- moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
168
- const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
169
- moduleContentArr.forEach(({ name }, moduleContentArrIndex) => {
170
- if (name === moduleName) {
171
- findModule = true;
172
- newModules.push({
173
- ...modules[moduleIndex],
174
- ...moduleContentArr[moduleContentArrIndex],
175
- });
176
- }
177
- });
178
- if (!findModule) {
179
- fail(`启动模块${moduleName}在${moduleConfigPath}没有找到,请检查配置`);
180
- process.exit(1);
181
- }
182
- } catch (e) {
183
- fail(`${moduleConfigPath}配置错误: ${e}`);
184
- newModules.push({
185
- ...modules[moduleIndex],
186
- });
187
- }
188
- } else {
189
- newModules.push({
190
- ...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,
191
161
  });
192
- }
162
+ });
193
163
  });
194
- return newModules;
164
+ return newSubPackages;
195
165
  };
196
166
 
197
167
  /**
198
- * 分包依赖了分包的模块 合并所依赖的modules
168
+ * 获取所有的模块,合并模块的依赖模块
199
169
  * @param { object } tmsConfig
200
170
  * @param {array} modules
201
- * @param {string} moduleDir
171
+ * @param {boolean} notFindIsQuit 找不到配置文件是否退出
202
172
  * @returns
203
173
  */
204
- const subModulesMergeDepModules = (tmsConfig, modules) => {
205
- const moduleNames = [];
206
- modules.forEach(({ name: moduleName }) => {
207
- moduleNames.push(moduleName);
208
- });
209
- let mergeModules = modules;
210
- let isOver = true;
211
-
212
- modules.forEach(({ dependencies: dependencyModules }) => {
213
- dependencyModules?.forEach((item) => {
214
- // 如果所有模块的dep都在moduleNames内,则所有依赖都齐了
215
- // 否则递归处理,根据name找到相关配置加到modules里
216
- if (moduleNames.indexOf(item) === -1) {
217
- const tmpModules = checkModules(tmsConfig, [...new Set([item])]);
218
- if (tmpModules.length > 0) {
219
- isOver = false;
220
- mergeModules = [...mergeModules, ...tmpModules];
221
- mergeModules = tmsModulesMergeLocalModuleCfg(mergeModules, tmsConfig.appName);
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);
222
193
  }
223
194
  }
224
195
  });
225
- });
226
- return isOver ? mergeModules : subModulesMergeDepModules(tmsConfig, mergeModules);
196
+ }
197
+ dfs(tmsConfig, modules);
198
+
199
+ const modulesArr = [];
200
+ for (const module of allModules.values()) {
201
+ modulesArr.push(module);
202
+ }
203
+ return modulesArr;
227
204
  };
228
205
 
229
206
  module.exports = {
230
207
  readTmsConfig,
231
208
  readTmsPrivateCf,
232
- getModuleConfig,
209
+ getModulesConfig,
233
210
  checkModules,
234
- tmsModulesMergeLocalModuleCfg,
235
- subModulesMergeDepModules,
211
+ getSubPackages,
212
+ getModulesByMergeDepModules,
236
213
  };
package/src/entry.js CHANGED
@@ -1,9 +1,9 @@
1
1
  module.exports = [
2
2
  {
3
- command: 'create <app-name>',
3
+ command: 'create <project-name>',
4
4
  description: '创建新的应用',
5
- action: (appName, cmd) => {
6
- require('./scripts/create')(appName, cmd);
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 { TEMPLATE_DIR, TEMPLATE_PATH, TEMPLATE_TKIT_DIR } = require('../../config/constant.js');
5
- const { downloadRepoForGit, createTask, resolve } = require('../../utils/widgets');
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 createAppDir(targetDir) {
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 } appType 项目类型
30
- * @param { string } appName 项目名称
67
+ * @param { string } projectType 项目类型
68
+ * @param { string } projectName 项目名称
31
69
  */
32
- async function create(appName) {
70
+ async function create(projectName) {
33
71
  const cwd = process.cwd();
34
- const targetDir = path.resolve(cwd, appName);
35
- const appType = 'mp';
36
- await createAppDir(targetDir);
72
+ const targetDir = path.resolve(cwd, projectName);
73
+ const { projectType } = await inquirer.prompt(CREATE_TEMPLATE_QUESTION);
37
74
 
38
- // 创建缓存目录
39
- io.ensureDirExist(TEMPLATE_DIR);
40
- // 拉取git模板
41
- await createTask(downloadRepoForGit, '拉取模板仓库', '拉取模板仓库完成')(
42
- 'https://git.woa.com/tmsfe/tms-frontend.git',
43
- TEMPLATE_DIR,
44
- 'master',
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(TEMPLATE_PATH, appType), targetDir, {
49
- appName,
50
- appType,
51
- }).then(() => {
52
- shelljs.cd(appName);
53
- const hooks = require(resolve(appName, TEMPLATE_TKIT_DIR, 'hooks.js'));
54
- if (hooks.afterCreate) {
55
- hooks.afterCreate.forEach((item) => {
56
- if (typeof item === 'function') {
57
- item.call(null, shelljs, { appName });
58
- } else {
59
- shelljs.exec(item);
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
- shelljs.rm('-rf', resolve(appName, TEMPLATE_TKIT_DIR));
104
+
64
105
  succeed('项目创建完成.');
65
106
  })
66
107
  .catch((err) => {
@@ -1,18 +1,22 @@
1
1
  const shelljs = require('shelljs');
2
- const { resolve } = require('../../../utils/widgets');
2
+ 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, env) {
6
+ async function build(tmsConfig, targetModules) {
7
7
  // 开始构建前,清理输出目录
8
8
  await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
9
9
 
10
- const { targetModules: newModules } = await init(tmsConfig, targetModules);
10
+ const { modules: newModules, subPackages } = await init(tmsConfig, targetModules);
11
11
 
12
+ const isDev = false;
12
13
  if (typeof tmsConfig?.hooks?.beforeCompile === 'function') {
13
- await tmsConfig?.hooks?.beforeCompile({ isDev: false, tmsConfig, modules: newModules });
14
+ await tmsConfig?.hooks?.beforeCompile({
15
+ isDev,
16
+ tmsConfig: filterField(tmsConfig, ['gitAccount']),
17
+ modules: newModules });
14
18
  };
15
- compileBuild(tmsConfig, newModules, env);
19
+ compileBuild(tmsConfig, newModules, subPackages, isDev);
16
20
  }
17
21
 
18
22
  module.exports = build;
@@ -1,20 +1,23 @@
1
1
  const shelljs = require('shelljs');
2
2
  const compileDev = require('../../../compile/dev');
3
- const { resolve } = require('../../../utils/widgets');
3
+ const { resolve, filterField } = require('../../../utils/widgets');
4
4
  const init = require('../init/index');
5
- const { tmsModulesMergeLocalModuleCfg } = require('../../../core/tmsMpconfig');
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 delOtherModule(tmsConfig, targetModules) {
13
- const modules = tmsModulesMergeLocalModuleCfg(tmsConfig.modules, tmsConfig.appName);
14
- const targetModulesName = targetModules.map(item => item.name);
15
- modules.forEach((item) => {
16
- if (item.root && targetModulesName.indexOf(item.name) === -1) {
17
- const moduleRootDir = resolve(`dist/${item.root}`);
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, env) {
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,15 +33,18 @@ async function dev(tmsConfig, targetModules, env) {
31
33
  }
32
34
 
33
35
  // 初始化操作
34
- const initData = await init(tmsConfig, newModules);
35
- newModules = initData.targetModules;
36
+ const { subPackages, modules: newModules } = await init(tmsConfig, targetModules);
36
37
 
37
- info('当前dev启动的有效模块', newModules.map(item => item.name).sort());
38
+ info('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
38
39
  if (typeof tmsConfig?.hooks?.beforeCompile === 'function') {
39
- await tmsConfig?.hooks?.beforeCompile({ isDev: true, tmsConfig, modules: newModules });
40
+ await tmsConfig?.hooks?.beforeCompile({
41
+ isDev: true,
42
+ tmsConfig: filterField(tmsConfig, ['gitAccount']),
43
+ modules: newModules,
44
+ });
40
45
  };
41
- delOtherModule(tmsConfig, newModules);
42
- compileDev(tmsConfig, newModules, env);
46
+ delOtherPackages(tmsConfig, subPackages);
47
+ compileDev(tmsConfig, newModules, subPackages, true);
43
48
  }
44
49
 
45
50
  module.exports = dev;