From 5d89847253469f4032b3c3f3faaf36ba7a4a3b99 Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Wed, 12 Feb 2025 16:55:08 +0530 Subject: [PATCH] add -y flag to auto select the defaults --- .changeset/new-eggs-tell.md | 5 ++ apps/cli/src/index.ts | 121 ++++++++++++++++++++++-------------- 2 files changed, 78 insertions(+), 48 deletions(-) create mode 100644 .changeset/new-eggs-tell.md diff --git a/.changeset/new-eggs-tell.md b/.changeset/new-eggs-tell.md new file mode 100644 index 0000000..09206c1 --- /dev/null +++ b/.changeset/new-eggs-tell.md @@ -0,0 +1,5 @@ +--- +"create-better-t-stack": patch +--- + +Add -y to auto select the defaults diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.ts index be7ccea..badca5f 100644 --- a/apps/cli/src/index.ts +++ b/apps/cli/src/index.ts @@ -8,60 +8,84 @@ import { logger } from "./utils/logger"; const program = new Command(); -async function main() { +type CliOptions = { + yes: boolean; +}; + +async function main(options: CliOptions) { try { renderTitle(); - console.log(chalk.bold("\nšŸš€ Creating a new Better-T Stack project...\n")); - const projectName = await input({ - message: "Project name:", - default: "my-better-t-app", - }); + const defaults = { + projectName: "my-better-t-app", + database: "libsql" as ProjectDatabase, + auth: true, + features: [] as ProjectFeature[], + }; - const database = await select({ - message: chalk.cyan("Select database:"), - choices: [ - { - value: "libsql", - name: "libSQL", - description: chalk.dim( - "(Recommended) - Turso's embedded SQLite database", - ), - }, - { - value: "postgres", - name: "PostgreSQL", - description: chalk.dim("Traditional relational database"), - }, - ], - }); + const projectName = options.yes + ? defaults.projectName + : await input({ + message: "Project name:", + default: defaults.projectName, + }); - const auth = await confirm({ - message: "Add authentication with Better-Auth?", - default: true, - }); + const database = options.yes + ? defaults.database + : await select({ + message: chalk.cyan("Select database:"), + choices: [ + { + value: "libsql", + name: "libSQL", + description: chalk.dim( + "(Recommended) - Turso's embedded SQLite database", + ), + }, + { + value: "postgres", + name: "PostgreSQL", + description: chalk.dim("Traditional relational database"), + }, + ], + }); - const features = await checkbox({ - message: chalk.cyan("Select additional features:"), - choices: [ - { - value: "docker", - name: "Docker setup", - description: chalk.dim("Containerize your application"), - }, - { - value: "github-actions", - name: "GitHub Actions", - description: chalk.dim("CI/CD workflows"), - }, - { - value: "SEO", - name: "Basic SEO setup", - description: chalk.dim("Search engine optimization configuration"), - }, - ], - }); + const auth = options.yes + ? defaults.auth + : await confirm({ + message: "Add authentication with Better-Auth?", + default: defaults.auth, + }); + + const features = options.yes + ? defaults.features + : await checkbox({ + message: chalk.cyan("Select additional features:"), + choices: [ + { + value: "docker", + name: "Docker setup", + description: chalk.dim("Containerize your application"), + }, + { + value: "github-actions", + name: "GitHub Actions", + description: chalk.dim("CI/CD workflows"), + }, + { + value: "SEO", + name: "Basic SEO setup", + description: chalk.dim( + "Search engine optimization configuration", + ), + }, + ], + }); + + if (options.yes) { + logger.info("Using default values due to -y flag"); + } const projectOptions = { projectName, @@ -93,6 +117,7 @@ program .name("create-better-t-stack") .description("Create a new Better-T Stack project") .version("1.0.0") - .action(main); + .option("-y, --yes", "Accept all defaults") + .action((options) => main(options)); program.parse();