@ttmg/cli 0.3.2-beta.3 → 0.3.2-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/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var os = require('os');
5
- var path = require('path');
6
- var fs = require('fs');
7
4
  var commander = require('commander');
8
5
  var inquirer = require('inquirer');
6
+ var fs = require('fs');
9
7
  var jsdom = require('jsdom');
10
8
  var prettier = require('prettier');
11
9
  var chalk = require('chalk');
12
10
  var express = require('express');
11
+ var path = require('path');
13
12
  var cheerio = require('cheerio');
13
+ var os = require('os');
14
14
  var worker_threads = require('worker_threads');
15
15
  var axios = require('axios');
16
16
  var qs = require('qs');
@@ -50,9 +50,9 @@ function _interopNamespaceDefault(e) {
50
50
  return Object.freeze(n);
51
51
  }
52
52
 
53
- var os__namespace = /*#__PURE__*/_interopNamespaceDefault(os);
54
- var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
55
53
  var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
54
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
55
+ var os__namespace = /*#__PURE__*/_interopNamespaceDefault(os);
56
56
  var glob__namespace = /*#__PURE__*/_interopNamespaceDefault(glob);
57
57
 
58
58
  const CONFIG_FILE_NAME = 'minigame.config.json';
@@ -274,6 +274,11 @@ const setTTMGRC = (config) => {
274
274
  fs.writeFileSync(CONFIG_PATH, JSON.stringify({ ...originConfig, ...config }));
275
275
  };
276
276
 
277
+ function printMessage(type, message) {
278
+ const prefix = type === 'Error' ? chalk.red('Error: ') : chalk.yellow('Warning: ');
279
+ const log = type === 'Error' ? console.error : console.warn;
280
+ log(prefix + message);
281
+ }
277
282
  let spinner$1;
278
283
  const LOGIN_TT4D = 'https://developers.tiktok.com/passport/web/email/login';
279
284
  const params = {
@@ -361,14 +366,40 @@ async function login(options) {
361
366
  if (!response?.data?.data?.user_id) {
362
367
  const errCode = response.data?.data?.error_code;
363
368
  const errMsg = response.data?.data?.description;
369
+ const statusText = response?.statusText ?? '';
370
+ spinner$1.fail(chalk.red('login failed'));
371
+ if (verbose) {
372
+ console.log(chalk.gray('Response status:'), response?.status);
373
+ console.log(chalk.gray('Response statusText:'), statusText || '(empty)');
374
+ console.log(chalk.gray('Response data:'), response?.data ?? '(empty)');
375
+ console.log('');
376
+ }
364
377
  if (errCode || errMsg) {
365
378
  log('Login failed (api)', { errCode, errMsg, fullData: response?.data });
366
- spinner$1.fail(chalk.red(`login failed: ${errMsg}${errCode ? `, error_code: ${errCode}` : ''}`));
379
+ printMessage('Error', `Login failed: ${errMsg}${errCode ? `, error_code: ${errCode}` : ''}`);
367
380
  }
368
381
  else {
369
- log('Login failed (no user_id)', { fullResponse: response?.data });
370
- spinner$1.fail(chalk.red(`login failed`));
371
- log('Login failed', { fullResponse: response });
382
+ log('Login failed (no user_id)', { responseBody: response?.data });
383
+ if (verbose)
384
+ log('Full response (for debugging)', response);
385
+ const looksLikeProxyResponse = statusText === 'Connection established' ||
386
+ (response?.status === 200 &&
387
+ (response?.data == null ||
388
+ typeof response.data !== 'object' ||
389
+ !('data' in response.data)));
390
+ if (looksLikeProxyResponse) {
391
+ printMessage('Warning', [
392
+ 'The response does not look like the login API (e.g. proxy returned "Connection established" instead of forwarding the real response).',
393
+ '',
394
+ 'The API is not reachable from mainland without proxy. Please ensure your proxy correctly forwards HTTPS to developers.tiktok.com: try another proxy node, or check that the proxy is in global/tunnel mode and not intercepting HTTPS.',
395
+ '',
396
+ 'Proxy troubleshooting doc:',
397
+ 'https://bytedance.larkoffice.com/wiki/ZblJwT0ZNil9jJkS8EgcFlcQnFc',
398
+ ].join('\n'));
399
+ }
400
+ else {
401
+ printMessage('Error', 'Login failed. No user_id in response.');
402
+ }
372
403
  }
373
404
  spinner$1.stop();
374
405
  process.exit(1);
@@ -387,13 +418,13 @@ async function login(options) {
387
418
  }
388
419
  catch (error) {
389
420
  log('Request error', error instanceof Error ? { message: error.message, name: error.name, stack: error.stack } : error);
390
- // 1. Error Title: Red and bold
391
421
  spinner$1.fail(chalk.red.bold('Failed to connect to login service'));
392
- // 2. Description: Normal text with bold keywords
393
- console.log(" Detected that the current terminal's " +
394
- chalk.bold('network proxy settings') +
395
- ' are preventing external network access.', chalk.yellow('Please check your local terminal proxy configuration.'));
396
- console.log(chalk.yellow('You can follow this doc to modify your terminal network settings:'), chalk.underline.yellow('https://bytedance.larkoffice.com/wiki/ZblJwT0ZNil9jJkS8EgcFlcQnFc'));
422
+ printMessage('Error', [
423
+ "Detected that the current terminal's network proxy settings are preventing external network access.",
424
+ '',
425
+ 'Please check your local terminal proxy configuration. You can follow this doc to modify your terminal network settings:',
426
+ 'https://bytedance.larkoffice.com/wiki/ZblJwT0ZNil9jJkS8EgcFlcQnFc',
427
+ ].join('\n'));
397
428
  process.exit(1);
398
429
  }
399
430
  }
@@ -429,6 +460,8 @@ async function request({ url, method, data, headers, params, }) {
429
460
  params,
430
461
  headers: {
431
462
  Cookie: cookie,
463
+ 'x-use-ppe': '1',
464
+ 'x-tt-env': 'ppe_upgrade_script',
432
465
  ...(headers || {}),
433
466
  },
434
467
  });
@@ -618,23 +651,6 @@ function ensureDirSync(dirPath) {
618
651
  }
619
652
  }
620
653
 
621
- var index = /*#__PURE__*/Object.freeze({
622
- __proto__: null,
623
- checkUpdate: checkUpdate,
624
- download: download,
625
- ensureDirSync: ensureDirSync,
626
- fetchGameInfo: fetchGameInfo,
627
- getCurrentUser: getCurrentUser,
628
- getLocalIP: getLocalIP,
629
- getTTMGRC: getTTMGRC,
630
- login: login,
631
- openUrl: openUrl,
632
- request: request,
633
- setTTMGRC: setTTMGRC,
634
- setup: setup,
635
- uploadGameToPlatform: uploadGameToPlatform
636
- });
637
-
638
654
  const bareToRelativePlugin = {
639
655
  name: 'bare-to-relative',
640
656
  setup(build) {
@@ -2836,7 +2852,25 @@ async function start() {
2836
2852
  app.use(express.urlencoded({ extended: true }));
2837
2853
  app.use('/game/files', express.static(outputDir));
2838
2854
  app.get('/game/config', async (req, res) => {
2839
- const basic = await ttmgPack.getPkgs({ entryDir: process.cwd() });
2855
+ const [basic, checkResult] = await Promise.all([
2856
+ ttmgPack.getPkgs({ entryDir: process.cwd() }),
2857
+ ttmgPack.checkPkgs({
2858
+ entry: process.cwd(),
2859
+ output: outputDir,
2860
+ dev: {
2861
+ enable: true,
2862
+ port: store.getState().nodeServerPort,
2863
+ host: 'localhost',
2864
+ enableSourcemap: false,
2865
+ enableLog: false,
2866
+ },
2867
+ build: {
2868
+ enableOdr: false,
2869
+ enableAPICheck: true,
2870
+ ...PKG_SIZE_LIMIT,
2871
+ },
2872
+ }),
2873
+ ]);
2840
2874
  const user = getCurrentUser();
2841
2875
  const { clientKey } = getClientKey();
2842
2876
  res.send({
@@ -2849,6 +2883,7 @@ async function start() {
2849
2883
  schema: `https://www.tiktok.com/ttmg/dev/${clientKey}?host=${getLocalIP()}&port=${store.getState().nodeWsPort}&host_list=${encodeURIComponent(JSON.stringify(getLocalIPs()))}`,
2850
2884
  ...basic,
2851
2885
  devToolVersion,
2886
+ checkResult,
2852
2887
  },
2853
2888
  });
2854
2889
  });
@@ -3337,7 +3372,7 @@ async function dev() {
3337
3372
  watch();
3338
3373
  }
3339
3374
 
3340
- var version = "0.3.2-beta.3";
3375
+ var version = "0.3.2-beta.5";
3341
3376
  var pkg = {
3342
3377
  version: version};
3343
3378
 
@@ -3383,12 +3418,6 @@ program
3383
3418
  .command('dev')
3384
3419
  .description('Open browser dev environment')
3385
3420
  .action(async () => {
3386
- const { getCurrentUser } = await Promise.resolve().then(function () { return index; });
3387
- const user = getCurrentUser();
3388
- if (!user) {
3389
- console.log('\n❌ 请先登录 TikTok 账号,执行命令: ttmg login\n');
3390
- process.exit(1);
3391
- }
3392
3421
  const options = program.opts();
3393
3422
  if (options.h5) {
3394
3423
  await dev$1();