Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/rude-candies-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"create-vorsteh-queue": patch
---

use static json list from our own website to fetch the available templates.

This solves the "Rate limit" problem which comes from the GitHub API.
2 changes: 2 additions & 0 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"class-variance-authority": "0.7.1",
"clsx": "2.1.1",
"date-fns": "^4.1.0",
"globby": "14.1.0",
"interweave": "13.1.1",
"lucide-react": "0.542.0",
"multimatch": "7.0.0",
Expand All @@ -45,6 +46,7 @@
"p-map": "7.0.3",
"react": "19.1.1",
"react-dom": "19.1.1",
"read-pkg": "^9.0.1",
"rehype-mdx-import-media": "1.2.0",
"remark-frontmatter": "5.0.0",
"remark-gfm": "4.0.1",
Expand Down
29 changes: 29 additions & 0 deletions apps/docs/src/app/templates.json/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as path from "path"
import { NextResponse } from "next/server"
import { globby } from "globby"
import pMap from "p-map"
import { readPackage } from "read-pkg"

export const dynamic = "force-static"

export async function GET() {
const examplePkgJson = await globby(["**/*/package.json"], {
cwd: path.join(process.cwd(), "..", "..", "examples"),
expandDirectories: true,
absolute: true,
deep: 2,
gitignore: true,
})

const parsedTemplates = await pMap(examplePkgJson, async (file) => {
const content = await readPackage({ cwd: path.dirname(file) })
return {
name: content.name || path.basename(path.dirname(file)),
alias: path.basename(path.dirname(file)),
path: path.join("examples", path.basename(path.dirname(file))),
description: content.description ?? "No description",
}
})

return NextResponse.json({ templates: parsedTemplates })
}
66 changes: 16 additions & 50 deletions packages/create-vorsteh-queue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,82 +11,48 @@ import terminalLink from "terminal-link"

interface Template {
name: string
alias: string
description: string
path: string
}

interface GitHubContent {
name: string
type: string
download_url?: string
}

interface GitHubFile {
content: string
}

interface NpmPackageData {
version: string
}

type PackageJson = Awaited<ReturnType<typeof readPackage>>

async function fetchTemplates(): Promise<Template[]> {
const s = spinner()
s.start("Discovering templates...")

try {
// Fetch examples directory contents
const response = await fetch(
"https://api.github.com/repos/noxify/vorsteh-queue/contents/examples",
)
if (!response.ok) throw new Error(`HTTP ${response.status}`)
const response = await fetch("https://vorsteh-queue.dev/templates.json")

const contents = (await response.json()) as GitHubContent[]
const templates: Template[] = []

// Process each directory in examples/
for (const item of contents) {
if (item.type === "dir") {
try {
// Fetch package.json for each example
const pkgResponse = await fetch(
`https://api.github.com/repos/noxify/vorsteh-queue/contents/examples/${item.name}/package.json`,
)
if (pkgResponse.ok) {
const pkgData = (await pkgResponse.json()) as GitHubFile
const pkgContent = JSON.parse(atob(pkgData.content)) as Partial<PackageJson>

templates.push({
name: pkgContent.name ?? item.name,
description: pkgContent.description ?? `${item.name} example`,
path: `examples/${item.name}`,
})
}
} catch (error) {
// Skip directories without valid package.json
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
console.warn(pc.yellow(`⚠️ Skipping ${item.name}: ${error}`))
}
}
if (!response.ok) {
throw new Error(`HTTP ${response.status}`)
}

s.stop(`Found ${templates.length} templates`)
return templates
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (error) {
s.stop("Failed to fetch templates")
const responseBody = (await response.json()) as { templates: Template[] }

s.stop(`Found ${responseBody.templates.length} templates`)
return responseBody.templates
} catch (error: unknown) {
s.stop(
`Failed to fetch templates - ${error instanceof Error ? error.toString() : String(error)}`,
)
// Fallback to hardcoded templates

console.warn(pc.yellow("⚠️ Using fallback templates"))
return [
{
name: "drizzle-postgres",
name: "drizzle-postgres-example",
alias: "drizzle-postgres",
description: "Drizzle ORM + postgres.js",
path: "examples/drizzle-postgres",
},
{
name: "drizzle-pglite",
name: "drizzle-pglite-example",
alias: "drizzle-pglite",
description: "Drizzle ORM + PGlite (Embedded)",
path: "examples/drizzle-pglite",
},
Expand Down
10 changes: 8 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading