@taobao-minigame/cli 0.0.1-beta.4 → 0.0.1-beta.6
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.md +95 -87
- package/lib/utils/common.js +1 -1
- package/lib/utils/logger.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,8 +18,8 @@ tbgame -h
|
|
|
18
18
|
## 快速开始
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
# 1.
|
|
22
|
-
tbgame
|
|
21
|
+
# 1. 设置调用凭证 Token(在开放平台后台「小游戏开发 → 开发设置」获取)
|
|
22
|
+
tbgame config set token <token>
|
|
23
23
|
|
|
24
24
|
# 2. 在项目根目录生成预览二维码
|
|
25
25
|
tbgame preview --appId <appId> --type minigame
|
|
@@ -28,70 +28,11 @@ tbgame preview --appId <appId> --type minigame
|
|
|
28
28
|
tbgame upload --appId <appId> --type minigame --version 1.0.0
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
以下以小游戏(`-t minigame`)为例,每个场景给出最少参数与最全参数两种写法。
|
|
34
|
-
|
|
35
|
-
### 查看和设置 token
|
|
36
|
-
|
|
37
|
-
登录态 token 由 `tbgame login` 自动写入,也可以手动查看/设置:
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
# 查看当前 token
|
|
41
|
-
tbgame config get token
|
|
42
|
-
|
|
43
|
-
# 手动设置 token
|
|
44
|
-
tbgame config set token <你的token>
|
|
45
|
-
|
|
46
|
-
# 查看全部本地配置(含 token、nick、env 等)
|
|
47
|
-
tbgame config show
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### 上传
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
# 最少参数:在项目根目录执行,不传 -v 时基于线上最新版本自动递增
|
|
54
|
-
tbgame upload -a 1234567 -t minigame
|
|
55
|
-
|
|
56
|
-
# 最全参数:显式指定项目目录、版本号、渲染模式
|
|
57
|
-
tbgame upload -i /path/to/project -a 1234567 -t minigame -v 1.0.0 --renderMode normal
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### 预览
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
# 最少参数:在项目根目录执行
|
|
64
|
-
tbgame preview -a 1234567 -t minigame
|
|
65
|
-
|
|
66
|
-
# 最全参数:显式指定目录、云构建、复制二维码、渲染模式;--noBuild 跳过构建复用上次缓存(与云构建二选一)
|
|
67
|
-
tbgame preview -i /path/to/project -a 1234567 -t minigame -c --copy --renderMode normal
|
|
68
|
-
tbgame preview -a 1234567 -t minigame --noBuild
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### 调试
|
|
72
|
-
|
|
73
|
-
调试即预览加 `-d/--debug`,开启真机调试:
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
# 最少参数
|
|
77
|
-
tbgame preview -a 1234567 -t minigame -d
|
|
78
|
-
|
|
79
|
-
# 最全参数:自动打开 DevTools(Chrome 路径取 PUPPETEER_PATH 配置)
|
|
80
|
-
tbgame preview -i /path/to/project -a 1234567 -t minigame -d -c --copy --renderMode normal --autoOpenDevtools
|
|
81
|
-
```
|
|
31
|
+
> 推荐使用 Token 认证:在开放平台后台「小游戏开发 → 开发设置」创建/查看 CLI Token,再通过 `tbgame config set token <token>` 写入本地。
|
|
32
|
+
> `tbgame login`(Chrome 扫码登录)仍可用,但**后续会下线**,请尽快迁移到 Token 方式。
|
|
82
33
|
|
|
83
34
|
## 命令
|
|
84
35
|
|
|
85
|
-
### tbgame login
|
|
86
|
-
|
|
87
|
-
获取淘宝登录态。会通过本地 Chrome 打开登录页,登录成功后凭证保存在本地,供后续命令使用。
|
|
88
|
-
|
|
89
|
-
如需指定 Chrome 可执行文件路径:
|
|
90
|
-
|
|
91
|
-
```bash
|
|
92
|
-
tbgame config set PUPPETEER_PATH /path/to/chrome
|
|
93
|
-
```
|
|
94
|
-
|
|
95
36
|
### tbgame preview
|
|
96
37
|
|
|
97
38
|
生成预览链接/二维码。
|
|
@@ -109,17 +50,20 @@ tbgame preview [options]
|
|
|
109
50
|
| `-c, --cloud` | 开启云构建 | `false` |
|
|
110
51
|
| `--copy` | 复制预览码到剪贴板 | `false` |
|
|
111
52
|
| `--renderMode <mode>` | 小游戏渲染模式:`highPerformance` \| `normal` | `highPerformance` |
|
|
112
|
-
| `--noBuild` |
|
|
53
|
+
| `--noBuild` | 跳过云构建,使用本地缓存的上一次构建结果生成二维码(无缓存时报错,与 `--cloud` 互斥) | `false` |
|
|
113
54
|
| `--autoOpenDevtools` | 真机调试拿到 DevTools 地址后自动用本地 Chrome 打开(路径取 `PUPPETEER_PATH` 配置,无则用系统默认 Chrome) | `false` |
|
|
114
55
|
|
|
115
56
|
示例:
|
|
116
57
|
|
|
117
58
|
```bash
|
|
118
|
-
#
|
|
119
|
-
tbgame preview
|
|
59
|
+
# 最少参数:在项目根目录执行
|
|
60
|
+
tbgame preview --appId 1234567 --type minigame
|
|
61
|
+
|
|
62
|
+
# 最全参数:显式目录 + 真机调试 + 云构建 + 复制二维码 + 渲染模式 + 自动打开 DevTools
|
|
63
|
+
tbgame preview --input /path/to/project --appId 1234567 --type minigame --debug --cloud --copy --renderMode highPerformance --autoOpenDevtools
|
|
120
64
|
|
|
121
|
-
#
|
|
122
|
-
tbgame preview
|
|
65
|
+
# --noBuild 与 --cloud 互斥:跳过构建,复用上次缓存生成二维码
|
|
66
|
+
tbgame preview --appId 1234567 --type minigame --noBuild
|
|
123
67
|
```
|
|
124
68
|
|
|
125
69
|
### tbgame upload
|
|
@@ -135,13 +79,17 @@ tbgame upload [options]
|
|
|
135
79
|
| `-i, --input <input>` | 应用根目录 | 当前目录 |
|
|
136
80
|
| `-a, --appId <appId>` | 指定应用 appId | - |
|
|
137
81
|
| `-t, --type <open_type>` | 应用类型,见下方[应用类型](#应用类型) | - |
|
|
138
|
-
| `-v, --version <version>` |
|
|
82
|
+
| `-v, --version <version>` | 指定上传的应用版本号,不传时基于线上最新版本自动递增 | - |
|
|
139
83
|
| `--renderMode <mode>` | (小游戏)渲染模式:`highPerformance` \| `normal` | `highPerformance` |
|
|
140
84
|
|
|
141
85
|
示例:
|
|
142
86
|
|
|
143
87
|
```bash
|
|
144
|
-
|
|
88
|
+
# 最少参数:项目根目录执行,不传 --version 时基于线上最新版本自动递增
|
|
89
|
+
tbgame upload --appId 1234567 --type minigame
|
|
90
|
+
|
|
91
|
+
# 最全参数:显式指定项目目录、版本号、渲染模式
|
|
92
|
+
tbgame upload --input /path/to/project --appId 1234567 --type minigame --version 1.0.0 --renderMode highPerformance
|
|
145
93
|
```
|
|
146
94
|
|
|
147
95
|
### tbgame app
|
|
@@ -149,7 +97,18 @@ tbgame upload -a 1234567 -t minigame -v 1.0.0
|
|
|
149
97
|
获取开放平台应用的基础信息(应用名称、最新线上版本)。
|
|
150
98
|
|
|
151
99
|
```bash
|
|
152
|
-
tbgame app
|
|
100
|
+
tbgame app [options]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
| 参数 | 说明 | 默认值 |
|
|
104
|
+
| --- | --- | --- |
|
|
105
|
+
| `-a, --appId <appId>` | 指定应用 appId | - |
|
|
106
|
+
|
|
107
|
+
示例:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# 本命令仅一个参数,最少即最全
|
|
111
|
+
tbgame app --appId 1234567
|
|
153
112
|
```
|
|
154
113
|
|
|
155
114
|
### tbgame config
|
|
@@ -157,32 +116,81 @@ tbgame app --appId <appId>
|
|
|
157
116
|
管理工具本地配置。
|
|
158
117
|
|
|
159
118
|
```bash
|
|
160
|
-
tbgame config set <key> <value>
|
|
161
|
-
tbgame config get <key>
|
|
162
|
-
tbgame config show
|
|
119
|
+
tbgame config set <key> <value>
|
|
120
|
+
tbgame config get <key>
|
|
121
|
+
tbgame config show
|
|
163
122
|
```
|
|
164
123
|
|
|
124
|
+
| 子命令 | 说明 |
|
|
125
|
+
| --- | --- |
|
|
126
|
+
| `config set <key> <value>` | 设置配置项 |
|
|
127
|
+
| `config get <key>` | 读取配置项 |
|
|
128
|
+
| `config show` | 查看全部配置 |
|
|
129
|
+
|
|
165
130
|
常用配置项:
|
|
166
131
|
|
|
167
|
-
| key | 说明 |
|
|
168
|
-
| --- | --- |
|
|
169
|
-
| `
|
|
132
|
+
| key | 说明 | 可选值 |
|
|
133
|
+
| --- | --- | --- |
|
|
134
|
+
| `env` | 服务环境 | `prod`(默认) / `pre` / `daily` |
|
|
135
|
+
| `PUPPETEER_PATH` | 本地 Chrome 可执行文件路径,`login` 与 `--autoOpenDevtools` 使用 | 绝对路径 |
|
|
136
|
+
| `token` | 调用凭证,从开放平台后台「小游戏开发 → 开发设置」获取(推荐认证方式);`login` 也会写入此项 | - |
|
|
137
|
+
|
|
138
|
+
示例:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
# 最少参数:查看全部配置
|
|
142
|
+
tbgame config show
|
|
143
|
+
|
|
144
|
+
# 读取单个配置项
|
|
145
|
+
tbgame config get env
|
|
146
|
+
|
|
147
|
+
# 最全参数:设置配置项
|
|
148
|
+
tbgame config set env daily
|
|
149
|
+
tbgame config set PUPPETEER_PATH /path/to/chrome
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### tbgame login
|
|
153
|
+
|
|
154
|
+
> ⚠️ **即将下线**:请优先使用 Token 认证(`tbgame config set token <token>`),`login` 后续版本会移除。
|
|
155
|
+
|
|
156
|
+
获取淘宝登录态。会通过本地 Chrome 打开登录页,登录成功后凭证保存在本地,供后续命令使用。
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
tbgame login
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
| 参数 | 说明 | 默认值 |
|
|
163
|
+
| --- | --- | --- |
|
|
164
|
+
| 无 | 本命令不接受命令行选项 | - |
|
|
165
|
+
|
|
166
|
+
> 登录依赖本地 Chrome。若无法自动定位,先用 `tbgame config set PUPPETEER_PATH <路径>` 指定。
|
|
167
|
+
|
|
168
|
+
示例:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
# 最少参数:本命令无参数,直接执行
|
|
172
|
+
tbgame login
|
|
173
|
+
|
|
174
|
+
# 最全参数:先设置本地 Chrome 路径,再登录
|
|
175
|
+
tbgame config set PUPPETEER_PATH /path/to/chrome
|
|
176
|
+
tbgame login
|
|
177
|
+
```
|
|
170
178
|
|
|
171
179
|
## 应用类型
|
|
172
180
|
|
|
173
|
-
`--type`
|
|
181
|
+
`--type` 参数取值(**后续将专注于小游戏 `minigame`,其余类型逐步不再支持**):
|
|
174
182
|
|
|
175
|
-
| 应用类型 | type 取值 |
|
|
176
|
-
| --- | --- |
|
|
177
|
-
|
|
|
178
|
-
|
|
|
179
|
-
|
|
|
180
|
-
| 标准化应用 | `standardizedApp` |
|
|
181
|
-
| 商家后台应用 | `isvCMS` |
|
|
182
|
-
| 配置应用 | `webapp` |
|
|
183
|
+
| 应用类型 | type 取值 | 支持状态 |
|
|
184
|
+
| --- | --- | --- |
|
|
185
|
+
| 小游戏 | `minigame` | ✅ 主力支持 |
|
|
186
|
+
| 小程序 | `miniapp` | ⚠️ 后续不再支持 |
|
|
187
|
+
| 小部件 | `widget` | ⚠️ 后续不再支持 |
|
|
188
|
+
| 标准化应用 | `standardizedApp` | ⚠️ 后续不再支持 |
|
|
189
|
+
| 商家后台应用 | `isvCMS` | ⚠️ 后续不再支持 |
|
|
190
|
+
| 配置应用 | `webapp` | ⚠️ 后续不再支持 |
|
|
183
191
|
|
|
184
192
|
## 常见问题
|
|
185
193
|
|
|
186
|
-
- **提示"当前路径没有绑定 appId"**:通过
|
|
194
|
+
- **提示"当前路径没有绑定 appId"**:通过 `--appId` 显式指定。
|
|
187
195
|
- **命令执行报错想看详细日志**:在命令上追加 `--showProcess` 查看完整执行过程日志。
|
|
188
196
|
- **登录失败或无法拉起浏览器**:先通过 `tbgame config set PUPPETEER_PATH <chrome路径>` 指定本地 Chrome。
|
package/lib/utils/common.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.tbTokenToIdeToken=exports.loginForToken=exports.getDefaultChromePath=void 0,exports.downRemoteFile=downRemoteFile,exports.downloadRemoteZip=downloadRemoteZip,exports.addExecuteAccess=addExecuteAccess,exports.getLocalPort=getLocalPort,exports.getAppJson=getAppJson,exports.autoAddVersion=autoAddVersion,exports.showQrCode=showQrCode,exports.getMd5=getMd5,exports.loopFn=loopFn,exports.sleep=sleep,exports.clipText=clipText;const fs_extra_1=__importDefault(require("fs-extra")),path_1=__importDefault(require("path")),https_1=__importDefault(require("https")),unzipper_1=__importDefault(require("unzipper")),get_port_1=__importDefault(require("get-port")),logger_1=require("./logger"),puppeteer_core_1=__importDefault(require("puppeteer-core")),query_string_1=__importDefault(require("query-string")),request_1=__importDefault(require("request")),http_1=__importDefault(require("http")),qr_image_1=__importDefault(require("qr-image")),clipboardy_1=__importDefault(require("clipboardy")),child_process_1=require("child_process")
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.tbTokenToIdeToken=exports.loginForToken=exports.getDefaultChromePath=void 0,exports.downRemoteFile=downRemoteFile,exports.downloadRemoteZip=downloadRemoteZip,exports.addExecuteAccess=addExecuteAccess,exports.getLocalPort=getLocalPort,exports.getAppJson=getAppJson,exports.autoAddVersion=autoAddVersion,exports.showQrCode=showQrCode,exports.getMd5=getMd5,exports.loopFn=loopFn,exports.sleep=sleep,exports.clipText=clipText;const fs_extra_1=__importDefault(require("fs-extra")),path_1=__importDefault(require("path")),https_1=__importDefault(require("https")),unzipper_1=__importDefault(require("unzipper")),get_port_1=__importDefault(require("get-port")),logger_1=require("./logger"),puppeteer_core_1=__importDefault(require("puppeteer-core")),query_string_1=__importDefault(require("query-string")),request_1=__importDefault(require("request")),http_1=__importDefault(require("http")),qr_image_1=__importDefault(require("qr-image")),clipboardy_1=__importDefault(require("clipboardy")),child_process_1=require("child_process"),constants_1=require("../constants"),logger=(0,logger_1.getLogger)("utils");function downRemoteFile(e){return new Promise(t=>{http_1.default.get(e,e=>{e.setEncoding("utf8");let o="";e.on("data",function(e){o+=e}),e.on("end",function(){t(o)})})})}function downloadRemoteZip(e,t){return new Promise(async o=>{fs_extra_1.default.emptyDirSync(t);const r=unzipper_1.default.Extract({path:t});https_1.default.get(e,function(e){e.pipe(r),r.on("close",()=>{o("end")})})})}function addExecuteAccess(e){return new Promise((t,o)=>{fs_extra_1.default.chmod(e,755,e=>{e&&o(e),t("")})})}const getDefaultChromePath=()=>"win32"===process.platform?"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe":"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome";async function getLocalPort(){return await(0,get_port_1.default)({port:[8e3,8001,8002,8003,8004,8005]})}function getAppJson(e,t=!1){const o=path_1.default.join(e,"app.json");try{return fs_extra_1.default.readJsonSync(o)}catch(e){if(t)throw"小程序的appJson不合法";return{}}}exports.getDefaultChromePath=getDefaultChromePath;const loginForToken=e=>new Promise(async t=>{logger.info("开始登录"),logger.debug("chrome path",`${e||(0,exports.getDefaultChromePath)()}`);const o=await puppeteer_core_1.default.launch({executablePath:`${e||(0,exports.getDefaultChromePath)()}`,headless:!1,args:["--test-type","--no-sandbox","--disable-setuid-sandbox"]}),r=await o.newPage();await r.goto("https://login.taobao.com/member/qrcode.htm?from=tbmp_ide&qrversion=2211&pcRedirectURL=https://market.m.taobao.com/app/polygon/adaptor-taobao/router.html"),o.on("targetchanged",async e=>{const r=e.url();if(r&&r.indexOf("adaptor-taobao/router.html")){const e=query_string_1.default.parseUrl(r);e&&e.query&&e.query.token&&e.query.nick&&(logger.success("登录成功账号用户名:",e.query.nick),await o.close(),t({token:e.query.token,nick:e.query.nick}))}})});exports.loginForToken=loginForToken;const tbTokenToIdeToken=(e,t)=>new Promise((o,r)=>{(0,request_1.default)(`${constants_1.ENV_HOST[e].LOGIN_HOST}/dologin`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({st:t})},(e,t,n)=>{let a=JSON.parse(n);a.success?o(a.result):r(n)})});function autoAddVersion(e){return e.replace(/\.(\d+)$/,function(e,t){return`.${parseInt(t,10)+1}`})}function showQrCode(e){const t=qr_image_1.default.imageSync(e,{size:1,margin:2}),o=require("console-png"),r={log:logger_1.$console.log};o.attachTo(r),r.png(t)}function getMd5(e){var t=require("crypto"),o=require("fs").readFileSync(e),r=t.createHash("md5");return r.update(o),r.digest("hex")}async function loopFn(e,t,o,r){let n=1;for(;;){if(!r(n,await e()))break;if(n++>o)break;await sleep(t)}}function sleep(e){return new Promise(t=>{setTimeout(()=>{t("")},e)})}function clipText(e){try{-1!==process.platform.indexOf("darwin")?clipboardy_1.default.writeSync(e):(0,child_process_1.exec)("clip").stdin.end(e)}catch(e){logger.error("clip text error",e)}}exports.tbTokenToIdeToken=tbTokenToIdeToken;
|
package/lib/utils/logger.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.showDebug=showDebug,exports.getLogger=getLogger,require("colors");let showDebugInfo=!1;function showDebug(){showDebugInfo=!0}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.$console=void 0,exports.showDebug=showDebug,exports.getLogger=getLogger,require("colors");let showDebugInfo=!1;function showDebug(){showDebugInfo=!0}function porcessArgs(...o){return o.map(o=>"function"==typeof o?o():o)}function getLogger(o){return{log(...o){const e=o.map(o=>"function"==typeof o?o():o);exports.$console.log(...e)},info(...o){this.log("[info]",...o)},error(...o){process.env.DEBUG?exports.$console.error(new Date,"[error]".red,...porcessArgs(...o)):exports.$console.error("[error]".red,...porcessArgs(...o))},warn(...o){this.log("[warn]".yellow,...o)},debug(...o){showDebugInfo&&this.log("[DEBUG]".bgYellow,...o)},success(...o){this.log("[success]".green,...o)},verbose(...o){showDebugInfo&&this.log("[verbos]",...o)}}}exports.$console={log:console.log,warn:console.warn,error:console.error},console.log=function(...o){showDebugInfo&&exports.$console.log(...o)},console.warn=function(...o){showDebugInfo&&exports.$console.warn(...o)},console.error=function(...o){showDebugInfo&&exports.$console.error(...o)};
|