@pagebridge/cli 0.0.1 → 0.0.2

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/src/migrate.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { resolve } from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ import { runMigrations } from "@pagebridge/db";
4
+ import { log } from "./logger.js";
5
+
6
+ export async function migrateIfRequested(shouldMigrate: boolean, dbUrl: string) {
7
+ if (!shouldMigrate) return;
8
+ log.info("Running database migrations...");
9
+ const pkgPath = import.meta.resolve("@pagebridge/db");
10
+ const migrationsFolder = resolve(fileURLToPath(pkgPath), "../../drizzle");
11
+ await runMigrations(dbUrl, migrationsFolder);
12
+ log.info("Migrations complete.");
13
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Resolves a config value from a CLI option first, then env var fallback.
3
+ */
4
+ export function resolve(
5
+ optionValue: string | undefined,
6
+ envVarName: string,
7
+ ): string | undefined {
8
+ return optionValue ?? process.env[envVarName];
9
+ }
10
+
11
+ interface ConfigEntry {
12
+ name: string;
13
+ flag: string;
14
+ envVar: string;
15
+ value: string | undefined;
16
+ }
17
+
18
+ /**
19
+ * Validates that all required config entries have values.
20
+ * If any are missing, prints a clear error listing every missing entry and exits.
21
+ */
22
+ export function requireConfig(entries: ConfigEntry[]): void {
23
+ const missing = entries.filter((e) => !e.value);
24
+ if (missing.length === 0) return;
25
+
26
+ console.error("Error: Missing required configuration.\n");
27
+ for (const entry of missing) {
28
+ console.error(` ${entry.name}`);
29
+ console.error(` ${entry.flag} or ${entry.envVar} env var\n`);
30
+ }
31
+ process.exit(1);
32
+ }