@seriousgaming/sdk-tools 1.5.0 → 1.6.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.
Files changed (160) hide show
  1. package/dist/bundling/ui-bundler.d.ts +12 -0
  2. package/dist/cli-25RWY5BQ.js +41 -0
  3. package/dist/cli-272KBNJH.js +97 -0
  4. package/dist/cli-2BH7FX27.js +52 -0
  5. package/dist/cli-2GOFEW26.js +81 -0
  6. package/dist/cli-3E3MD5U4.js +21 -0
  7. package/dist/cli-3HE4AVZG.js +115 -0
  8. package/dist/cli-4AKVLEC4.js +1387 -0
  9. package/dist/cli-4BV45LBH.js +126 -0
  10. package/dist/cli-4LKXZQ2B.js +48 -0
  11. package/dist/cli-4UWFQNGF.js +54 -0
  12. package/dist/cli-4YB3ROVR.js +78 -0
  13. package/dist/cli-57RXC3HQ.js +36 -0
  14. package/dist/cli-5JEGTVTG.js +96 -0
  15. package/dist/cli-6AMT3BUO.js +97 -0
  16. package/dist/cli-6RRVEGFB.js +80 -0
  17. package/dist/cli-6WXLXJVX.js +36 -0
  18. package/dist/cli-7OGYADZ3.js +97 -0
  19. package/dist/cli-AK7OIPWY.js +229 -0
  20. package/dist/cli-B4TN6PJP.js +124 -0
  21. package/dist/cli-B6YHEKIJ.js +248 -0
  22. package/dist/cli-BPYMTOUL.js +89 -0
  23. package/dist/cli-BWX5E7TQ.js +23 -0
  24. package/dist/cli-BYJWFFCF.js +37 -0
  25. package/dist/cli-C3NVCKO6.js +43 -0
  26. package/dist/cli-C47GJATR.js +42 -0
  27. package/dist/cli-C5QOJJWX.js +46 -0
  28. package/dist/cli-C6TH5S7K.js +6417 -0
  29. package/dist/cli-DL2CVMRF.js +89 -0
  30. package/dist/cli-DMW2OQIJ.js +76 -0
  31. package/dist/cli-DZW3XD5F.js +143 -0
  32. package/dist/cli-E2NLWIFE.js +1331 -0
  33. package/dist/cli-E33CJRRQ.js +36 -0
  34. package/dist/cli-E6DJIMYD.js +142 -0
  35. package/dist/cli-EEFJKIGL.js +151 -0
  36. package/dist/cli-EVFS55WN.js +185 -0
  37. package/dist/cli-F2D4GGUA.js +549 -0
  38. package/dist/cli-FBTRTIZJ.js +226 -0
  39. package/dist/cli-FWFRKQNE.js +11 -0
  40. package/dist/cli-FYINNRML.js +760 -0
  41. package/dist/cli-G522CPRL.js +88 -0
  42. package/dist/cli-G6KELFSX.js +2847 -0
  43. package/dist/cli-G6UE5NL4.js +90 -0
  44. package/dist/cli-GBFM76BF.js +16 -0
  45. package/dist/cli-GDQ6ILJY.js +101 -0
  46. package/dist/cli-GFBGYFYD.js +50 -0
  47. package/dist/cli-GGPDQNM3.js +35 -0
  48. package/dist/cli-GTSGLN3Z.js +307 -0
  49. package/dist/cli-GUXKQMJ7.js +13641 -0
  50. package/dist/cli-GXD36NF2.js +60 -0
  51. package/dist/cli-HCRTYQQS.js +16 -0
  52. package/dist/cli-HYY64SUD.js +185 -0
  53. package/dist/cli-I355WTAF.js +463 -0
  54. package/dist/cli-IDKYF5XB.js +59 -0
  55. package/dist/cli-ILKCQNM6.js +8 -0
  56. package/dist/cli-IRZ5KB7D.js +36 -0
  57. package/dist/cli-IUS2YCD3.js +31 -0
  58. package/dist/cli-J4DKUUTK.js +138 -0
  59. package/dist/cli-JFU22EJ2.js +187 -0
  60. package/dist/cli-JMZLT65J.js +226 -0
  61. package/dist/cli-JZM7XTNV.js +89 -0
  62. package/dist/cli-K2B6WHKA.js +81 -0
  63. package/dist/cli-KL3756X6.js +126 -0
  64. package/dist/cli-KNOOKGYW.js +88 -0
  65. package/dist/cli-LFGRFIEO.js +226 -0
  66. package/dist/cli-LFM7GJHI.js +0 -0
  67. package/dist/cli-LMDJCHHD.js +304 -0
  68. package/dist/cli-LXYPE3L5.js +99 -0
  69. package/dist/cli-M6BCQRID.js +153 -0
  70. package/dist/cli-MBNMPVDC.js +367 -0
  71. package/dist/cli-MJUYJIEP.js +13 -0
  72. package/dist/cli-MMN4BPO4.js +145 -0
  73. package/dist/cli-MYJGMA6U.js +40 -0
  74. package/dist/cli-N6H6T2E2.js +616 -0
  75. package/dist/cli-O5KP4OVN.js +61 -0
  76. package/dist/cli-O6PWMJTZ.js +25 -0
  77. package/dist/cli-ORIG557O.js +141 -0
  78. package/dist/cli-PFFCNGHI.js +243 -0
  79. package/dist/cli-PNLYX6R6.js +131 -0
  80. package/dist/cli-PQBXVLEU.js +649 -0
  81. package/dist/cli-PTT5RGKO.js +62 -0
  82. package/dist/cli-Q2XJF5AS.js +127 -0
  83. package/dist/cli-QEVDDBNO.js +60 -0
  84. package/dist/cli-QEVE5HUM.js +167 -0
  85. package/dist/cli-QUIJCBYB.js +391 -0
  86. package/dist/cli-QUNIRH7A.js +57 -0
  87. package/dist/cli-QVASWX2A.js +187 -0
  88. package/dist/cli-QWQMPCL6.js +253 -0
  89. package/dist/cli-R4PCG5YX.js +131 -0
  90. package/dist/cli-RA673NGF.js +53 -0
  91. package/dist/cli-RN6IWTL2.js +36 -0
  92. package/dist/cli-ROT3DRKU.js +145 -0
  93. package/dist/cli-RZITKPJX.js +367 -0
  94. package/dist/cli-S5IVGDDD.js +32 -0
  95. package/dist/cli-S5QDONIQ.js +218 -0
  96. package/dist/cli-SIPDUBFL.js +36 -0
  97. package/dist/cli-SMFSZF2G.js +4009 -0
  98. package/dist/cli-SRHBXZCN.js +159 -0
  99. package/dist/cli-TCY5LJ7E.js +88 -0
  100. package/dist/cli-TDSQSCX4.js +131 -0
  101. package/dist/cli-TIDQ4WUE.js +257 -0
  102. package/dist/cli-TLLA6KAP.js +79 -0
  103. package/dist/cli-TPU4TUR6.js +132 -0
  104. package/dist/cli-U2UE7I7J.js +30 -0
  105. package/dist/cli-UELGBQG7.js +101 -0
  106. package/dist/cli-UHSZBKYO.js +97 -0
  107. package/dist/cli-UJ4UCL2Z.js +38 -0
  108. package/dist/cli-UKQYZYFK.js +31 -0
  109. package/dist/cli-UMFFURZ7.js +81 -0
  110. package/dist/cli-UNAJ2OTE.js +15 -0
  111. package/dist/cli-UNJ5X6BU.js +89 -0
  112. package/dist/cli-UTJU4IYG.js +117 -0
  113. package/dist/cli-V4GHRWOV.js +1837 -0
  114. package/dist/cli-VCI3CG36.js +73 -0
  115. package/dist/cli-VCKOC2EV.js +256 -0
  116. package/dist/cli-VL2P354N.js +46 -0
  117. package/dist/cli-WAE26SVW.js +72 -0
  118. package/dist/cli-WOGIAU2E.js +100 -0
  119. package/dist/cli-WU43JT4T.js +52 -0
  120. package/dist/cli-XCO2VQOH.js +122 -0
  121. package/dist/cli-XSVGKI3R.js +39 -0
  122. package/dist/cli-YOTGR3NB.js +82 -0
  123. package/dist/cli-YVVXUD2G.js +197 -0
  124. package/dist/cli-ZISJ36MM.js +89 -0
  125. package/dist/cli-ZTWOE3ZT.js +65 -0
  126. package/dist/cli-ZVSFYDPQ.js +205 -0
  127. package/dist/cli-ZWPYIXNI.js +68 -0
  128. package/dist/cli.js +148 -43093
  129. package/dist/client/build-surfaces.d.ts +33 -0
  130. package/dist/client/dev-server.d.ts +6 -0
  131. package/dist/client/index.d.ts +1 -0
  132. package/dist/client/playwright.d.ts +62 -0
  133. package/dist/client.js +228 -48
  134. package/dist/core/session.d.ts +15 -1
  135. package/dist/dev/console/assets/{index-BVF8exas.js → index-CuMOOH9m.js} +1 -1
  136. package/dist/dev/console/index.html +1 -1
  137. package/dist/dev/shell.d.ts +19 -0
  138. package/dist/dev/surfaces.d.ts +7 -0
  139. package/dist/docs/api/index.md +14 -12
  140. package/dist/docs/api/sdk-tools-client.md +29 -0
  141. package/dist/docs/api/sdk-tools-playwright.md +104 -0
  142. package/dist/docs/changelog.md +19 -0
  143. package/dist/docs/cli-and-dev-server.md +21 -0
  144. package/dist/docs/cli-reference.md +45 -31
  145. package/dist/docs/environment-variables.md +6 -0
  146. package/dist/docs/guides/designing-a-game.md +29 -4
  147. package/dist/docs/guides/starter-game.md +2 -2
  148. package/dist/docs/guides/testing.md +33 -18
  149. package/dist/docs/page-index.md +8 -7
  150. package/dist/docs/recipes/e2e-testing.md +19 -20
  151. package/dist/playwright.js +32232 -0
  152. package/dist/templates/package/claude/rules/workflow-test-engine-or-ui.md +1 -1
  153. package/dist/templates/package/global-setup.ts.template +7 -18
  154. package/dist/templates/package/playwright.config.ts.liquid +8 -11
  155. package/dist/templates/starter-game/playwright.config.ts +8 -11
  156. package/dist/templates/starter-game/testing/e2e/game.spec.ts +1 -1
  157. package/dist/templates/starter-game/testing/e2e/global-setup.ts +7 -18
  158. package/dist/utils/prompt.d.ts +5 -5
  159. package/dist/utils/resource-scan.d.ts +39 -0
  160. package/package.json +7 -3
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ CliError
4
+ } from "./cli-N6H6T2E2.js";
5
+
6
+ // cli/dev/lockfile.ts
7
+ import { createHash, randomUUID } from "crypto";
8
+ import { existsSync as existsSync2 } from "fs";
9
+ import { mkdir, readFile, rm, writeFile } from "fs/promises";
10
+ import { hostname } from "os";
11
+ import { basename, dirname as dirname2, join as join2, resolve as resolve2 } from "path";
12
+
13
+ // cli/dev/tools-identity.ts
14
+ import { existsSync, readFileSync, realpathSync } from "fs";
15
+ import { dirname, join, resolve, sep } from "path";
16
+ import { fileURLToPath } from "url";
17
+ var cached = null;
18
+ function toolsIdentity() {
19
+ cached ??= readIdentity(fileURLToPath(import.meta.url));
20
+ return cached;
21
+ }
22
+ function readIdentity(filename) {
23
+ const here = dirname(filename);
24
+ const fromSource = filename.includes(`${sep}cli${sep}dev${sep}`);
25
+ const root = fromSource ? resolve(here, "..", "..") : resolve(here, "..");
26
+ const entry = fromSource ? join(root, "cli", "cli.ts") : join(here, "cli.js");
27
+ let version = "0.0.0";
28
+ try {
29
+ const manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf-8"));
30
+ version = manifest.version ?? version;
31
+ } catch {
32
+ }
33
+ return { version, path: existsSync(entry) ? realpathSync(entry) : entry };
34
+ }
35
+
36
+ // cli/dev/lockfile.ts
37
+ var DEV_STATE_DIR_ENV_VAR = "SERIOUSGAMING_DEV_STATE_DIR";
38
+ var ownInstances = /* @__PURE__ */ new Set();
39
+ function lockFilePath(packagePath, env = process.env) {
40
+ const stateDir = env[DEV_STATE_DIR_ENV_VAR]?.trim();
41
+ if (!stateDir) return join2(packagePath, ".seriousgaming-sdk", "session.json");
42
+ const absolute = resolve2(packagePath);
43
+ const key = createHash("sha256").update(absolute).digest("hex").slice(0, 12);
44
+ return join2(resolve2(stateDir), `${basename(absolute)}-${key}`, "session.json");
45
+ }
46
+ async function writeLockFile(packagePath, details) {
47
+ const path = lockFilePath(packagePath);
48
+ await mkdir(dirname2(path), { recursive: true });
49
+ const tools = toolsIdentity();
50
+ const lock = {
51
+ pid: process.pid,
52
+ port: details.port,
53
+ startedAt: (/* @__PURE__ */ new Date()).toISOString(),
54
+ toolsVersion: tools.version,
55
+ toolsPath: tools.path,
56
+ hostname: hostname(),
57
+ instanceId: details.instanceId,
58
+ background: details.background ?? false
59
+ };
60
+ ownInstances.add(details.instanceId);
61
+ await writeFile(path, `${JSON.stringify(lock, null, 4)}
62
+ `, "utf-8");
63
+ }
64
+ async function removeLockFile(packagePath, instanceId) {
65
+ if (instanceId !== void 0) ownInstances.delete(instanceId);
66
+ await rm(lockFilePath(packagePath), { force: true });
67
+ }
68
+ function newInstanceId() {
69
+ return randomUUID();
70
+ }
71
+ async function readLockFile(packagePath, options = {}) {
72
+ const inspection = await inspectLockFile(packagePath, options);
73
+ if (inspection.status === "live") return inspection.lock;
74
+ if (inspection.status === "unresponsive") {
75
+ if (options.unresponsive === "accept") return inspection.lock;
76
+ throw unresponsiveError(inspection.lock);
77
+ }
78
+ if (inspection.status === "stale") await rm(lockFilePath(packagePath), { force: true });
79
+ return null;
80
+ }
81
+ async function inspectLockFile(packagePath, options = {}) {
82
+ const path = lockFilePath(packagePath);
83
+ if (!existsSync2(path)) return { status: "none" };
84
+ let lock;
85
+ try {
86
+ lock = JSON.parse(await readFile(path, "utf-8"));
87
+ } catch {
88
+ return { status: "stale", reason: "unreadable" };
89
+ }
90
+ if (typeof lock.pid !== "number" || typeof lock.port !== "number") {
91
+ return { status: "stale", reason: "unreadable" };
92
+ }
93
+ const own = typeof lock.instanceId === "string" && ownInstances.has(lock.instanceId);
94
+ if (lock.pid === process.pid && !own) return { status: "stale", reason: "this-process" };
95
+ if (typeof lock.hostname === "string" && lock.hostname !== hostname()) {
96
+ return { status: "stale", reason: "other-host" };
97
+ }
98
+ if (!isAlive(lock.pid)) return { status: "stale", reason: "process-gone" };
99
+ const answer = await (options.probe ?? probeInstance)(lock.port);
100
+ if (answer === "refused") return { status: "stale", reason: "not-answering" };
101
+ if (answer === "unknown") return { status: "unresponsive", lock };
102
+ if (typeof lock.instanceId === "string" && answer !== lock.instanceId) {
103
+ return { status: "stale", reason: "other-instance" };
104
+ }
105
+ return { status: "live", lock };
106
+ }
107
+ var PROBE_TIMEOUT_MS = 5e3;
108
+ async function probeInstance(port, options = {}) {
109
+ try {
110
+ const response = await fetch(`http://localhost:${port}/api/session`, {
111
+ signal: AbortSignal.timeout(options.timeoutMs ?? PROBE_TIMEOUT_MS)
112
+ });
113
+ if (!response.ok) return null;
114
+ const body = await response.json().catch(() => ({}));
115
+ return typeof body.instanceId === "string" ? body.instanceId : null;
116
+ } catch (error) {
117
+ return refused(error) ? "refused" : "unknown";
118
+ }
119
+ }
120
+ function refused(error) {
121
+ const cause = error?.cause;
122
+ if (cause?.code === "ECONNREFUSED") return true;
123
+ return (cause?.errors ?? []).length > 0 ? (cause?.errors ?? []).every((inner) => inner.code === "ECONNREFUSED") : false;
124
+ }
125
+ function unresponsiveError(lock) {
126
+ return new CliError(
127
+ "DEV_SERVER_UNRESPONSIVE",
128
+ `The dev server for this package (pid ${lock.pid}, port ${lock.port}) accepts connections but did not answer within ${PROBE_TIMEOUT_MS / 1e3}s. Its logic is most likely stuck in a synchronous loop.`,
129
+ {
130
+ hint: "Stop it with `sdk dev stop`, which kills it if it does not exit, then run the command again."
131
+ }
132
+ );
133
+ }
134
+ async function lockOnDisk(packagePath) {
135
+ try {
136
+ return JSON.parse(await readFile(lockFilePath(packagePath), "utf-8"));
137
+ } catch {
138
+ return null;
139
+ }
140
+ }
141
+ function isAlive(pid) {
142
+ try {
143
+ process.kill(pid, 0);
144
+ return true;
145
+ } catch (error) {
146
+ return error.code === "EPERM";
147
+ }
148
+ }
149
+
150
+ export {
151
+ toolsIdentity,
152
+ writeLockFile,
153
+ removeLockFile,
154
+ newInstanceId,
155
+ readLockFile,
156
+ inspectLockFile,
157
+ lockOnDisk,
158
+ isAlive
159
+ };
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ deleteHookFiles,
4
+ findHookReferences
5
+ } from "./cli-FYINNRML.js";
6
+ import "./cli-IUS2YCD3.js";
7
+ import "./cli-QUNIRH7A.js";
8
+ import "./cli-BYJWFFCF.js";
9
+ import {
10
+ loadPackageContext
11
+ } from "./cli-XSVGKI3R.js";
12
+ import "./cli-MBNMPVDC.js";
13
+ import "./cli-GFBGYFYD.js";
14
+ import {
15
+ operationError,
16
+ recordOperationResult
17
+ } from "./cli-UELGBQG7.js";
18
+ import {
19
+ confirmAction
20
+ } from "./cli-ZTWOE3ZT.js";
21
+ import {
22
+ generateCommand
23
+ } from "./cli-4BV45LBH.js";
24
+ import "./cli-4AKVLEC4.js";
25
+ import "./cli-VCKOC2EV.js";
26
+ import "./cli-E2NLWIFE.js";
27
+ import "./cli-25RWY5BQ.js";
28
+ import "./cli-QWQMPCL6.js";
29
+ import "./cli-SMFSZF2G.js";
30
+ import "./cli-F2D4GGUA.js";
31
+ import {
32
+ logger
33
+ } from "./cli-4YB3ROVR.js";
34
+ import "./cli-N6H6T2E2.js";
35
+
36
+ // cli/commands/resources/hook/delete.ts
37
+ async function deleteHook(identifier, options) {
38
+ logger.info("\nDeleting hook...\n");
39
+ loadPackageContext(options.workingDir);
40
+ const references = findHookReferences({
41
+ packagePath: options.workingDir,
42
+ identifier
43
+ });
44
+ logger.info(`Hook: ${identifier}`);
45
+ if (references.length > 0) {
46
+ logger.info("\nThis hook is referenced in:");
47
+ for (const ref of references) {
48
+ logger.info(` - ${ref}`);
49
+ }
50
+ logger.info("\nThese references will be removed.");
51
+ }
52
+ const confirmed = await confirmAction(
53
+ { message: "Are you sure you want to delete this hook?" },
54
+ options.yes
55
+ );
56
+ if (!confirmed) {
57
+ logger.info("\nDeletion cancelled.\n");
58
+ return;
59
+ }
60
+ logger.info("");
61
+ const result = deleteHookFiles({
62
+ packagePath: options.workingDir,
63
+ identifier
64
+ });
65
+ if (!result.success) {
66
+ throw operationError(result, "Failed to delete hook files");
67
+ }
68
+ recordOperationResult(result);
69
+ for (const file of result.filesDeleted || []) {
70
+ logger.info(` \u2713 Deleted: ${file}`);
71
+ }
72
+ for (const ref of result.referencesRemoved || []) {
73
+ logger.info(` \u2713 Removed reference from: ${ref}`);
74
+ }
75
+ logger.info(" \u2713 Updated seriousgaming.sdk.json");
76
+ logger.info("\nRegenerating TypeScript types...\n");
77
+ try {
78
+ await generateCommand({ workingDir: options.workingDir });
79
+ logger.success("TypeScript types regenerated successfully!");
80
+ } catch (error) {
81
+ logger.warn("\nWarning: Failed to regenerate TypeScript types:");
82
+ logger.warn(error instanceof Error ? error.message : "Unknown error");
83
+ }
84
+ logger.success("Hook deleted successfully!");
85
+ }
86
+ export {
87
+ deleteHook
88
+ };
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ loadGlobalSettings
4
+ } from "./cli-MMN4BPO4.js";
5
+
6
+ // cli/utils/env-loader.ts
7
+ import { readFileSync, existsSync } from "fs";
8
+ import { join } from "path";
9
+ function parseEnvFile(content) {
10
+ const vars = {};
11
+ const lines = content.split(/\r?\n/);
12
+ for (const line of lines) {
13
+ const trimmed = line.trim();
14
+ if (!trimmed || trimmed.startsWith("#")) {
15
+ continue;
16
+ }
17
+ const match = trimmed.match(/^([A-Z_][A-Z0-9_]*)=(.*)$/i);
18
+ if (match) {
19
+ const key = match[1];
20
+ let value = match[2];
21
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
22
+ value = value.slice(1, -1);
23
+ }
24
+ vars[key] = value;
25
+ }
26
+ }
27
+ return vars;
28
+ }
29
+ function loadEnvironmentConfig(workingDir, flags) {
30
+ const config = {};
31
+ const ttsVoicePresets = {};
32
+ applyGlobalSettings(config);
33
+ const envPath = join(workingDir, ".env");
34
+ if (existsSync(envPath)) {
35
+ try {
36
+ const content = readFileSync(envPath, "utf-8");
37
+ const envVars = parseEnvFile(content);
38
+ if (envVars.ELEVENLABS_API_KEY) {
39
+ config.elevenLabsApiKey = envVars.ELEVENLABS_API_KEY;
40
+ }
41
+ if (envVars.TTS_MODEL_QUICK) {
42
+ config.ttsQuickModel = envVars.TTS_MODEL_QUICK;
43
+ }
44
+ if (envVars.TTS_MODEL_STANDARD) {
45
+ config.ttsStandardModel = envVars.TTS_MODEL_STANDARD;
46
+ }
47
+ if (envVars.TTS_MODEL_EXPERT) {
48
+ config.ttsExpertModel = envVars.TTS_MODEL_EXPERT;
49
+ }
50
+ if (envVars.SERIOUSGAMING_API_KEY) {
51
+ config.seriousGamingApiKey = envVars.SERIOUSGAMING_API_KEY;
52
+ }
53
+ if (envVars.SERIOUSGAMING_API_HOST) {
54
+ config.seriousGamingApiHost = envVars.SERIOUSGAMING_API_HOST;
55
+ }
56
+ if (envVars.SERIOUSGAMING_PUBLISHER) {
57
+ config.defaultPublisher = envVars.SERIOUSGAMING_PUBLISHER;
58
+ }
59
+ collectVoicePresets(envVars, ttsVoicePresets);
60
+ } catch (error) {
61
+ console.warn(
62
+ "Warning: Failed to read .env file:",
63
+ error instanceof Error ? error.message : "Unknown error"
64
+ );
65
+ }
66
+ }
67
+ if (process.env.ELEVENLABS_API_KEY) {
68
+ config.elevenLabsApiKey = process.env.ELEVENLABS_API_KEY;
69
+ }
70
+ if (process.env.TTS_MODEL_QUICK) {
71
+ config.ttsQuickModel = process.env.TTS_MODEL_QUICK;
72
+ }
73
+ if (process.env.TTS_MODEL_STANDARD) {
74
+ config.ttsStandardModel = process.env.TTS_MODEL_STANDARD;
75
+ }
76
+ if (process.env.TTS_MODEL_EXPERT) {
77
+ config.ttsExpertModel = process.env.TTS_MODEL_EXPERT;
78
+ }
79
+ if (process.env.SERIOUSGAMING_API_KEY) {
80
+ config.seriousGamingApiKey = process.env.SERIOUSGAMING_API_KEY;
81
+ }
82
+ if (process.env.SERIOUSGAMING_API_HOST) {
83
+ config.seriousGamingApiHost = process.env.SERIOUSGAMING_API_HOST;
84
+ }
85
+ if (process.env.SERIOUSGAMING_PUBLISHER) {
86
+ config.defaultPublisher = process.env.SERIOUSGAMING_PUBLISHER;
87
+ }
88
+ collectVoicePresets(process.env, ttsVoicePresets);
89
+ if (flags?.seriousGamingApiKey) {
90
+ config.seriousGamingApiKey = flags.seriousGamingApiKey;
91
+ }
92
+ if (flags?.seriousGamingApiHost) {
93
+ config.seriousGamingApiHost = flags.seriousGamingApiHost;
94
+ }
95
+ if (flags?.defaultPublisher) {
96
+ config.defaultPublisher = flags.defaultPublisher;
97
+ }
98
+ if (Object.keys(ttsVoicePresets).length > 0) {
99
+ config.ttsVoicePresets = ttsVoicePresets;
100
+ }
101
+ return config;
102
+ }
103
+ function applyGlobalSettings(config) {
104
+ const settings = loadGlobalSettings();
105
+ if (settings.elevenLabs?.apiKey) {
106
+ config.elevenLabsApiKey = settings.elevenLabs.apiKey;
107
+ }
108
+ if (settings.platform?.apiHost) {
109
+ config.seriousGamingApiHost = settings.platform.apiHost;
110
+ }
111
+ if (settings.platform?.apiKey) {
112
+ config.seriousGamingApiKey = settings.platform.apiKey;
113
+ }
114
+ if (settings.platform?.defaultPublisher) {
115
+ config.defaultPublisher = settings.platform.defaultPublisher;
116
+ }
117
+ }
118
+ function collectVoicePresets(source, target) {
119
+ const prefix = "TTS_VOICE_";
120
+ for (const [key, value] of Object.entries(source)) {
121
+ if (!key.startsWith(prefix)) continue;
122
+ if (!value) continue;
123
+ const preset = key.slice(prefix.length).toLowerCase();
124
+ if (!preset) continue;
125
+ target[preset] = value;
126
+ }
127
+ }
128
+
129
+ export {
130
+ loadEnvironmentConfig
131
+ };
@@ -0,0 +1,257 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ resolveDocsPath
4
+ } from "./cli-UNAJ2OTE.js";
5
+ import {
6
+ CliError,
7
+ reportResult
8
+ } from "./cli-N6H6T2E2.js";
9
+
10
+ // cli/commands/docs.ts
11
+ import { readFileSync as readFileSync2, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
12
+ import { existsSync } from "fs";
13
+ import { join as join2, resolve } from "path";
14
+
15
+ // cli/docs-reference/anchors.ts
16
+ var ATX_HEADING = /^ {0,3}#{1,6}\s+(.*?)\s*#*\s*$/;
17
+ function slug(text) {
18
+ return text.replace(/<[^>]+>/g, "").replace(/!?\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/[*_`~]/g, (character) => character === "_" ? "_" : "").trim().toLowerCase().replace(/[^\p{L}\p{M}\p{N}\p{Pc}\- ]/gu, "").replace(/ /g, "-");
19
+ }
20
+ function atxHeadingText(line) {
21
+ return ATX_HEADING.exec(line)?.[1];
22
+ }
23
+ function createAnchorSlugger() {
24
+ const seen = /* @__PURE__ */ new Map();
25
+ return (headingText2) => {
26
+ const base = slug(headingText2);
27
+ const count = seen.get(base) ?? 0;
28
+ seen.set(base, count + 1);
29
+ return count === 0 ? base : `${base}-${count}`;
30
+ };
31
+ }
32
+
33
+ // cli/docs-reference/outline.ts
34
+ var FENCE = /^\s*(`{3,}|~{3,})/;
35
+ function headingText(raw) {
36
+ return raw.replace(/<[^>]+>/g, "").replace(/!?\[([^\]]*)\]\([^)]*\)/g, "$1").trim();
37
+ }
38
+ function readOutline(markdown) {
39
+ const slugFor = createAnchorSlugger();
40
+ const headings = [];
41
+ let fence;
42
+ let offset = 0;
43
+ const lines = markdown.split("\n");
44
+ lines.forEach((line, index) => {
45
+ const start = offset;
46
+ offset += line.length + 1;
47
+ const opener = FENCE.exec(line);
48
+ if (fence) {
49
+ const closes = opener && opener[1][0] === fence.marker && opener[1].length >= fence.size && line.trim() === opener[1];
50
+ if (closes) fence = void 0;
51
+ return;
52
+ }
53
+ if (opener) {
54
+ fence = { marker: opener[1][0], size: opener[1].length };
55
+ return;
56
+ }
57
+ const raw = atxHeadingText(line);
58
+ if (raw === void 0) return;
59
+ headings.push({
60
+ level: /^ {0,3}(#+)/.exec(line)?.[1].length ?? 1,
61
+ text: headingText(raw),
62
+ slug: slugFor(raw),
63
+ line: index + 1,
64
+ start
65
+ });
66
+ });
67
+ return headings.map((heading, index) => {
68
+ const next = headings.slice(index + 1).find((candidate) => candidate.level <= heading.level);
69
+ const end = next ? next.start : markdown.length;
70
+ return { ...heading, end, length: end - heading.start };
71
+ });
72
+ }
73
+ function normalise(text) {
74
+ return text.replace(/[`*_]/g, "").replace(/\s+/g, " ").trim().toLowerCase();
75
+ }
76
+ function findSections(outline, query) {
77
+ const wanted = query.trim().replace(/^#/, "");
78
+ const bySlug = outline.filter((heading) => heading.slug === wanted.toLowerCase());
79
+ if (bySlug.length > 0) return bySlug;
80
+ return outline.filter((heading) => normalise(heading.text) === normalise(wanted));
81
+ }
82
+
83
+ // cli/docs-reference/page-index.ts
84
+ import { readdirSync, readFileSync, statSync } from "node:fs";
85
+ import { join, posix, relative, sep } from "node:path";
86
+ var PAGE_INDEX = "page-index.md";
87
+
88
+ // cli/commands/docs.ts
89
+ function buildFileTree(dir, basePath = "") {
90
+ try {
91
+ const entries = readdirSync2(dir);
92
+ const nodes = [];
93
+ for (const entry of entries) {
94
+ if (entry.startsWith(".") || entry === "node_modules") {
95
+ continue;
96
+ }
97
+ const fullPath = join2(dir, entry);
98
+ const relativePath = basePath ? join2(basePath, entry) : entry;
99
+ const stat = statSync2(fullPath);
100
+ if (stat.isDirectory()) {
101
+ nodes.push({
102
+ name: entry,
103
+ path: relativePath,
104
+ isDir: true,
105
+ children: buildFileTree(fullPath, relativePath)
106
+ });
107
+ } else if (entry.endsWith(".md")) {
108
+ nodes.push({
109
+ name: entry,
110
+ path: relativePath,
111
+ isDir: false,
112
+ children: []
113
+ });
114
+ }
115
+ }
116
+ return nodes.sort((a, b) => {
117
+ if (a.isDir !== b.isDir) {
118
+ return a.isDir ? -1 : 1;
119
+ }
120
+ return a.name.localeCompare(b.name);
121
+ });
122
+ } catch {
123
+ return [];
124
+ }
125
+ }
126
+ function formatTree(nodes, prefix = "") {
127
+ const lines = [];
128
+ nodes.forEach((node, index) => {
129
+ const isLastNode = index === nodes.length - 1;
130
+ const connector = isLastNode ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
131
+ const icon = node.isDir ? "\u{1F4C1} " : "\u{1F4C4} ";
132
+ lines.push(prefix + connector + icon + node.name);
133
+ if (node.isDir && node.children.length > 0) {
134
+ const extension = isLastNode ? " " : "\u2502 ";
135
+ const childLines = formatTree(node.children, prefix + extension);
136
+ lines.push(...childLines);
137
+ }
138
+ });
139
+ return lines;
140
+ }
141
+ function filePaths(nodes) {
142
+ return nodes.flatMap((node) => node.isDir ? filePaths(node.children) : [node.path]);
143
+ }
144
+ function printTree(docsPath) {
145
+ const fileTree = buildFileTree(docsPath);
146
+ reportResult({ files: filePaths(fileTree), index: PAGE_INDEX }, () => {
147
+ if (fileTree.length === 0) {
148
+ console.log("No documentation files found. Create .md files in the docs/ directory.");
149
+ return;
150
+ }
151
+ console.log("\n\u{1F4DA} Serious Gaming SDK Documentation\n");
152
+ console.log("docs/");
153
+ formatTree(fileTree).forEach((line) => console.log(line));
154
+ console.log(
155
+ "\nStart at page-index.md: every page with a one-sentence summary and its length.\n\nUsage: pnpm run sdk docs view <file-path> [--outline | --section <heading>]\nExample: pnpm run sdk docs view page-index.md\nExample: pnpm run sdk docs view guides/engine.md --outline\n"
156
+ );
157
+ });
158
+ }
159
+ function readDocFile(docsPath, filePath) {
160
+ const resolved = resolve(join2(docsPath, filePath));
161
+ if (!resolved.startsWith(resolve(docsPath))) {
162
+ throw new CliError("USAGE_BAD_ARGUMENT", "Invalid file path: it is outside the docs");
163
+ }
164
+ if (!resolved.endsWith(".md")) {
165
+ throw new CliError("USAGE_BAD_ARGUMENT", "Only .md files are supported");
166
+ }
167
+ try {
168
+ return readFileSync2(resolved, "utf-8");
169
+ } catch (error) {
170
+ if (error.code === "ENOENT") {
171
+ throw new CliError("FILE_NOT_FOUND", `File not found: ${filePath}`, {
172
+ hint: 'Run "pnpm run sdk docs view" to see available files.'
173
+ });
174
+ }
175
+ throw new CliError("FILE_NOT_FOUND", `Error reading file: ${error.message}`);
176
+ }
177
+ }
178
+ function describeHeading({ level, text, slug: slug2, length }) {
179
+ return { level, text, slug: slug2, length };
180
+ }
181
+ function printOutline(filePath, content) {
182
+ const headings = readOutline(content).map(describeHeading);
183
+ reportResult({ file: filePath, length: content.length, headings }, () => {
184
+ console.log(`${filePath} (${content.length.toLocaleString("en-GB")} characters)
185
+ `);
186
+ for (const heading of headings) {
187
+ const indent = " ".repeat(heading.level - 1);
188
+ console.log(
189
+ `${indent}${"#".repeat(heading.level)} ${heading.text} [${heading.slug}, ${heading.length.toLocaleString("en-GB")} characters]`
190
+ );
191
+ }
192
+ console.log(
193
+ `
194
+ Read one section with: pnpm run sdk docs view ${filePath} --section <slug or heading>`
195
+ );
196
+ });
197
+ }
198
+ function printSection(filePath, content, query) {
199
+ const outline = readOutline(content);
200
+ const matches = findSections(outline, query);
201
+ const available = outline.map((heading2) => heading2.slug);
202
+ if (matches.length === 0) {
203
+ throw new CliError("DOCS_SECTION_NOT_FOUND", `${filePath} has no section '${query}'`, {
204
+ hint: `Run "pnpm run sdk docs view ${filePath} --outline" to see its sections.`,
205
+ details: { file: filePath, section: query, available }
206
+ });
207
+ }
208
+ if (matches.length > 1) {
209
+ throw new CliError(
210
+ "USAGE_BAD_FLAG",
211
+ `More than one section of ${filePath} is headed '${query}': ` + matches.map((heading2) => heading2.slug).join(", "),
212
+ {
213
+ hint: "Name the section by its slug instead.",
214
+ details: { file: filePath, section: query, matches: matches.map((h) => h.slug) }
215
+ }
216
+ );
217
+ }
218
+ const [heading] = matches;
219
+ const section = `${content.slice(heading.start, heading.end).trimEnd()}
220
+ `;
221
+ reportResult(
222
+ { file: filePath, heading: describeHeading(heading), content: section },
223
+ () => console.log(section)
224
+ );
225
+ }
226
+ async function docsCommand(filePath, options = {}) {
227
+ const docsPath = resolveDocsPath();
228
+ if (!existsSync(docsPath)) {
229
+ throw new CliError(
230
+ "SDK_INCOMPLETE",
231
+ "Documentation files not found. Make sure the SDK is properly installed."
232
+ );
233
+ }
234
+ if (options.outline && options.section !== void 0) {
235
+ throw new CliError("USAGE_BAD_FLAG", "--outline and --section cannot be combined", {
236
+ hint: "Read the outline first, then ask for one of its sections."
237
+ });
238
+ }
239
+ if (!filePath) {
240
+ if (options.outline || options.section !== void 0) {
241
+ throw new CliError(
242
+ "USAGE_MISSING_ARGUMENT",
243
+ `${options.outline ? "--outline" : "--section"} needs a page to read`,
244
+ { hint: `Name one, such as ${PAGE_INDEX} or guides/engine.md.` }
245
+ );
246
+ }
247
+ printTree(docsPath);
248
+ return;
249
+ }
250
+ const content = readDocFile(docsPath, filePath);
251
+ if (options.outline) printOutline(filePath, content);
252
+ else if (options.section !== void 0) printSection(filePath, content, options.section);
253
+ else reportResult({ file: filePath, content }, () => console.log(content));
254
+ }
255
+ export {
256
+ docsCommand
257
+ };