tt-minigame-ide-cli 0.0.1-beta.4 → 1.0.1-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 +14 -31
- package/README.md +14 -32
- package/bin/tmg.js +13 -51
- package/lib/upload.js +13 -1
- package/lib/util/request.js +35 -3
- package/lib/version.js +44 -0
- package/package.json +8 -2
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.
|
@@ -96,7 +68,7 @@ Options:
|
|
96
68
|
-f, --force Preview project without local cache(deprecated)
|
97
69
|
--disable-cache Preview project without local cache
|
98
70
|
-s, --small Use small QR Code, but it does not take effect in some environments
|
99
|
-
-
|
71
|
+
-u, --copy Copy remote url to clipboard
|
100
72
|
-p, --proxy <proxy> Preview with proxy
|
101
73
|
-h, --help output usage information
|
102
74
|
-o, --output <path> QRCode image output path
|
@@ -115,7 +87,18 @@ Options:
|
|
115
87
|
-v, --app-version <version> App version (eg: [major].[minor].[patch])
|
116
88
|
-c, --app-changelog <log> Changelog for this version
|
117
89
|
-p, --proxy <proxy> Update request proxy
|
118
|
-
-
|
90
|
+
-u, --copy Copy remote url to clipboard
|
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%
|
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
|
登录到开发者平台。支持代理设置。
|
@@ -97,7 +69,7 @@ Options:
|
|
97
69
|
-f, --force Preview project without local cache(deprecated)
|
98
70
|
--disable-cache Preview project without local cache
|
99
71
|
-s, --small Use small QR Code, but it does not take effect in some environments
|
100
|
-
-
|
72
|
+
-u, --copy Copy remote url to clipboard
|
101
73
|
-p, --proxy <proxy> Preview with proxy
|
102
74
|
-h, --help output usage information
|
103
75
|
-o, --output <path> QRCode image output path
|
@@ -116,7 +88,17 @@ Options:
|
|
116
88
|
-v, --app-version <version> App version (eg: [major].[minor].[patch])
|
117
89
|
-c, --app-changelog <log> Changelog for this version
|
118
90
|
-p, --proxy <proxy> Update request proxy
|
119
|
-
-
|
91
|
+
-u, --copy Copy remote url to clipboard
|
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
|
@@ -103,7 +54,7 @@ program
|
|
103
54
|
.option('-f, --force', 'Preview project without local cache(deprecated)')
|
104
55
|
.option('--disable-cache', 'Preview project without local cache')
|
105
56
|
.option('-s, --small', 'Use small QR Code, it may fail in some environments')
|
106
|
-
.option('-
|
57
|
+
.option('-u, --copy', 'Copy remote url to clipboard')
|
107
58
|
.option('-p, --proxy <proxy>', 'Preview with proxy')
|
108
59
|
.option('-o, --output <path>', 'QRCode image output path')
|
109
60
|
.action((entry, cmd) => {
|
@@ -139,7 +90,7 @@ program
|
|
139
90
|
)
|
140
91
|
.requiredOption('-c, --app-changelog <log>', 'Changelog for this version')
|
141
92
|
.option('-p, --proxy <proxy>', 'Update request proxy')
|
142
|
-
.option('-
|
93
|
+
.option('-u, --copy', 'Copy remote url to clipboard')
|
143
94
|
.option('-o, --output <path>', 'QRCode image output path')
|
144
95
|
.action((entry, cmd) => {
|
145
96
|
const options = cleanArgs(cmd);
|
@@ -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/upload.js
CHANGED
@@ -17,7 +17,8 @@ const {
|
|
17
17
|
uploadProject,
|
18
18
|
getCompileProgress,
|
19
19
|
checkUserPermissions,
|
20
|
-
getQrCode
|
20
|
+
getQrCode,
|
21
|
+
checkUploadVersion,
|
21
22
|
} = require('./util/request');
|
22
23
|
const {
|
23
24
|
generateQrCode
|
@@ -50,6 +51,17 @@ async function upload(entry, options) {
|
|
50
51
|
console.log(chalk.red(errMsg));
|
51
52
|
throw new Error(errMsg);
|
52
53
|
}
|
54
|
+
|
55
|
+
const {
|
56
|
+
success: checkVersionSuccess,
|
57
|
+
msg: checkVersionMsg,
|
58
|
+
} = await checkUploadVersion(appId, options.appVersion);
|
59
|
+
if (!checkVersionSuccess) {
|
60
|
+
const errMsg = `[CLI UPLOAD ERROR]: ${checkVersionMsg}`;
|
61
|
+
console.log(chalk.red(errMsg));
|
62
|
+
throw new Error(errMsg);
|
63
|
+
}
|
64
|
+
|
53
65
|
const tempDir = options.tempDir || path.join(__dirname, '../temp');
|
54
66
|
await fs.emptyDir(tempDir);
|
55
67
|
|
package/lib/util/request.js
CHANGED
@@ -4,6 +4,7 @@ const querystring = require('querystring');
|
|
4
4
|
const url = require('url');
|
5
5
|
const fs = require('fs');
|
6
6
|
const execa = require('execa');
|
7
|
+
const compareVersions = require('compare-versions');
|
7
8
|
const {
|
8
9
|
getUserCookies
|
9
10
|
} = require('./cookie');
|
@@ -32,8 +33,8 @@ axios.interceptors.request.use(config => {
|
|
32
33
|
config.headers.Referer = REFERER;
|
33
34
|
if (config.data instanceof FormData) {
|
34
35
|
Object.assign(config.headers, config.data.getHeaders());
|
35
|
-
|
36
|
-
if(config.proxy) {
|
36
|
+
}
|
37
|
+
if (config.proxy) {
|
37
38
|
const parseURL = URL.parse(config.proxy.host);
|
38
39
|
config.httpsAgent = require('tunnel').httpsOverHttp({
|
39
40
|
proxy: {
|
@@ -340,6 +341,7 @@ exports.checkUserPermissions = function (appId, proxy) {
|
|
340
341
|
}
|
341
342
|
});
|
342
343
|
}
|
344
|
+
|
343
345
|
// 该方法暂无调用
|
344
346
|
exports.checkRemoteVersion = async function () {
|
345
347
|
const registry = (await execa('npm', ['config', 'get', 'registry'])).stdout;
|
@@ -359,4 +361,34 @@ exports.checkRemoteVersion = async function () {
|
|
359
361
|
msg: err.message
|
360
362
|
}
|
361
363
|
});
|
362
|
-
}
|
364
|
+
}
|
365
|
+
|
366
|
+
// 获取远程版本号
|
367
|
+
exports.checkUploadVersion = async function (appId, version) {
|
368
|
+
try {
|
369
|
+
const current = await getProjectReleaseVersion(appId);
|
370
|
+
if (compareVersions(version, current) > 0) {
|
371
|
+
return {
|
372
|
+
current,
|
373
|
+
success: true,
|
374
|
+
}
|
375
|
+
} else {
|
376
|
+
return {
|
377
|
+
current,
|
378
|
+
success: false,
|
379
|
+
msg: `The version you uploaded must be greater than ${current}.`,
|
380
|
+
}
|
381
|
+
}
|
382
|
+
} catch (err) {
|
383
|
+
return {
|
384
|
+
success: false,
|
385
|
+
msg: err.message
|
386
|
+
}
|
387
|
+
}
|
388
|
+
}
|
389
|
+
|
390
|
+
const getProjectReleaseVersion = async function (appId) {
|
391
|
+
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()}`)
|
392
|
+
return res.data.data.version;
|
393
|
+
}
|
394
|
+
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": "
|
3
|
+
"version": "1.0.1-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": {
|
@@ -17,6 +19,7 @@
|
|
17
19
|
"chalk": "^3.0.0",
|
18
20
|
"clipboardy": "^2.2.0",
|
19
21
|
"commander": "^4.1.1",
|
22
|
+
"compare-versions": "^4.1.3",
|
20
23
|
"execa": "^4.0.0",
|
21
24
|
"folder-hash": "^3.3.0",
|
22
25
|
"form-data": "^3.0.0",
|
@@ -31,5 +34,8 @@
|
|
31
34
|
},
|
32
35
|
"engines": {
|
33
36
|
"node": ">=8.9"
|
37
|
+
},
|
38
|
+
"devDependencies": {
|
39
|
+
"doctoc": "^2.2.0"
|
34
40
|
}
|
35
41
|
}
|