diff --git a/README.md b/README.md index c22bb24..5e08020 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Currently, there are three templates available: - `JavaScript`/`js` - `Vite`/`v` -> [!NOTE] +> [!TIP] > You can also specify any vite template directly, e.g. `vue-ts` To use a template, run `localpen` with the `-t` flag: @@ -64,6 +64,6 @@ This prompt can be skipped by passing the `--keep` (`-k`) or the `--delete` (`-d ### Todo - [ ] ensure all the vite templates work -- [ ] list the vite templates in the help message +- [x] list the vite templates in the help message [bun]: https://bun.sh diff --git a/src/constants.ts b/src/constants.ts index 9b2d407..1e4a43f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,5 @@ import { blue, bold, gray, magenta, yellow } from "kolorist" +import { getViteTemplateVariantsColors } from "./create-vite" export type TemplateBuiltin = { name: string @@ -36,14 +37,28 @@ export const templates: Template[] = [ entry: ["bun", "run", "--watch", "index.js"], }, { - name: "create-vite", + name: "Vite", alias: "v", color: magenta, vite: true, }, ] -export const helpMessage = ` +export const helpMessage = async () => { + const viteTemplateStrings = [] + const viteVariants = await getViteTemplateVariantsColors() + + for (const [name, data] of viteVariants) { + let variantString = data.color(name) + + for (const [variant, color] of data.variants) { + if (variant === "TypeScript") variantString += ` (-${color("ts")})` + } + + viteTemplateStrings.push(variantString) + } + + return ` Usage: localpen [options] ${gray("Options:")} @@ -57,4 +72,8 @@ ${gray("Deletion options, pick either or get prompted:")} Available templates: ${templates .map((t) => ` - ${t.color(t.name)}${t.alias ? `/${t.color(t.alias)}` : ""}`) - .join("\n")}` + .join("\n")} + +Vite templates: +${viteTemplateStrings.map((t) => ` - ${t}`).join("\n")}` +} diff --git a/src/create-vite.ts b/src/create-vite.ts index 486eedc..ae681b3 100644 --- a/src/create-vite.ts +++ b/src/create-vite.ts @@ -10,7 +10,7 @@ import prompts from "prompts" const __dirname = dirname(fileURLToPath(import.meta.url)) export const VITE_TEMPLATES_FOLDER = join(__dirname, "../templates/vite") -const COLOR_STARTS_WITH = Object.entries({ +export const VITE_COLOR_STARTS_WITH = Object.entries({ vanilla: colors.yellow, vue: colors.green, react: colors.cyan, @@ -35,7 +35,7 @@ export const getViteTemplateVariantsColors = async (): Promise< const map: ViteTemplateMap = {} for (const viteTemplate of contents) { - const colorMatch = COLOR_STARTS_WITH.find(([color]) => + const colorMatch = VITE_COLOR_STARTS_WITH.find(([color]) => viteTemplate.startsWith(color), ) const color = colorMatch ? colorMatch[1] : colors.gray diff --git a/src/index.ts b/src/index.ts index 56a7137..55e1965 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,7 +37,7 @@ const argv = minimist<{ }) if (argv.help) { - console.log(helpMessage) + console.log(await helpMessage()) process.exit(0) } @@ -86,7 +86,7 @@ if (argv.template) { if (!template) { console.log(red(bold(`Template ${black(argv.template ?? "")} not found`))) - console.log(`${helpMessage}`) + console.log(await helpMessage()) process.exit(1) }