@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.
@@ -7,8 +7,14 @@ const HOME_DIR = os.homedir();
7
7
  // 所有文件的缓存目录
8
8
  const CACHE_DIR = path.resolve(HOME_DIR, '.tmskit');
9
9
 
10
- // 缓存文件
11
- const CACHE_FILE = 'cache_file.json';
10
+ // 版本管理的CDN地址
11
+ const VERSION_URL = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/version.json';
12
+
13
+ // version缓存文件
14
+ const VERSION_CACHE_FILE = path.resolve(CACHE_DIR, 'version_cache_file.json');
15
+
16
+ // npm缓存文件
17
+ const NPM_CACHE_FILE = path.resolve(CACHE_DIR, 'npm_cache_file.json');
12
18
 
13
19
  // 脚手架模板代码所在目录
14
20
  const TEMPLATE_DIR = path.resolve(CACHE_DIR, 'template');
@@ -16,8 +22,17 @@ const TEMPLATE_DIR = path.resolve(CACHE_DIR, 'template');
16
22
  // 第三方模块源码存放的临时缓存目录
17
23
  const MODULE_CODE_DIR = path.resolve(CACHE_DIR, 'modules_code');
18
24
 
19
- // 脚手架模板代码的具体路径
20
- const TEMPLATE_PATH = path.resolve(TEMPLATE_DIR, 'tools/tmskit-template');
25
+ // 缓存分包node_modules的目录
26
+ const NODE_MODULES_DIR = path.resolve(CACHE_DIR, 'node_modules');
27
+
28
+ // 扩展命令源码的存放处
29
+ const EXTEND_CMD = path.resolve(CACHE_DIR, 'cmd');
30
+
31
+ // 创建模板的名称
32
+ const TEMPLATE_NAME = 'tmskit-template';
33
+
34
+ // 脚手架模板的远程地址
35
+ const TEMPLATE_URL = 'https://tms-web-1g1czzwka2fd06f2-1301126013.tcloudbaseapp.com/tmskit-template/tmskit-template.zip';
21
36
 
22
37
  // 脚手架的名称
23
38
  const TMS_NAME = 'tmskit';
@@ -42,7 +57,7 @@ const DEFAULT_WEBPACK_ENTRY = {
42
57
  };
43
58
 
44
59
  // 默认从源码拷贝到编译后的配置
45
- const DEFAULT_COPY_CONFIG = ['package.json', 'sitemap.json'];
60
+ const DEFAULT_COPY_CONFIG = ['package.json', 'sitemap.json', 'project.config.json'];
46
61
 
47
62
  const ENV = {
48
63
  dev: 'development',
@@ -51,22 +66,46 @@ const ENV = {
51
66
 
52
67
  const TEMPLATE_TKIT_DIR = '_tmskit';
53
68
 
54
-
55
- export {
69
+ const CREATE_TEMPLATE_QUESTION = [
70
+ {
71
+ type: 'list',
72
+ name: 'projectType',
73
+ message: '选择你要创建的模板',
74
+ choices: [{
75
+ name: '小程序项目',
76
+ value: 'mp',
77
+ }, {
78
+ name: '小程序模块',
79
+ value: 'mp-module',
80
+ }, {
81
+ name: '构建工具扩展命令',
82
+ value: 'cmd',
83
+ }],
84
+ },
85
+ ];
86
+
87
+
88
+ module.exports = {
56
89
  HOME_DIR,
57
90
  CACHE_DIR,
58
- CACHE_FILE,
91
+ NPM_CACHE_FILE,
92
+ VERSION_CACHE_FILE,
59
93
  TEMPLATE_DIR,
60
- TEMPLATE_PATH,
94
+ TEMPLATE_NAME,
61
95
  TMS_NAME,
62
96
  TMS_CONFIG_FILENAME,
63
97
  TMS_PRIVATE_FILENAME,
64
98
  DEFAULT_MODULE_DIR,
65
99
  MODULE_CONFIG_FILENAME,
100
+ EXTEND_CMD,
66
101
  DEFAULT_WEBPACK_ENTRY,
67
102
  DEFAULT_COPY_CONFIG,
68
103
  MODULE_CODE_DIR,
104
+ NODE_MODULES_DIR,
69
105
  ENV,
70
106
  TEMPLATE_TKIT_DIR,
71
107
  DEFAULT_CLOUD_MODULE_DIR,
108
+ CREATE_TEMPLATE_QUESTION,
109
+ TEMPLATE_URL,
110
+ VERSION_URL,
72
111
  };
@@ -3,12 +3,13 @@
3
3
  */
4
4
  /* eslint-disable no-param-reassign */
5
5
  const fs = require('fs');
6
- const { MODULE_CONFIG_FILENAME } = require('../config/constant');
7
- const { getModuleConfig } = require('./tmsMpconfig');
8
- const { fail } = require('../utils/log');
9
- const { resolve, isObject, filterField } = require('../utils/widgets');
6
+ const { getSubPackages, getModulesConfig } = require('./tmsMpconfig');
7
+ const { fail, info } = require('../utils/log');
8
+ const { resolve, filterField } = require('../utils/widgets');
10
9
  const { handleError } = require('./handleError');
11
10
  const { global } = require('../utils/global');
11
+ const report = require('../core/report');
12
+
12
13
 
13
14
  /**
14
15
  * 更新appJson里面的主包配置
@@ -58,19 +59,7 @@ const getAppJsonContent = (sourceAppJsonPath) => {
58
59
  appJson.pages = [];
59
60
  return appJson;
60
61
  };
61
- /**
62
- * 更新app.json中的subpackages
63
- * @param {Object} appJson
64
- * @param {Object} modulesConfigs
65
- */
66
- const updateSubpackages = (appJson, modulesConfigs) => {
67
- // eslint-disable-next-line
68
- for (const modulePath in modulesConfigs) {
69
- const moduleInfo = isObject(modulesConfigs[modulePath]) ? [modulesConfigs[modulePath]] : modulesConfigs[modulePath];
70
- appJson.subpackages = appJson.subpackages.concat(moduleInfo);
71
- }
72
- appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name));
73
- };
62
+
74
63
 
75
64
  /**
76
65
  * 处理合并subpackages后的appjson, 整理重复不合法的地方
@@ -109,7 +98,7 @@ const fixAppJson = (appJson) => {
109
98
  appJson[key] = preloadRuleMap;
110
99
  }
111
100
  });
112
- return filterField(subp, [...arrOfFileType, ...objOfFileType, 'dependencies']);
101
+ return filterField(subp, [...arrOfFileType, ...objOfFileType, 'dependencies', 'path']);
113
102
  });
114
103
  // 如果plugins重复,则错误提示
115
104
  const pluginsErrMsg = Object.keys(pluginsMap).map((pk) => {
@@ -133,12 +122,17 @@ const fixAppJson = (appJson) => {
133
122
  */
134
123
  function buildOutputAppJson(tmsConfig, modules) {
135
124
  try {
136
- // 获取当前 modules 下的所有子模块的配置内容
137
- const modulesConfigs = getModuleConfig(modules, tmsConfig.appName, MODULE_CONFIG_FILENAME);
125
+ // 获取所有模块,合并模块依赖的模块
126
+ const modulesConfig = getModulesConfig(modules, tmsConfig.appName, false);
127
+ // 获取所有的分包
128
+ const subPackages = getSubPackages(modulesConfig);
138
129
  // 获取app.json的配置
139
130
  const appJson = getAppJsonContent(resolve('./app.json'));
131
+
140
132
  // 更新app.json中的subpackages
141
- updateSubpackages(appJson, modulesConfigs);
133
+ appJson.subpackages = subPackages;
134
+ appJson.subpackages.sort((item1, item2) => item1.name.localeCompare(item2.name));
135
+
142
136
  // 处理appJson中重复||冲突的地方
143
137
  fixAppJson(appJson);
144
138
  // 更新主包,需在subpackages处理完成后执行, pages/
@@ -153,10 +147,12 @@ function buildOutputAppJson(tmsConfig, modules) {
153
147
  appJson,
154
148
  isDev: global.getData('isDev'),
155
149
  });
150
+ report('hooks:updateAppJson');
156
151
  }
157
152
  return appJson;
158
153
  } catch (e) {
159
154
  handleError(`生成app.json出现错误: ${e}`);
155
+ info(e);
160
156
  }
161
157
  }
162
158
 
@@ -1,24 +1,20 @@
1
1
  const fs = require('fs');
2
2
  const semver = require('semver');
3
- const { resolve } = require('../utils/widgets');
3
+ const { resolve, getAbsolutePath } = require('../utils/widgets');
4
4
  const path = require('path');
5
5
  const shelljs = require('shelljs');
6
6
  const { handleError } = require('./handleError');
7
7
 
8
8
  const getLatestVersion = (npmName) => {
9
9
  const data = shelljs.exec(`npm view ${npmName} version`);
10
- return data.stdout || '0.0.0';
10
+ if (data.code === 0) {
11
+ return data.stdout;
12
+ }
13
+ return '0.0.0';
11
14
  };
12
15
 
13
- /**
14
- * 检查package.json的依赖大于node_module的版本,则返回true
15
- * @param {*} modules 模块
16
- * @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
17
- * @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
18
- * @returns
19
- */
20
- const isDependenciesUpdate = (modules, cwd, outputDir) => {
21
- // 步骤1. 收集package.json
16
+ // 收集package.json
17
+ function collectPackageJson(subPackages, cwd, outputDir) {
22
18
  const packageJsonName = 'package.json'; // 查找文件名
23
19
  // 1.1根目录的package.json
24
20
  const packageArr = [
@@ -28,8 +24,8 @@ const isDependenciesUpdate = (modules, cwd, outputDir) => {
28
24
  },
29
25
  ];
30
26
  // 1.2模块的package.json
31
- modules.forEach((item) => {
32
- const srcPackageDir = path.join(cwd, item.path, 'package.json');
27
+ subPackages.forEach((item) => {
28
+ const srcPackageDir = `${getAbsolutePath(item.path)}/package.json`;
33
29
  if (fs.existsSync(srcPackageDir)) {
34
30
  packageArr.push({
35
31
  srcPackageDir,
@@ -37,17 +33,40 @@ const isDependenciesUpdate = (modules, cwd, outputDir) => {
37
33
  });
38
34
  }
39
35
  });
36
+ return packageArr;
37
+ }
38
+
39
+ // 读取package.json的依赖
40
+ function readPackageDependencies(srcPackageDir) {
41
+ const packageJson = fs.readFileSync(srcPackageDir, 'utf-8');
42
+ let dependencies = {};
43
+ try {
44
+ const json = packageJson ? JSON.parse(packageJson) : {};
45
+ dependencies = json?.dependencies || {};
46
+ } catch (e) {
47
+ handleError(`解析${srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
48
+ }
49
+ return dependencies;
50
+ }
40
51
 
52
+ /**
53
+ * 检查package.json的依赖大于node_module的版本,则返回true
54
+ * @param {*} subPackages 模块
55
+ * @param {*} cwd 待检查package.json所在的目录 (eg: 当前执行脚本的目录)
56
+ * @param {*} outputDir 待检查node_modules存放的目录 (eg: dist/node_modules)
57
+ * @returns
58
+ */
59
+ const isDependenciesUpdate = (subPackages, cwd, outputDir) => {
60
+ // 步骤1. 收集package.json
61
+ const packageArr = collectPackageJson(subPackages, cwd, outputDir);
41
62
  // 步骤2. 比较package.json的依赖与node_modules依赖的版本号
63
+ return checkPackageVersion(packageArr);
64
+ };
65
+
66
+ // 比较package.json的依赖与node_modules依赖的版本号
67
+ const checkPackageVersion = (packageArr) => {
42
68
  for (const item of packageArr) {
43
- const packageJson = fs.readFileSync(item.srcPackageDir, 'utf-8');
44
- let dependencies = {};
45
- try {
46
- const json = JSON.parse(packageJson);
47
- dependencies = json?.dependencies ? json?.dependencies : {};
48
- } catch (e) {
49
- handleError(`解析${item.srcPackageDir}报错,请检查是否是正确的json配置项 ${e}`);
50
- }
69
+ const dependencies = readPackageDependencies(item.srcPackageDir);
51
70
  const dependenciesKeys = Object.keys(dependencies);
52
71
  for (const key of dependenciesKeys) {
53
72
  const depPath = path.join(item.destNpmDir, key);
@@ -74,4 +93,5 @@ const isDependenciesUpdate = (modules, cwd, outputDir) => {
74
93
 
75
94
  module.exports = {
76
95
  isDependenciesUpdate,
96
+ checkPackageVersion,
77
97
  };
@@ -21,9 +21,7 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
21
21
  const tmsConfig = global.getData('tmsConfig');
22
22
 
23
23
  let gitUrl = httpRepoUrl;
24
- const { username = '', pass = '' } = tmsConfig?.gitAccout?.[moduleName]
25
- || tmsConfig?.gitAccount?.[moduleName]
26
- || {};
24
+ const { username = '', pass = '' } = tmsConfig?.gitAccount?.[moduleName] || {};
27
25
 
28
26
  const urlPrefixReg = /http(s)?:\/\//;
29
27
  if (username && pass && urlPrefixReg.test(gitUrl)) {
@@ -41,6 +39,9 @@ function replaceGitUrlAccount(httpRepoUrl, moduleName) {
41
39
  * @returns { undefined } no return
42
40
  */
43
41
  function moveFile(sourceDir, targetDir, ignore = []) {
42
+ if (fs.existsSync(targetDir)) {
43
+ shelljs.rm('-rf', targetDir);
44
+ }
44
45
  // 删除不是文件夹的文件
45
46
  return new Promise((resolve, reject) => {
46
47
  MetalSmith(__dirname)
@@ -122,10 +123,10 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
122
123
  const downloadTasksMap = new Map();
123
124
  for (const moduleInfo of modules) {
124
125
  if (moduleInfo.repoInfo) {
125
- const { repoInfo: { buildGitTag: branch, httpRepoUrl, path: gitPath = '' }, path, name } = moduleInfo;
126
+ const { repoInfo: { buildGitTag: branch, httpRepoUrl, path: gitPath = '' }, path, moduleName } = moduleInfo;
126
127
 
127
128
  // 处理仓库权限问题
128
- const gitUrl = replaceGitUrlAccount(httpRepoUrl, name);
129
+ const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
129
130
  // 根据gitUrl与branch计算md5
130
131
  const md5Key = md5ByGitUrlBranch(gitUrl, branch);
131
132
  // git源码临时存在的源目录
@@ -191,8 +192,8 @@ function collectDownLoadTasksMap(sourceDir, targetDir, modules) {
191
192
  */
192
193
  function checkRemoteModGitUrlBranch(sourceDir, moduleInfo) {
193
194
  if (moduleInfo.repoInfo) {
194
- const { repoInfo: { buildGitTag, httpRepoUrl }, name } = moduleInfo;
195
- const gitUrl = replaceGitUrlAccount(httpRepoUrl, name);
195
+ const { repoInfo: { buildGitTag, httpRepoUrl }, moduleName } = moduleInfo;
196
+ const gitUrl = replaceGitUrlAccount(httpRepoUrl, moduleName);
196
197
  const md5Key = md5ByGitUrlBranch(gitUrl, buildGitTag);
197
198
  if (!fs.existsSync(`${sourceDir}/${md5Key}`)) {
198
199
  return true;
@@ -1,8 +1,14 @@
1
1
  const { fail } = require('../utils/log');
2
2
  const { global } = require('../utils/global');
3
3
 
4
- function handleError(error) {
4
+ function handleError(error, isQuit = false) {
5
5
  const errMsg = typeof error === 'object' ? error.message : error;
6
+
7
+ if (isQuit) {
8
+ fail(errMsg);
9
+ process.exit(1);
10
+ }
11
+
6
12
  const isDev = global.getData('isDev');
7
13
  if (isDev) {
8
14
  fail(errMsg);
package/src/core/npm.js CHANGED
@@ -6,10 +6,10 @@ const fsExtra = require('fs-extra');
6
6
  const crypto = require('crypto');
7
7
  const path = require('path');
8
8
  const shell = require('shelljs');
9
- const glob = require('glob-ignore');
10
9
  const log = require('../utils/log');
11
10
  const { npmInstall } = require('../utils/widgets');
12
11
  const { handleError } = require('./handleError');
12
+ const { global } = require('../utils/global');
13
13
 
14
14
  const shellJsOption = { async: false, silent: true };
15
15
  const dirPath = process.cwd(); // 项目根目录
@@ -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
  };
@@ -71,7 +76,8 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
71
76
  fsExtra.emptydirSync(cacheNMPath);
72
77
  shell.cp('-f', packageJsonPath, cacheNMPath);
73
78
  log.info(`npm install: ${packageJsonPath}`);
74
- return npmInstall(cacheNMPath).then(() => {
79
+ const tmsConfig = global.getData('tmsConfig');
80
+ return npmInstall(cacheNMPath, tmsConfig.npm).then(() => {
75
81
  const newShellJsOption = {
76
82
  ...shellJsOption,
77
83
  cwd: cacheNMPath,
@@ -99,9 +105,9 @@ const collectNpmTasksMap = (packageJsonFiles, cacheDir) => {
99
105
 
100
106
 
101
107
  // 遍历安装指定目录下所有项目的npm依赖
102
- const npmInstallAll = async (modules, contextDir, cacheDir) => {
108
+ const npmInstallAll = async (subPackages, contextDir, cacheDir) => {
103
109
  const cwd = process.cwd();
104
- const packageJsonFiles = await findAllPackageJson(modules, contextDir);
110
+ const packageJsonFiles = await findAllPackageJson(subPackages, contextDir);
105
111
 
106
112
  // 收集npm install的任务
107
113
  const npmTasksMap = collectNpmTasksMap(packageJsonFiles, cacheDir);
@@ -118,7 +124,7 @@ const npmInstallAll = async (modules, contextDir, cacheDir) => {
118
124
  return Promise.all(callArr);
119
125
  })
120
126
  .catch((e) => {
121
- handleError(`npm install ${params.packageJsonPath}出现错误:${e}`);
127
+ handleError(`npm install ${params.packageJsonPath}出现错误:${e}`, true);
122
128
  }));
123
129
  });
124
130
 
@@ -184,10 +190,6 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
184
190
  const result = [path.join(cwd, packageJsonName)]; // 默认填充根目录下的package.json
185
191
 
186
192
  subRoots.forEach((subRoot) => {
187
- if (!subRoot.root) {
188
- log.fail(`请检查${subRoot.name}的module.config.json是否有root字段`);
189
- process.exit(1);
190
- }
191
193
  const toppath = path.join(cwd, subRoot.root); // 从该目录开始查找package.json文件
192
194
  const list = findFilesByFilter(toppath, packageJsonName);
193
195
 
@@ -197,26 +199,10 @@ const findAllPackageJson = (subRoots = [], contextDir) => {
197
199
  return result;
198
200
  };
199
201
 
200
- function cloudNpmInstall(contextDir) {
201
- return new Promise((resolve, reject) => {
202
- glob(`${contextDir}/**/package.json`, ['node_modules', 'miniprogram_npm'], (err, files) => {
203
- if (err) {
204
- reject(err);
205
- }
206
- files.forEach((file) => {
207
- const dir = path.dirname(file);
208
- shell.cd(dir);
209
- shell.exec('npx npm install --production --registry http://mirrors.tencent.com/npm/', { silent: false });
210
- });
211
- resolve();
212
- });
213
- });
214
- }
215
-
216
202
 
217
203
  module.exports = {
218
- cloudNpmInstall,
219
204
  npmInstallAll,
220
205
  findAllPackageJson,
206
+ findFilesByFilter,
221
207
  };
222
208
 
@@ -0,0 +1,118 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const shelljs = require('shelljs');
4
+ const chalk = require('chalk');
5
+ const request = require('request');
6
+ const inquirer = require('inquirer');
7
+ const { infoNoTime } = require('../utils/log');
8
+ const packageJson = require('../../package.json');
9
+ const { VERSION_CACHE_FILE, VERSION_URL } = require('../config/constant');
10
+ const { ensureDirExist } = require('../utils/io');
11
+ const { versionCompare } = require('../utils/widgets');
12
+
13
+ // 获取推荐的tmskit版本
14
+ function getRecommendVersion() {
15
+ return new Promise((resolve, reject) => {
16
+ request(`${VERSION_URL}?v=${new Date().getTime()}`, (error, response, body) => {
17
+ if (!error && response && response.statusCode === 200) {
18
+ resolve(JSON.parse(body));
19
+ } else {
20
+ reject(response.statusCode);
21
+ }
22
+ });
23
+ });
24
+ }
25
+
26
+ // 获取当前用户tmskit的版本
27
+ function getUserTmskitVersion() {
28
+ const data = shelljs.exec('tmskit -v', { async: false, silent: true });
29
+ if (data.code === 0) {
30
+ // tmskit 0.0.21 => 0.0.21
31
+ return data.slice(7);
32
+ }
33
+ return '0.0.0';
34
+ }
35
+
36
+ // 询问用户是否安装最新版本
37
+ function isInstallLatestVersion() {
38
+ return inquirer.prompt([
39
+ {
40
+ type: 'confirm',
41
+ name: 'isInstall',
42
+ message: '是否安装最新版本',
43
+ choices: [{
44
+ name: '否',
45
+ value: false,
46
+ }, {
47
+ name: '是',
48
+ value: true,
49
+ }],
50
+ },
51
+ ]);
52
+ }
53
+
54
+ // 获取tmskit的版本是否推荐过
55
+ function getVersionIsRecommend(version) {
56
+ const filePath = VERSION_CACHE_FILE;
57
+ if (!fs.existsSync(filePath)) {
58
+ return false;
59
+ }
60
+ const content = require(filePath);
61
+ return content?.[version];
62
+ }
63
+
64
+ // 设置tmskit版本推荐过
65
+ function setVersionRecommend(version, isRecommend) {
66
+ const filePath = VERSION_CACHE_FILE;
67
+ if (!fs.existsSync(filePath)) {
68
+ const dir = path.dirname(filePath);
69
+ ensureDirExist(dir);
70
+ fs.writeFileSync(filePath, '{}');
71
+ }
72
+ const content = require(filePath);
73
+ content[version] = isRecommend;
74
+ fs.writeFileSync(filePath, JSON.stringify(content, null, 2));
75
+ }
76
+
77
+ // 推荐理由
78
+ function displayRecommends(arr = []) {
79
+ infoNoTime(chalk.green('构建工具有新的版本~~:'));
80
+ arr.forEach((item) => {
81
+ infoNoTime(chalk.green(item));
82
+ });
83
+ }
84
+
85
+ // 推荐tmskit的安装版本
86
+ async function recommendVersion() {
87
+ try {
88
+ // 获取当前用户安装的版本
89
+ const tmskitVersion = getUserTmskitVersion();
90
+ // 获取官方推荐版本
91
+ const recommendRes = await getRecommendVersion();
92
+ const recommendVersion = recommendRes.version;
93
+ // 当前用户安装版本小于官方推荐版本 && 该版本没有推荐过
94
+ if (versionCompare(tmskitVersion, recommendVersion) === -1 && !getVersionIsRecommend(recommendVersion)) {
95
+ displayRecommends(recommendRes.version_detail);
96
+ // 设置该版本推荐过
97
+ setVersionRecommend(recommendVersion, true);
98
+ // 询问用户是否安装最新版本
99
+ const installRes = await isInstallLatestVersion(recommendRes);
100
+ if (installRes.isInstall) {
101
+ // mac
102
+ if (process.platform === 'darwin') {
103
+ infoNoTime(`将执行以下命令: ${chalk.green(`sudo npm install -g ${packageJson.name}@${recommendVersion}`)}`);
104
+ shelljs.exec(`sudo npm install -g ${packageJson.name}@${recommendVersion}`, { async: false, silent: false });
105
+ process.exit(-1);
106
+ } else {
107
+ // window
108
+ infoNoTime(`请使用超级管理员执行以下命令: ${chalk.green(`npm install -g ${packageJson.name}@${recommendVersion}`)}`);
109
+ process.exit(-1);
110
+ }
111
+ }
112
+ }
113
+ } catch {}
114
+ }
115
+
116
+ module.exports = {
117
+ recommendVersion,
118
+ };
@@ -0,0 +1,30 @@
1
+ const request = require('request');
2
+ const shelljs = require('shelljs');
3
+ const apiUrl = 'https://tim.map.qq.com/basic/tmskit/upload';
4
+
5
+ function getGitUser() {
6
+ const res = shelljs.exec('git config user.name', { async: false, silent: true });
7
+ return res.stdout;
8
+ }
9
+
10
+ const report = (name, attrs = {}) => {
11
+ try {
12
+ const param = [];
13
+ param[27] = name;
14
+ param[28] = 'tmskit';
15
+ param[29] = getGitUser();
16
+ param[30] = JSON.stringify(attrs);
17
+
18
+ for (let i = 0; i < 40; i++) {
19
+ if (!param[i]) param[i] = null;
20
+ };
21
+
22
+ request.post({ url: apiUrl, json: { param } });
23
+ // (error, response, body) => {
24
+ // console.log('body:', body);
25
+ // }
26
+ } catch (e) {
27
+ }
28
+ };
29
+
30
+ module.exports = report;
@@ -1,32 +1,30 @@
1
1
  const fs = require('fs');
2
2
  const { resolve } = require('../utils/widgets');
3
- const { handleError } = require('./handleError');
4
3
  const { ensureDirExist } = require('../utils/io');
5
- const { warn } = require('../utils/log');
4
+ const { warn, succeed } = require('../utils/log');
6
5
 
7
6
  /**
8
7
  * 根据相关配置创建软链接
9
8
  * @param { object } tmsConfig
10
9
  */
11
10
  const symLink = (tmsConfig) => {
12
- try {
13
- ensureDirExist(resolve(tmsConfig.cloudDir));
14
- if (tmsConfig.cloudModules) {
15
- tmsConfig.cloudModules.forEach((item) => {
16
- const sourcePath = resolve(item.path);
17
- const targetPath = resolve(tmsConfig.cloudDir, item.name);
11
+ ensureDirExist(resolve(tmsConfig.cloudDir));
12
+ if (tmsConfig.cloudModules) {
13
+ tmsConfig.cloudModules.forEach((item) => {
14
+ const sourcePath = resolve(item.path);
15
+ const targetPath = resolve(tmsConfig.cloudDir, item.name);
18
16
 
19
- if (!fs.existsSync(sourcePath)) {
20
- warn(`云函数${sourcePath}不存在`);
21
- return;
22
- }
23
- if (!fs.existsSync(targetPath)) {
24
- fs.symlinkSync(sourcePath, targetPath);
25
- }
26
- });
27
- }
28
- } catch (e) {
29
- handleError(`创建软链错误: ${e}`);
17
+ if (!fs.existsSync(sourcePath)) {
18
+ warn(`云函数${sourcePath}不存在`);
19
+ return;
20
+ }
21
+ if (!fs.existsSync(targetPath)) {
22
+ fs.symlinkSync(sourcePath, targetPath);
23
+ }
24
+ });
25
+ succeed('云函数创建软链成功');
26
+ } else {
27
+ warn('你没有在tms.config.js的cloudModules注册云函数');
30
28
  }
31
29
  };
32
30