replace commander with brocli, update inquirer and add biome

This commit is contained in:
Aman Varshney
2025-02-10 23:50:08 +05:30
parent 85fa93c1a8
commit eccfd8a92a
9 changed files with 740 additions and 4035 deletions

View File

@@ -1,56 +1,62 @@
import { execa } from 'execa';
import fs from 'fs-extra';
import ora from 'ora';
import path from 'path';
import { execa } from "execa";
import fs from "fs-extra";
import ora from "ora";
import path from "node:path";
interface ProjectOptions {
projectName: string;
typescript: boolean;
git: boolean;
database: 'libsql' | 'postgres';
database: "libsql" | "postgres";
auth: boolean;
features: string[];
}
export async function createProject(options: ProjectOptions) {
const spinner = ora('Creating project directory...').start();
const spinner = ora("Creating project directory...").start();
const projectDir = path.resolve(process.cwd(), options.projectName);
try {
await fs.ensureDir(projectDir);
spinner.succeed();
spinner.start('Cloning template repository...');
await execa('git', ['clone', '--depth', '1', 'https://github.com/AmanVarshney01/Better-T-Stack.git', projectDir]);
spinner.start("Cloning template repository...");
await execa("git", [
"clone",
"--depth",
"1",
"https://github.com/AmanVarshney01/Better-T-Stack.git",
projectDir,
]);
spinner.succeed();
spinner.start('Removing template .git folder...');
await fs.remove(path.join(projectDir, '.git'));
spinner.start("Removing template .git folder...");
await fs.remove(path.join(projectDir, ".git"));
spinner.succeed();
if (options.git) {
spinner.start('Initializing git repository...');
await execa('git', ['init'], { cwd: projectDir });
spinner.start("Initializing git repository...");
await execa("git", ["init"], { cwd: projectDir });
spinner.succeed();
}
spinner.start('Installing dependencies...');
await execa('bun', ['install'], { cwd: projectDir });
spinner.start("Installing dependencies...");
await execa("bun", ["install"], { cwd: projectDir });
spinner.succeed();
spinner.start('Setting up database...');
if (options.database === 'libsql') {
await execa('bun', ['run', 'db:local'], { cwd: projectDir });
await execa('bun', ['run', 'db:push'], { cwd: projectDir });
spinner.start("Setting up database...");
if (options.database === "libsql") {
await execa("bun", ["run", "db:local"], { cwd: projectDir });
await execa("bun", ["run", "db:push"], { cwd: projectDir });
}
spinner.succeed();
console.log('\n✨ Project created successfully!\n');
console.log('Next steps:');
console.log("\n✨ Project created successfully!\n");
console.log("Next steps:");
console.log(` cd ${options.projectName}`);
console.log(' bun dev');
console.log(" bun dev");
} catch (error) {
spinner.fail('Failed to create project');
spinner.fail("Failed to create project");
console.error(error);
process.exit(1);
}
}
}