@tmsfe/tmskit 0.0.6 → 0.0.9-beta.0

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.
Files changed (40) hide show
  1. package/README.md +1 -1
  2. package/dist/index.cjs.js +1203 -977
  3. package/main.js +1 -3
  4. package/package.json +2 -4
  5. package/src/{gulp → compile}/build.js +0 -0
  6. package/src/{gulp → compile}/compile.js +10 -7
  7. package/src/{gulp → compile}/dev.js +42 -15
  8. package/src/{gulp → compile}/plugins/less.js +0 -0
  9. package/src/{gulp → compile}/plugins/mpCommonDep.js +1 -1
  10. package/src/{gulp → compile}/plugins/mpJsonDep.js +7 -3
  11. package/src/{gulp → compile}/plugins/mpWxmlDep.js +1 -1
  12. package/src/{gulp → compile}/plugins/postcss-font-base64.js +0 -0
  13. package/src/{gulp → compile}/plugins/replaceEnv.js +0 -0
  14. package/src/{gulp → compile}/plugins/utils/pluginError.js +0 -0
  15. package/src/config/constant.js +6 -8
  16. package/src/{utils → core}/buildAppJson.js +14 -69
  17. package/src/{utils → core}/checkDependencies.js +3 -3
  18. package/src/core/cloneModules.js +203 -0
  19. package/src/{utils → core}/handleError.js +4 -2
  20. package/src/core/isInIt.js +69 -0
  21. package/src/{utils/mpCiUtils.js → core/mpCi.js} +0 -0
  22. package/src/core/npm.js +218 -0
  23. package/src/core/symbolicLink.js +24 -0
  24. package/src/{utils/tkitUtils.js → core/tmsMpconfig.js} +85 -9
  25. package/src/entry.js +13 -11
  26. package/src/index.js +7 -6
  27. package/src/init.js +2 -2
  28. package/src/scripts/create/index.js +2 -2
  29. package/src/scripts/run/build/index.js +3 -4
  30. package/src/scripts/run/dev/index.js +11 -53
  31. package/src/scripts/run/index.js +57 -28
  32. package/src/scripts/run/init/index.js +19 -11
  33. package/src/scripts/run/install/index.js +8 -6
  34. package/src/utils/global.js +19 -33
  35. package/src/utils/io.js +3 -2
  36. package/src/utils/log.js +3 -0
  37. package/src/utils/widgets.js +54 -43
  38. package/src/utils/cliUtils.js +0 -35
  39. package/src/utils/cloneModules.js +0 -116
  40. package/src/utils/npmUtils.js +0 -166
@@ -1,54 +1,12 @@
1
- const gulpDev = require('../../../gulp/dev');
2
- const fs = require('fs');
1
+ const shelljs = require('shelljs');
2
+ const compileDev = require('../../../compile/dev');
3
3
  const { resolve } = require('../../../utils/widgets');
4
4
  const init = require('../init/index');
5
- const { MODULE_CONFIG_FILENAME } = require('../../../config/constant');
6
- const { tmsModulesMergeLocalModuleCfg } = require('../../../utils/tkitUtils');
7
- const { checkDependencies } = require('../../../utils/checkDependencies');
8
- const { fail } = require('../../../utils/log');
9
- const shelljs = require('shelljs');
10
- // const io = require('../../../utils/io');
11
-
12
- function isInit(tmsConfig, targetModules, contextDir, isDev) {
13
- // 判断是否存在dist目录
14
- if (!fs.existsSync(contextDir)) {
15
- return true;
16
- }
17
- // 判断dist是否存在node_modules
18
- if (!fs.existsSync(`${contextDir}/node_modules`)) {
19
- return true;
20
- }
21
-
22
- // 判断dist是否存在miniprogram_npm
23
- if (!fs.existsSync(`${contextDir}/miniprogram_npm`)) {
24
- return true;
25
- }
5
+ const { isInit } = require('../../../core/isInIt');
6
+ const { tmsModulesMergeLocalModuleCfg } = require('../../../core/tmsMpconfig');
7
+ const { info } = require('../../../utils/log');
8
+ const { global } = require('../../../utils/global');
26
9
 
27
- // 判断dist是否存在app.json
28
- if (!fs.existsSync(`${contextDir}/app.json`)) {
29
- return true;
30
- }
31
-
32
- // 判断\源码\dist\是否存在用户指定的模块
33
- for (const item of targetModules) {
34
- // 此模块没有root字段(原因:没有merge到module.config.json的配置项。第三方模块的代码可能还没有下载)
35
- if (!item.root) {
36
- return true;
37
- }
38
- // 判断dist目录是否有该模块
39
- if (!fs.existsSync(`${contextDir}/${item.root}/${MODULE_CONFIG_FILENAME}`)) {
40
- return true;
41
- }
42
- // 判断源码目录是否有该模块
43
- if (item.path && !fs.existsSync(resolve(item.path))) {
44
- fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
45
- process.exit(1);
46
- }
47
- }
48
-
49
- // 判断package.json的版本是否有新的版本
50
- return checkDependencies(targetModules, resolve('./'), tmsConfig.outputDir, isDev);
51
- }
52
10
 
53
11
  // 用户编译分包时,需要将dist中其他分包(主包不能删除)的内容删除,否则其他分包的内容混入到主包(导致主包的体积超2M)
54
12
  function delOtherModule(tmsConfig, targetModules) {
@@ -66,18 +24,18 @@ function delOtherModule(tmsConfig, targetModules) {
66
24
 
67
25
  async function dev(tmsConfig, targetModules, env) {
68
26
  let newModules = targetModules;
69
- const isDev = true;
27
+ const isLatest = global.getData('cmd').latest;
70
28
 
71
29
  // 判断是否进行init命令
72
- if (isInit(tmsConfig, targetModules, resolve('dist'), isDev)) {
30
+ if (isLatest || isInit(tmsConfig, targetModules, resolve('dist'))) {
73
31
  // init函数 下载第三方代码后,会将最新的tms.config.js的modules 合并 module.config.json的配置项返回
74
- const initData = await init(tmsConfig, newModules, isDev);
32
+ const initData = await init(tmsConfig, newModules);
75
33
  newModules = initData.targetModules;
76
34
  }
77
35
 
78
- console.log('当前dev启动的有效模块', newModules.map(item => item.name).sort());
36
+ info('当前dev启动的有效模块', newModules.map(item => item.name).sort());
79
37
  delOtherModule(tmsConfig, newModules);
80
- gulpDev(tmsConfig, newModules, env);
38
+ compileDev(tmsConfig, newModules, env);
81
39
  }
82
40
 
83
41
  module.exports = dev;
@@ -2,62 +2,91 @@ const init = require('./init/index');
2
2
  const dev = require('./dev/index');
3
3
  const build = require('./build/index');
4
4
  const install = require('./install/index');
5
- const { createTask } = require('../../utils/widgets');
6
- const { MODE } = require('../../config/constant');
7
- const { readTmsConfig, readTmsPrivateCf, checkModules } = require('../../utils/tkitUtils');
8
- const { tmsModulesMergeLocalModuleCfg, subModulesMergeDepModules } = require('../../utils/tkitUtils');
5
+ const { global } = require('../../utils/global');
6
+ const {
7
+ readTmsConfig,
8
+ readTmsPrivateCf,
9
+ checkModules,
10
+ tmsModulesMergeLocalModuleCfg,
11
+ subModulesMergeDepModules,
12
+ } = require('../../core/tmsMpconfig');
9
13
 
10
- const handleModulesArg = (cmd, tmsPrivateCg) => {
14
+ const handleModuleArg = (cmd) => {
11
15
  // 单模块或多模块开发-用户通过脚手架参数指定的模块
12
- if (cmd.module) {
13
- const { argv } = process;
14
- const reset = argv.indexOf('-m') > -1 ? argv.slice(argv.indexOf('-m') + 1) : [];
15
- return [
16
- cmd.module,
17
- ...reset,
18
- ];
16
+ if (typeof cmd.module === 'string') {
17
+ return cmd.module.split(',');
18
+ }
19
+ return [];
20
+ };
21
+ /**
22
+ * 获取用户指定要跑的模块
23
+ * @param {Array} moduleArg 参数指定的模块
24
+ * @param {Object} modulePrivateCfg 私有配置里的模块
25
+ * @param {Array} moduleAll 当前小程序全部模块
26
+ */
27
+ const getSpecificModules = (moduleArg, modulePrivateCfg, moduleAll) => {
28
+ if (moduleArg.length > 0) {
29
+ return moduleArg;
19
30
  }
20
31
  // 单模块或多模块开发-用户在tms.private.js指定的模块
21
- if (tmsPrivateCg?.modules && tmsPrivateCg?.modules.length > 0) {
22
- return tmsPrivateCg?.modules;
32
+ if (modulePrivateCfg) {
33
+ if (modulePrivateCfg.include?.length > 0) {
34
+ return modulePrivateCfg.include;
35
+ }
36
+ if (modulePrivateCfg.exclude?.length > 0) {
37
+ return moduleAll.filter(module => !modulePrivateCfg.exclude.includes(module.name)).map(item => item.name);
38
+ }
39
+ if (modulePrivateCfg.blockRemote === true) {
40
+ return moduleAll.filter(module => module.repoInfo === undefined).map(item => item.name);
41
+ }
23
42
  }
24
- // 全量模块
25
- return MODE.all;
43
+ return moduleAll.map(item => item.name);
26
44
  };
27
45
 
28
46
  async function run(commandName, cmd) {
29
47
  // 用户本地的私有项目配置(用来配置环境\模块信息\账号信息)
30
- const tmsPrivateCg = readTmsPrivateCf();
48
+ const tmsPrivateCf = readTmsPrivateCf();
49
+ const { env = tmsPrivateCf?.env } = cmd;
50
+ const tmsConfig = readTmsConfig(env);
31
51
  // 处理module参数
32
- const moduleArg = handleModulesArg(cmd, tmsPrivateCg);
33
- const { env = tmsPrivateCg?.env } = cmd;
34
- const tmsConfig = await createTask(readTmsConfig, '开始读取脚手架的配置项', '读取脚手架的配置项完成')(env);
52
+ const specificModules = getSpecificModules(
53
+ handleModuleArg(cmd),
54
+ tmsPrivateCf.modules,
55
+ tmsConfig.modules,
56
+ );
35
57
 
36
- let modules;
37
- if (moduleArg === MODE.all) {
38
- // 全量模块
39
- modules = tmsConfig.modules;
40
- } else {
41
- // 检查用户输入modules的有效性
42
- modules = checkModules(tmsConfig, [...new Set([...tmsConfig.mainPackages, ...moduleArg])]);
43
- }
58
+ const modules = checkModules(tmsConfig, [
59
+ ...new Set([
60
+ ...tmsConfig.mainPackages,
61
+ ...specificModules,
62
+ ]),
63
+ ]);
44
64
 
45
65
  // tms.config.js的modules 合并 module.config.json的配置项
46
66
  let newModules = tmsModulesMergeLocalModuleCfg(modules, tmsConfig.appName);
47
67
  // A分包依赖了B分包的代码, merge B分包进行编译;
48
68
  newModules = subModulesMergeDepModules(tmsConfig, newModules);
49
69
 
70
+ // 缓存数据
71
+ global.setData({
72
+ env,
73
+ cmd,
74
+ tmsPrivateCf,
75
+ });
76
+
50
77
  switch (commandName) {
51
78
  case 'init':
52
79
  init(tmsConfig, newModules, env);
53
80
  return;
54
81
  case 'dev':
82
+ global.setData('isDev', true);
55
83
  dev(tmsConfig, newModules, env);
56
84
  return;
57
85
  case 'install':
58
86
  install(tmsConfig, newModules, env);
59
87
  return;
60
88
  case 'build':
89
+ global.setData('isDev', false);
61
90
  build(tmsConfig, newModules, env);
62
91
  return;
63
92
  default:
@@ -2,11 +2,12 @@ const shelljs = require('shelljs');
2
2
  const fs = require('fs');
3
3
  const io = require('../../../utils/io');
4
4
  const { resolve, createTask } = require('../../../utils/widgets');
5
- const { buildOutputAppJson } = require('../../../utils/buildAppJson');
6
- const { MODULE_CODE_DIR, DEFAULT_COPY_CONFIG } = require('../../../config/constant');
7
- const { cloneModules } = require('../../../utils/cloneModules');
8
- const { tmsModulesMergeLocalModuleCfg, subModulesMergeDepModules } = require('../../../utils/tkitUtils');
9
- const { fail } = require('../../../utils/log');
5
+ const { buildOutputAppJson } = require('../../../core/buildAppJson');
6
+ const { symLink } = require('../../../core/symbolicLink');
7
+ const { MODULE_CODE_DIR, DEFAULT_COPY_CONFIG } = require('../../../config/constant');
8
+ const { cloneModules } = require('../../../core/cloneModules');
9
+ const { tmsModulesMergeLocalModuleCfg, subModulesMergeDepModules } = require('../../../core/tmsMpconfig');
10
+ const { fail, info } = require('../../../utils/log');
10
11
  const install = require('../install');
11
12
 
12
13
  /**
@@ -38,13 +39,13 @@ const cpFilesToOutput = function (tmsConfig, targetModules, defaultFiles) {
38
39
  });
39
40
  };
40
41
 
41
- async function task(tmsConfig, targetModules, isDev) {
42
+ async function task(tmsConfig, targetModules) {
42
43
  // 下载和移动代码
43
44
  await createTask(
44
45
  cloneModules,
45
- '开始下载模块代码完成',
46
+ '开始下载模块代码',
46
47
  '下载模块代码码完成',
47
- )(MODULE_CODE_DIR, resolve('./'), targetModules, isDev);
48
+ )(MODULE_CODE_DIR, resolve('./'), targetModules);
48
49
 
49
50
  // tms.config.js的modules 合并 module.config.json的配置项
50
51
  let newModules = tmsModulesMergeLocalModuleCfg(targetModules, tmsConfig.appName);
@@ -66,13 +67,19 @@ async function task(tmsConfig, targetModules, isDev) {
66
67
  buildOutputAppJson,
67
68
  '开始生成编译后的app.json',
68
69
  '生成编译后的app.json完成',
69
- )(tmsConfig, newModules, isDev);
70
+ )(tmsConfig, newModules);
71
+
72
+ await createTask(
73
+ symLink,
74
+ '开始创建软链接',
75
+ '创建软链接完成',
76
+ )(tmsConfig);
70
77
 
71
78
  return newModules;
72
79
  }
73
- async function init(tmsConfig, targetModules, isDev) {
80
+ async function init(tmsConfig, targetModules) {
74
81
  try {
75
- const newModules = await task(tmsConfig, targetModules, isDev);
82
+ const newModules = await task(tmsConfig, targetModules);
76
83
 
77
84
  return {
78
85
  targetModules: newModules,
@@ -80,6 +87,7 @@ async function init(tmsConfig, targetModules, isDev) {
80
87
  } catch (error) {
81
88
  const errMsg = typeof error === 'object' ? error.message : error;
82
89
  fail(`init流程出现错误${errMsg}`);
90
+ info('详细的错误信息', error);
83
91
  process.exit(1);
84
92
  }
85
93
  }
@@ -1,7 +1,8 @@
1
1
  const { createTask, resolve } = require('../../../utils/widgets');
2
- const { buildMpNpm } = require('../../../utils/mpCiUtils');
2
+ const { buildMpNpm } = require('../../../core/mpCi');
3
3
  const { CACHE_DIR } = require('../../../config/constant');
4
- const { cloudNpmInstall, mpNpmInstallAll } = require('../../../utils/npmUtils');
4
+ const { cloudNpmInstall, mpNpmInstallAll } = require('../../../core/npm');
5
+ const { global } = require('../../../utils/global');
5
6
 
6
7
  async function install(tmsConfig, modules, isCloud = false) {
7
8
  // 小程序npm install
@@ -11,12 +12,13 @@ async function install(tmsConfig, modules, isCloud = false) {
11
12
  '小程序npm install 完成',
12
13
  )(modules, resolve(tmsConfig.outputDir), `${CACHE_DIR}/node_modules`);
13
14
 
14
- // 构建miniprograme_npm
15
+ const tmsPrivateCf = global.getData('tmsPrivateCf');
16
+ // 构建miniprogram_npm
15
17
  await createTask(
16
18
  buildMpNpm,
17
- '开始构建miniprograme_npm',
18
- '构建miniprograme_npm 完成',
19
- )({ appId: tmsConfig.appId, projectPath: resolve('./'), privateKey: tmsConfig.privateKey });
19
+ '开始构建miniprogram_npm',
20
+ '构建miniprogram_npm 完成',
21
+ )({ appId: tmsConfig.appId, projectPath: resolve('./'), privateKey: tmsPrivateCf.privateKey });
20
22
 
21
23
  // 安装云函数的
22
24
  isCloud && createTask(
@@ -1,36 +1,22 @@
1
- class Globale {
2
- constructor() {
3
- this.moduleCache = {};
4
- }
5
-
6
- setModuleCache(url, branch, dest) {
7
- const instance = getGlobalInstance();
8
-
9
- const key = `${branch}:${url}`;
10
-
11
- instance.moduleCache[key] = {
12
- dest,
13
- };
14
-
15
- return instance.moduleCache[key];
16
- }
17
-
18
- getModuleCache(url, branch) {
19
- const instance = getGlobalInstance();
20
-
21
- return instance.moduleCache[`${branch}:${url}`];
22
- }
23
- }
24
-
25
- let instance;
26
- function getGlobalInstance() {
27
- if (instance) {
28
- return instance;
29
- }
30
-
31
- return instance = new Globale();
32
- }
1
+ const global = {
2
+ data: {},
3
+ setData(...args) {
4
+ if (args.length === 1) {
5
+ Object.keys(args[0]).forEach((k) => {
6
+ if (args[0][k]) {
7
+ this.data[k] = args[0][k];
8
+ }
9
+ });
10
+ } else {
11
+ const [name, value] = args;
12
+ this.data[name] = value;
13
+ }
14
+ },
15
+ getData(name) {
16
+ return this.data[name];
17
+ },
18
+ };
33
19
 
34
20
  module.exports = {
35
- getGlobalInstance,
21
+ global,
36
22
  };
package/src/utils/io.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
+ const { info } = require('../utils/log');
3
4
  /**
4
5
  * 判断目录是否为空
5
6
  * @param {string} dirname 目录名
@@ -43,11 +44,11 @@ function diffContentCopyFile(originFile, destFile) {
43
44
  const depDestContent = fs.readFileSync(destFile, 'utf8');
44
45
  const depOriginContent = fs.readFileSync(originFile, 'utf8');
45
46
  if (depDestContent !== depOriginContent) {
46
- console.log(`拷贝${originFile}内容到${destFile}`);
47
+ info(`拷贝${originFile}内容到${destFile}`);
47
48
  copyFile(originFile, destFile);
48
49
  }
49
50
  } else {
50
- console.log(`拷贝${originFile}内容到${destFile}`);
51
+ info(`拷贝${originFile}内容到${destFile}`);
51
52
  copyFile(originFile, destFile);
52
53
  }
53
54
  }
package/src/utils/log.js CHANGED
@@ -37,8 +37,11 @@ const warn = (message) => {
37
37
  console.log(chalk.yellow(message));
38
38
  };
39
39
 
40
+ const info = (...args) => console.log(...args);
41
+
40
42
  module.exports = {
41
43
  fail,
42
44
  succeed,
43
45
  warn,
46
+ info,
44
47
  };
@@ -5,9 +5,9 @@ const ora = require('ora');
5
5
  const path = require('path');
6
6
  const fs = require('fs');
7
7
  const shelljs = require('shelljs');
8
- const download = require('download-git-repo');
8
+ const { info } = require('./log');
9
9
  const chalk = require('chalk');
10
- const shelljsOptions = { slient: true };
10
+ const shelljsOptions = { slient: true, async: false };
11
11
 
12
12
  // 获取当前目录
13
13
  const cwd = process.cwd();
@@ -15,11 +15,6 @@ function resolve(...args) {
15
15
  return path.resolve(cwd, ...args);
16
16
  };
17
17
 
18
- /**
19
- * 封装logs
20
- * @returns {Undefined} 无需返回值
21
- */
22
- const log = (...args) => console.log(...args);
23
18
 
24
19
  /**
25
20
  * 用户输入命令时,进行提示
@@ -38,7 +33,7 @@ const suggestCommands = (unknownCommand) => {
38
33
  });
39
34
 
40
35
  if (suggestion) {
41
- log(` ${chalk.red(`Did you mean ${chalk.yellow(suggestion)}?`)}`);
36
+ info(` ${chalk.red(`Did you mean ${chalk.yellow(suggestion)}?`)}`);
42
37
  }
43
38
  };
44
39
 
@@ -60,58 +55,74 @@ function isArray(obj) {
60
55
  return Object.prototype.toString.call(obj) === '[object Array]';
61
56
  }
62
57
 
58
+
63
59
  /**
64
- * 下载模块到目标目录
60
+ * 下载模块代码
61
+ * @param { string } url 模块地址
65
62
  * @param { string } dest 目标地址
66
- * @param { object } downloadOptions 模块下载配置 { repoUrl-仓库地址, gitUrl-git地址, branch-分支或者tag }
63
+ * @param { string } branch 分支名
67
64
  * @returns { undefined } no return
68
65
  */
69
- function downloadRepo(dest, downloadOptions = { repoUrl: '', gitUrl: '', branch: '' }) {
70
- const { repoUrl, gitUrl, branch } = downloadOptions;
66
+ function downloadRepoForGit(url, dest, branch) {
67
+ const cwd = process.cwd();
68
+ return new Promise((resolve, reject) => {
69
+ // 如果目标目录不存在
70
+ if (fs.existsSync(dest)) {
71
+ shelljs.rm('-rf', path.join(dest));
72
+ }
71
73
 
72
- if (fs.existsSync(dest)) {
73
- shelljs.rm('-rf', dest);
74
- }
74
+ shelljs.mkdir('-p', dest);
75
+ shelljs.cd(dest);
75
76
 
76
- shelljs.mkdir('-p', dest);
77
- return new Promise((resolve) => {
78
- download(`${repoUrl}#${branch}`, dest, { clone: true }, async (e) => {
79
- if (e) {
80
- console.log(e) // eslint-disable-line
81
- await downloadRepoForGit(gitUrl, dest, branch);
77
+ shelljs.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, { silent: true }, (code, stdout, stderr) => {
78
+ if (code !== 0) {
79
+ reject(stderr);
82
80
  }
83
-
81
+ shelljs.cd(cwd);
84
82
  resolve();
85
83
  });
86
84
  });
87
85
  }
88
86
 
87
+
89
88
  /**
90
- * 下载模块到目标目录备用方案
91
- * @param { string } url 模块地址
92
- * @param { string } dest 目标地址
89
+ * pull模块代码
90
+ * @param { string } dest 下载代码的路径
93
91
  * @param { string } branch 分支名
94
92
  * @returns { undefined } no return
95
93
  */
96
- function downloadRepoForGit(url, dest, branch) {
94
+ function pullRepoForGit(dest, branch) {
97
95
  const cwd = process.cwd();
98
-
99
96
  return new Promise((resolve, reject) => {
100
- // 如果目标目录不存在
101
- if (fs.existsSync(dest)) {
102
- shelljs.rm('-rf', path.join(dest));
103
- }
104
-
105
- shelljs.mkdir('-p', dest);
106
97
  shelljs.cd(dest);
98
+ shelljs.exec('git config pull.rebase false', shelljsOptions);
99
+ shelljs.exec(`git pull origin ${branch}`, { silent: true }, (code, stdout, stderr) => {
100
+ if (code !== 0) {
101
+ reject(stderr);
102
+ }
103
+ shelljs.cd(cwd);
104
+ resolve();
105
+ });
106
+ });
107
+ }
107
108
 
108
- const gitCloneRes = shelljs.exec(`git clone ${url} ${dest} --branch ${branch} --depth 1`, shelljsOptions);
109
- if (gitCloneRes.code !== 0) {
110
- reject(gitCloneRes.stderr);
111
- }
112
-
113
- shelljs.cd(cwd);
114
- resolve();
109
+ /**
110
+ * npm 下载依赖
111
+ * @param {*} dir
112
+ * @returns
113
+ */
114
+ function npmInstall(dir) {
115
+ return new Promise((resolve, reject) => {
116
+ shelljs.exec(
117
+ 'npx yarn --production --registry http://mirrors.tencent.com/npm/',
118
+ { cwd: dir, silent: true },
119
+ (code, stdout, stderr) => {
120
+ if (code !== 0) {
121
+ reject(stderr);
122
+ }
123
+ resolve();
124
+ },
125
+ );
115
126
  });
116
127
  }
117
128
 
@@ -136,7 +147,7 @@ function createTask(task, startText, endText) {
136
147
  const spinner = ora(startText);
137
148
 
138
149
  spinner.start();
139
- console.log('\n');
150
+ info('\n');
140
151
 
141
152
  const result = await task(...args);
142
153
 
@@ -156,12 +167,12 @@ const camelize = str => str.replace(/-(\w)/g, (a, c) => (c ? c.toUpperCase() : '
156
167
 
157
168
  module.exports = {
158
169
  resolve,
159
- log,
160
170
  isObject,
161
171
  isArray,
162
172
  createTask,
163
- downloadRepo,
164
173
  downloadRepoForGit,
174
+ pullRepoForGit,
165
175
  suggestCommands,
166
176
  camelize,
177
+ npmInstall,
167
178
  };
@@ -1,35 +0,0 @@
1
- const fs = require('fs');
2
- const cp = require('child_process');
3
-
4
- const getDevtoolCliPath = async () => {
5
- let cliPath;
6
- if (process.platform === 'darwin') {
7
- cliPath = '/Applications/wechatwebdevtools.app/Contents/MacOS/cli';
8
- } else if (process.platform === 'win32') {
9
- cliPath = 'C:/Program Files (x86)/Tencent/微信web开发者工具/cli.bat';
10
- } else {
11
- // 其余平台暂不支持
12
- throw new Error('unsupported platform');
13
- }
14
- const exists = await new Promise(resolve => fs.exists(cliPath, resolve));
15
- if (!exists) {
16
- // 找不到开发工具
17
- throw new Error(`未找到微信小程序开发者工具,请确认是否安装,如未安装请前往
18
- https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html 下载`);
19
- }
20
- return cliPath;
21
- };
22
-
23
- const openDevtool = async (path) => {
24
- const cliPath = await getDevtoolCliPath();
25
- const child = cp.spawn(cliPath, ['open', '--project', path], {
26
- detached: true,
27
- stdio: 'inherit',
28
- });
29
- child.unref();
30
- };
31
-
32
- module.exports = {
33
- getDevtoolCliPath,
34
- openDevtool,
35
- };