@tmsfe/tmskit 0.0.19 → 0.0.22

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.
@@ -1,18 +1,28 @@
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');
18
+ const report = require('../../core/report');
9
19
 
10
20
  /**
11
21
  * 如果该目录下面存在文件,换个名字
12
22
  * @param { string } targetDir 当前文件夹
13
23
  * @returns { undefined }
14
24
  */
15
- async function createAppDir(targetDir) {
25
+ async function createProjectDir(targetDir) {
16
26
  // 如果目录非空或者已经存在,提示用户,做选择
17
27
  if (fs.existsSync(targetDir)) {
18
28
  if (!await io.isDirEmpty(targetDir)) {
@@ -24,43 +34,76 @@ async function createAppDir(targetDir) {
24
34
  }
25
35
  }
26
36
 
37
+ /**
38
+ * 下载和解压远程的小程序模板
39
+ * @param {string} templateDir
40
+ * @param {string} templateUrl
41
+ * @param {string} templateName
42
+ * @returns
43
+ */
44
+ function downloadAndUnZipTemplate(templateDir, templateUrl, templateName) {
45
+ return new Promise((resolve, reject) => {
46
+ const localZipPath = `${templateDir}/${templateName}.zip`;
47
+ const stream = fs.createWriteStream(localZipPath);
48
+ request(`${templateUrl}?v=${new Date().getTime()}`).pipe(stream)
49
+ .on('close', (err) => {
50
+ if (err) {
51
+ reject(err);
52
+ return;
53
+ }
54
+ fs.createReadStream(localZipPath).pipe(unzip.Extract({ path: templateDir }))
55
+ .on('close', (err) => {
56
+ if (err) {
57
+ reject(err);
58
+ return;
59
+ }
60
+ resolve();
61
+ });
62
+ });
63
+ });
64
+ }
65
+
27
66
  /**
28
67
  * 创建本地小程序运行环境
29
- * @param { string } appType 项目类型
30
- * @param { string } appName 项目名称
68
+ * @param { string } projectType 项目类型
69
+ * @param { string } projectName 项目名称
31
70
  */
32
- async function create(appName) {
71
+ async function create(projectName) {
33
72
  const cwd = process.cwd();
34
- const targetDir = path.resolve(cwd, appName);
35
- const appType = 'mp';
36
- await createAppDir(targetDir);
73
+ const targetDir = path.resolve(cwd, projectName);
74
+ const { projectType } = await inquirer.prompt(CREATE_TEMPLATE_QUESTION);
75
+ report('create-start', { projectType });
37
76
 
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
- );
77
+ // 创建项目目录
78
+ await createProjectDir(targetDir);
79
+
80
+ // 新创建缓存目录
81
+ if (fs.existsSync(TEMPLATE_DIR)) {
82
+ shelljs.rm('-rf', TEMPLATE_DIR);
83
+ }
84
+ fs.mkdirSync(TEMPLATE_DIR, { recursive: true });
85
+
86
+ // 下载和解压模板
87
+ await downloadAndUnZipTemplate(TEMPLATE_DIR, TEMPLATE_URL, TEMPLATE_NAME);
46
88
 
47
89
  // 生成模板(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
- });
90
+ generator(path.join(TEMPLATE_DIR, TEMPLATE_NAME, projectType), targetDir).then(() => {
91
+ shelljs.cd(projectName);
92
+ const hookFilePath = resolve(projectName, TEMPLATE_TKIT_DIR, 'hooks.js');
93
+ if (fs.existsSync(hookFilePath)) {
94
+ const hooks = require(hookFilePath);
95
+ if (hooks.afterCreate) {
96
+ hooks.afterCreate.forEach((item) => {
97
+ if (typeof item === 'function') {
98
+ item.call(null, shelljs, { projectName });
99
+ } else {
100
+ shelljs.exec(item);
101
+ }
102
+ });
103
+ }
104
+ shelljs.rm('-rf', resolve(projectName, TEMPLATE_TKIT_DIR));
62
105
  }
63
- shelljs.rm('-rf', resolve(appName, TEMPLATE_TKIT_DIR));
106
+ report('create-success', { projectType });
64
107
  succeed('项目创建完成.');
65
108
  })
66
109
  .catch((err) => {
@@ -0,0 +1,74 @@
1
+
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const shellJs = require('shelljs');
5
+ const { ensureDirExist } = require('../../utils/io');
6
+ const { EXTEND_CMD } = require('../../config/constant');
7
+ const { createTask } = require('../../utils/widgets');
8
+ const { info, fail } = require('../../utils/log');
9
+
10
+ /**
11
+ * 下载扩展命令的npm包
12
+ * @param {string} npmName npm包名
13
+ * @param {object} cmd {registry: 'http://mirrors.tencent.com/npm/'} 用户输入执行install-cmd的参数
14
+ */
15
+ async function installCmd(npmName, cmd) {
16
+ try {
17
+ const cmdPackageJson = `${EXTEND_CMD}/package.json`;
18
+ if (!fs.existsSync(cmdPackageJson)) {
19
+ ensureDirExist(EXTEND_CMD);
20
+ fs.writeFileSync(cmdPackageJson, JSON.stringify({ dependencies: {} }, null, 2));
21
+ }
22
+ shellJs.cd(EXTEND_CMD);
23
+ await createTask(npmName => new Promise((resolve, reject) => {
24
+ const registry = cmd.registry ? `--registry=${cmd.registry}` : '';
25
+ shellJs.exec(
26
+ `npm install --save ${npmName} ${registry}`,
27
+ { cwd: EXTEND_CMD, silent: true },
28
+ (code, stdout, stderr) => {
29
+ if (code !== 0) {
30
+ reject(stderr);
31
+ }
32
+ resolve();
33
+ },
34
+ );
35
+ }), `开始下载${npmName}`, `下载${npmName}完成`)(npmName);
36
+ } catch (e) {
37
+ fail('构建出现错误:');
38
+ info(e);
39
+ process.exit(1);
40
+ }
41
+ }
42
+
43
+
44
+ /**
45
+ * 加载扩展命令的npm包
46
+ * @returns
47
+ */
48
+ function loadExtendCmd() {
49
+ const cmdPackageJson = `${EXTEND_CMD}/package.json`;
50
+ const cmdNpmDir = `${EXTEND_CMD}/node_modules`;
51
+ if (fs.existsSync(cmdPackageJson)) {
52
+ const content = fs.readFileSync(cmdPackageJson, 'utf8');
53
+ const json = JSON.parse(content);
54
+ const deps = json.dependencies || {};
55
+
56
+ const cmdConfigs = [];
57
+ Object.keys(deps).forEach((name) => {
58
+ // 检索cmd的npm包
59
+ if (!/^tmskit-cmd-|^@[^/]+\/tmskit-cmd-/.test(name)) return false;
60
+ const cmdConfig = path.join(cmdNpmDir, name, 'tms.config.js');
61
+ if (fs.existsSync(cmdConfig)) {
62
+ cmdConfigs.push(cmdConfig);
63
+ }
64
+ });
65
+ return cmdConfigs;
66
+ }
67
+ return [];
68
+ }
69
+
70
+
71
+ module.exports = {
72
+ installCmd,
73
+ loadExtendCmd,
74
+ };
@@ -2,20 +2,23 @@ const shelljs = require('shelljs');
2
2
  const { resolve, filterField } = require('../../../utils/widgets');
3
3
  const init = require('../init/index');
4
4
  const compileBuild = require('../../../compile/build');
5
+ const report = require('../../../core/report');
5
6
 
6
- async function build(tmsConfig, targetModules, env) {
7
+ async function build(tmsConfig, targetModules) {
7
8
  // 开始构建前,清理输出目录
8
9
  await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
9
10
 
10
- const { targetModules: newModules } = await init(tmsConfig, targetModules);
11
+ const { modules: newModules } = await init(tmsConfig, targetModules);
11
12
 
13
+ const isDev = false;
12
14
  if (typeof tmsConfig?.hooks?.beforeCompile === 'function') {
13
15
  await tmsConfig?.hooks?.beforeCompile({
14
- isDev: false,
16
+ isDev,
15
17
  tmsConfig: filterField(tmsConfig, ['gitAccount']),
16
18
  modules: newModules });
19
+ report('hooks:beforeCompile');
17
20
  };
18
- compileBuild(tmsConfig, newModules, env);
21
+ compileBuild(tmsConfig, newModules, isDev);
19
22
  }
20
23
 
21
24
  module.exports = build;
@@ -1,11 +1,9 @@
1
1
  const { symLink } = require('../../../core/symbolicLink');
2
2
  const { handleError } = require('../../../core/handleError');
3
- const { succeed } = require('../../../utils/log');
4
3
 
5
4
  module.exports = async (tmsConfig) => {
6
5
  try {
7
6
  await symLink(tmsConfig);
8
- succeed('云函数创建软链成功');
9
7
  } catch (e) {
10
8
  handleError(`创建软链错误: ${e}`);
11
9
  }
@@ -2,18 +2,23 @@ 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 { 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
- const { CACHE_DIR } = require('../../../config/constant');
8
+ const { MODULE_CODE_DIR, NODE_MODULES_DIR } = require('../../../config/constant');
9
+ const report = require('../../../core/report');
10
+ const { recommendVersion } = require('../../../core/recommendVersion');
9
11
 
10
12
 
11
13
  // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
12
- function delOtherModule(tmsConfig, targetModules) {
13
- const modules = tmsModulesMergeLocalModuleCfg(tmsConfig.modules.all, tmsConfig.appName);
14
- const targetModulesName = targetModules.map(item => item.name);
15
- modules.forEach((item) => {
16
- if (item.root && targetModulesName.indexOf(item.name) === -1) {
14
+ function delOtherPackages(tmsConfig, targetSubPackages) {
15
+ // 获取所有模块,合并模块依赖的模块
16
+ const allModules = getModulesByMergeDepModules(tmsConfig, tmsConfig.modules.all);
17
+ // 获取所有的分包
18
+ const allSubPackages = getSubPackages(allModules);
19
+ const targetSubPackagesName = targetSubPackages.map(item => item.name);
20
+ allSubPackages.forEach((item) => {
21
+ if (item.root && targetSubPackagesName.indexOf(item.name) === -1) {
17
22
  const moduleRootDir = resolve(`${tmsConfig.outputDir}/${item.root}`);
18
23
  shelljs.rm('-rf', `${moduleRootDir}/*`, { silent: true });
19
24
  // 解决微信开发者工具(dist/app.json: ["subpackages"][0]["root"] 字段需为 目录)错误 - 提前创建该目录
@@ -22,28 +27,30 @@ function delOtherModule(tmsConfig, targetModules) {
22
27
  });
23
28
  }
24
29
 
25
- async function dev(tmsConfig, targetModules, env) {
26
- let newModules = targetModules;
30
+ async function dev(tmsConfig, targetModules) {
27
31
  const { noCache } = global.getData('cmd');
28
32
  if (noCache) {
29
33
  shelljs.rm('-rf', resolve(tmsConfig.outputDir));
30
- shelljs.rm('-rf', CACHE_DIR);
34
+ shelljs.rm('-rf', MODULE_CODE_DIR);
35
+ shelljs.rm('-rf', NODE_MODULES_DIR);
31
36
  }
37
+ // 推荐tmskit的版本
38
+ await recommendVersion();
32
39
 
33
40
  // 初始化操作
34
- const initData = await init(tmsConfig, newModules);
35
- newModules = initData.targetModules;
41
+ const { subPackages, modules: newModules } = await init(tmsConfig, targetModules);
36
42
 
37
- info('当前dev启动的有效模块', newModules.map(item => item.name).sort());
43
+ info('当前dev启动的有效模块', newModules.map(item => item.moduleName).sort());
38
44
  if (typeof tmsConfig?.hooks?.beforeCompile === 'function') {
39
45
  await tmsConfig?.hooks?.beforeCompile({
40
46
  isDev: true,
41
47
  tmsConfig: filterField(tmsConfig, ['gitAccount']),
42
48
  modules: newModules,
43
49
  });
50
+ report('hooks:beforeCompile');
44
51
  };
45
- delOtherModule(tmsConfig, newModules);
46
- compileDev(tmsConfig, newModules, env);
52
+ delOtherPackages(tmsConfig, subPackages);
53
+ compileDev(tmsConfig, newModules, true);
47
54
  }
48
55
 
49
56
  module.exports = dev;
@@ -1,17 +1,17 @@
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
+ const report = require('../../core/report');
9
10
  const {
10
- readTmsConfig,
11
- readTmsPrivateCf,
12
- checkModules,
13
- tmsModulesMergeLocalModuleCfg,
14
- subModulesMergeDepModules,
11
+ getTmsConfig,
12
+ getModulesByMergeDepModules,
13
+ getSubPackages,
14
+ getModulesByModuleNames,
15
15
  } = require('../../core/tmsMpconfig');
16
16
 
17
17
  const handleModuleArg = (cmd) => {
@@ -27,7 +27,7 @@ const handleModuleArg = (cmd) => {
27
27
  * @param {Object} modulePrivateCfg 私有配置里的模块
28
28
  * @param {Array} moduleAll 当前小程序全部模块
29
29
  */
30
- const getSpecificModules = (moduleArg, modules) => {
30
+ const getSpecificModuleNames = (moduleArg, modules) => {
31
31
  if (moduleArg.length > 0) {
32
32
  return moduleArg;
33
33
  }
@@ -37,83 +37,73 @@ const getSpecificModules = (moduleArg, modules) => {
37
37
  return include;
38
38
  }
39
39
  if (exclude?.length > 0) {
40
- return all.filter(module => !exclude.includes(module.name)).map(item => item.name);
40
+ return all.filter(module => !exclude.includes(module.moduleName)).map(item => item.moduleName);
41
41
  }
42
42
  if (blockRemote === true) {
43
- return all.filter(module => module.repoInfo === undefined).map(item => item.name);
43
+ return all.filter(module => module.repoInfo === undefined).map(item => item.moduleName);
44
44
  }
45
- return all.map(item => item.name);
46
- };
47
-
48
- const mergeConfig = (tmsConfig, tmsPrivateCf) => {
49
- const modules = {};
50
- if (Array.isArray(tmsConfig.modules)) {
51
- modules.all = tmsConfig.modules;
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
- });
60
-
61
- return res;
45
+ return all.map(item => item.moduleName);
62
46
  };
63
47
 
64
48
  async function run(commandName, cmd) {
65
- // 用户本地的私有项目配置
66
- const tmsPrivateCf = readTmsPrivateCf();
67
- const { env = tmsPrivateCf?.env } = cmd;
68
- let tmsConfig = readTmsConfig(env);
69
- tmsConfig = mergeConfig(tmsConfig, tmsPrivateCf);
49
+ // 用户本地的配置
50
+ const tmsConfig = getTmsConfig();
51
+ try {
52
+ // 缓存数据
53
+ global.setData({
54
+ cmd,
55
+ tmsConfig,
56
+ });
70
57
 
58
+ if (commandName === 'cloud') {
59
+ cloud(tmsConfig);
60
+ report('run:cloud', { appName: tmsConfig?.appName });
61
+ return;
62
+ }
63
+ otherCommands(tmsConfig, commandName, cmd);
64
+ } catch (error) {
65
+ const errMsg = typeof error === 'object' ? error.message : error;
66
+ report('run', { errMsg, appName: tmsConfig?.appName });
67
+ fail(`构建出现错误: ${errMsg}`);
68
+ info('详细错误信息', error);
69
+ process.exit(1);
70
+ }
71
+ }
72
+
73
+ function otherCommands(tmsConfig, commandName, cmd) {
71
74
  // 处理module参数
72
- const specificModules = getSpecificModules(
75
+ const specificModuleNames = getSpecificModuleNames(
73
76
  handleModuleArg(cmd),
74
77
  tmsConfig.modules,
75
78
  );
76
79
 
77
- const modules = checkModules(
78
- tmsConfig,
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);
80
+ // moduleNames => ['home', 'car']
81
+ const moduleNames = [...new Set([...specificModuleNames])];
82
+ const modules = getModulesByModuleNames(tmsConfig, moduleNames, false);
92
83
 
93
- // 缓存数据
94
- global.setData({
95
- env,
96
- cmd,
97
- tmsConfig,
98
- });
84
+ // 获取所有模块,合并模块依赖的模块
85
+ const newModules = getModulesByMergeDepModules(tmsConfig, modules, false);
86
+ // 获取所有的分包
87
+ const subPackages = getSubPackages(newModules);
99
88
 
100
89
  switch (commandName) {
101
90
  case 'init':
102
- init(tmsConfig, newModules, env);
91
+ init(tmsConfig, newModules);
92
+ report('run:init', { appName: tmsConfig?.appName });
103
93
  return;
104
94
  case 'dev':
105
95
  global.setData('isDev', true);
106
- dev(tmsConfig, newModules, env);
107
- return;
108
- case 'cloud':
109
- cloud(tmsConfig, env);
96
+ dev(tmsConfig, newModules);
97
+ report('run:dev', { appName: tmsConfig?.appName });
110
98
  return;
111
99
  case 'install':
112
- install(tmsConfig, newModules, env, false);
100
+ install(tmsConfig, subPackages, false);
101
+ report('run:install', { appName: tmsConfig?.appName });
113
102
  return;
114
103
  case 'build':
115
104
  global.setData('isDev', false);
116
- build(tmsConfig, newModules, env);
105
+ build(tmsConfig, newModules);
106
+ report('run:build', { appName: tmsConfig?.appName });
117
107
  return;
118
108
  default:
119
109
  return;
@@ -5,7 +5,7 @@ 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 { tmsModulesMergeLocalModuleCfg, subModulesMergeDepModules } = require('../../../core/tmsMpconfig');
8
+ const { getModulesByMergeDepModules, getSubPackages } = require('../../../core/tmsMpconfig');
9
9
  const { fail, info } = require('../../../utils/log');
10
10
  const install = require('../install');
11
11
 
@@ -26,25 +26,6 @@ const cpFilesToOutput = function (tmsConfig, defaultFiles) {
26
26
  });
27
27
  };
28
28
 
29
- /**
30
- * 校验相关配置项
31
- * @param {*} targetModules
32
- * @returns
33
- */
34
- function checkConfig(targetModules) {
35
- for (const item of targetModules) {
36
- if (!item.root) {
37
- throw new Error(`检查${item.name} module.config.json的root字段`);
38
- }
39
-
40
- // 判断源码目录是否有该模块
41
- if (item.path && !fs.existsSync(resolve(item.path))) {
42
- throw new Error(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
43
- }
44
- }
45
- return true;
46
- }
47
-
48
29
  async function task(tmsConfig, targetModules) {
49
30
  // 下载和移动代码
50
31
  await createTask(
@@ -53,12 +34,10 @@ async function task(tmsConfig, targetModules) {
53
34
  '下载模块代码码完成',
54
35
  )(MODULE_CODE_DIR, resolve('./'), targetModules);
55
36
 
56
- // tms.config.js的modules 合并 module.config.json的配置项
57
- let newModules = tmsModulesMergeLocalModuleCfg(targetModules, tmsConfig.appName);
58
- // A分包依赖了B分包的代码, merge B分包进行编译;
59
- newModules = subModulesMergeDepModules(tmsConfig, newModules);
60
-
61
- checkConfig(newModules);
37
+ // 获取所有模块,合并模块依赖的模块
38
+ const newModules = getModulesByMergeDepModules(tmsConfig, targetModules, true);
39
+ // 获取所有的分包
40
+ const newSubPackages = getSubPackages(newModules);
62
41
 
63
42
  // 拷贝相关配置文件到输出目录
64
43
  await createTask(
@@ -68,8 +47,7 @@ async function task(tmsConfig, targetModules) {
68
47
  )(tmsConfig, DEFAULT_COPY_CONFIG);
69
48
 
70
49
  // install
71
- await install(tmsConfig, newModules);
72
-
50
+ await install(tmsConfig, newSubPackages, true);
73
51
 
74
52
  // 动态生成编译后的app.json;
75
53
  await createTask(
@@ -78,18 +56,19 @@ async function task(tmsConfig, targetModules) {
78
56
  '生成编译后的app.json完成',
79
57
  )(tmsConfig, newModules);
80
58
 
81
- return newModules;
59
+ return {
60
+ modules: newModules,
61
+ subPackages: newSubPackages,
62
+ };
82
63
  }
83
64
  async function init(tmsConfig, targetModules) {
84
65
  try {
85
- const newModules = await task(tmsConfig, targetModules);
66
+ const taskRes = await task(tmsConfig, targetModules);
86
67
 
87
- return {
88
- targetModules: newModules,
89
- };
68
+ return taskRes;
90
69
  } catch (error) {
91
70
  const errMsg = typeof error === 'object' ? error.message : error;
92
- fail(`初始化流程出现错误${errMsg}`);
71
+ fail(`初始化流程出现错误: ${errMsg}`);
93
72
  info('详细的错误信息', error);
94
73
  process.exit(1);
95
74
  }
@@ -1,10 +1,10 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
- const { CACHE_FILE, CACHE_DIR } = require('../config/constant');
4
- const { ensureDirExist } = require('../utils/io');
3
+ const { NPM_CACHE_FILE } = require('../../../config/constant');
4
+ const { ensureDirExist } = require('../../../utils/io');
5
5
 
6
6
  function getCache(projectDir, type) {
7
- const filePath = `${CACHE_DIR}/${CACHE_FILE}`;
7
+ const filePath = NPM_CACHE_FILE;
8
8
  if (!fs.existsSync(filePath)) {
9
9
  return null;
10
10
  }
@@ -14,7 +14,7 @@ function getCache(projectDir, type) {
14
14
 
15
15
 
16
16
  function setCache(projectDir, type = 'miniprogram_npm', data) {
17
- const filePath = `${CACHE_DIR}/${CACHE_FILE}`;
17
+ const filePath = NPM_CACHE_FILE;
18
18
  if (!fs.existsSync(filePath)) {
19
19
  const dir = path.dirname(filePath);
20
20
  ensureDirExist(dir);