@leonxin/meetgames 0.1.13 → 0.1.14

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.
@@ -62,7 +62,7 @@ node dist/entry.js setup \
62
62
  --app-id 791251136341225472 \
63
63
  --app-secret 'YOUR_APP_SECRET' \
64
64
  --channel-type APPLE \
65
- --project-root ./fixtures/ios-test-project/tooltest \
65
+ --project-root ./fixtures/ios-test-project/native-sample \
66
66
  --env test \
67
67
  --verbose
68
68
  ```
@@ -84,6 +84,32 @@ Android 接入时会根据 `meetsdk-remote-config.json` 和内置默认配置检
84
84
 
85
85
  `doctor` 会校验仓库、依赖、`resValue`、Firebase 文件等是否已正确接入。
86
86
 
87
+ ## 重复运行 setup 的幂等行为
88
+
89
+ `setup` 可以在同一个 Android / iOS 工程上重复执行。判断粒度是每一个配置项,而不是整个文件:缺少的配置会插入;key 已存在但 value 不同时更新 value;key 和 value 都相同时保持该配置项不变,不追加重复项。
90
+
91
+ Android:
92
+
93
+ - App Module `build.gradle` 中的 `applicationId` 按远程配置 `packageName` 更新。
94
+ - App Module `defaultConfig` 中的 `resValue` 按第二个参数 key 去重更新,例如已有 `top_app_id` 时更新 value,不再追加第二条 `top_app_id`。
95
+ - TOPSDK 管理的仓库、插件、依赖块只在缺失或内容不一致时写入;已有相同声明时保持原状,避免重复插入和无意义格式变更。
96
+ - 控制台会通过 `PipelineReport.logs` 打印变更前后值,例如:
97
+ - `[meetgames] Android applicationId com.example.old -> com.meet.integrate.androidsample`
98
+ - `[meetgames] Android resValue top_app_id string:old-app-id -> string:mock-topsdk-app-id`
99
+ - `[meetgames] Android resValue facebook_app_id <missing> -> string:0000000000000000`
100
+
101
+ iOS:
102
+
103
+ - `Info.plist` 顶层 key 使用覆盖写入;已有同名 key 更新 value,缺少时新增。
104
+ - `LSApplicationQueriesSchemes` 和 `CFBundleURLTypes` 按 scheme 去重;同一个 URL Scheme / Queries Scheme 重复运行不会追加第二份。
105
+ - Xcode `build settings` 按 key 更新;framework、resource、source、system framework、system lib 和 `TopSDKInstall.swift` 引用重复运行后保持单份有效 build entry。
106
+ - Delegate / SceneDelegate 代码注入会识别已存在代码,不会重复插入。
107
+ - 控制台会通过 `PipelineReport.logs` 打印变更前后值;未变化时也会打印当前值,例如:
108
+ - `SUCCESS: info.plist配置key:FacebookAppID old-facebook-app-id -> 883695101201170`
109
+ - `SUCCESS: info.plist配置key:FacebookAppID 未变化 value:883695101201170`
110
+ - `SUCCESS: BuildSetting设置VALIDATE_WORKSPACE <missing> -> YES`
111
+ - `SUCCESS: BuildSetting设置VALIDATE_WORKSPACE 未变化 value:YES`
112
+
87
113
  ## iOS 接入内容
88
114
 
89
115
  iOS 接入时会根据缓存 iOS SDK 中的 `config.t.json` 执行:
@@ -101,7 +127,9 @@ iOS 接入时会根据缓存 iOS SDK 中的 `config.t.json` 执行:
101
127
 
102
128
  ### iOS 旧工具日志对齐记录
103
129
 
104
- 2026-06-25 已用老工具 `topsdk-tool-ios` 在测试工程 `/Users/work/Workspace/Test/native-sample-old` 上的运行日志作为对齐基准;同源测试工程已放入 `fixtures/ios-test-project/native-sample`。`meet-sdk-tool` 的 iOS 接入在 apply 模式下需要保留同类运行日志,并完成同一批功能点。
130
+ 2026-06-25 / 2026-06-26 已用老工具 `topsdk-tool-ios` 在测试工程 `/Users/work/Workspace/Test/native-sample-old` 上的运行日志作为对齐基准;同源测试工程已放入 `fixtures/ios-test-project/native-sample`。`meet-sdk-tool` 的 iOS 接入在 apply 模式下需要保留同类运行日志,并完成同一批功能点。
131
+
132
+ 完整旧日志要求按插件段连续打印:插件开始行、该插件资源导入、build setting、plist / queries / url scheme / capability、插件完成行都必须在同一个插件段内;`TOPSDK` 的 Delegate 注入日志必须出现在 `SUCCESS: 插件TOPSDK接入完成` 之前。当前回归测试会约束这些关键日志的先后顺序。
105
133
 
106
134
  旧日志覆盖的插件顺序和功能点:
107
135
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leonxin/meetgames",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "bin": {
@@ -31,6 +31,17 @@ function stripPermissionManagedBlock(content: string): string {
31
31
 
32
32
  export function insertPermissions(content: string, permissions: string[]): { content: string; changed: boolean } {
33
33
  const names = new Set(permissions);
34
+ const existingNames = content
35
+ .split("\n")
36
+ .map(extractPermissionName)
37
+ .filter((name): name is string => Boolean(name));
38
+ const existingNameSet = new Set(existingNames);
39
+ const hasDuplicateTargetPermission = permissions.some(
40
+ (permission) => existingNames.filter((name) => name === permission).length > 1
41
+ );
42
+ if (!hasDuplicateTargetPermission && permissions.every((permission) => existingNameSet.has(permission))) {
43
+ return { content, changed: false };
44
+ }
34
45
  let cleaned = removePermissionLinesByNames(content, names);
35
46
  cleaned = stripPermissionManagedBlock(cleaned);
36
47
 
@@ -64,7 +64,8 @@ export function escapeGroovyDoubleQuotedInner(value: string): string {
64
64
  return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
65
65
  }
66
66
 
67
- const RES_VALUE_KEY_RE = /resValue\s*\(\s*'[^']+'\s*,\s*'([^']+)'/;
67
+ const RES_VALUE_KEY_RE = /resValue\s*\(\s*['"][^'"]+['"]\s*,\s*['"]([^'"]+)['"]/;
68
+ const RES_VALUE_RE = /resValue\s*\(\s*(['"])([^'"]+)\1\s*,\s*(['"])([^'"]+)\3\s*,\s*(['"])(.*?)\5\s*\)/;
68
69
  const IMPLEMENTATION_COORD_RE = /implementation\s+["']([^"']+)["']/;
69
70
  const APPLY_PLUGIN_ID_RE = /apply\s+plugin:\s*['"]([^'"]+)['"]/;
70
71
  const PLUGINS_DSL_ID_RE = /^\s*id\s+(?:\(\s*)?['"]([^'"]+)['"](?:\s*\))?/;
@@ -99,6 +100,12 @@ export function extractResValueKey(line: string): string | null {
99
100
  return m?.[1] ?? null;
100
101
  }
101
102
 
103
+ function parseResValueLine(line: string): { type: string; key: string; value: string } | null {
104
+ const m = line.trim().match(RES_VALUE_RE);
105
+ if (!m) return null;
106
+ return { type: m[2], key: m[4], value: m[6] };
107
+ }
108
+
102
109
  /** Maven coordinate key for upsert: `group:artifact` (version ignored). */
103
110
  export function mavenGroupArtifactKey(coordinate: string): string {
104
111
  const parts = coordinate.split(":");
@@ -251,6 +258,9 @@ function repositoryToGradleLine(repo: string): string {
251
258
  }
252
259
 
253
260
  export function mergeRepositoriesInBlock(blockText: string, repositories: readonly string[]): string {
261
+ if (repositories.length && repositories.every((repo) => blockText.split("\n").some((line) => lineDeclaresRepository(line, repo)))) {
262
+ return blockText;
263
+ }
254
264
  let cleaned = removeRepositoryLinesByKeys(blockText, repositories);
255
265
  cleaned = stripManagedBlocks(cleaned, TOPSDK_REPO_AUTO_START, TOPSDK_REPO_AUTO_END);
256
266
  if (!repositories.length) return cleaned;
@@ -266,6 +276,16 @@ export function mergeRepositoriesInBlock(blockText: string, repositories: readon
266
276
  * Upsert buildscript classpaths: drop existing lines with same coordinate, then write TOPSDK AUTO block.
267
277
  */
268
278
  export function mergeClasspathsInBlock(blockText: string, classpaths: readonly string[]): string {
279
+ if (
280
+ classpaths.length &&
281
+ classpaths.every((classpath) =>
282
+ blockText
283
+ .split("\n")
284
+ .some((line) => extractClasspathCoordinate(line) === classpath)
285
+ )
286
+ ) {
287
+ return blockText;
288
+ }
269
289
  const coords = new Set(classpaths);
270
290
  let cleaned = removeClasspathLinesByCoordinates(blockText, coords);
271
291
  cleaned = stripManagedBlocks(cleaned, TOPSDK_AUTO_START, TOPSDK_AUTO_END);
@@ -312,6 +332,9 @@ function insertAfterLeadingApplyPlugins(content: string, snippet: string): strin
312
332
  */
313
333
  export function mergeApplyPluginsInContent(content: string, applyPlugins: readonly string[]): string {
314
334
  if (!applyPlugins.length) return content;
335
+ if (applyPlugins.every((plugin) => content.split("\n").some((line) => extractApplyPluginId(line) === plugin))) {
336
+ return content;
337
+ }
315
338
  const ids = new Set(applyPlugins);
316
339
  let cleaned = removeApplyPluginLinesByIds(content, ids);
317
340
  cleaned = stripManagedBlocks(cleaned, TOPSDK_PLUGIN_AUTO_START, TOPSDK_PLUGIN_AUTO_END);
@@ -342,25 +365,77 @@ export function mergeResValuesInDefaultConfigBlock(blockText: string, managedSni
342
365
  .split("\n")
343
366
  .map((l) => l.trimEnd())
344
367
  .filter((l) => l.includes("resValue("));
345
- const keys = new Set(
346
- [...desiredLines.map((l) => extractResValueKey(l)).filter((k): k is string => Boolean(k)), ...TOPSDK_MANAGED_RESVALUE_KEYS]
368
+ const desiredByKey = new Map(
369
+ desiredLines
370
+ .map((line) => {
371
+ const spec = parseResValueLine(line);
372
+ return spec ? ([spec.key, { ...spec, line }] as const) : null;
373
+ })
374
+ .filter((entry): entry is readonly [string, { type: string; key: string; value: string; line: string }] =>
375
+ Boolean(entry)
376
+ )
347
377
  );
348
- let cleaned = removeResValueLinesByKeys(blockText, keys);
378
+ if (resValuesAlreadyMatch(blockText, desiredByKey)) return blockText;
379
+ const keys = new Set([...desiredByKey.keys(), ...TOPSDK_MANAGED_RESVALUE_KEYS]);
380
+ const seen = new Set<string>();
381
+ let cleaned = blockText
382
+ .split("\n")
383
+ .filter((line) => {
384
+ if (line.includes(TOPSDK_AUTO_START) || line.includes(TOPSDK_AUTO_END)) return false;
385
+ const current = parseResValueLine(line);
386
+ if (!current || !keys.has(current.key)) return true;
387
+ const desired = desiredByKey.get(current.key);
388
+ if (!desired) return false;
389
+ if (current.type === desired.type && current.value === desired.value && !seen.has(current.key)) {
390
+ seen.add(current.key);
391
+ return true;
392
+ }
393
+ return false;
394
+ })
395
+ .join("\n");
349
396
  cleaned = stripManagedBlocks(cleaned, TOPSDK_AUTO_START, TOPSDK_AUTO_END);
397
+ const missingLines = desiredLines.filter((line) => {
398
+ const spec = parseResValueLine(line);
399
+ return spec ? !seen.has(spec.key) : false;
400
+ });
401
+ if (missingLines.length === 0) return cleaned;
402
+ const missingSnippet = [TOPSDK_AUTO_START, ...missingLines, TOPSDK_AUTO_END].join("\n");
350
403
  return replaceOrInsertManaged(
351
404
  cleaned,
352
405
  { start: 0, openBrace: 0, end: cleaned.length },
353
406
  TOPSDK_AUTO_START,
354
407
  TOPSDK_AUTO_END,
355
- managedSnippet
408
+ missingSnippet
356
409
  );
357
410
  }
358
411
 
412
+ function resValuesAlreadyMatch(
413
+ blockText: string,
414
+ desiredByKey: ReadonlyMap<string, { type: string; key: string; value: string; line: string }>
415
+ ): boolean {
416
+ const lines = blockText.split("\n");
417
+ const seen = new Set<string>();
418
+ for (const line of lines) {
419
+ const current = parseResValueLine(line);
420
+ if (!current) continue;
421
+ const desired = desiredByKey.get(current.key);
422
+ if (!desired) {
423
+ if ((TOPSDK_MANAGED_RESVALUE_KEYS as readonly string[]).includes(current.key)) return false;
424
+ continue;
425
+ }
426
+ if (seen.has(current.key)) return false;
427
+ if (current.type !== desired.type || current.value !== desired.value) return false;
428
+ seen.add(current.key);
429
+ }
430
+ return [...desiredByKey.keys()].every((key) => seen.has(key));
431
+ }
432
+
359
433
  function mergeDependenciesInBlock(
360
434
  blockText: string,
361
435
  managedSnippet: string,
362
436
  fallbackGroupId: string
363
437
  ): string {
438
+ if (dependenciesAlreadyMatch(blockText, managedSnippet, fallbackGroupId)) return blockText;
364
439
  const lookupText = `${blockText}\n${managedSnippet}`;
365
440
  const desiredLines = managedSnippet
366
441
  .split("\n")
@@ -388,6 +463,32 @@ function mergeDependenciesInBlock(
388
463
  );
389
464
  }
390
465
 
466
+ function dependenciesAlreadyMatch(blockText: string, managedSnippet: string, fallbackGroupId: string): boolean {
467
+ const lookupText = `${blockText}\n${managedSnippet}`;
468
+ const desiredLines = managedSnippet
469
+ .split("\n")
470
+ .map((l) => l.trimEnd())
471
+ .filter((l) => l.includes("implementation "));
472
+ const desiredKeys = desiredLines
473
+ .map((l) => extractImplementationKey(l, lookupText, fallbackGroupId))
474
+ .filter((k): k is string => Boolean(k));
475
+ const existingKeys = blockText
476
+ .split("\n")
477
+ .map((line) => extractImplementationKey(line, blockText, fallbackGroupId))
478
+ .filter((k): k is string => Boolean(k));
479
+ const existingKeySet = new Set(existingKeys);
480
+ if (!desiredKeys.every((key) => existingKeySet.has(key))) return false;
481
+ const versionMatch = managedSnippet.match(/def\s+topsdk_version\s*=\s*["']([^"']+)["']/);
482
+ const groupMatch = managedSnippet.match(/def\s+groupId\s*=\s*["']([^"']+)["']/);
483
+ if (versionMatch && !new RegExp(`def\\s+topsdk_version\\s*=\\s*["']${escapeRegExp(versionMatch[1])}["']`).test(blockText)) return false;
484
+ if (groupMatch && !new RegExp(`def\\s+groupId\\s*=\\s*["']${escapeRegExp(groupMatch[1])}["']`).test(blockText)) return false;
485
+ return true;
486
+ }
487
+
488
+ function escapeRegExp(value: string): string {
489
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
490
+ }
491
+
391
492
  function stripManagedBlocks(text: string, startMarker: string, endMarker: string): string {
392
493
  const start = text.indexOf(startMarker);
393
494
  const end = text.indexOf(endMarker);
@@ -576,6 +677,7 @@ function mergePluginsDslInBlock(blockText: string, specs: readonly MeetSdkGradle
576
677
  */
577
678
  export function mergePluginsDslInContent(content: string, specs: readonly MeetSdkGradlePluginDslSpec[]): string {
578
679
  if (!specs.length) return content;
680
+ if (pluginsDslAlreadyMatch(content, specs)) return content;
579
681
  const ids = new Set(specs.map((s) => s.id));
580
682
  let cleaned = removePluginsDslLinesByIds(content, ids);
581
683
  cleaned = removeApplyPluginLinesByIds(cleaned, ids);
@@ -589,6 +691,20 @@ export function mergePluginsDslInContent(content: string, specs: readonly MeetSd
589
691
  return cleaned.slice(0, pluginsBlock.openBrace + 1) + merged + cleaned.slice(pluginsBlock.end);
590
692
  }
591
693
 
694
+ function pluginsDslAlreadyMatch(content: string, specs: readonly MeetSdkGradlePluginDslSpec[]): boolean {
695
+ const lines = content.split("\n");
696
+ return specs.every((spec) =>
697
+ lines.some((line) => {
698
+ if (extractPluginsDslId(line) !== spec.id) return false;
699
+ if (spec.version && !line.includes(`version '${spec.version}'`) && !line.includes(`version "${spec.version}"`)) {
700
+ return false;
701
+ }
702
+ if (spec.applyFalse && !/\bapply\s+false\b/.test(line)) return false;
703
+ return true;
704
+ })
705
+ );
706
+ }
707
+
592
708
  function stripBuildscriptClasspaths(content: string, classpaths: readonly string[]): string {
593
709
  if (!classpaths.length) return content;
594
710
  const buildscript = findBlockRange(content, "buildscript");
@@ -746,8 +862,10 @@ function buildRemoteDependenciesSnippet(config: MeetSdkRemoteConfig): string {
746
862
  function updateDefaultConfigApplicationId(content: string, defaultConfigBlock: { openBrace: number; end: number }, applicationId: string): string {
747
863
  const escaped = escapeGroovyDoubleQuotedInner(applicationId);
748
864
  const blockText = content.slice(defaultConfigBlock.openBrace + 1, defaultConfigBlock.end);
749
- const existing = /(^[ \t]*)applicationId\s+(?:=+\s*)?["'][^"']*["']/m;
750
- if (existing.test(blockText)) {
865
+ const existing = /(^[ \t]*)applicationId\s+(?:=+\s*)?(["'])([^"']*)\2/m;
866
+ const match = blockText.match(existing);
867
+ if (match) {
868
+ if (match[3] === applicationId) return content;
751
869
  const updatedBlockText = blockText.replace(existing, `$1applicationId "${escaped}"`);
752
870
  return content.slice(0, defaultConfigBlock.openBrace + 1) + updatedBlockText + content.slice(defaultConfigBlock.end);
753
871
  }
@@ -100,6 +100,16 @@ export const IOS_PLUGIN_FOLDER_BY_SUBKEY: Record<string, string> = {
100
100
  facebookdata: "FacebookManager",
101
101
  };
102
102
 
103
+ const IOS_PLUGIN_ORDER = [
104
+ "GuestSignin",
105
+ "UI",
106
+ "IAPPay",
107
+ "AppsFlyerManager",
108
+ "FacebookSignin",
109
+ "GoogleSignin",
110
+ "AppleSignin",
111
+ ] as const;
112
+
103
113
  export function enabledIosPluginFolders(config: MeetSdkRemoteConfig): string[] {
104
114
  const folders: string[] = ["UI"];
105
115
  for (const [scope, bucket] of Object.entries(config.sdkModules)) {
@@ -111,7 +121,13 @@ export function enabledIosPluginFolders(config: MeetSdkRemoteConfig): string[] {
111
121
  if (folder) folders.push(folder);
112
122
  }
113
123
  }
114
- return [...new Set(folders)];
124
+ const unique = [...new Set(folders)];
125
+ return unique.sort((a, b) => {
126
+ const ai = IOS_PLUGIN_ORDER.indexOf(a as (typeof IOS_PLUGIN_ORDER)[number]);
127
+ const bi = IOS_PLUGIN_ORDER.indexOf(b as (typeof IOS_PLUGIN_ORDER)[number]);
128
+ if (ai !== -1 || bi !== -1) return (ai === -1 ? Number.MAX_SAFE_INTEGER : ai) - (bi === -1 ? Number.MAX_SAFE_INTEGER : bi);
129
+ return unique.indexOf(a) - unique.indexOf(b);
130
+ });
115
131
  }
116
132
 
117
133
  export function unsupportedIosModuleKeys(config: MeetSdkRemoteConfig): string[] {