67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
#!/usr/bin/env bun
|
|
|
|
import * as p from "@clack/prompts";
|
|
import { initRenderer } from '@gregorlohaus/tdir'
|
|
import { z } from 'zod'
|
|
import path from "node:path";
|
|
|
|
p.intro("create-glstack");
|
|
|
|
const project = await p.group(
|
|
{
|
|
name: () =>
|
|
p.text({
|
|
message: "What would you like to name your project?",
|
|
placeholder: "glstack-test",
|
|
defaultValue: "glstack-test",
|
|
validate: (value) => {
|
|
return undefined
|
|
},
|
|
}),
|
|
frontend: async () =>
|
|
await p.select({
|
|
message: 'Pick a frontend framework.',
|
|
options: [
|
|
{value: "svelte-kit", label:"SvelteKit"},
|
|
{value: "solid-start", label:"SolidStart"}
|
|
]
|
|
})
|
|
,
|
|
goprefix: () =>
|
|
p.text({
|
|
message: "What would you like to use as a go package prefix?",
|
|
placeholder: "github.com/glstack-test",
|
|
defaultValue: "github.com/glstack-test",
|
|
validate: (value) => {
|
|
return undefined
|
|
},
|
|
}),
|
|
},
|
|
{
|
|
onCancel: () => {
|
|
p.cancel("Operation cancelled.");
|
|
process.exit(0);
|
|
},
|
|
}
|
|
);
|
|
const createRenderer = initRenderer(path.join(import.meta.dir, '..', 'template'))
|
|
const render = createRenderer(z.object({
|
|
project: z.object({
|
|
name: z.string(),
|
|
goprefix: z.string(),
|
|
frontend: z.literal("svelte-kit").or(z.literal("solid-start"))
|
|
})
|
|
}))
|
|
const destDir = path.join("./",project.name);
|
|
render(destDir,{project})
|
|
// TODO: template rendering — copy/generate files into destDir
|
|
|
|
const s = p.spinner();
|
|
s.start("Installing dependencies");
|
|
await Bun.$`bun install`.cwd(path.join(destDir)).quiet();
|
|
await Bun.$`bun install`.cwd(path.join(destDir,'packages','rpc')).quiet();
|
|
await Bun.$`bun install`.cwd(path.join(destDir,'apps','web')).quiet();
|
|
s.stop("Dependencies installed.");
|
|
|
|
p.outro("You're all set!");
|