add -y flag to auto select the defaults

This commit is contained in:
Aman Varshney
2025-02-12 16:55:08 +05:30
parent 9de81de596
commit 5d89847253
2 changed files with 78 additions and 48 deletions

View File

@@ -0,0 +1,5 @@
---
"create-better-t-stack": patch
---
Add -y to auto select the defaults

View File

@@ -8,18 +8,32 @@ 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({
const defaults = {
projectName: "my-better-t-app",
database: "libsql" as ProjectDatabase,
auth: true,
features: [] as ProjectFeature[],
};
const projectName = options.yes
? defaults.projectName
: await input({
message: "Project name:",
default: "my-better-t-app",
default: defaults.projectName,
});
const database = await select<ProjectDatabase>({
const database = options.yes
? defaults.database
: await select<ProjectDatabase>({
message: chalk.cyan("Select database:"),
choices: [
{
@@ -37,12 +51,16 @@ async function main() {
],
});
const auth = await confirm({
const auth = options.yes
? defaults.auth
: await confirm({
message: "Add authentication with Better-Auth?",
default: true,
default: defaults.auth,
});
const features = await checkbox<ProjectFeature>({
const features = options.yes
? defaults.features
: await checkbox<ProjectFeature>({
message: chalk.cyan("Select additional features:"),
choices: [
{
@@ -58,11 +76,17 @@ async function main() {
{
value: "SEO",
name: "Basic SEO setup",
description: chalk.dim("Search engine optimization configuration"),
description: chalk.dim(
"Search engine optimization configuration",
),
},
],
});
if (options.yes) {
logger.info("Using default values due to -y flag");
}
const projectOptions = {
projectName,
git: true,
@@ -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();