diff --git a/create-farc/bin.ts b/create-farc/bin.ts index 47aa77de..e77be927 100644 --- a/create-farc/bin.ts +++ b/create-farc/bin.ts @@ -8,7 +8,13 @@ const pkg = require('../package.json') const cli = cac('create-farc') -cli.usage('[options]').option('-n, --name [name]', 'Name of project') +cli + .usage('[options]') + .option('-n, --name [name]', 'Name of project.') + .option( + '-t, --template [template]', + 'Project template to use. Templates: default, vercel', + ) cli.help() cli.version(pkg.version) diff --git a/create-farc/create.ts b/create-farc/create.ts index 0ceae64d..9fe2227d 100644 --- a/create-farc/create.ts +++ b/create-farc/create.ts @@ -1,18 +1,16 @@ import { dirname, resolve } from 'node:path' import { fileURLToPath } from 'node:url' -import { intro, log, outro, text } from '@clack/prompts' +import { intro, log, outro, select, text } from '@clack/prompts' import { default as fs } from 'fs-extra' import { default as pc } from 'picocolors' -export type CreateParameters = { name: string } +export type CreateParameters = { name: string; template: 'default' | 'vercel' } const __dirname = dirname(fileURLToPath(import.meta.url)) export async function create(params: CreateParameters) { intro('Welcome to Farc!') - const templateDir = resolve(__dirname, '../templates/default') - const displayName = params.name || ((await text({ @@ -27,6 +25,19 @@ export async function create(params: CreateParameters) { const destDir = resolve(process.cwd(), name) + const templateName = + params.template || + ((await select({ + message: 'Choose a template', + options: [ + { value: 'default', label: 'Default' }, + { value: 'vercel', label: 'Vercel' }, + ], + initialValue: 'default', + })) as string) + + const templateDir = resolve(__dirname, `../templates/${templateName}`) + // Copy contents fs.copySync(templateDir, destDir) diff --git a/create-farc/templates/default/package.json b/create-farc/templates/default/package.json index 33c21049..4869b7d8 100644 --- a/create-farc/templates/default/package.json +++ b/create-farc/templates/default/package.json @@ -1,5 +1,5 @@ { - "name": "Example", + "name": "example", "private": true, "scripts": { "dev": "bun run --hot src/index.tsx" diff --git a/create-farc/templates/vercel/README.md b/create-farc/templates/vercel/README.md new file mode 100644 index 00000000..61b52124 --- /dev/null +++ b/create-farc/templates/vercel/README.md @@ -0,0 +1 @@ +This is a [Farc](https://farc.dev) project bootstrapped with `create-farc`. diff --git a/create-farc/templates/vercel/_gitignore b/create-farc/templates/vercel/_gitignore new file mode 100644 index 00000000..609201b1 --- /dev/null +++ b/create-farc/templates/vercel/_gitignore @@ -0,0 +1,24 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# production +/docs/dist + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# typescript +*.tsbuildinfo + +# vercel +.vercel \ No newline at end of file diff --git a/create-farc/templates/vercel/api/index.tsx b/create-farc/templates/vercel/api/index.tsx new file mode 100644 index 00000000..ac3e8d7a --- /dev/null +++ b/create-farc/templates/vercel/api/index.tsx @@ -0,0 +1,67 @@ +import { Button, Farc, TextInput } from 'farc' +import { handle } from 'hono/vercel' + +const app = new Farc({ basePath: '/api' }) + +export const config = { + // runtime: 'edge', // Uncomment to use Edge Runtime +} + +app.frame('/', (context) => { + const { buttonValue, inputText, status } = context + const fruit = inputText || buttonValue + return { + image: ( +