tt-minigame-ide-cli 1.0.0 → 1.0.2-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.
package/README.en.md CHANGED
@@ -9,12 +9,11 @@
9
9
 
10
10
  - [Installation](#installation)
11
11
  - [Usage](#usage)
12
- <!-- - [Create Project](#create-project)
13
- - [Open existing project](#open-existing-project) -->
14
12
  - [Login](#login)
15
13
  - [Login by email](#login-by-email)
16
14
  - [Preview project](#preview-project)
17
15
  - [Upload project](#upload-project)
16
+ - [Get project version](#get-project-version)
18
17
 
19
18
  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
20
19
 
@@ -28,33 +27,6 @@ npm install -g tt-minigame-ide-cli
28
27
 
29
28
  ## Usage
30
29
 
31
- <!-- ### Create Project
32
-
33
- Create a new blank miniprogram project with given name in current folder.
34
-
35
- ```
36
- Usage: tmg create <project-name>
37
-
38
- Create a new project with given name in current folder
39
-
40
- Options:
41
-
42
- -f, --force Overwrite target directory if it exists
43
- -h, --help Output usage information
44
- ``` -->
45
-
46
- <!-- ### Open existing project
47
-
48
- Open existing project with given path in microapp IDE.
49
-
50
- If the path is not available, start up the IDE only.
51
-
52
- ```
53
- Usage: tmg open <project-path>
54
-
55
- Open target project by path
56
- ``` -->
57
-
58
30
  ### Login
59
31
 
60
32
  Login to the developer Platform. Proxy is supported.
@@ -119,3 +91,14 @@ Options:
119
91
  -h, --help output usage information
120
92
  -o, --output <path> QRCode image output path
121
93
  ```
94
+
95
+ ### Get project version
96
+
97
+ Get latest released version of project.
98
+
99
+ ```
100
+ Usage: tmg version [entry]
101
+
102
+ Get latest released version of project
103
+ ```
104
+
package/README.md CHANGED
@@ -9,12 +9,11 @@
9
9
 
10
10
  - [安装](#%E5%AE%89%E8%A3%85)
11
11
  - [使用](#%E4%BD%BF%E7%94%A8)
12
- <!-- - [创建新项目](#%E5%88%9B%E5%BB%BA%E6%96%B0%E9%A1%B9%E7%9B%AE)
13
- - [打开已有项目](#%E6%89%93%E5%BC%80%E5%B7%B2%E6%9C%89%E9%A1%B9%E7%9B%AE) -->
14
12
  - [登录](#%E7%99%BB%E5%BD%95)
15
13
  - [通过 email 登录](#%E9%80%9A%E8%BF%87-email-%E7%99%BB%E5%BD%95)
16
- - [预览小游戏](#%E9%A2%84%E8%A7%88%E5%B0%8F%E7%A8%8B%E5%BA%8F)
14
+ - [预览小游戏](#%E9%A2%84%E8%A7%88%E5%B0%8F%E6%B8%B8%E6%88%8F)
17
15
  - [上传项目](#%E4%B8%8A%E4%BC%A0%E9%A1%B9%E7%9B%AE)
16
+ - [获取项目版本](#%E8%8E%B7%E5%8F%96%E9%A1%B9%E7%9B%AE%E7%89%88%E6%9C%AC)
18
17
 
19
18
  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
20
19
 
@@ -28,33 +27,6 @@ npm install -g tt-minigame-ide-cli
28
27
 
29
28
  ## 使用
30
29
 
31
- <!-- ### 创建新项目
32
-
33
- 在当前目录下,以给定的项目名字创建一个空白的小程序项目。
34
-
35
- ```
36
- Usage: tmg create <project-name>
37
-
38
- Create a new project with given name in current folder
39
-
40
- Options:
41
-
42
- -f, --force Overwrite target directory if it exists
43
- -h, --help Output usage information
44
- ``` -->
45
-
46
- <!-- ### 打开已有项目
47
-
48
- 在小程序开发者工具中打开给定目录的项目。
49
-
50
- 如果给定的目录不存在,则仅打开开发者工具。
51
-
52
- ```
53
- Usage: tmg open <project-path>
54
-
55
- Open target project by path
56
- ``` -->
57
-
58
30
  ### 登录
59
31
 
60
32
  登录到开发者平台。支持代理设置。
@@ -120,3 +92,13 @@ Options:
120
92
  -h, --help output usage information
121
93
  -o, --output <path> QRCode image output path
122
94
  ```
95
+
96
+ ### 获取项目版本
97
+
98
+ 获取项目线上版本号。
99
+
100
+ ```
101
+ Usage: tmg version [entry]
102
+
103
+ Get latest released version of project
104
+ ```
package/bin/tmg.js CHANGED
@@ -13,55 +13,6 @@ checkNodeVersion(requiredVersion);
13
13
  // Get version
14
14
  program.version(getVersion(), '-V, --version', 'Output the current version');
15
15
 
16
- //#region open project
17
-
18
- // program
19
- // .command('open <project-path>')
20
- // .description('Open target project by path')
21
- // .action((projectPath) => {
22
- // const isMac = process.platform === 'darwin',
23
- // IDE_SCHEMA = 'bytedanceide:';
24
- // const openCmd = isMac ? `open ${IDE_SCHEMA}` : `explorer ${IDE_SCHEMA}`;
25
- // let openPath;
26
- // if (!path.isAbsolute(projectPath)) {
27
- // projectPath = path.join(process.cwd(), projectPath);
28
- // }
29
- // if (fs.existsSync(projectPath)) {
30
- // // open project with existing path
31
- // console.log(chalk.green(`open projectPath: ${projectPath}`));
32
- // openPath = `${openCmd}?path=${projectPath}`;
33
- // } else {
34
- // // project folder not exist,
35
- // // open IDE
36
- // console.log(chalk.green(`open IDE`));
37
- // openPath = openCmd;
38
- // }
39
-
40
- // cp.exec(openPath, (error) => {
41
- // if (!error) {
42
- // console.log('打开IDE成功');
43
- // } else {
44
- // console.log(chalk.red('打开IDE失败', error));
45
- // }
46
- // });
47
- // });
48
-
49
- //#endregion
50
-
51
- //#region create new project
52
-
53
- // program
54
- // .command('create <project-name>')
55
- // .description('Create a new project with given name in current folder')
56
- // .option('-f, --force', 'Overwrite target directory if it exists')
57
- // .action((name, cmd) => {
58
- // const options = cleanArgs(cmd);
59
- // checkArgNum(1);
60
- // require('../lib/create')(name, options);
61
- // });
62
-
63
- //#endregion
64
-
65
16
  //#region Login by mobile or email
66
17
 
67
18
  program
@@ -150,6 +101,17 @@ program
150
101
 
151
102
  //#endregion
152
103
 
104
+ //#region version
105
+ program
106
+ .command('version [entry]')
107
+ .description('Get latest released version of project')
108
+ .action((entry, cmd) => {
109
+ const options = cleanArgs(cmd);
110
+ checkArgNum(1);
111
+ require('../lib/version')(entry, options);
112
+ });
113
+ //#endregion
114
+
153
115
  program.parse(process.argv);
154
116
 
155
117
  //#region helpers
package/lib/preview.js CHANGED
@@ -28,7 +28,7 @@ async function preview(entry, options) {
28
28
  }
29
29
  }
30
30
 
31
- const { success, msg, appId } = await checkBeforeUpload(entry);
31
+ const { success, msg, appId, appConfig, } = await checkBeforeUpload(entry);
32
32
  if (!success) {
33
33
  const errMsg = `[CLI PREVIEW ERROR]: ${msg}`;
34
34
  console.log(chalk.red(errMsg));
@@ -45,7 +45,13 @@ async function preview(entry, options) {
45
45
  throw new Error(errMsg);
46
46
  return;
47
47
  }
48
- await uploadProject({ type: 'preview', appId, zipPath: filePath, proxy: options.proxy });
48
+ await uploadProject({
49
+ type: 'preview',
50
+ appId,
51
+ zipPath: filePath,
52
+ proxy: options.proxy,
53
+ appConfig,
54
+ });
49
55
 
50
56
  outputResult('info', 'WAIT', 'Compiling...\n');
51
57
  return await new Promise((resolve, reject) => {
package/lib/upload.js CHANGED
@@ -44,7 +44,8 @@ async function upload(entry, options) {
44
44
  const {
45
45
  success: beforeSuccess,
46
46
  msg: beforeMsg,
47
- appId
47
+ appId,
48
+ appConfig,
48
49
  } = await checkBeforeUpload(entry);
49
50
  if (!beforeSuccess) {
50
51
  const errMsg = `[CLI UPLOAD ERROR]: ${beforeMsg}`;
@@ -88,6 +89,7 @@ async function upload(entry, options) {
88
89
  versionInfo: options.appVersion,
89
90
  updateInfo: options.appChangelog,
90
91
  proxy: options.proxy,
92
+ appConfig,
91
93
  });
92
94
 
93
95
  outputResult('info', 'WAIT', 'Compiling...\n');
package/lib/util/check.js CHANGED
@@ -50,7 +50,7 @@ async function checkBeforeUpload(entry) {
50
50
  )} command`,
51
51
  };
52
52
  }
53
- return { success: true, appId };
53
+ return { success: true, appId, appConfig };
54
54
  }
55
55
  // 该方法暂无调用
56
56
  async function checkNeedUpdate() {
@@ -168,7 +168,8 @@ exports.uploadProject = function ({
168
168
  zipPath,
169
169
  versionInfo,
170
170
  updateInfo,
171
- proxy
171
+ proxy,
172
+ appConfig
172
173
  }) {
173
174
  return new Promise(function (resolve, reject) {
174
175
  let path;
@@ -185,6 +186,8 @@ exports.uploadProject = function ({
185
186
  // form.append('render_type', 3);
186
187
  form.append('source', fs.createReadStream(zipPath));
187
188
  form.append('local_compile_version', '4.0.0-rc.12.ide');
189
+ const hasSubPackages = (appConfig.subPackages || appConfig.subpackages || []).length > 0;
190
+ form.append('subpackage', hasSubPackages.toString());
188
191
  const uploadOptions = {
189
192
  method: 'put',
190
193
  headers: {
@@ -366,16 +369,17 @@ exports.checkRemoteVersion = async function () {
366
369
  // 获取远程版本号
367
370
  exports.checkUploadVersion = async function (appId, version) {
368
371
  try {
369
- const res = await axios.get(`/api/apps/v3/meta?appid=${appId}&aid=13&version=current&ttcode=OVCNW/U0UREwv0sHdY9Rm16vBgGrCQIBOWurUCmJ1H6d/2XHLKeOYTYfEJIEeC0AOCwBZAR2j34C4tFN7Nqfq9tHVEpM4OuJM2b8qz0INtUs1qLhKFOtnGa9/Ey0WW86GGocJk074eP72MMhzNmePzaTQzXwn/eqEq4GHwyF2Tg=&t=${new Date().getTime()}`)
370
- const current = res.data.data.version;
372
+ const current = await getProjectReleaseVersion(appId);
371
373
  if (compareVersions(version, current) > 0) {
372
374
  return {
375
+ current,
373
376
  success: true,
374
377
  }
375
378
  } else {
376
379
  return {
380
+ current,
377
381
  success: false,
378
- msg: `The version you uploaded must be greater than the current version ${current}.`,
382
+ msg: `The version you uploaded must be greater than ${current}.`,
379
383
  }
380
384
  }
381
385
  } catch (err) {
@@ -384,4 +388,10 @@ exports.checkUploadVersion = async function (appId, version) {
384
388
  msg: err.message
385
389
  }
386
390
  }
387
- }
391
+ }
392
+
393
+ const getProjectReleaseVersion = async function (appId) {
394
+ const res = await axios.get(`/api/apps/v3/meta?appid=${appId}&aid=13&version=current&ttcode=OVCNW/U0UREwv0sHdY9Rm16vBgGrCQIBOWurUCmJ1H6d/2XHLKeOYTYfEJIEeC0AOCwBZAR2j34C4tFN7Nqfq9tHVEpM4OuJM2b8qz0INtUs1qLhKFOtnGa9/Ey0WW86GGocJk074eP72MMhzNmePzaTQzXwn/eqEq4GHwyF2Tg=&t=${new Date().getTime()}`)
395
+ return res.data.data.version;
396
+ }
397
+ exports.getProjectReleaseVersion = getProjectReleaseVersion;
package/lib/version.js ADDED
@@ -0,0 +1,44 @@
1
+ // Get project version
2
+ const path = require('path');
3
+ const chalk = require('chalk');
4
+ const {
5
+ checkBeforeUpload,
6
+ isValidAppVersion,
7
+ } = require('./util/check');
8
+ const {
9
+ getProjectReleaseVersion
10
+ } = require('./util/request');
11
+
12
+ async function version(entry, options) {
13
+ const cwd = options.cwd || process.cwd();
14
+ if (!entry) {
15
+ entry = cwd
16
+ } else if (path.isAbsolute(entry)) {
17
+ // skip if entry if absolute path
18
+ } else {
19
+ // resolve the relative entry with cwd
20
+ entry = path.resolve(cwd, entry);
21
+ }
22
+
23
+ const {
24
+ success: beforeSuccess,
25
+ msg: beforeMsg,
26
+ appId
27
+ } = await checkBeforeUpload(entry);
28
+ if (!beforeSuccess) {
29
+ const errMsg = `[CLI VERSION ERROR]: ${beforeMsg}`;
30
+ console.log(chalk.red(errMsg));
31
+ throw new Error(errMsg);
32
+ }
33
+
34
+ const version = await getProjectReleaseVersion(appId);
35
+ console.log(version);
36
+ }
37
+
38
+ module.exports = (...args) => {
39
+ return version(...args).catch(err => {
40
+ const errMsg = `[CLI VERSION ERROR]: ${err}`;
41
+ console.log(chalk.red(errMsg));
42
+ throw new Error(errMsg);
43
+ });
44
+ }
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "tt-minigame-ide-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.2-beta.0",
4
4
  "description": "Command line interface for micro app development",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
7
7
  "tmg": "bin/tmg.js"
8
8
  },
9
- "scripts": {},
9
+ "scripts": {
10
+ "doctoc": "doctoc README.md README.en.md"
11
+ },
10
12
  "author": "liubowen.howard@bytedance.com",
11
13
  "license": "ISC",
12
14
  "dependencies": {
@@ -32,5 +34,8 @@
32
34
  },
33
35
  "engines": {
34
36
  "node": ">=8.9"
37
+ },
38
+ "devDependencies": {
39
+ "doctoc": "^2.2.0"
35
40
  }
36
41
  }