Skip to content

Commit 7ba74d1

Browse files
authored
Merge pull request #11 from SpawnDock/codex/dev-tunnel-log-telegram-tma-link
feat(dev-tunnel): print telegram TMA link during startup
2 parents 3ecf56c + eadc509 commit 7ba74d1

4 files changed

Lines changed: 83 additions & 11 deletions

File tree

src/__tests__/config.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,21 @@ describe("resolveConfig", () => {
7070
const config = resolveConfig([], dir);
7171
expect(config.previewPath).toBe("/preview/my-app");
7272
});
73+
74+
it("reads telegramMiniAppUrl from legacy spawndock.config.json", () => {
75+
const dir = mkdtempSync(join(tmpdir(), "spawndock-config-"));
76+
writeFileSync(
77+
join(dir, "spawndock.config.json"),
78+
JSON.stringify({
79+
controlPlaneUrl: "http://localhost:8787",
80+
projectSlug: "my-app",
81+
deviceSecret: "secret123",
82+
localPort: 4010,
83+
telegramMiniAppUrl: "https://t.me/TMASpawnerBot/tma?startapp=my-app",
84+
}),
85+
);
86+
87+
const config = resolveConfig([], dir);
88+
expect(config.telegramMiniAppUrl).toBe("https://t.me/TMASpawnerBot/tma?startapp=my-app");
89+
});
7390
});

src/__tests__/index.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { describe, expect, it } from "vitest";
2+
import { buildStartupMessages } from "../index.js";
3+
4+
describe("buildStartupMessages", () => {
5+
it("prints the tunnel target and Telegram link when available", () => {
6+
expect(buildStartupMessages({
7+
controlPlane: "https://spawn-dock.w3voice.net",
8+
projectSlug: "demo-app",
9+
deviceSecret: "secret_123",
10+
port: 3001,
11+
telegramMiniAppUrl: "https://t.me/TMASpawnerBot/tma?startapp=demo-app",
12+
})).toEqual([
13+
"SpawnDock dev tunnel: demo-app -> http://127.0.0.1:3001",
14+
"TMA URL: https://t.me/TMASpawnerBot/tma?startapp=demo-app",
15+
]);
16+
});
17+
18+
it("omits the Telegram link when the config does not include one", () => {
19+
expect(buildStartupMessages({
20+
controlPlane: "https://spawn-dock.w3voice.net",
21+
projectSlug: "demo-app",
22+
deviceSecret: "secret_123",
23+
port: 3001,
24+
})).toEqual([
25+
"SpawnDock dev tunnel: demo-app -> http://127.0.0.1:3001",
26+
]);
27+
});
28+
});

src/config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface TunnelConfig {
77
deviceSecret: string;
88
port: number;
99
previewPath?: string;
10+
telegramMiniAppUrl?: string;
1011
}
1112

1213
const PRIMARY_CONFIG_FILE = "spawndock.dev-tunnel.json";
@@ -49,8 +50,10 @@ function normalizeConfig(data: unknown): Partial<TunnelConfig> {
4950
: undefined;
5051
const previewPath =
5152
typeof record.previewPath === "string" ? record.previewPath : undefined;
53+
const telegramMiniAppUrl =
54+
typeof record.telegramMiniAppUrl === "string" ? record.telegramMiniAppUrl : undefined;
5255

53-
return { controlPlane, projectSlug, deviceSecret, port, previewPath };
56+
return { controlPlane, projectSlug, deviceSecret, port, previewPath, telegramMiniAppUrl };
5457
}
5558

5659
function readConfigFile(dir: string): Partial<TunnelConfig> {
@@ -145,10 +148,11 @@ export function resolveConfig(
145148
const deviceSecret = args.deviceSecret ?? env.deviceSecret ?? file.deviceSecret;
146149
const port = args.port ?? env.port ?? file.port ?? 3000;
147150
const previewPath = file.previewPath;
151+
const telegramMiniAppUrl = file.telegramMiniAppUrl;
148152

149153
if (!controlPlane) throw new Error("Missing --control-plane or SPAWNDOCK_CONTROL_PLANE");
150154
if (!projectSlug) throw new Error("Missing --project-slug or SPAWNDOCK_PROJECT_SLUG");
151155
if (!deviceSecret) throw new Error("Missing --device-secret or SPAWNDOCK_DEVICE_SECRET");
152156

153-
return { controlPlane, projectSlug, deviceSecret, port, previewPath };
157+
return { controlPlane, projectSlug, deviceSecret, port, previewPath, telegramMiniAppUrl };
154158
}

src/index.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
11
#!/usr/bin/env node
2-
import { resolveConfig } from "./config.js";
2+
import { pathToFileURL } from "node:url";
3+
import { resolveConfig, type TunnelConfig } from "./config.js";
34
import { createTunnel } from "./tunnel.js";
45

5-
try {
6-
const config = resolveConfig();
7-
console.log(
6+
export function buildStartupMessages(config: TunnelConfig): string[] {
7+
const lines = [
88
`SpawnDock dev tunnel: ${config.projectSlug} -> http://127.0.0.1:${config.port}`,
9-
);
10-
createTunnel(config);
11-
} catch (err: any) {
12-
console.error(`Error: ${err.message}`);
13-
process.exit(1);
9+
];
10+
11+
if (typeof config.telegramMiniAppUrl === "string" && config.telegramMiniAppUrl.length > 0) {
12+
lines.push(`TMA URL: ${config.telegramMiniAppUrl}`);
13+
}
14+
15+
return lines;
16+
}
17+
18+
export function runCli(): void {
19+
try {
20+
const config = resolveConfig();
21+
for (const line of buildStartupMessages(config)) {
22+
console.log(line);
23+
}
24+
createTunnel(config);
25+
} catch (err: any) {
26+
console.error(`Error: ${err.message}`);
27+
process.exit(1);
28+
}
29+
}
30+
31+
const currentEntrypoint = process.argv[1]
32+
? pathToFileURL(process.argv[1]).href
33+
: "";
34+
35+
if (currentEntrypoint === import.meta.url) {
36+
runCli();
1437
}

0 commit comments

Comments
 (0)