@ttmg/cli 0.1.2 → 0.1.3-beta.2

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/CHANGELOG.md CHANGED
@@ -45,4 +45,13 @@ feat: 支持文件变更监听,告知浏览器文件变更,提醒开发者
45
45
  发布最新版本,提醒开发者升级最新版本
46
46
 
47
47
  ## 0.1.2
48
- 发布最新版本,支持 sourcemap
48
+
49
+ 发布最新版本,支持 sourcemap
50
+
51
+ ## 0.1.3-beta.1
52
+
53
+ 优化显示二维码问题
54
+
55
+ ## 0.1.3-beta.2
56
+
57
+ 彻底修复二维码兼容问题
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ ## @ttmg/cli
2
+
3
+ `ttmg` 是一个用于管理和开发小游戏项目的命令行工具,支持 H5 小游戏和原生小游戏的初始化、开发调试和打包构建。
4
+
5
+ ### 安装
6
+
7
+ 你可以通过 npm 本地安装或全局安装:
8
+
9
+ ```
10
+ npm install @ttmg/cli -g
11
+ ```
12
+
13
+ 或者在项目中作为开发依赖:
14
+
15
+ ```
16
+ npm install @ttmg/cli --save-dev
17
+ ```
18
+
19
+ ### 使用方法
20
+
21
+ 安装后,可以在命令行中使用 `ttmg` 命令。
22
+
23
+ #### 查看帮助
24
+
25
+ ```
26
+ ttmg --help
27
+ ```
28
+
29
+ #### 命令说明
30
+
31
+ ##### 1. 初始化项目
32
+
33
+ - 对基于游戏引擎构建好的 H5 小游戏进行初始化
34
+
35
+ ```
36
+ ttmg init --h5
37
+ ```
38
+
39
+ - 对基于游戏引擎构建好的 Native 小游戏进行初始化
40
+
41
+ ```
42
+ ttmg init --native
43
+ ```
44
+
45
+ ##### 2. 开发调试
46
+
47
+ 启动本地开发环境,打开浏览器进行调试。
48
+
49
+ - H5 小游戏调试
50
+
51
+ ```
52
+ ttmg dev --h5
53
+ ```
54
+
55
+ - 原生小游戏调试
56
+
57
+ ```
58
+ ttmg dev --native
59
+ ```
60
+
61
+ ##### 3. 项目打包
62
+
63
+ 打包项目用于发布。
64
+
65
+ - 打包 H5 小游戏
66
+
67
+ ```
68
+ ttmg build --h5
69
+ ```
70
+
71
+ - 打包原生小游戏
72
+ ttmg build --native
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ var chromeLauncher = require('chrome-launcher');
14
14
  var os = require('os');
15
15
  var child_process = require('child_process');
16
16
  var https = require('https');
17
+ var semver = require('semver');
17
18
  var require$$6 = require('crypto');
18
19
  var require$$5$1 = require('archiver');
19
20
  var multer = require('multer');
@@ -22,7 +23,7 @@ var glob = require('glob');
22
23
  var got = require('got');
23
24
  var FormData = require('form-data');
24
25
  var ttmgPack = require('ttmg-pack');
25
- var qrcode = require('qrcode-terminal');
26
+ var QRCode = require('qrcode');
26
27
 
27
28
  function _interopNamespaceDefault(e) {
28
29
  var n = Object.create(null);
@@ -383,12 +384,22 @@ async function checkUpdate() {
383
384
  const boxen = (await import('boxen')).default;
384
385
  const pkgName = '@ttmg/cli';
385
386
  const oldVersion = getGlobalVersion(pkgName);
386
- const newVersion = await getLatestVersion(pkgName);
387
+ const newVersion = (await getLatestVersion(pkgName));
387
388
  if (!oldVersion) {
388
389
  console.log(chalk.yellow(`未检测到全局安装的 ${pkgName}`));
389
390
  return;
390
391
  }
391
392
  if (oldVersion !== newVersion) {
393
+ const oldVersionIsBeta = oldVersion.includes('beta');
394
+ const newVersionIsBeta = newVersion.includes('beta');
395
+ if (oldVersionIsBeta && newVersionIsBeta) {
396
+ return;
397
+ }
398
+ const oldVersionMajor = semver.major(oldVersion);
399
+ const newVersionMajor = semver.major(newVersion);
400
+ if (oldVersionIsBeta && oldVersionMajor >= newVersionMajor) {
401
+ return;
402
+ }
392
403
  const message = `
393
404
  ${chalk.bold('Update available!')} ${chalk.red(oldVersion)} ${chalk.white('→')} ${chalk.green(newVersion)}.
394
405
  ${chalk.magenta('Changelog:')} ${chalk.cyan(`https://npmjs.com/package/${pkgName}/v/${newVersion}`)}
@@ -912,6 +923,9 @@ async function createServer() {
912
923
  const { fileName } = req.params;
913
924
  res.sendFile(path.join(outputDir, fileName));
914
925
  });
926
+ app.get('/game/qrcode', async (req, res) => {
927
+ res.sendFile(path.join(OUTPUT_DIR, `dev-qrcode.png`));
928
+ });
915
929
  /**
916
930
  * 支持文件访问
917
931
  */
@@ -951,7 +965,7 @@ async function createServer() {
951
965
  });
952
966
  // 启动服务
953
967
  server = app.listen(port, () => {
954
- console.log(chalk.cyan.bold(`Node devServer is running on port ${port}`));
968
+ console.log(chalk.cyan.bold(`Node devServer is running on port ${port}\n`));
955
969
  });
956
970
  return {
957
971
  port,
@@ -1258,27 +1272,48 @@ async function watchChange() {
1258
1272
  });
1259
1273
  }
1260
1274
 
1275
+ // 保持你原来的 import
1276
+ // 你的静态服务器运行的端口
1277
+ // --- 修改结束 ---
1261
1278
  async function showSchema() {
1279
+ if (!fs.existsSync(OUTPUT_DIR)) {
1280
+ fs.mkdirSync(OUTPUT_DIR, { recursive: true });
1281
+ }
1262
1282
  const clientKey = getClientKey();
1263
- const outputDir = path.join(OUTPUT_DIR, clientKey);
1264
- const localIP = getLocalIP();
1265
- console.log(chalk.green.bold('Tips:'));
1266
- console.log(` 1. ${chalk.yellow.bold('Scan the QR code to start the client devServer.')}`);
1267
- console.log(` 2. ${chalk.yellow.bold('Will auto upload compiled resource to client.')} ${chalk.bold(outputDir)}`);
1268
- console.log(` 3. ${chalk.yellow.bold('Debug your game in the browser.')}\n`);
1269
- const schema = `https://www.tiktok.com/ttmg/dev/${clientKey}?host=${localIP}&port=${DEV_WS_PORT}`;
1270
- qrcode.generate(schema, {
1271
- small: true,
1272
- }, qr => {
1273
- console.log(qr);
1274
- });
1283
+ // 2. 定义二维码图片的文件名和完整路径
1284
+ const qrCodeFileName = 'dev-qrcode.png';
1285
+ const qrCodeImagePath = path.join(OUTPUT_DIR, qrCodeFileName);
1286
+ const schema = `https://www.tiktok.com/ttmg/dev/${clientKey}?host=${getLocalIP()}&port=${DEV_WS_PORT}`;
1287
+ try {
1288
+ // 3. 使用 QRCode.toFile 生成图片到你的静态目录
1289
+ await QRCode.toFile(qrCodeImagePath, schema, {
1290
+ type: 'png',
1291
+ width: 200,
1292
+ margin: 1,
1293
+ });
1294
+ // 4. 构建可通过静态服务器访问的 URL
1295
+ const qrCodeUrl = `http://localhost:${DEV_PORT}/game/qrcode`;
1296
+ // 5. 打印更新后的提示信息
1297
+ console.log(chalk.green.bold('Tips:'));
1298
+ console.log(` 1. ${chalk.yellow.bold('Open the link below in your browser to see the QR code, then scan it.')}`);
1299
+ console.log(` ${chalk.cyan.underline(qrCodeUrl)}`);
1300
+ console.log(` 2. ${chalk.yellow.bold('Will auto upload compiled resource to client.')}`);
1301
+ console.log(` 3. ${chalk.yellow.bold('Debug your game in the browser.')}\n`);
1302
+ /**
1303
+ * 自动打开浏览器
1304
+ */
1305
+ openUrl(qrCodeUrl);
1306
+ }
1307
+ catch (err) {
1308
+ console.error(chalk.red('Failed to generate QR code image.'), err);
1309
+ }
1275
1310
  }
1276
1311
 
1277
1312
  async function dev() {
1278
1313
  /**
1279
1314
  * 1. 准备游戏资源
1280
1315
  */
1281
- await prepareResource();
1316
+ prepareResource();
1282
1317
  /**
1283
1318
  * 2. 创建本地调试服务
1284
1319
  */
@@ -1293,7 +1328,7 @@ async function dev() {
1293
1328
  await watchChange();
1294
1329
  }
1295
1330
 
1296
- var version = "0.1.2";
1331
+ var version = "0.1.3-beta.2";
1297
1332
  var pkg = {
1298
1333
  version: version};
1299
1334
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttmg/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3-beta.2",
4
4
  "description": "TikTok Mini Game Command Line Tool",
5
5
  "license": "ISC",
6
6
  "bin": {
@@ -41,8 +41,9 @@
41
41
  "multer": "^2.0.2",
42
42
  "open": "^10.2.0",
43
43
  "prettier": "^3.6.2",
44
- "qrcode-terminal": "^0.12.0",
45
- "ttmg-pack": "0.0.22",
44
+ "qrcode": "^1.5.4",
45
+ "semver": "^7.7.2",
46
+ "ttmg-pack": "0.0.25",
46
47
  "ws": "^8.18.3"
47
48
  },
48
49
  "devDependencies": {