Skip to content

Commit f4f7e7b

Browse files
feat(database-ui): consolidate api and ui for db studio into one folder
1 parent fac5946 commit f4f7e7b

File tree

5 files changed

+66
-4720
lines changed

5 files changed

+66
-4720
lines changed

packages/cli/src/main/kotlin/elide/tool/cli/cmd/db/DbStudioCommand.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,6 @@ internal class DbStudioCommand : AbstractSubcommand<ToolState, CommandContext>()
228228
}
229229
copyDirectory(uiSource, uiDir)
230230

231-
val indexFile = apiDir.resolve(STUDIO_INDEX_FILE)
232-
val baseContent = indexFile.readText()
233-
234231
// Always use databases array - either discover or create from single path
235232
val databases = if (databasePath == null) {
236233
val discovered = discoverDatabases()
@@ -259,14 +256,22 @@ internal class DbStudioCommand : AbstractSubcommand<ToolState, CommandContext>()
259256
)
260257
}
261258

262-
val json = Json { prettyPrint = false }
259+
// Generate config.ts with port and databases
260+
val json = Json { prettyPrint = true }
263261
val databasesJson = json.encodeToString(databases)
264262

265-
val processedContent = baseContent
266-
.replace("__PORT__", apiPort.toString())
267-
.replace("\"__DATABASES__\"", databasesJson)
263+
val configContent = buildString {
264+
appendLine("// Auto-generated configuration by DbStudioCommand")
265+
appendLine("// Do not edit this file manually")
266+
appendLine()
267+
appendLine("export default {")
268+
appendLine(" port: $apiPort,")
269+
appendLine(" databases: $databasesJson")
270+
appendLine("};")
271+
}
268272

269-
indexFile.writeText(processedContent)
273+
val configFile = apiDir.resolve("config.ts")
274+
configFile.writeText(configContent)
270275

271276
output {
272277
appendLine("Database Studio files generated in: ${outputDir.toAbsolutePath()}")

packages/cli/src/projects/db-studio/api/index.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { Database } from "elide:sqlite";
44
import { startServer } from "./server.ts";
55
import type { DiscoveredDatabase } from "./database.ts";
6+
import config from "./config.ts";
67

78
/**
89
* Database Studio - Entry Point
@@ -13,13 +14,8 @@ import type { DiscoveredDatabase } from "./database.ts";
1314

1415
export { Database };
1516

16-
// Configuration injected by DbStudioCommand.kt
17-
// These are global variables that will be replaced at runtime
18-
declare const __PORT__: number;
19-
declare const __DATABASES__: string;
20-
21-
const port: number = __PORT__;
22-
const databases: DiscoveredDatabase[] = JSON.parse(__DATABASES__) as DiscoveredDatabase[];
17+
// Configuration loaded from config.json (generated by DbStudioCommand.kt)
18+
const { port, databases } = config;
2319

2420
// Start the server with injected configuration
2521
startServer({ port, databases, Database });

packages/cli/src/projects/db-studio/ui/dist/assets/index-51fPNOLC.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)