ludicord 2.2.5 → 3.0.1
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/README.md +6 -4
- package/dist/activity/game-loop.d.ts +16 -0
- package/dist/activity/game-loop.js +33 -0
- package/dist/activity/index.d.ts +12 -0
- package/dist/activity/index.js +6 -0
- package/dist/activity/lifecycle.d.ts +11 -0
- package/dist/activity/lifecycle.js +41 -0
- package/dist/activity/presence.d.ts +10 -0
- package/dist/activity/presence.js +15 -0
- package/dist/activity/query.d.ts +21 -0
- package/dist/activity/query.js +148 -0
- package/dist/activity/shared-state.d.ts +10 -0
- package/dist/activity/shared-state.js +100 -0
- package/dist/activity/storage.d.ts +16 -0
- package/dist/activity/storage.js +88 -0
- package/dist/api/runtime.d.ts +5 -2
- package/dist/api/runtime.js +53 -10
- package/dist/auth/client.d.ts +0 -1
- package/dist/auth/client.js +3 -5
- package/dist/auth/index.d.ts +0 -1
- package/dist/auth/index.js +0 -1
- package/dist/auth/server.d.ts +2 -1
- package/dist/auth/server.js +161 -16
- package/dist/auth/types.d.ts +5 -1
- package/dist/auth/types.js +0 -1
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +116 -19
- package/dist/cli/project-commands.d.ts +1 -5
- package/dist/cli/project-commands.js +14 -162
- package/dist/compiler/build.d.ts +10 -1
- package/dist/compiler/build.js +124 -16
- package/dist/compiler/bundle-report.d.ts +17 -0
- package/dist/compiler/bundle-report.js +60 -0
- package/dist/compiler/client-entry.d.ts +0 -1
- package/dist/compiler/client-entry.js +28 -4
- package/dist/compiler/client-tooling.d.ts +0 -1
- package/dist/compiler/client-tooling.js +8 -2
- package/dist/compiler/index.d.ts +3 -1
- package/dist/compiler/index.js +2 -1
- package/dist/compiler/scanner.d.ts +0 -1
- package/dist/compiler/scanner.js +59 -4
- package/dist/compiler/server-bundle.d.ts +1 -2
- package/dist/compiler/server-bundle.js +11 -2
- package/dist/compiler/type-generation.d.ts +0 -1
- package/dist/compiler/type-generation.js +2 -1
- package/dist/compiler/write-manifests.d.ts +0 -1
- package/dist/compiler/write-manifests.js +0 -1
- package/dist/config/defaults.d.ts +0 -1
- package/dist/config/defaults.js +14 -2
- package/dist/config/environment.d.ts +0 -1
- package/dist/config/environment.js +0 -1
- package/dist/config/index.d.ts +0 -1
- package/dist/config/index.js +0 -1
- package/dist/config/loader.d.ts +0 -1
- package/dist/config/loader.js +0 -1
- package/dist/config/project-root.d.ts +0 -1
- package/dist/config/project-root.js +0 -1
- package/dist/config/types.d.ts +25 -1
- package/dist/config/types.js +0 -1
- package/dist/discord/assets.d.ts +5 -0
- package/dist/discord/assets.js +29 -0
- package/dist/discord/data.d.ts +38 -2
- package/dist/discord/data.js +178 -11
- package/dist/discord/events.d.ts +28 -2
- package/dist/discord/events.js +109 -39
- package/dist/discord/index.d.ts +6 -5
- package/dist/discord/index.js +3 -3
- package/dist/discord/payload.d.ts +6 -0
- package/dist/discord/payload.js +5 -0
- package/dist/discord/runtime.d.ts +0 -1
- package/dist/discord/runtime.js +0 -1
- package/dist/discord/safe-area.d.ts +0 -1
- package/dist/discord/safe-area.js +0 -1
- package/dist/discord/testing.d.ts +0 -1
- package/dist/discord/testing.js +0 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +3 -1
- package/dist/lint/index.d.ts +6 -0
- package/dist/lint/index.js +71 -0
- package/dist/manifests/types.d.ts +11 -1
- package/dist/manifests/types.js +0 -1
- package/dist/metadata/index.d.ts +13 -0
- package/dist/metadata/index.js +4 -0
- package/dist/navigation/index.d.ts +3 -1
- package/dist/navigation/index.js +1 -1
- package/dist/navigation/link.d.ts +8 -0
- package/dist/navigation/link.js +38 -0
- package/dist/router/match.d.ts +0 -1
- package/dist/router/match.js +0 -1
- package/dist/runtime/client/dev-panel.d.ts +0 -1
- package/dist/runtime/client/dev-panel.js +722 -38
- package/dist/runtime/client/embed-router.d.ts +8 -1
- package/dist/runtime/client/embed-router.js +116 -62
- package/dist/runtime/client/files.d.ts +5 -1
- package/dist/runtime/client/files.js +0 -1
- package/dist/runtime/client/minimize-card.d.ts +0 -1
- package/dist/runtime/client/minimize-card.js +0 -1
- package/dist/runtime/client/minimize.d.ts +0 -1
- package/dist/runtime/client/minimize.js +0 -1
- package/dist/runtime/client/root.d.ts +5 -3
- package/dist/runtime/client/root.js +28 -3
- package/dist/runtime/index.d.ts +1 -2
- package/dist/runtime/index.js +0 -1
- package/dist/runtime/server/dev-server.d.ts +0 -1
- package/dist/runtime/server/dev-server.js +187 -30
- package/dist/runtime/server/diagnostics.d.ts +1 -1
- package/dist/runtime/server/diagnostics.js +5 -4
- package/dist/runtime/server/index.d.ts +0 -1
- package/dist/runtime/server/index.js +0 -1
- package/dist/runtime/server/production-server.d.ts +2 -1
- package/dist/runtime/server/production-server.js +145 -25
- package/dist/security/discord.d.ts +0 -1
- package/dist/security/discord.js +0 -1
- package/dist/security/index.d.ts +0 -1
- package/dist/security/index.js +0 -1
- package/dist/security/secret-scan.d.ts +0 -1
- package/dist/security/secret-scan.js +0 -1
- package/dist/server/discord-rest.d.ts +42 -7
- package/dist/server/discord-rest.js +135 -18
- package/dist/server/index.d.ts +7 -2
- package/dist/server/index.js +3 -1
- package/dist/server/instrumentation.d.ts +16 -0
- package/dist/server/instrumentation.js +3 -0
- package/dist/server/proxy.d.ts +21 -0
- package/dist/server/proxy.js +76 -0
- package/dist/server/session.d.ts +0 -1
- package/dist/server/session.js +0 -1
- package/dist/server/types.d.ts +0 -1
- package/dist/server/types.js +0 -1
- package/dist/sessions/cookies.d.ts +0 -1
- package/dist/sessions/cookies.js +0 -1
- package/dist/sessions/crypto.d.ts +0 -1
- package/dist/sessions/crypto.js +0 -1
- package/dist/sessions/data-store.d.ts +18 -0
- package/dist/sessions/data-store.js +45 -0
- package/dist/shared/errors.d.ts +0 -1
- package/dist/shared/errors.js +0 -1
- package/dist/testing/index.d.ts +0 -1
- package/dist/testing/index.js +2 -2
- package/dist/version.d.ts +1 -2
- package/dist/version.js +1 -2
- package/dist/ws/client.d.ts +0 -1
- package/dist/ws/client.js +0 -1
- package/dist/ws/index.d.ts +3 -2
- package/dist/ws/index.js +1 -1
- package/dist/ws/server.d.ts +5 -3
- package/dist/ws/server.js +65 -19
- package/dist/ws/shared-state.d.ts +13 -0
- package/dist/ws/shared-state.js +137 -0
- package/package.json +14 -1
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
|
+
import { unwatchFile, watchFile } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
4
6
|
import { redact } from "../runtime/server/diagnostics.js";
|
|
5
7
|
import { loadProjectEnvironment } from "../config/environment.js";
|
|
6
8
|
import { loadLudicordConfig } from "../config/loader.js";
|
|
@@ -8,8 +10,9 @@ import { resolveProjectRoot } from "../config/project-root.js";
|
|
|
8
10
|
import { buildLudicordProject } from "../compiler/build.js";
|
|
9
11
|
import { createLudicordDevServer } from "../runtime/server/dev-server.js";
|
|
10
12
|
import { createLudicordProductionServer } from "../runtime/server/production-server.js";
|
|
11
|
-
import { cleanLudicordBuild, formatInfo, formatRoutes,
|
|
13
|
+
import { cleanLudicordBuild, formatBundleAnalysis, formatInfo, formatRoutes, } from "./project-commands.js";
|
|
12
14
|
import { LUDICORD_VERSION } from "../version.js";
|
|
15
|
+
import { lintLudicordProject } from "../lint/index.js";
|
|
13
16
|
const HELP = `Ludicord ${LUDICORD_VERSION}
|
|
14
17
|
Discord Activity Framework
|
|
15
18
|
|
|
@@ -26,8 +29,9 @@ Commands:
|
|
|
26
29
|
dev Start the development server
|
|
27
30
|
build Create a production .ludicord build
|
|
28
31
|
start Run an existing production build
|
|
29
|
-
routes List Activity, embed, API, and
|
|
30
|
-
|
|
32
|
+
routes List Activity, embed, API, WebSocket, and proxy routes
|
|
33
|
+
lint Validate React Hooks in Activity source
|
|
34
|
+
analyze Inspect production client bundle sizes
|
|
31
35
|
info Print environment and project information
|
|
32
36
|
clean Remove the .ludicord build and cache
|
|
33
37
|
`;
|
|
@@ -96,17 +100,25 @@ function environmentPort() {
|
|
|
96
100
|
async function runDevCommand(args, output) {
|
|
97
101
|
const parsed = parseDevArguments(args);
|
|
98
102
|
const projectRoot = resolveProjectRoot();
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
const resolveAddress = async () => {
|
|
104
|
+
loadProjectEnvironment(projectRoot, "development");
|
|
105
|
+
const loaded = await loadLudicordConfig(projectRoot);
|
|
106
|
+
return {
|
|
107
|
+
port: parsed.port ?? environmentPort() ?? loaded.config.server.port,
|
|
108
|
+
host: parsed.host ?? process.env.HOST ?? loaded.config.server.host,
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
const start = async () => {
|
|
112
|
+
const { port, host } = await resolveAddress();
|
|
113
|
+
return createLudicordDevServer({
|
|
114
|
+
projectRoot,
|
|
115
|
+
port,
|
|
116
|
+
host,
|
|
117
|
+
hmr: parsed.hmr,
|
|
118
|
+
debug: parsed.debug,
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
let server = await start();
|
|
110
122
|
output.stdout(server.formatReadyMessage());
|
|
111
123
|
if (parsed.open) {
|
|
112
124
|
const command = process.platform === "win32" ? "rundll32.exe" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
@@ -114,7 +126,67 @@ async function runDevCommand(args, output) {
|
|
|
114
126
|
child.on("error", () => output.stderr("Ludicord could not open a browser. Open the Local URL above."));
|
|
115
127
|
child.unref();
|
|
116
128
|
}
|
|
129
|
+
const restartFiles = new Set([
|
|
130
|
+
"ludicord.config.mjs",
|
|
131
|
+
".env",
|
|
132
|
+
".env.local",
|
|
133
|
+
".env.development",
|
|
134
|
+
".env.development.local",
|
|
135
|
+
]);
|
|
136
|
+
let restartTimer;
|
|
137
|
+
let restartQueue = Promise.resolve();
|
|
138
|
+
let shuttingDown = false;
|
|
139
|
+
const scheduleRestart = (label) => {
|
|
140
|
+
if (shuttingDown)
|
|
141
|
+
return;
|
|
142
|
+
clearTimeout(restartTimer);
|
|
143
|
+
restartTimer = setTimeout(() => {
|
|
144
|
+
restartQueue = restartQueue.then(async () => {
|
|
145
|
+
if (shuttingDown)
|
|
146
|
+
return;
|
|
147
|
+
try {
|
|
148
|
+
await resolveAddress();
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
output.stderr(`Ludicord config error\n${redact(error instanceof Error ? error.message : String(error))}`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
output.stdout(`\nrestarting ${label}...`);
|
|
155
|
+
await server.close();
|
|
156
|
+
if (shuttingDown)
|
|
157
|
+
return;
|
|
158
|
+
try {
|
|
159
|
+
server = await start();
|
|
160
|
+
output.stdout(`restarted ${label}\n${server.formatReadyMessage()}`);
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
output.stderr(`Ludicord restart failed\n${redact(error instanceof Error ? error.message : String(error))}\nSave ${label} to retry.`);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}, 120);
|
|
167
|
+
};
|
|
168
|
+
const watchedConfigFiles = [...restartFiles].map((name) => ({
|
|
169
|
+
name,
|
|
170
|
+
file: path.join(projectRoot, name),
|
|
171
|
+
}));
|
|
172
|
+
for (const { name, file } of watchedConfigFiles) {
|
|
173
|
+
watchFile(file, { interval: 250 }, (current, previous) => {
|
|
174
|
+
if (current.mtimeMs !== previous.mtimeMs ||
|
|
175
|
+
current.ctimeMs !== previous.ctimeMs ||
|
|
176
|
+
current.size !== previous.size ||
|
|
177
|
+
current.ino !== previous.ino) {
|
|
178
|
+
scheduleRestart(name);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
117
182
|
const shutdown = async () => {
|
|
183
|
+
if (shuttingDown)
|
|
184
|
+
return;
|
|
185
|
+
shuttingDown = true;
|
|
186
|
+
clearTimeout(restartTimer);
|
|
187
|
+
for (const { file } of watchedConfigFiles)
|
|
188
|
+
unwatchFile(file);
|
|
189
|
+
await restartQueue;
|
|
118
190
|
await server.close();
|
|
119
191
|
};
|
|
120
192
|
process.once("SIGINT", () => void shutdown());
|
|
@@ -169,9 +241,25 @@ async function runProjectCommand(command, args, output) {
|
|
|
169
241
|
output.stdout(cleanLudicordBuild(projectRoot));
|
|
170
242
|
return 0;
|
|
171
243
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
244
|
+
return 0;
|
|
245
|
+
}
|
|
246
|
+
async function runLintCommand(args, output) {
|
|
247
|
+
if (args.length > 0)
|
|
248
|
+
throw new Error(`LUDICORD0002: Unknown lint option "${args[0]}".`);
|
|
249
|
+
const result = await lintLudicordProject(resolveProjectRoot());
|
|
250
|
+
if (result.output !== "")
|
|
251
|
+
output.stdout(result.output);
|
|
252
|
+
output.stdout(result.errorCount === 0
|
|
253
|
+
? `✓ React Hooks lint passed${result.warningCount === 0 ? "" : ` with ${result.warningCount} warning${result.warningCount === 1 ? "" : "s"}`}`
|
|
254
|
+
: `✗ React Hooks lint found ${result.errorCount} error${result.errorCount === 1 ? "" : "s"}`);
|
|
255
|
+
return result.errorCount === 0 ? 0 : 1;
|
|
256
|
+
}
|
|
257
|
+
async function runAnalyzeCommand(args, output) {
|
|
258
|
+
if (args.some((argument) => argument !== "--json") || args.filter((argument) => argument === "--json").length > 1) {
|
|
259
|
+
throw new Error(`LUDICORD0002: Unknown analyze option "${args.find((argument) => argument !== "--json") ?? args[0]}".`);
|
|
260
|
+
}
|
|
261
|
+
output.stdout(formatBundleAnalysis(resolveProjectRoot(), args.includes("--json")));
|
|
262
|
+
return 0;
|
|
175
263
|
}
|
|
176
264
|
export async function runLudicordCli(args = process.argv.slice(2), output = defaultOutput) {
|
|
177
265
|
const [command] = args;
|
|
@@ -204,7 +292,6 @@ export async function runLudicordCli(args = process.argv.slice(2), output = defa
|
|
|
204
292
|
}
|
|
205
293
|
}
|
|
206
294
|
if (command === "routes" ||
|
|
207
|
-
command === "doctor" ||
|
|
208
295
|
command === "info" ||
|
|
209
296
|
command === "clean") {
|
|
210
297
|
try {
|
|
@@ -215,6 +302,17 @@ export async function runLudicordCli(args = process.argv.slice(2), output = defa
|
|
|
215
302
|
return 1;
|
|
216
303
|
}
|
|
217
304
|
}
|
|
305
|
+
if (command === "lint" || command === "analyze") {
|
|
306
|
+
try {
|
|
307
|
+
return command === "lint"
|
|
308
|
+
? await runLintCommand(args.slice(1), output)
|
|
309
|
+
: await runAnalyzeCommand(args.slice(1), output);
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
output.stderr(redact(error instanceof Error ? error.message : String(error)));
|
|
313
|
+
return 1;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
218
316
|
output.stderr(`LUDICORD0001: Unknown or unavailable command "${command}".`);
|
|
219
317
|
output.stderr("Run `ludicord --help` to see the available foundation commands.");
|
|
220
318
|
return Promise.resolve(1);
|
|
@@ -223,4 +321,3 @@ const entryPath = process.argv[1];
|
|
|
223
321
|
if (entryPath !== undefined && import.meta.url === pathToFileURL(entryPath).href) {
|
|
224
322
|
process.exitCode = await runLudicordCli();
|
|
225
323
|
}
|
|
226
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
export declare function formatRoutes(projectRoot: string): string;
|
|
2
|
-
export declare function runDoctor(projectRoot: string): Promise<{
|
|
3
|
-
readonly output: string;
|
|
4
|
-
readonly healthy: boolean;
|
|
5
|
-
}>;
|
|
6
2
|
export declare function formatInfo(projectRoot: string): string;
|
|
7
3
|
export declare function cleanLudicordBuild(projectRoot: string): string;
|
|
8
|
-
|
|
4
|
+
export declare function formatBundleAnalysis(projectRoot: string, json?: boolean): string;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { existsSync, readFileSync, rmSync, } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
|
-
import { createServer } from "node:net";
|
|
5
|
-
import { loadProjectEnvironment } from "../config/environment.js";
|
|
6
|
-
import { clientContainsSecret } from "../security/secret-scan.js";
|
|
7
|
-
import { loadLudicordConfig } from "../config/loader.js";
|
|
8
4
|
import { generateManifests } from "../compiler/scanner.js";
|
|
9
5
|
import { LUDICORD_VERSION } from "../version.js";
|
|
6
|
+
import { formatBundleReport } from "../compiler/bundle-report.js";
|
|
10
7
|
function formatTree(lines) {
|
|
11
8
|
return lines
|
|
12
9
|
.map((line, index) => `${index === lines.length - 1 ? "└─" : "├─"} ${line}`)
|
|
@@ -37,163 +34,10 @@ HTTP
|
|
|
37
34
|
${api.length === 0 ? "└─ (none)" : formatTree(api)}
|
|
38
35
|
|
|
39
36
|
WebSocket
|
|
40
|
-
${websocket.length === 0 ? "└─ (none)" : formatTree(websocket)}
|
|
41
|
-
}
|
|
42
|
-
function diagnosticLine(diagnostic) {
|
|
43
|
-
const icon = diagnostic.level === "ok"
|
|
44
|
-
? "✓"
|
|
45
|
-
: diagnostic.level === "warning"
|
|
46
|
-
? "⚠"
|
|
47
|
-
: "✗";
|
|
48
|
-
return `${icon} ${diagnostic.message}${diagnostic.detail === undefined ? "" : `\n ${diagnostic.detail}`}`;
|
|
49
|
-
}
|
|
50
|
-
export async function runDoctor(projectRoot) {
|
|
51
|
-
loadProjectEnvironment(projectRoot, "production");
|
|
52
|
-
const diagnostics = [];
|
|
53
|
-
const [nodeMajor = 0, nodeMinor = 0] = process.versions.node.split(".").map(Number);
|
|
54
|
-
diagnostics.push({
|
|
55
|
-
level: nodeMajor > 20 || (nodeMajor === 20 && nodeMinor >= 19) ? "ok" : "error",
|
|
56
|
-
message: `Node.js ${process.versions.node}`,
|
|
57
|
-
});
|
|
58
|
-
let manifests;
|
|
59
|
-
let config;
|
|
60
|
-
try {
|
|
61
|
-
manifests = generateManifests(projectRoot);
|
|
62
|
-
diagnostics.push({ level: "ok", message: "app/pages.tsx" });
|
|
63
|
-
diagnostics.push({
|
|
64
|
-
level: "ok",
|
|
65
|
-
message: `${manifests.embeds.length} embed route(s)`,
|
|
66
|
-
});
|
|
67
|
-
diagnostics.push({
|
|
68
|
-
level: "ok",
|
|
69
|
-
message: `${manifests.api.length} API route(s)`,
|
|
70
|
-
});
|
|
71
|
-
diagnostics.push({
|
|
72
|
-
level: "ok",
|
|
73
|
-
message: `${manifests.websocket.length} WebSocket route(s)`,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
diagnostics.push({
|
|
78
|
-
level: "error",
|
|
79
|
-
message: error instanceof Error ? error.message : String(error),
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
try {
|
|
83
|
-
({ config } = await loadLudicordConfig(projectRoot));
|
|
84
|
-
diagnostics.push({ level: "ok", message: "ludicord.config.mjs" });
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
diagnostics.push({
|
|
88
|
-
level: "error",
|
|
89
|
-
message: "Invalid ludicord.config.mjs",
|
|
90
|
-
detail: error instanceof Error ? error.message : String(error),
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
if (config !== undefined && config.discord.auth.required) {
|
|
94
|
-
const clientId = config.discord.clientId ?? process.env.LUDICORD_DISCORD_CLIENT_ID;
|
|
95
|
-
diagnostics.push({
|
|
96
|
-
level: clientId === undefined || clientId === "" ? "error" : "ok",
|
|
97
|
-
message: "Discord Client ID",
|
|
98
|
-
...(clientId === undefined || clientId === ""
|
|
99
|
-
? { detail: "Set LUDICORD_DISCORD_CLIENT_ID." }
|
|
100
|
-
: {}),
|
|
101
|
-
});
|
|
102
|
-
diagnostics.push({
|
|
103
|
-
level: !process.env.LUDICORD_DISCORD_CLIENT_SECRET?.trim() ? "error" : "ok",
|
|
104
|
-
message: "Discord Client Secret",
|
|
105
|
-
...(!process.env.LUDICORD_DISCORD_CLIENT_SECRET?.trim()
|
|
106
|
-
? { detail: "Set LUDICORD_DISCORD_CLIENT_SECRET." }
|
|
107
|
-
: {}),
|
|
108
|
-
});
|
|
109
|
-
const sessionSecret = process.env.LUDICORD_SESSION_SECRET;
|
|
110
|
-
diagnostics.push({
|
|
111
|
-
level: sessionSecret !== undefined && sessionSecret.length >= 32
|
|
112
|
-
? "ok"
|
|
113
|
-
: "error",
|
|
114
|
-
message: "Session secret",
|
|
115
|
-
...(sessionSecret !== undefined && sessionSecret.length >= 32
|
|
116
|
-
? {}
|
|
117
|
-
: { detail: "LUDICORD_SESSION_SECRET must contain at least 32 characters." }),
|
|
118
|
-
});
|
|
119
|
-
if (config.discord.auth.proxyVerification &&
|
|
120
|
-
!process.env.LUDICORD_DISCORD_PUBLIC_KEY?.trim()) {
|
|
121
|
-
diagnostics.push({
|
|
122
|
-
level: "error",
|
|
123
|
-
message: "Discord Public Key",
|
|
124
|
-
detail: "Required while proxy verification is enabled.",
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
else if (!config.discord.auth.proxyVerification) {
|
|
128
|
-
diagnostics.push({
|
|
129
|
-
level: "warning",
|
|
130
|
-
message: "Discord proxy signature verification is disabled",
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
if (config.discord.auth.activityInstanceVerification &&
|
|
134
|
-
!process.env.LUDICORD_DISCORD_BOT_TOKEN?.trim()) {
|
|
135
|
-
diagnostics.push({
|
|
136
|
-
level: "error",
|
|
137
|
-
message: "Activity Instance verification token",
|
|
138
|
-
detail: "Set LUDICORD_DISCORD_BOT_TOKEN or disable verification.",
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (config) {
|
|
143
|
-
if (!config.discord.scopes.includes("guilds"))
|
|
144
|
-
diagnostics.push({ level: "warning", message: 'Add the "guilds" scope for guild and channel details.' });
|
|
145
|
-
if (config.discord.auth.required && !config.discord.auth.activityInstanceVerification)
|
|
146
|
-
diagnostics.push({ level: "warning", message: "Activity Instance verification is disabled; client-provided guild/channel/instance IDs are unverified." });
|
|
147
|
-
if (process.env.LUDICORD_DEV_FAKE_AUTH === "true")
|
|
148
|
-
diagnostics.push({ level: "warning", message: "Development fake authentication is enabled locally; never use fake sessions in production." });
|
|
149
|
-
if (config.server.port !== 0) {
|
|
150
|
-
const available = await new Promise((resolve) => {
|
|
151
|
-
const probe = createServer();
|
|
152
|
-
probe.once("error", () => resolve(false));
|
|
153
|
-
probe.listen(config.server.port, "127.0.0.1", () => probe.close(() => resolve(true)));
|
|
154
|
-
});
|
|
155
|
-
diagnostics.push({ level: available ? "ok" : "warning", message: available ? `Port ${config.server.port} is available` : `Port ${config.server.port} is occupied or unavailable; stop the existing server or select --port.` });
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
const metadataFile = path.join(projectRoot, ".ludicord", "build.json");
|
|
159
|
-
if (existsSync(metadataFile)) {
|
|
160
|
-
try {
|
|
161
|
-
const metadata = JSON.parse(readFileSync(metadataFile, "utf8"));
|
|
162
|
-
if (metadata.frameworkVersion !== LUDICORD_VERSION)
|
|
163
|
-
diagnostics.push({ level: "warning", message: "Production output was built with a different framework version. Run ludicord build." });
|
|
164
|
-
}
|
|
165
|
-
catch {
|
|
166
|
-
diagnostics.push({ level: "error", message: "Invalid production build metadata. Run ludicord build." });
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
diagnostics.push({
|
|
170
|
-
level: existsSync(path.join(projectRoot, ".ludicord", "build.json"))
|
|
171
|
-
? "ok"
|
|
172
|
-
: "warning",
|
|
173
|
-
message: existsSync(path.join(projectRoot, ".ludicord", "build.json"))
|
|
174
|
-
? "Production build"
|
|
175
|
-
: "Production build not created",
|
|
176
|
-
...(existsSync(path.join(projectRoot, ".ludicord", "build.json"))
|
|
177
|
-
? {}
|
|
178
|
-
: { detail: "Run ludicord build before ludicord start." }),
|
|
179
|
-
});
|
|
180
|
-
const leaked = clientContainsSecret(path.join(projectRoot, ".ludicord", "client"));
|
|
181
|
-
diagnostics.push({
|
|
182
|
-
level: leaked ? "error" : "ok",
|
|
183
|
-
message: leaked
|
|
184
|
-
? "Server secret detected in client output"
|
|
185
|
-
: "No server secret leakage detected",
|
|
186
|
-
});
|
|
187
|
-
diagnostics.push({
|
|
188
|
-
level: "warning",
|
|
189
|
-
message: "Discord local testing requires an HTTPS tunnel and URL Mapping",
|
|
190
|
-
});
|
|
191
|
-
return {
|
|
192
|
-
output: `Ludicord Doctor
|
|
37
|
+
${websocket.length === 0 ? "└─ (none)" : formatTree(websocket)}
|
|
193
38
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
};
|
|
39
|
+
Proxy
|
|
40
|
+
${manifests.activity.proxy === undefined ? "└─ (none)" : `└─ ${manifests.activity.proxy}`}`;
|
|
197
41
|
}
|
|
198
42
|
function dependencyVersion(projectRoot, packageName) {
|
|
199
43
|
try {
|
|
@@ -224,7 +68,8 @@ Project
|
|
|
224
68
|
Activity: ${manifests.activity.root}
|
|
225
69
|
Embeds: ${manifests.embeds.length}
|
|
226
70
|
API routes: ${manifests.api.length}
|
|
227
|
-
WS routes: ${manifests.websocket.length}
|
|
71
|
+
WS routes: ${manifests.websocket.length}
|
|
72
|
+
Proxy: ${manifests.activity.proxy ?? "none"}`;
|
|
228
73
|
}
|
|
229
74
|
export function cleanLudicordBuild(projectRoot) {
|
|
230
75
|
const target = path.resolve(projectRoot, ".ludicord");
|
|
@@ -235,4 +80,11 @@ export function cleanLudicordBuild(projectRoot) {
|
|
|
235
80
|
rmSync(target, { recursive: true, force: true });
|
|
236
81
|
return "✓ Removed .ludicord build and cache";
|
|
237
82
|
}
|
|
238
|
-
|
|
83
|
+
export function formatBundleAnalysis(projectRoot, json = false) {
|
|
84
|
+
const file = path.join(path.resolve(projectRoot), ".ludicord", "bundle-report.json");
|
|
85
|
+
if (!existsSync(file)) {
|
|
86
|
+
throw new Error("LUDICORD7005: Bundle report not found. Run `ludicord build` first.");
|
|
87
|
+
}
|
|
88
|
+
const report = JSON.parse(readFileSync(file, "utf8"));
|
|
89
|
+
return json ? JSON.stringify(report, null, 2) : formatBundleReport(report);
|
|
90
|
+
}
|
package/dist/compiler/build.d.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import type { ResolvedLudicordConfig } from "../config/types.js";
|
|
2
2
|
import type { LudicordManifests } from "../manifests/types.js";
|
|
3
|
+
import type { LudicordBundleReport } from "./bundle-report.js";
|
|
4
|
+
export declare const LUDICORD_BUILD_SCHEMA_VERSION: 2;
|
|
3
5
|
export interface RouteBundle {
|
|
4
6
|
readonly source: string;
|
|
5
7
|
readonly bundle: string;
|
|
6
8
|
}
|
|
7
9
|
export interface LudicordBuildMetadata {
|
|
10
|
+
readonly buildSchemaVersion: typeof LUDICORD_BUILD_SCHEMA_VERSION;
|
|
8
11
|
readonly frameworkVersion: string;
|
|
9
12
|
readonly createdAt: string;
|
|
10
13
|
readonly clientEntry: string;
|
|
11
14
|
readonly api: readonly RouteBundle[];
|
|
12
15
|
readonly websocket: readonly RouteBundle[];
|
|
16
|
+
readonly instrumentation?: RouteBundle;
|
|
17
|
+
readonly proxy?: RouteBundle;
|
|
18
|
+
readonly bundleReport: LudicordBundleReport;
|
|
13
19
|
readonly config: {
|
|
14
20
|
readonly discord: {
|
|
15
21
|
readonly clientId?: string;
|
|
@@ -22,6 +28,8 @@ export interface LudicordBuildMetadata {
|
|
|
22
28
|
readonly defaultEmbed: string;
|
|
23
29
|
readonly outsideDiscord: string;
|
|
24
30
|
};
|
|
31
|
+
readonly react: ResolvedLudicordConfig["react"];
|
|
32
|
+
readonly build: ResolvedLudicordConfig["build"];
|
|
25
33
|
readonly server: ResolvedLudicordConfig["server"];
|
|
26
34
|
readonly websocket: ResolvedLudicordConfig["websocket"];
|
|
27
35
|
};
|
|
@@ -30,7 +38,8 @@ export interface LudicordBuildResult {
|
|
|
30
38
|
readonly outputDirectory: string;
|
|
31
39
|
readonly manifests: LudicordManifests;
|
|
32
40
|
readonly metadata: LudicordBuildMetadata;
|
|
41
|
+
readonly bundleReport: LudicordBundleReport;
|
|
33
42
|
formatSummary(): string;
|
|
34
43
|
}
|
|
44
|
+
export declare function cleanupStaleBuildDirectories(projectRoot: string, now?: number): string[];
|
|
35
45
|
export declare function buildLudicordProject(projectRoot: string): Promise<LudicordBuildResult>;
|
|
36
|
-
//# sourceMappingURL=build.d.ts.map
|