@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
@@ -0,0 +1,69 @@
1
+ const fs = require('fs');
2
+ const { resolve } = require('../utils/widgets');
3
+ const { MODULE_CONFIG_FILENAME, 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, contextDir) {
9
+ // 判断\源码\dist\是否存在用户指定的模块
10
+ for (const item of targetModules) {
11
+ // 此模块没有root字段(原因:没有merge到module.config.json的配置项。第三方模块的代码可能还没有下载)
12
+ if (!item.root) {
13
+ return true;
14
+ }
15
+ // 判断dist目录是否有该模块
16
+ if (!fs.existsSync(`${contextDir}/${item.root}/${MODULE_CONFIG_FILENAME}`)) {
17
+ return true;
18
+ }
19
+
20
+ // 判断第三方远程模块git地址与branch是否有更新
21
+ if (checkRemoteModGitUrlBranch(MODULE_CODE_DIR, item)) {
22
+ return true;
23
+ }
24
+
25
+ // 判断源码目录是否有该模块
26
+ if (item.path && !fs.existsSync(resolve(item.path))) {
27
+ fail(`${item.path}模块代码路径不存在, 请检查tms.config.js的${item.name}模块的path`);
28
+ process.exit(1);
29
+ }
30
+ }
31
+ return false;
32
+ }
33
+
34
+ function isInit(tmsConfig, targetModules, contextDir) {
35
+ // 判断是否存在dist目录
36
+ if (!fs.existsSync(contextDir)) {
37
+ return true;
38
+ }
39
+ // 判断dist是否存在node_modules
40
+ if (!fs.existsSync(`${contextDir}/node_modules`)) {
41
+ return true;
42
+ }
43
+
44
+ // 判断dist是否存在miniprogram_npm
45
+ if (!fs.existsSync(`${contextDir}/miniprogram_npm`)) {
46
+ return true;
47
+ }
48
+
49
+ // 判断dist是否存在app.json
50
+ if (!fs.existsSync(`${contextDir}/app.json`)) {
51
+ return true;
52
+ }
53
+
54
+ // 判断模块信息
55
+ if (checkModule(targetModules, contextDir)) {
56
+ return true;
57
+ }
58
+
59
+ // 判断package.json的版本是否有新的版本
60
+ if (checkDependencies(targetModules, resolve('./'), tmsConfig.outputDir)) {
61
+ return true;
62
+ }
63
+ return false;
64
+ }
65
+
66
+
67
+ module.exports = {
68
+ isInit,
69
+ };
File without changes
@@ -0,0 +1,218 @@
1
+ /**
2
+ * 本文件主要负责项目或者分包依赖的npm的安装
3
+ */
4
+ const fs = require('fs');
5
+ const fsExtra = require('fs-extra');
6
+ const crypto = require('crypto');
7
+ const path = require('path');
8
+ const shell = require('shelljs');
9
+ const glob = require('glob-ignore');
10
+ const log = require('../utils/log');
11
+ const { npmInstall } = require('../utils/widgets');
12
+ const { handleError } = require('./handleError');
13
+ const { info } = require('console');
14
+
15
+ const shellJsOption = { async: false, silent: true };
16
+ const dirPath = process.cwd(); // 项目根目录
17
+
18
+ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
19
+ // 下载代码任务 Map (key解释 缓存代码路径/md5(package.json.dependencies)
20
+ // {
21
+ // '/Users/odile/.tmskit/node_modules/026cb72509c2369dbd75779181f820bc': {
22
+ // promiseTask, 下载的任务
23
+ // params: { 下载代码时的参数
24
+ // gitUrl,
25
+ // sourcePath,
26
+ // branch,
27
+ // },
28
+ // callbacks: [callback],// 下载完代码后的回调
29
+ // }
30
+ // }
31
+ const npmTasksMap = new Map();
32
+ for (const packageJsonPath of packageJsonFiles) {
33
+ const packageContent = fs.readFileSync(packageJsonPath);
34
+ const packageJson = JSON.parse(packageContent);
35
+ const md5Obj = {
36
+ dependencies: packageJson.dependencies || {},
37
+ };
38
+
39
+ if (Object.keys(md5Obj.dependencies).length !== 0) {
40
+ const md5Key = crypto.createHash('md5').update(JSON.stringify(md5Obj))
41
+ .digest('hex');
42
+ const cacheNMPath = path.join(cacheDir, md5Key);
43
+ const cacheNMTarFile = path.join(cacheNMPath, 'node_modules.tar.gz');
44
+
45
+ // 下载后,添加回调函数 (拷贝node_modules.tar.gz到编译目录并解压)
46
+ const callback = {
47
+ params: { cacheNMPath, cacheNMTarFile, packageJsonDir: path.dirname(packageJsonPath), shell },
48
+ fn: async (cacheNMPath, cacheNMTarFile, packageJsonDir, shell) => {
49
+ shell.cd(cacheNMPath);
50
+ shell.cp('-Rf', cacheNMTarFile, `${packageJsonDir}/`);
51
+ const newShellJsOption = {
52
+ ...shellJsOption,
53
+ cwd: packageJsonDir,
54
+ };
55
+ shell.exec('tar -xzvf ./node_modules.tar.gz -C ./', newShellJsOption);
56
+ shell.exec('rm -rf ./node_modules.tar.gz', newShellJsOption);
57
+ },
58
+ };
59
+
60
+ if (npmTasksMap.has(cacheNMPath)) {
61
+ const task = npmTasksMap.get(cacheNMPath);
62
+ task.callbacks.push(callback);
63
+ npmTasksMap.set(cacheNMPath, task);
64
+ } else {
65
+ const missCache = !fsExtra.pathExistsSync(cacheNMPath)
66
+ || !fsExtra.existsSync(cacheNMTarFile)
67
+ || fsExtra.statSync(cacheNMTarFile).size < 512;
68
+ let promiseTask = () => Promise.resolve();
69
+ if (missCache) {
70
+ promiseTask = (packageJsonPath, cacheNMPath, shell) => {
71
+ fsExtra.emptydirSync(cacheNMPath);
72
+ shell.cp('-f', packageJsonPath, cacheNMPath);
73
+ info(`npm install: ${packageJsonPath}`);
74
+ return npmInstall(cacheNMPath).then(() => {
75
+ const newShellJsOption = {
76
+ ...shellJsOption,
77
+ cwd: cacheNMPath,
78
+ };
79
+ shell.exec('tar -zcvf ./node_modules.tar.gz ./node_modules', newShellJsOption);
80
+ shell.exec('rm -rf ./node_modules', newShellJsOption);
81
+ });
82
+ };
83
+ }
84
+ npmTasksMap.set(cacheNMPath, {
85
+ promiseTask,
86
+ params: {
87
+ packageJsonPath,
88
+ cacheNMPath,
89
+ shell,
90
+ },
91
+ callbacks: [callback],
92
+ });
93
+ }
94
+ }
95
+ }
96
+ return npmTasksMap;
97
+ };
98
+
99
+
100
+ // 遍历安装指定目录下所有项目的npm依赖
101
+ const mpNpmInstallAll = async (modules, contextDir, cacheDir) => {
102
+ const packageJsonFiles = await findAllPackageJson(modules, contextDir);
103
+
104
+ // 收集npm install的任务
105
+ const npmTasksMap = collectNpmTasksMap(packageJsonFiles, cacheDir);
106
+
107
+ // 开始执行npm install和回调(移动)的任务
108
+ const arrPromises = [];
109
+ npmTasksMap.forEach(({ promiseTask, params, callbacks }) => {
110
+ arrPromises.push(promiseTask(...Object.keys(params).map(key => params[key]))
111
+ .then(async () => {
112
+ const callArr = callbacks.map(async ({
113
+ params: cParams,
114
+ fn,
115
+ }) => fn(...Object.keys(cParams).map(key => cParams[key])));
116
+ return Promise.all(callArr);
117
+ })
118
+ .catch((e) => {
119
+ handleError(`npm install ${params.packageJsonPath}出现错误:${e}`);
120
+ }));
121
+ });
122
+
123
+ await Promise.all(arrPromises);
124
+ };
125
+
126
+ /**
127
+ * 递归查找指定条件的文件
128
+ * @param {String} startPath 开始查找的根路径
129
+ * @param {String} filter 匹配的字符串
130
+ * @returns {Array<String>} 查找到的文件路径列表
131
+ */
132
+ const findFilesByFilter = (startPath, filter) => {
133
+ const result = [];
134
+ /**
135
+ * 根据指定的筛选器查找文件
136
+ * @param {String} startPath 开始查找的文件夹路径
137
+ * @param {String} filter 筛选器
138
+ * @returns {Undefined} 无需返回值
139
+ */
140
+ const find = (startPath, filter) => {
141
+ // 目录不存在
142
+ if (!fs.existsSync(startPath)) {
143
+ log.fail(`${startPath}目录不存在`);
144
+ process.exit(-1);
145
+ return;
146
+ }
147
+
148
+ // 当前目录下的所有文件 / 文件夹
149
+ const exceptDir = ['node_modules', 'miniprogram_npm'];
150
+ if (exceptDir.find(item => startPath.indexOf(item) > -1)) {
151
+ return;
152
+ }
153
+ const files = fs.readdirSync(startPath);
154
+ files.forEach((file) => {
155
+ const filename = path.join(startPath, file);
156
+ const stat = fs.lstatSync(filename);
157
+ // 当前文件是文件夹类型,继续递归
158
+ if (stat.isDirectory()) {
159
+ find(filename, filter);
160
+ } else if (filename.indexOf(filter) >= 0) {
161
+ // 文件类型
162
+ result.push(filename);
163
+ };
164
+ });
165
+ };
166
+
167
+ find(startPath, filter);
168
+ return result;
169
+ };
170
+
171
+ /**
172
+ * 找到项目中所有的package.json文件
173
+ * @param {Array<String>} subRoots 需要安装npm依赖的路径
174
+ * @param {String} contextDir 命令运行的目录
175
+ * @returns {Array<String>} 找到的所有package.json文件的路径
176
+ */
177
+ const findAllPackageJson = (subRoots = [], contextDir) => {
178
+ const packageJsonName = 'package.json'; // 查找文件名
179
+ const cwd = contextDir || dirPath;
180
+ const result = [path.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
181
+
182
+ subRoots.forEach((subRoot) => {
183
+ if (!subRoot.root) {
184
+ log.fail(`请检查${subRoot.name}的module.config.json是否有root字段`);
185
+ process.exit(1);
186
+ }
187
+ const toppath = path.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
188
+ const list = findFilesByFilter(toppath, packageJsonName);
189
+
190
+ result.push(...list);
191
+ });
192
+
193
+ return result;
194
+ };
195
+
196
+ function cloudNpmInstall(contextDir) {
197
+ return new Promise((resolve, reject) => {
198
+ glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
199
+ if (err) {
200
+ reject(err);
201
+ }
202
+ files.forEach((file) => {
203
+ const dir = path.dirname(file);
204
+ shell.cd(dir);
205
+ shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', { silent: false });
206
+ });
207
+ resolve();
208
+ });
209
+ });
210
+ }
211
+
212
+
213
+ module.exports = {
214
+ cloudNpmInstall,
215
+ mpNpmInstallAll,
216
+ findAllPackageJson,
217
+ };
218
+
@@ -0,0 +1,24 @@
1
+ const fs = require('fs');
2
+ const { resolve } = require('../utils/widgets');
3
+ const { handleError } = require('./handleError');
4
+ const { DEFAULT_CLOUD_MODULE_DIR } = require('../config/constant');
5
+
6
+ /**
7
+ * 根据相关配置创建软链接
8
+ * @param { object } tmsConfig
9
+ */
10
+ const symLink = (tmsConfig) => {
11
+ try {
12
+ if (tmsConfig.cloudModules) {
13
+ tmsConfig.cloudModules.forEach((item) => {
14
+ fs.symlinkSync(resolve(item.path), resolve(DEFAULT_CLOUD_MODULE_DIR, item.name));
15
+ });
16
+ }
17
+ } catch (e) {
18
+ handleError(`创建软链错误: ${e}`);
19
+ }
20
+ };
21
+
22
+ module.exports = {
23
+ symLink,
24
+ };
@@ -1,10 +1,12 @@
1
+ /**
2
+ * 用来读取处理tms.config.js与module.config.json字段
3
+ */
1
4
  const loadash = require('lodash');
2
5
  const fs = require('fs');
3
6
  const { TMS_NAME, TMS_CONFIG_FILENAME, MODULE_CONFIG_FILENAME, TMS_PRIVATE_FILENAME } = require('../config/constant');
4
- const { resolve, isObject } = require('./widgets');
5
- const { setModuleConfig, getValidModules } = require('./buildAppJson');
7
+ const { resolve, isObject, isArray } = require('../utils/widgets');
6
8
  const defaultTmsConfig = require('../config/defaultTmsConfig');
7
- const { fail } = require('./log');
9
+ const { fail } = require('../utils/log');
8
10
  const path = require('path');
9
11
 
10
12
  /**
@@ -23,6 +25,7 @@ const readTmsConfig = function (env) {
23
25
  });
24
26
  // 合并默认值
25
27
  loadash.mergeWith(tmsConfig, defaultTmsConfig);
28
+
26
29
  // modules兼容处理
27
30
  tmsConfig.modules = convertModules(tmsConfig.modules);
28
31
  return tmsConfig;
@@ -31,7 +34,7 @@ const readTmsConfig = function (env) {
31
34
  // convertModules 处理默认值
32
35
  const convertModules = (modules) => {
33
36
  const newModules = [];
34
- modules.forEach((module, index) => {
37
+ modules.forEach((module) => {
35
38
  const newModule = {};
36
39
  if (typeof module === 'string') {
37
40
  // 路径字符串
@@ -51,15 +54,21 @@ const convertModules = (modules) => {
51
54
  };
52
55
 
53
56
  /**
54
- * 读取tms.private.js
57
+ * 读取tms.private.config.js
55
58
  */
56
59
  const readTmsPrivateCf = function () {
57
- let tmsPrivateCg;
60
+ let tmsPrivateCf = {};
58
61
  const tmsPrivatePath = resolve(TMS_PRIVATE_FILENAME);
59
62
  if (fs.existsSync(tmsPrivatePath)) {
60
- tmsPrivateCg = require(tmsPrivatePath);
63
+ tmsPrivateCf = require(tmsPrivatePath);
61
64
  }
62
- return tmsPrivateCg;
65
+ // 处理modules字段
66
+ if (tmsPrivateCf.modules instanceof Array) {
67
+ Object.assign(tmsPrivateCf.modules, {
68
+ include: tmsPrivateCf.modules,
69
+ });
70
+ }
71
+ return tmsPrivateCf;
63
72
  };
64
73
 
65
74
  /**
@@ -81,6 +90,64 @@ const checkModules = function (tmsConfig, modules) {
81
90
  return targetModules;
82
91
  };
83
92
 
93
+ /**
94
+ * 过滤页面为空的分包
95
+ * @param {Array} moduleCfg 模块配置内容
96
+ * @returns pages不为空的分包
97
+ */
98
+ const getValidModules = (moduleCfg) => {
99
+ // 过滤 pages 为空的情况
100
+ const validModules = moduleCfg.filter(item => item.pages.length > 0);
101
+ return validModules;
102
+ };
103
+
104
+ /**
105
+ * 适配处理module.config.json的字段
106
+ * @param { object } fileContent module.config.json的内容
107
+ * @param { string } appName 小程序的名称
108
+ */
109
+ function adaptMpCgContent(fileContent, appName) {
110
+ const content = fileContent.contents ? JSON.parse(fileContent.contents.toString()) : JSON.parse(fileContent);
111
+
112
+ if (isArray(content)) {
113
+ let i = content.length - 1;
114
+ while (i >= 0) {
115
+ let current = content[i];
116
+
117
+ if (appName && current.mpConfig && current.mpConfig[appName]) {
118
+ current = { ...current, ...current.mpConfig[appName] };
119
+ }
120
+
121
+ delete current.mpConfig;
122
+ delete current.isSubpackages;
123
+
124
+ content[i] = current;
125
+ i--; // eslint-disable-line
126
+ }
127
+ }
128
+ return content;
129
+ }
130
+
131
+ /**
132
+ * 递归获取本地所有模块的配置信息
133
+ * @param {array} modules 用户要编译的模块列表
134
+ * @param { string } appName 小程序的名称
135
+ * @param { string } moduleConfigFilename moduleConfig的文件名
136
+ */
137
+ function getModuleConfig(modules = [], appName, moduleConfigFilename) {
138
+ const modulesConfig = {};
139
+
140
+ modules.forEach(({ path }) => {
141
+ const moduleConfigPath = resolve(path, moduleConfigFilename);
142
+ if (fs.existsSync(moduleConfigPath)) {
143
+ const content = fs.readFileSync(moduleConfigPath, 'utf-8');
144
+ modulesConfig[moduleConfigPath] = adaptMpCgContent(content, appName);
145
+ }
146
+ });
147
+
148
+ return modulesConfig;
149
+ }
150
+
84
151
  /**
85
152
  * tms.config.js的modules 合并 module.config.json的配置项
86
153
  * @param {array} modules
@@ -94,17 +161,23 @@ const tmsModulesMergeLocalModuleCfg = (modules, appName) => {
94
161
  const moduleConfigPath = resolve(relativePath, MODULE_CONFIG_FILENAME);
95
162
  if (fs.existsSync(moduleConfigPath)) {
96
163
  try {
164
+ let findModule = false;
97
165
  let moduleConfigContent = fs.readFileSync(moduleConfigPath, 'utf-8');
98
- moduleConfigContent = setModuleConfig(moduleConfigContent, appName);
166
+ moduleConfigContent = adaptMpCgContent(moduleConfigContent, appName);
99
167
  const moduleContentArr = isObject(moduleConfigContent) ? [moduleConfigContent] : moduleConfigContent;
100
168
  getValidModules(moduleContentArr).forEach(({ name }, moduleContentArrIndex) => {
101
169
  if (name === moduleName) {
170
+ findModule = true;
102
171
  newModules.push({
103
172
  ...modules[moduleIndex],
104
173
  ...moduleContentArr[moduleContentArrIndex],
105
174
  });
106
175
  }
107
176
  });
177
+ if (!findModule) {
178
+ fail(`启动模块${moduleName}在${moduleConfigPath}没有找到,请检查配置`);
179
+ process.exit(1);
180
+ }
108
181
  } catch (e) {
109
182
  fail(`${moduleConfigPath}配置错误: ${e}`);
110
183
  newModules.push({
@@ -134,6 +207,7 @@ const subModulesMergeDepModules = (tmsConfig, modules) => {
134
207
  });
135
208
  let mergeModules = modules;
136
209
  let isOver = true;
210
+
137
211
  modules.forEach(({ dependencies: dependencyModules }) => {
138
212
  dependencyModules?.forEach((item) => {
139
213
  // 如果所有模块的dep都在moduleNames内,则所有依赖都齐了
@@ -152,6 +226,8 @@ const subModulesMergeDepModules = (tmsConfig, modules) => {
152
226
  module.exports = {
153
227
  readTmsConfig,
154
228
  readTmsPrivateCf,
229
+ getModuleConfig,
230
+ getValidModules,
155
231
  checkModules,
156
232
  tmsModulesMergeLocalModuleCfg,
157
233
  subModulesMergeDepModules,
package/src/entry.js CHANGED
@@ -28,6 +28,7 @@ module.exports = [
28
28
  options: [
29
29
  ['-m, --module [moduleName]', '模块名称'],
30
30
  ['-e, --env [env]', '环境变量'],
31
+ ['-latest, --latest', '下载最新第三方模块代码、安装最新依赖'],
31
32
  ],
32
33
  action: (cmd) => {
33
34
  require('./scripts/run/index')('dev', cmd);
@@ -44,17 +45,18 @@ module.exports = [
44
45
  require('./scripts/run/index')('build', cmd);
45
46
  },
46
47
  },
47
- {
48
- command: 'init',
49
- description: '根据模块配置初始化项目(eg: 动态拷贝模块、下载依赖、生成app.json等)',
50
- options: [
51
- ['-m, --module [moduleName]', '模块名称'],
52
- ['-e, --env [env]', '环境变量'],
53
- ],
54
- action: (cmd) => {
55
- require('./scripts/run/index')('init', cmd);
56
- },
57
- },
48
+ // 对外暂不暴露该命令
49
+ // {
50
+ // command: 'init',
51
+ // description: '模块配置初始化项目(eg: 下载第三方模块代码、安装依赖、生成app.json等)',
52
+ // options: [
53
+ // ['-m, --module [moduleName]', '模块名称'],
54
+ // ['-e, --env [env]', '环境变量'],
55
+ // ],
56
+ // action: (cmd) => {
57
+ // require('./scripts/run/index')('init', cmd);
58
+ // },
59
+ // },
58
60
  ],
59
61
  },
60
62
  ];
package/src/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const chalk = require('chalk');
2
2
  const commander = require('commander');
3
- const { log, suggestCommands } = require('./utils/widgets');
3
+ const { suggestCommands } = require('./utils/widgets');
4
+ const { info } = require('./utils/log');
4
5
  const { TMS_NAME } = require('./config/constant.js');
5
6
  const commands = require('./entry');
6
7
  const init = require('./init');
@@ -38,9 +39,9 @@ function registerCommand(program, commands) {
38
39
  registerCommand(program, commands);
39
40
 
40
41
  program.on('--help', () => {
41
- log();
42
- log(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
43
- log();
42
+ info();
43
+ info(` Run ${chalk.cyan(`${TMS_NAME} <command> --help`)} for detailed usage of given command.`);
44
+ info();
44
45
  });
45
46
 
46
47
  // 捕获未注册的命令
@@ -48,8 +49,8 @@ program
48
49
  .arguments('<command>')
49
50
  .action((cmd) => {
50
51
  program.outputHelp();
51
- log(` ${chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)}`);
52
- log();
52
+ info(` ${chalk.red(`Unknown command ${chalk.yellow(cmd)}.`)}`);
53
+ info();
53
54
  suggestCommands(cmd);
54
55
  process.exitCode = 1;
55
56
  });
package/src/init.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const semver = require('semver');
2
2
  const packageJson = require('../package.json');
3
3
  const chalk = require('chalk');
4
- const { log } = require('./utils/widgets');
4
+ const { info } = require('./utils/log');
5
5
 
6
6
  const requiredVersion = packageJson.engines.node;
7
7
  const packName = packageJson.name;
@@ -14,7 +14,7 @@ const packName = packageJson.name;
14
14
  */
15
15
  const checkNodeVersion = (wanted, id) => {
16
16
  if (!semver.satisfies(process.version, wanted, { includePrerelease: true })) {
17
- log(chalk.red(`你正在使用的Node版本: ${process.version}, 但是此版本的 ${id
17
+ info(chalk.red(`你正在使用的Node版本: ${process.version}, 但是此版本的 ${id
18
18
  } 需要的Node最小版本 ${wanted}.\n请先升级你的Node版本.`));
19
19
  process.exit(1);
20
20
  }
@@ -4,7 +4,7 @@ const shelljs = require('shelljs');
4
4
  const { TEMPLATE_DIR, TEMPLATE_PATH, TEMPLATE_TKIT_DIR } = require('../../config/constant.js');
5
5
  const { downloadRepoForGit, createTask, resolve } = require('../../utils/widgets');
6
6
  const io = require('../../utils/io');
7
- const { fail, succeed } = require('../../utils/log');
7
+ const { fail, succeed, info } = require('../../utils/log');
8
8
  const generator = require('./generator');
9
9
 
10
10
  /**
@@ -65,7 +65,7 @@ async function create(appName) {
65
65
  })
66
66
  .catch((err) => {
67
67
  fail(err.message);
68
- console.log('详细的错误信息:', err);
68
+ info('详细的错误信息:', err);
69
69
  });
70
70
  }
71
71
 
@@ -1,16 +1,15 @@
1
1
  const shelljs = require('shelljs');
2
2
  const { resolve } = require('../../../utils/widgets');
3
3
  const init = require('../init/index');
4
- const gulpBuild = require('../../../gulp/build');
4
+ const compileBuild = require('../../../compile/build');
5
5
 
6
6
  async function build(tmsConfig, targetModules, env) {
7
7
  // 开始构建前,清理输出目录
8
8
  await shelljs.rm('-rf', resolve(tmsConfig.outputDir));
9
9
 
10
- const isDev = false;
11
- const { targetModules: newModules } = await init(tmsConfig, targetModules, isDev);
10
+ const { targetModules: newModules } = await init(tmsConfig, targetModules);
12
11
 
13
- gulpBuild(tmsConfig, newModules, env);
12
+ compileBuild(tmsConfig, newModules, env);
14
13
  }
15
14
 
16
15
  module.exports = build;