tt-minigame-ide-cli 0.0.1-beta.2 → 0.0.1-beta.5
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 +12 -10
- package/README.md +15 -13
- package/bin/tmg.js +41 -41
- package/lib/upload.js +13 -1
- package/lib/util/helper.js +8 -10
- package/lib/util/request.js +27 -2
- package/package.json +2 -1
- package/template/app.js +0 -5
- package/template/app.json +0 -11
- package/template/app.ttss +0 -0
- package/template/pages/index/index.js +0 -10
- package/template/pages/index/index.ttml +0 -1
- package/template/pages/index/index.ttss +0 -4
package/README.en.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# tmg-cli
|
2
2
|
|
3
|
-
> `tmg` cli is the official tool for bytedance
|
3
|
+
> `tmg` cli is the official tool for bytedance minigame development.
|
4
4
|
|
5
5
|
[中文](./README.md)
|
6
6
|
|
@@ -9,8 +9,8 @@
|
|
9
9
|
|
10
10
|
- [Installation](#installation)
|
11
11
|
- [Usage](#usage)
|
12
|
-
- [Create Project](#create-project)
|
13
|
-
- [Open existing project](#open-existing-project)
|
12
|
+
<!-- - [Create Project](#create-project)
|
13
|
+
- [Open existing project](#open-existing-project) -->
|
14
14
|
- [Login](#login)
|
15
15
|
- [Login by email](#login-by-email)
|
16
16
|
- [Preview project](#preview-project)
|
@@ -23,12 +23,12 @@
|
|
23
23
|
It's recommended to install `tmg` globally.
|
24
24
|
|
25
25
|
```
|
26
|
-
npm install -g tt-ide-cli
|
26
|
+
npm install -g tt-minigame-ide-cli
|
27
27
|
```
|
28
28
|
|
29
29
|
## Usage
|
30
30
|
|
31
|
-
### Create Project
|
31
|
+
<!-- ### Create Project
|
32
32
|
|
33
33
|
Create a new blank miniprogram project with given name in current folder.
|
34
34
|
|
@@ -41,9 +41,9 @@ Options:
|
|
41
41
|
|
42
42
|
-f, --force Overwrite target directory if it exists
|
43
43
|
-h, --help Output usage information
|
44
|
-
```
|
44
|
+
``` -->
|
45
45
|
|
46
|
-
### Open existing project
|
46
|
+
<!-- ### Open existing project
|
47
47
|
|
48
48
|
Open existing project with given path in microapp IDE.
|
49
49
|
|
@@ -53,7 +53,7 @@ If the path is not available, start up the IDE only.
|
|
53
53
|
Usage: tmg open <project-path>
|
54
54
|
|
55
55
|
Open target project by path
|
56
|
-
```
|
56
|
+
``` -->
|
57
57
|
|
58
58
|
### Login
|
59
59
|
|
@@ -96,9 +96,10 @@ Options:
|
|
96
96
|
-f, --force Preview project without local cache(deprecated)
|
97
97
|
--disable-cache Preview project without local cache
|
98
98
|
-s, --small Use small QR Code, but it does not take effect in some environments
|
99
|
-
-
|
99
|
+
-u, --copy Copy remote url to clipboard
|
100
100
|
-p, --proxy <proxy> Preview with proxy
|
101
101
|
-h, --help output usage information
|
102
|
+
-o, --output <path> QRCode image output path
|
102
103
|
```
|
103
104
|
|
104
105
|
### Upload project
|
@@ -114,6 +115,7 @@ Options:
|
|
114
115
|
-v, --app-version <version> App version (eg: [major].[minor].[patch])
|
115
116
|
-c, --app-changelog <log> Changelog for this version
|
116
117
|
-p, --proxy <proxy> Update request proxy
|
117
|
-
-
|
118
|
+
-u, --copy Copy remote url to clipboard
|
118
119
|
-h, --help output usage information
|
120
|
+
-o, --output <path> QRCode image output path
|
119
121
|
```
|
package/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# tmg-cli
|
2
2
|
|
3
|
-
> `tmg`
|
3
|
+
> `tmg` 是字节跳动小小游戏官方提供的命令行工具。
|
4
4
|
|
5
5
|
[English](./README.en.md)
|
6
6
|
|
@@ -9,11 +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)
|
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
14
|
- [登录](#%E7%99%BB%E5%BD%95)
|
15
15
|
- [通过 email 登录](#%E9%80%9A%E8%BF%87-email-%E7%99%BB%E5%BD%95)
|
16
|
-
- [
|
16
|
+
- [预览小游戏](#%E9%A2%84%E8%A7%88%E5%B0%8F%E7%A8%8B%E5%BA%8F)
|
17
17
|
- [上传项目](#%E4%B8%8A%E4%BC%A0%E9%A1%B9%E7%9B%AE)
|
18
18
|
|
19
19
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
@@ -23,12 +23,12 @@
|
|
23
23
|
建议在全局安装 `tmg` 。
|
24
24
|
|
25
25
|
```
|
26
|
-
npm install -g tt-ide-cli
|
26
|
+
npm install -g tt-minigame-ide-cli
|
27
27
|
```
|
28
28
|
|
29
29
|
## 使用
|
30
30
|
|
31
|
-
### 创建新项目
|
31
|
+
<!-- ### 创建新项目
|
32
32
|
|
33
33
|
在当前目录下,以给定的项目名字创建一个空白的小程序项目。
|
34
34
|
|
@@ -41,9 +41,9 @@ Options:
|
|
41
41
|
|
42
42
|
-f, --force Overwrite target directory if it exists
|
43
43
|
-h, --help Output usage information
|
44
|
-
```
|
44
|
+
``` -->
|
45
45
|
|
46
|
-
### 打开已有项目
|
46
|
+
<!-- ### 打开已有项目
|
47
47
|
|
48
48
|
在小程序开发者工具中打开给定目录的项目。
|
49
49
|
|
@@ -53,7 +53,7 @@ Options:
|
|
53
53
|
Usage: tmg open <project-path>
|
54
54
|
|
55
55
|
Open target project by path
|
56
|
-
```
|
56
|
+
``` -->
|
57
57
|
|
58
58
|
### 登录
|
59
59
|
|
@@ -84,9 +84,9 @@ Options:
|
|
84
84
|
|
85
85
|
```
|
86
86
|
|
87
|
-
###
|
87
|
+
### 预览小游戏
|
88
88
|
|
89
|
-
|
89
|
+
将项目上传后,扫码二维码来预览小游戏。
|
90
90
|
|
91
91
|
```
|
92
92
|
Usage: tmg preview [options] [entry]
|
@@ -97,9 +97,10 @@ Options:
|
|
97
97
|
-f, --force Preview project without local cache(deprecated)
|
98
98
|
--disable-cache Preview project without local cache
|
99
99
|
-s, --small Use small QR Code, but it does not take effect in some environments
|
100
|
-
-
|
100
|
+
-u, --copy Copy remote url to clipboard
|
101
101
|
-p, --proxy <proxy> Preview with proxy
|
102
102
|
-h, --help output usage information
|
103
|
+
-o, --output <path> QRCode image output path
|
103
104
|
```
|
104
105
|
|
105
106
|
### 上传项目
|
@@ -115,6 +116,7 @@ Options:
|
|
115
116
|
-v, --app-version <version> App version (eg: [major].[minor].[patch])
|
116
117
|
-c, --app-changelog <log> Changelog for this version
|
117
118
|
-p, --proxy <proxy> Update request proxy
|
118
|
-
-
|
119
|
+
-u, --copy Copy remote url to clipboard
|
119
120
|
-h, --help output usage information
|
121
|
+
-o, --output <path> QRCode image output path
|
120
122
|
```
|
package/bin/tmg.js
CHANGED
@@ -15,50 +15,50 @@ program.version(getVersion(), '-V, --version', 'Output the current version');
|
|
15
15
|
|
16
16
|
//#region open project
|
17
17
|
|
18
|
-
program
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
48
|
|
49
49
|
//#endregion
|
50
50
|
|
51
51
|
//#region create new project
|
52
52
|
|
53
|
-
program
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
62
|
|
63
63
|
//#endregion
|
64
64
|
|
@@ -103,7 +103,7 @@ program
|
|
103
103
|
.option('-f, --force', 'Preview project without local cache(deprecated)')
|
104
104
|
.option('--disable-cache', 'Preview project without local cache')
|
105
105
|
.option('-s, --small', 'Use small QR Code, it may fail in some environments')
|
106
|
-
.option('-
|
106
|
+
.option('-u, --copy', 'Copy remote url to clipboard')
|
107
107
|
.option('-p, --proxy <proxy>', 'Preview with proxy')
|
108
108
|
.option('-o, --output <path>', 'QRCode image output path')
|
109
109
|
.action((entry, cmd) => {
|
@@ -139,7 +139,7 @@ program
|
|
139
139
|
)
|
140
140
|
.requiredOption('-c, --app-changelog <log>', 'Changelog for this version')
|
141
141
|
.option('-p, --proxy <proxy>', 'Update request proxy')
|
142
|
-
.option('-
|
142
|
+
.option('-u, --copy', 'Copy remote url to clipboard')
|
143
143
|
.option('-o, --output <path>', 'QRCode image output path')
|
144
144
|
.action((entry, cmd) => {
|
145
145
|
const options = cleanArgs(cmd);
|
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/helper.js
CHANGED
@@ -24,21 +24,19 @@ function mixEncode(data) {
|
|
24
24
|
}
|
25
25
|
|
26
26
|
async function zipFile(sourcePath, targetPath) {
|
27
|
-
const
|
28
|
-
const isMiniProgram = await fs.pathExists(appJsonPath);
|
29
|
-
const subpackageInfoPath = path.join(sourcePath, `${isMiniProgram ? 'app.json' : 'game.json'}`);
|
27
|
+
const subpackageInfoPath = path.join(sourcePath, 'game.json');
|
30
28
|
const projectConfigJson = fs.readJSONSync(subpackageInfoPath);
|
31
29
|
const subPackagesArr = projectConfigJson.subPackages || projectConfigJson.subpackages;
|
32
30
|
const zipFileRet = {
|
33
31
|
filePath: null,
|
34
32
|
};
|
35
33
|
if (subPackagesArr && subPackagesArr.length > 0) {
|
36
|
-
const ifSubPackageUploadable = await verifySubPackageSize(projectConfigJson,
|
34
|
+
const ifSubPackageUploadable = await verifySubPackageSize(projectConfigJson, sourcePath);
|
37
35
|
if (ifSubPackageUploadable) {
|
38
|
-
zipFileRet.filePath = await normalZipFile(sourcePath, targetPath,
|
36
|
+
zipFileRet.filePath = await normalZipFile(sourcePath, targetPath, true);
|
39
37
|
}
|
40
38
|
} else {
|
41
|
-
zipFileRet.filePath = await normalZipFile(sourcePath, targetPath,
|
39
|
+
zipFileRet.filePath = await normalZipFile(sourcePath, targetPath, false);
|
42
40
|
}
|
43
41
|
return zipFileRet;
|
44
42
|
}
|
@@ -46,7 +44,7 @@ async function zipFile(sourcePath, targetPath) {
|
|
46
44
|
/**
|
47
45
|
* @description 校验分包大小, 小游戏和小程序的不同在于子包不同
|
48
46
|
*/
|
49
|
-
async function verifySubPackageSize(projectConfigJson,
|
47
|
+
async function verifySubPackageSize(projectConfigJson, sourcePath) {
|
50
48
|
let subPackageTotalSize = 0; // 子包+主包
|
51
49
|
// 做大小比较全拿字节数,精确
|
52
50
|
const packageSizeConfig = {
|
@@ -56,7 +54,7 @@ async function verifySubPackageSize(projectConfigJson, isMiniProgram, sourcePath
|
|
56
54
|
};
|
57
55
|
// console.log('校验', projectConfigJson, packageSizeConfig);
|
58
56
|
// 开放数据域文件校验,可以认为开放数据域也作为一个子包
|
59
|
-
if (
|
57
|
+
if (projectConfigJson.openDataContext) {
|
60
58
|
const openDataContextPath = path.join(sourcePath, projectConfigJson.openDataContext);
|
61
59
|
const openDataContextSize = await getFolderSize(openDataContextPath);
|
62
60
|
if (openDataContextSize > packageSizeConfig.subPackageSize) {
|
@@ -111,9 +109,9 @@ async function verifySubPackageSize(projectConfigJson, isMiniProgram, sourcePath
|
|
111
109
|
return true;
|
112
110
|
}
|
113
111
|
|
114
|
-
async function normalZipFile(sourcePath, targetPath,
|
112
|
+
async function normalZipFile(sourcePath, targetPath, isSubPackage) {
|
115
113
|
|
116
|
-
const packageSize =
|
114
|
+
const packageSize = 8;
|
117
115
|
const zipPath = path.join(targetPath, `${path.basename(sourcePath)}.zip`);
|
118
116
|
return new Promise(function (resolve, reject) {
|
119
117
|
const output = fs.createWriteStream(zipPath);
|
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,27 @@ exports.checkRemoteVersion = async function () {
|
|
359
361
|
msg: err.message
|
360
362
|
}
|
361
363
|
});
|
364
|
+
}
|
365
|
+
|
366
|
+
// 获取远程版本号
|
367
|
+
exports.checkUploadVersion = async function (appId, version) {
|
368
|
+
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;
|
371
|
+
if (compareVersions(version, current) > 0) {
|
372
|
+
return {
|
373
|
+
success: true,
|
374
|
+
}
|
375
|
+
} else {
|
376
|
+
return {
|
377
|
+
success: false,
|
378
|
+
msg: `The version you uploaded must be greater than the current version ${current}.`,
|
379
|
+
}
|
380
|
+
}
|
381
|
+
} catch (err) {
|
382
|
+
return {
|
383
|
+
success: false,
|
384
|
+
msg: err.message
|
385
|
+
}
|
386
|
+
}
|
362
387
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "tt-minigame-ide-cli",
|
3
|
-
"version": "0.0.1-beta.
|
3
|
+
"version": "0.0.1-beta.5",
|
4
4
|
"description": "Command line interface for micro app development",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"bin": {
|
@@ -17,6 +17,7 @@
|
|
17
17
|
"chalk": "^3.0.0",
|
18
18
|
"clipboardy": "^2.2.0",
|
19
19
|
"commander": "^4.1.1",
|
20
|
+
"compare-versions": "^4.1.3",
|
20
21
|
"execa": "^4.0.0",
|
21
22
|
"folder-hash": "^3.3.0",
|
22
23
|
"form-data": "^3.0.0",
|
package/template/app.js
DELETED
package/template/app.json
DELETED
package/template/app.ttss
DELETED
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
<view class="intro">Welcome to Mini Program</view>
|