You've already forked domainstack.io
mirror of
https://github.com/jakejarvis/domainstack.io.git
synced 2025-12-02 19:33:48 -05:00
70 lines
1.6 KiB
TypeScript
70 lines
1.6 KiB
TypeScript
import * as dotenv from "dotenv";
|
|
|
|
// Load common local envs first if present, then default .env
|
|
dotenv.config({ path: ".env.local" });
|
|
dotenv.config();
|
|
|
|
import { db } from "@/lib/db/client";
|
|
import { type providerCategory, providers } from "@/lib/db/schema";
|
|
import {
|
|
CA_PROVIDERS,
|
|
DNS_PROVIDERS,
|
|
EMAIL_PROVIDERS,
|
|
HOSTING_PROVIDERS,
|
|
REGISTRAR_PROVIDERS,
|
|
} from "@/lib/providers/catalog";
|
|
|
|
function slugify(input: string): string {
|
|
return input
|
|
.trim()
|
|
.toLowerCase()
|
|
.replace(/[^a-z0-9]+/g, "-")
|
|
.replace(/(^-|-$)+/g, "");
|
|
}
|
|
|
|
type SeedDef = {
|
|
name: string;
|
|
domain: string | null;
|
|
category: (typeof providerCategory.enumValues)[number];
|
|
aliases?: string[];
|
|
};
|
|
|
|
function collect(): SeedDef[] {
|
|
const arr: SeedDef[] = [];
|
|
const push = (
|
|
cat: SeedDef["category"],
|
|
src: { name: string; domain: string }[],
|
|
) => {
|
|
for (const p of src)
|
|
arr.push({ name: p.name, domain: p.domain ?? null, category: cat });
|
|
};
|
|
push("dns", DNS_PROVIDERS);
|
|
push("email", EMAIL_PROVIDERS);
|
|
push("hosting", HOSTING_PROVIDERS);
|
|
push("registrar", REGISTRAR_PROVIDERS);
|
|
push("ca", CA_PROVIDERS);
|
|
return arr;
|
|
}
|
|
|
|
async function main() {
|
|
const defs = collect();
|
|
for (const def of defs) {
|
|
const slug = slugify(def.name);
|
|
await db
|
|
.insert(providers)
|
|
.values({
|
|
name: def.name,
|
|
domain: def.domain ?? undefined,
|
|
category: def.category,
|
|
slug,
|
|
})
|
|
.onConflictDoNothing({ target: [providers.category, providers.slug] });
|
|
}
|
|
console.log(`Seeded ${defs.length} provider rows (existing skipped).`);
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|