@ttmg/cli 0.4.7 → 0.4.8-alpha.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/dist/index.js CHANGED
@@ -18363,7 +18363,7 @@ async function authStatus(options = {}) {
18363
18363
  return result;
18364
18364
  }
18365
18365
 
18366
- var version = "0.4.7";
18366
+ var version = "0.4.8-alpha.0";
18367
18367
  var engines = {
18368
18368
  node: ">=20.19.1 <21 || >=22"
18369
18369
  };
@@ -23769,6 +23769,8 @@ const store = Store.getInstance({
23769
23769
  remoteCdnResources: undefined,
23770
23770
  nodeResourceHost: '',
23771
23771
  previewRemoteResources: undefined,
23772
+ // 打包产出的屏幕配置(packageConfig.screen_config),没有时为 undefined
23773
+ screenConfig: undefined,
23772
23774
  isUnderCompiling: false,
23773
23775
  isUnderUploading: false,
23774
23776
  isWaitingForUpload: false,
@@ -24413,7 +24415,7 @@ async function compile(context) {
24413
24415
  if (context?.signal?.aborted)
24414
24416
  return;
24415
24417
  if (msg.type === 'status' && msg.status === 'end') {
24416
- const { isSuccess, errorMsg, packages } = msg;
24418
+ const { isSuccess, errorMsg, packages, screenConfig } = msg;
24417
24419
  if (!isSuccess) {
24418
24420
  store.setState({
24419
24421
  isUnderCompiling: false,
@@ -24443,6 +24445,7 @@ async function compile(context) {
24443
24445
  isUnderCompiling: false,
24444
24446
  packages,
24445
24447
  remoteCdnResources: msg.remoteCdnResources,
24448
+ screenConfig,
24446
24449
  });
24447
24450
  /**
24448
24451
  * 编译成功后,需要触发上传
@@ -24887,6 +24890,7 @@ function listen$1() {
24887
24890
  wsServer.sendUploadStatus('success', {
24888
24891
  status: 'success',
24889
24892
  packages: store.getState().packages,
24893
+ screenConfig: store.getState().screenConfig,
24890
24894
  clientKey: getClientKey().clientKey,
24891
24895
  isSuccess: true,
24892
24896
  });
@@ -25407,6 +25411,90 @@ const gameAssetsRoute = {
25407
25411
  },
25408
25412
  };
25409
25413
 
25414
+ const DEBUG_META_DATA = {
25415
+ allowed_domains: [],
25416
+ client_key_type: 2,
25417
+ stage: 2,
25418
+ description: 'TTMG Dev Game',
25419
+ entity: '',
25420
+ icon_big_url: '',
25421
+ icon_url: '',
25422
+ minis_category: 'mini_game',
25423
+ minis_status: 1,
25424
+ minis_tech_type: 0,
25425
+ minis_type: 2,
25426
+ scopes: ['user.info.open_id', 'user.info.basic'],
25427
+ tos_url: '',
25428
+ update_time: Date.now(),
25429
+ status_code: 0,
25430
+ status_msg: '',
25431
+ name: 'TikTok Mini Game',
25432
+ };
25433
+ function isObject$1(value) {
25434
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
25435
+ }
25436
+ /**
25437
+ * Debug link query for a package the packer judged landscape (screen_config),
25438
+ * so the client can pick the landscape container before the debug meta
25439
+ * arrives. Portrait and unknown packages add nothing.
25440
+ */
25441
+ function devLaunchOrientationQuery(screenConfig) {
25442
+ return isObject$1(screenConfig) && screenConfig.orientation === 'landscape'
25443
+ ? '&screen_orientation=landscape'
25444
+ : '';
25445
+ }
25446
+ function assertDevRuntimePackages(value) {
25447
+ if (!isObject$1(value) || Object.keys(value).length === 0) {
25448
+ throw new Error('Compiled package metadata must be a non-empty object keyed by package name.');
25449
+ }
25450
+ for (const [name, entry] of Object.entries(value)) {
25451
+ if (!isObject$1(entry)) {
25452
+ throw new Error(`Compiled package metadata for ${name} is invalid.`);
25453
+ }
25454
+ for (const field of ['url', 'md5', 'root', 'main', 'output', 'type']) {
25455
+ if (typeof entry[field] !== 'string') {
25456
+ throw new Error(`Compiled package metadata for ${name} is missing string field ${field}.`);
25457
+ }
25458
+ }
25459
+ if (!Array.isArray(entry.dependencies)) {
25460
+ throw new Error(`Compiled package metadata for ${name} is missing dependencies.`);
25461
+ }
25462
+ }
25463
+ if (!isObject$1(value.__GAME__) || typeof value.__GAME__.main !== 'string') {
25464
+ throw new Error('Compiled package metadata must contain the __GAME__ main package.');
25465
+ }
25466
+ }
25467
+ function buildDevMeta(options) {
25468
+ assertDevRuntimePackages(options.packages);
25469
+ const remoteResources = buildDevRemoteCdnResources(options.remoteCdnResources, options.remoteResourceBaseUrl);
25470
+ const { scopes, update_time, display_icon_url, request_allowed_domains, name, terms_of_service_link, privacy_policy_link, description, } = options.gameDetail || DEBUG_META_DATA;
25471
+ return {
25472
+ ...DEBUG_META_DATA,
25473
+ tos_url: terms_of_service_link,
25474
+ privacy_url: privacy_policy_link,
25475
+ name: name || DEBUG_META_DATA.name,
25476
+ icon_url: display_icon_url || DEBUG_META_DATA.icon_url,
25477
+ icon_big_url: display_icon_url || DEBUG_META_DATA.icon_url,
25478
+ client_key: options.clientKey,
25479
+ minis_url: `https://minis-${options.clientKey}-vdebug-minigame.tiktok-minis.us/`,
25480
+ package_config: JSON.stringify({
25481
+ packages: options.packages,
25482
+ ...(remoteResources ? { remote_cdn_resources: remoteResources } : {}),
25483
+ ...(options.screenConfig === undefined
25484
+ ? {}
25485
+ : { screen_config: options.screenConfig }),
25486
+ }),
25487
+ allowed_domains: remoteResources
25488
+ ? [...new Set([...(request_allowed_domains || []), new URL(remoteResources.platform_cdn_base_url).origin])]
25489
+ : request_allowed_domains || [],
25490
+ status_code: 0,
25491
+ status_msg: '',
25492
+ update_time,
25493
+ description,
25494
+ scopes,
25495
+ };
25496
+ }
25497
+
25410
25498
  function buildCheckPkgsOptions(outputDir) {
25411
25499
  return {
25412
25500
  entry: process.cwd(),
@@ -25450,7 +25538,7 @@ const gameConfigRoute = {
25450
25538
  nodeServerPort: store.getState().nodeServerPort,
25451
25539
  nodeWsPort: store.getState().nodeWsPort,
25452
25540
  clientKey,
25453
- schema: `https://www.tiktok.com/ttmg/dev/${clientKey}?host=${localHost}&port=${store.getState().nodeWsPort}&host_list=${encodeURIComponent(JSON.stringify(localIPs))}`,
25541
+ schema: `https://www.tiktok.com/ttmg/dev/${clientKey}?host=${localHost}&port=${store.getState().nodeWsPort}&host_list=${encodeURIComponent(JSON.stringify(localIPs))}${devLaunchOrientationQuery(store.getState().screenConfig)}`,
25454
25542
  ...basic,
25455
25543
  devToolVersion,
25456
25544
  checkResult: checkResult.map(localizePackCheckResult),
@@ -29311,8 +29399,8 @@ function redactSensitive(value) {
29311
29399
  }
29312
29400
  return value;
29313
29401
  }
29314
- function buildDevLaunchUrl({ clientKey, host, hosts, wsPort, mode = 'default', configuration, }) {
29315
- const base = `https://www.tiktok.com/ttmg/dev/${encodeURIComponent(clientKey)}?host=${encodeURIComponent(host)}&port=${wsPort}&host_list=${encodeURIComponent(JSON.stringify(hosts))}`;
29402
+ function buildDevLaunchUrl({ clientKey, host, hosts, wsPort, mode = 'default', configuration, screenConfig, }) {
29403
+ const base = `https://www.tiktok.com/ttmg/dev/${encodeURIComponent(clientKey)}?host=${encodeURIComponent(host)}&port=${wsPort}&host_list=${encodeURIComponent(JSON.stringify(hosts))}${devLaunchOrientationQuery(screenConfig)}`;
29316
29404
  if (mode !== 'client-preview')
29317
29405
  return base;
29318
29406
  const config = configuration || parseLaunchConfig({ schemaVersion: '1' });
@@ -29359,7 +29447,7 @@ class DevSessionReporter {
29359
29447
  this.options.onEvent?.(event);
29360
29448
  return event;
29361
29449
  }
29362
- async writeReadyManifest({ pageUrl, version, hosts, httpPort, wsPort, control = null, scanPageUrl, runtimeLogsDirectory, updateMode, }) {
29450
+ async writeReadyManifest({ pageUrl, version, hosts, httpPort, wsPort, control = null, scanPageUrl, runtimeLogsDirectory, updateMode, screenConfig, }) {
29363
29451
  const advertisedHost = hosts[0] || '127.0.0.1';
29364
29452
  const rawUrl = buildDevLaunchUrl({
29365
29453
  clientKey: this.options.clientKey,
@@ -29368,6 +29456,7 @@ class DevSessionReporter {
29368
29456
  wsPort,
29369
29457
  mode: this.options.mode || 'default',
29370
29458
  configuration: this.options.configuration,
29459
+ screenConfig,
29371
29460
  });
29372
29461
  await QRCode.toFile(this.qrFile, rawUrl, { width: 320, margin: 2 });
29373
29462
  const manifest = {
@@ -29580,7 +29669,7 @@ function parseJsonBody(response) {
29580
29669
  return null;
29581
29670
  }
29582
29671
  }
29583
- function isObject$1(value) {
29672
+ function isObject(value) {
29584
29673
  return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
29585
29674
  }
29586
29675
  function fallbackFormattedLine(record) {
@@ -29588,7 +29677,7 @@ function fallbackFormattedLine(record) {
29588
29677
  return `[${level}][${record.category || record.source}] ${record.message}`;
29589
29678
  }
29590
29679
  function normalizeRuntimeRecord(value) {
29591
- if (!isObject$1(value))
29680
+ if (!isObject(value))
29592
29681
  return null;
29593
29682
  if (!isDecimalCursor(value.sequence) ||
29594
29683
  typeof value.timestamp_ms !== 'number' ||
@@ -29626,7 +29715,7 @@ function normalizeRuntimeRecord(value) {
29626
29715
  delete normalized.category;
29627
29716
  else
29628
29717
  normalized.category = category;
29629
- if (!isObject$1(value.attributes))
29718
+ if (!isObject(value.attributes))
29630
29719
  delete normalized.attributes;
29631
29720
  if (rawLevel === undefined)
29632
29721
  delete normalized.raw_level;
@@ -29638,7 +29727,7 @@ function redactSensitiveValue(value, token) {
29638
29727
  if (Array.isArray(value)) {
29639
29728
  return value.map(child => redactSensitiveValue(child, token));
29640
29729
  }
29641
- if (isObject$1(value)) {
29730
+ if (isObject(value)) {
29642
29731
  return Object.fromEntries(Object.entries(value).map(([key, child]) => [
29643
29732
  key,
29644
29733
  /access[_-]?token|authorization|cookie/i.test(key)
@@ -29842,7 +29931,7 @@ class RuntimeDebugClient {
29842
29931
  return;
29843
29932
  }
29844
29933
  if (message?.method === 'error') {
29845
- const payload = isObject$1(message.payload) ? message.payload : {};
29934
+ const payload = isObject(message.payload) ? message.payload : {};
29846
29935
  websocketError = new RuntimeDebugError(mapWireErrorCode(payload.code, 'websocket'), protocolErrorMessage('websocket'));
29847
29936
  this.reconnectBlocked = true;
29848
29937
  this.setStatus('disconnected', {
@@ -29854,7 +29943,7 @@ class RuntimeDebugClient {
29854
29943
  return;
29855
29944
  }
29856
29945
  if (message?.method === 'runtimeLogStreamReady') {
29857
- const payload = isObject$1(message.payload) ? message.payload : {};
29946
+ const payload = isObject(message.payload) ? message.payload : {};
29858
29947
  if (payload.protocol_version !== RUNTIME_DEBUG_PROTOCOL_VERSION) {
29859
29948
  websocketError = new RuntimeDebugError('RUNTIME_DEBUG_UNSUPPORTED', 'Runtime authentication returned an unsupported protocol version.');
29860
29949
  this.reconnectBlocked = true;
@@ -29898,7 +29987,7 @@ class RuntimeDebugClient {
29898
29987
  if (message?.method === 'runtimeLogBatch') {
29899
29988
  if (!authenticated)
29900
29989
  return;
29901
- const payload = isObject$1(message.payload) ? message.payload : {};
29990
+ const payload = isObject(message.payload) ? message.payload : {};
29902
29991
  if (payload.protocol_version !== RUNTIME_DEBUG_PROTOCOL_VERSION ||
29903
29992
  payload.session_id !== discovery.runtimeSessionId ||
29904
29993
  !isDecimalCursor(payload.from_cursor) ||
@@ -30063,10 +30152,10 @@ class RuntimeDebugClient {
30063
30152
  readProtocolEnvelope(response, operation) {
30064
30153
  const discovery = this.requireDiscovery();
30065
30154
  const body = parseJsonBody(response);
30066
- if (!isObject$1(body)) {
30155
+ if (!isObject(body)) {
30067
30156
  throw new RuntimeDebugError(mapWireErrorCode(null, operation), protocolErrorMessage(operation));
30068
30157
  }
30069
- const data = isObject$1(body.data) ? body.data : {};
30158
+ const data = isObject(body.data) ? body.data : {};
30070
30159
  if (typeof data.session_id === 'string' &&
30071
30160
  data.session_id !== discovery.runtimeSessionId) {
30072
30161
  throw new RuntimeDebugError('RUNTIME_SESSION_MISMATCH', 'The Runtime Debug response belongs to a different session.');
@@ -30098,8 +30187,8 @@ class RuntimeDebugClient {
30098
30187
  signal,
30099
30188
  });
30100
30189
  const body = parseJsonBody(response);
30101
- if (isObject$1(body)) {
30102
- const data = isObject$1(body.data) ? body.data : {};
30190
+ if (isObject(body)) {
30191
+ const data = isObject(body.data) ? body.data : {};
30103
30192
  if (typeof data.session_id === 'string' &&
30104
30193
  data.session_id !== this.runtimeSessionId) {
30105
30194
  throw new RuntimeDebugError('RUNTIME_SESSION_MISMATCH', 'The Runtime Debug response belongs to a different session.');
@@ -30401,77 +30490,6 @@ function runtimeFailurePayload(error) {
30401
30490
  };
30402
30491
  }
30403
30492
 
30404
- const DEBUG_META_DATA = {
30405
- allowed_domains: [],
30406
- client_key_type: 2,
30407
- stage: 2,
30408
- description: 'TTMG Dev Game',
30409
- entity: '',
30410
- icon_big_url: '',
30411
- icon_url: '',
30412
- minis_category: 'mini_game',
30413
- minis_status: 1,
30414
- minis_tech_type: 0,
30415
- minis_type: 2,
30416
- scopes: ['user.info.open_id', 'user.info.basic'],
30417
- tos_url: '',
30418
- update_time: Date.now(),
30419
- status_code: 0,
30420
- status_msg: '',
30421
- name: 'TikTok Mini Game',
30422
- };
30423
- function isObject(value) {
30424
- return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
30425
- }
30426
- function assertDevRuntimePackages(value) {
30427
- if (!isObject(value) || Object.keys(value).length === 0) {
30428
- throw new Error('Compiled package metadata must be a non-empty object keyed by package name.');
30429
- }
30430
- for (const [name, entry] of Object.entries(value)) {
30431
- if (!isObject(entry)) {
30432
- throw new Error(`Compiled package metadata for ${name} is invalid.`);
30433
- }
30434
- for (const field of ['url', 'md5', 'root', 'main', 'output', 'type']) {
30435
- if (typeof entry[field] !== 'string') {
30436
- throw new Error(`Compiled package metadata for ${name} is missing string field ${field}.`);
30437
- }
30438
- }
30439
- if (!Array.isArray(entry.dependencies)) {
30440
- throw new Error(`Compiled package metadata for ${name} is missing dependencies.`);
30441
- }
30442
- }
30443
- if (!isObject(value.__GAME__) || typeof value.__GAME__.main !== 'string') {
30444
- throw new Error('Compiled package metadata must contain the __GAME__ main package.');
30445
- }
30446
- }
30447
- function buildDevMeta(options) {
30448
- assertDevRuntimePackages(options.packages);
30449
- const remoteResources = buildDevRemoteCdnResources(options.remoteCdnResources, options.remoteResourceBaseUrl);
30450
- const { scopes, update_time, display_icon_url, request_allowed_domains, name, terms_of_service_link, privacy_policy_link, description, } = options.gameDetail || DEBUG_META_DATA;
30451
- return {
30452
- ...DEBUG_META_DATA,
30453
- tos_url: terms_of_service_link,
30454
- privacy_url: privacy_policy_link,
30455
- name: name || DEBUG_META_DATA.name,
30456
- icon_url: display_icon_url || DEBUG_META_DATA.icon_url,
30457
- icon_big_url: display_icon_url || DEBUG_META_DATA.icon_url,
30458
- client_key: options.clientKey,
30459
- minis_url: `https://minis-${options.clientKey}-vdebug-minigame.tiktok-minis.us/`,
30460
- package_config: JSON.stringify({
30461
- packages: options.packages,
30462
- ...(remoteResources ? { remote_cdn_resources: remoteResources } : {}),
30463
- }),
30464
- allowed_domains: remoteResources
30465
- ? [...new Set([...(request_allowed_domains || []), new URL(remoteResources.platform_cdn_base_url).origin])]
30466
- : request_allowed_domains || [],
30467
- status_code: 0,
30468
- status_msg: '',
30469
- update_time,
30470
- description,
30471
- scopes,
30472
- };
30473
- }
30474
-
30475
30493
  // Accept a complete set so malformed or partial requests never reset defaults.
30476
30494
  function parseDebugSettings(value) {
30477
30495
  if (!value || typeof value !== 'object' || Array.isArray(value))
@@ -30582,11 +30600,12 @@ function guardBuildObservation(result) {
30582
30600
 
30583
30601
  // Called synchronously by compileSuccess, before the next serialized compile
30584
30602
  // can rewrite outputDir. Uploads and /game/meta always consume this same build.
30585
- function capturePreviewBuild(sourceDirectory = getOutputDir(), packages = store.getState().packages) {
30603
+ function capturePreviewBuild(sourceDirectory = getOutputDir(), packages = store.getState().packages, screenConfig = store.getState().screenConfig) {
30586
30604
  const directory = fs$1.mkdtempSync(path$1.join(os$1.tmpdir(), 'ttmg-preview-build-'));
30587
30605
  const dispose = () => fs$1.rmSync(directory, { recursive: true, force: true });
30588
30606
  try {
30589
30607
  const metadata = structuredClone(packages);
30608
+ const screenConfigSnapshot = structuredClone(screenConfig);
30590
30609
  fs$1.cpSync(sourceDirectory, directory, {
30591
30610
  recursive: true,
30592
30611
  dereference: true,
@@ -30595,7 +30614,13 @@ function capturePreviewBuild(sourceDirectory = getOutputDir(), packages = store.
30595
30614
  const remoteCdnResources = fs$1.existsSync(configPath)
30596
30615
  ? readDevRemoteCdnResources(JSON.parse(fs$1.readFileSync(configPath, 'utf8')).remote_cdn_resources)
30597
30616
  : undefined;
30598
- return { directory, packages: metadata, remoteCdnResources, dispose };
30617
+ return {
30618
+ directory,
30619
+ packages: metadata,
30620
+ remoteCdnResources,
30621
+ screenConfig: screenConfigSnapshot,
30622
+ dispose,
30623
+ };
30599
30624
  }
30600
30625
  catch {
30601
30626
  dispose();
@@ -30895,6 +30920,7 @@ class ClientPreviewOrchestrator {
30895
30920
  meta = buildDevMeta({
30896
30921
  clientKey: this.options.clientKey,
30897
30922
  packages: build.packages,
30923
+ screenConfig: build.screenConfig,
30898
30924
  gameDetail: gameInfo,
30899
30925
  remoteCdnResources: build.remoteCdnResources,
30900
30926
  remoteResourceBaseUrl: build.remoteCdnResources ? getRemoteResourceBaseUrl() : undefined,
@@ -33144,6 +33170,7 @@ async function dev(options = {}) {
33144
33170
  control: controlServer?.address || null,
33145
33171
  scanPageUrl: scanPage?.url(startedServer.port),
33146
33172
  updateMode,
33173
+ screenConfig: store.getState().screenConfig,
33147
33174
  });
33148
33175
  scanPage?.activate({
33149
33176
  port: startedServer.port,