mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
refractor: migrate inquirer to @clack/prompts
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
},
|
||||
"files": ["dist", "templates"],
|
||||
"dependencies": {
|
||||
"@inquirer/prompts": "^7.3.1",
|
||||
"@clack/prompts": "^0.10.0",
|
||||
"chalk": "^5.3.0",
|
||||
"commander": "^13.1.0",
|
||||
"execa": "^8.0.1",
|
||||
|
||||
@@ -1,164 +1,96 @@
|
||||
import path from "node:path";
|
||||
import { confirm, select } from "@inquirer/prompts";
|
||||
import { cancel, confirm, isCancel, log, spinner, tasks } from "@clack/prompts";
|
||||
import chalk from "chalk";
|
||||
import { $ } from "execa";
|
||||
import fs from "fs-extra";
|
||||
import ora from "ora";
|
||||
import { DEFAULT_CONFIG } from "../consts";
|
||||
import type { PackageManager, ProjectConfig } from "../types";
|
||||
import { getUserPkgManager } from "../utils/get-package-manager";
|
||||
import { logger } from "../utils/logger";
|
||||
import type { ProjectConfig } from "../types";
|
||||
import { setupTurso } from "./db-setup";
|
||||
|
||||
export async function createProject(options: ProjectConfig) {
|
||||
const spinner = ora("Creating project directory...").start();
|
||||
const s = spinner();
|
||||
const projectDir = path.resolve(process.cwd(), options.projectName);
|
||||
let shouldInstallDeps = false;
|
||||
|
||||
try {
|
||||
await fs.ensureDir(projectDir);
|
||||
spinner.succeed();
|
||||
console.log();
|
||||
await tasks([
|
||||
{
|
||||
title: "Creating project directory",
|
||||
task: async () => {
|
||||
await fs.ensureDir(projectDir);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Cloning template repository",
|
||||
task: async () => {
|
||||
try {
|
||||
await $`npx degit AmanVarshney01/Better-T-Stack ${projectDir}`;
|
||||
} catch (error) {
|
||||
log.error("Failed to clone template repository");
|
||||
if (error instanceof Error) {
|
||||
log.error(error.message);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Initializing git repository",
|
||||
task: async () => {
|
||||
if (options.git) {
|
||||
await $`git init ${projectDir}`;
|
||||
}
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
spinner.start("Cloning template repository...");
|
||||
await $`npx degit https://github.com/AmanVarshney01/Better-T-Stack.git ${projectDir}`;
|
||||
spinner.succeed();
|
||||
console.log();
|
||||
|
||||
let shouldInitGit = options.git;
|
||||
|
||||
if (!options.yes && shouldInitGit) {
|
||||
shouldInitGit = await confirm({
|
||||
message: chalk.blue.bold("🔄 Initialize a git repository?"),
|
||||
default: true,
|
||||
}).catch((error) => {
|
||||
spinner.stop();
|
||||
console.log();
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
if (shouldInitGit) {
|
||||
spinner.start("Initializing git repository...");
|
||||
await $`git init ${projectDir}`;
|
||||
spinner.succeed();
|
||||
}
|
||||
|
||||
const detectedPackageManager = getUserPkgManager();
|
||||
let packageManager = options.packageManager ?? detectedPackageManager;
|
||||
|
||||
if (!options.yes) {
|
||||
const useDetectedPackageManager = await confirm({
|
||||
message: chalk.blue.bold(
|
||||
`📦 Use detected package manager (${chalk.cyan(
|
||||
detectedPackageManager,
|
||||
)})?`,
|
||||
),
|
||||
default: true,
|
||||
}).catch((error) => {
|
||||
spinner.stop();
|
||||
throw error;
|
||||
});
|
||||
|
||||
if (!useDetectedPackageManager) {
|
||||
console.log();
|
||||
packageManager = await select<PackageManager>({
|
||||
message: chalk.blue.bold("📦 Select package manager:"),
|
||||
choices: [
|
||||
{
|
||||
value: "npm",
|
||||
name: chalk.yellow("npm"),
|
||||
description: chalk.dim("Node Package Manager"),
|
||||
},
|
||||
{
|
||||
value: "yarn",
|
||||
name: chalk.blue("yarn"),
|
||||
description: chalk.dim(
|
||||
"Fast, reliable, and secure dependency management",
|
||||
),
|
||||
},
|
||||
{
|
||||
value: "pnpm",
|
||||
name: chalk.magenta("pnpm"),
|
||||
description: chalk.dim(
|
||||
"Fast, disk space efficient package manager",
|
||||
),
|
||||
},
|
||||
{
|
||||
value: "bun",
|
||||
name: chalk.cyan("bun"),
|
||||
description: chalk.dim("All-in-one JavaScript runtime & toolkit"),
|
||||
},
|
||||
],
|
||||
}).catch((error) => {
|
||||
spinner.stop();
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const installDeps = await confirm({
|
||||
message: chalk.blue.bold(
|
||||
`📦 Install dependencies using ${chalk.cyan(packageManager)}?`,
|
||||
),
|
||||
default: true,
|
||||
}).catch((error) => {
|
||||
spinner.stop();
|
||||
throw error;
|
||||
const installDepsResponse = await confirm({
|
||||
message: `📦 Install dependencies using ${options.packageManager}?`,
|
||||
});
|
||||
|
||||
console.log();
|
||||
if (isCancel(installDepsResponse)) {
|
||||
cancel("Operation cancelled");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (installDeps) {
|
||||
spinner.start(`📦 Installing dependencies using ${packageManager}...`);
|
||||
switch (packageManager ?? DEFAULT_CONFIG.packageManager) {
|
||||
case "npm":
|
||||
await $`cd ${projectDir} && npm install`;
|
||||
break;
|
||||
case "yarn":
|
||||
await $`cd ${projectDir} && yarn install`;
|
||||
break;
|
||||
case "pnpm":
|
||||
await $`cd ${projectDir} && pnpm install`;
|
||||
break;
|
||||
case "bun":
|
||||
await $`cd ${projectDir} && bun install`;
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unsupported package manager");
|
||||
shouldInstallDeps = installDepsResponse;
|
||||
|
||||
if (shouldInstallDeps) {
|
||||
s.start(`Installing dependencies using ${options.packageManager}...`);
|
||||
try {
|
||||
await $({
|
||||
cwd: projectDir,
|
||||
stdio: "inherit",
|
||||
})`${options.packageManager} install`;
|
||||
s.stop("Dependencies installed successfully");
|
||||
} catch (error) {
|
||||
s.stop("Failed to install dependencies");
|
||||
if (error instanceof Error) {
|
||||
log.error(`Installation error: ${error.message}`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
spinner.succeed();
|
||||
console.log();
|
||||
}
|
||||
|
||||
if (options.database === "libsql") {
|
||||
await setupTurso(projectDir);
|
||||
}
|
||||
|
||||
logger.success("\n✨ Project created successfully!\n");
|
||||
logger.info("Next steps:");
|
||||
logger.info(` cd ${options.projectName}`);
|
||||
if (!installDeps) {
|
||||
logger.info(` ${packageManager} install`);
|
||||
log.success("✨ Project created successfully!\n");
|
||||
log.info(chalk.dim("Next steps:"));
|
||||
log.info(` cd ${options.projectName}`);
|
||||
if (!shouldInstallDeps) {
|
||||
log.info(` ${options.packageManager} install`);
|
||||
}
|
||||
logger.info(
|
||||
` ${packageManager === "npm" ? "npm run" : packageManager} dev`,
|
||||
log.info(
|
||||
` ${
|
||||
options.packageManager === "npm" ? "npm run" : options.packageManager
|
||||
} dev`,
|
||||
);
|
||||
} catch (error) {
|
||||
spinner.stop();
|
||||
|
||||
if (
|
||||
error instanceof Error &&
|
||||
(error.name === "ExitPromptError" ||
|
||||
error.message.includes("User force closed"))
|
||||
) {
|
||||
console.log("\n");
|
||||
logger.warn("Operation cancelled");
|
||||
process.exit(0);
|
||||
return;
|
||||
s.stop("Failed");
|
||||
if (error instanceof Error) {
|
||||
log.error(`Error during project creation: ${error.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
spinner.fail("Failed to create project");
|
||||
logger.error("Error during project creation:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { confirm, input } from "@inquirer/prompts";
|
||||
import chalk from "chalk";
|
||||
import * as p from "@clack/prompts";
|
||||
import { $ } from "execa";
|
||||
import fs from "fs-extra";
|
||||
import ora, { type Ora } from "ora";
|
||||
import { logger } from "../utils/logger";
|
||||
import { isTursoInstalled, isTursoLoggedIn } from "../utils/turso-cli";
|
||||
|
||||
interface TursoConfig {
|
||||
@@ -13,21 +10,21 @@ interface TursoConfig {
|
||||
authToken: string;
|
||||
}
|
||||
|
||||
async function loginToTurso(spinner: Ora) {
|
||||
async function loginToTurso() {
|
||||
const spinner = p.spinner();
|
||||
try {
|
||||
spinner.start("Logging in to Turso...");
|
||||
await $`turso auth login`;
|
||||
spinner.succeed("Logged in to Turso successfully!");
|
||||
console.log();
|
||||
spinner.stop("Logged in to Turso successfully!");
|
||||
} catch (error) {
|
||||
spinner.fail("Failed to log in to Turso");
|
||||
spinner.stop("Failed to log in to Turso");
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function installTursoCLI(isMac: boolean, spinner: Ora) {
|
||||
async function installTursoCLI(isMac: boolean) {
|
||||
const spinner = p.spinner();
|
||||
try {
|
||||
console.log();
|
||||
spinner.start("Installing Turso CLI...");
|
||||
|
||||
if (isMac) {
|
||||
@@ -38,15 +35,14 @@ async function installTursoCLI(isMac: boolean, spinner: Ora) {
|
||||
await $`bash -c '${installScript}'`;
|
||||
}
|
||||
|
||||
spinner.succeed("Turso CLI installed successfully!");
|
||||
console.log();
|
||||
spinner.stop("Turso CLI installed successfully!");
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes("User force closed")) {
|
||||
spinner.stop();
|
||||
logger.warn("\nTurso CLI installation cancelled by user");
|
||||
p.log.warn("Turso CLI installation cancelled by user");
|
||||
throw new Error("Installation cancelled");
|
||||
}
|
||||
spinner.fail("Failed to install Turso CLI");
|
||||
spinner.stop("Failed to install Turso CLI");
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +58,6 @@ async function createTursoDatabase(dbName: string): Promise<TursoConfig> {
|
||||
}
|
||||
|
||||
const { stdout: dbUrl } = await $`turso db show ${dbName} --url`;
|
||||
|
||||
const { stdout: authToken } = await $`turso db tokens create ${dbName}`;
|
||||
|
||||
return {
|
||||
@@ -83,27 +78,28 @@ TURSO_AUTH_TOKEN=`;
|
||||
}
|
||||
|
||||
function displayManualSetupInstructions() {
|
||||
logger.info("\n📝 Manual Turso Setup Instructions:");
|
||||
logger.info("1. Visit https://turso.tech and create an account");
|
||||
logger.info("2. Create a new database from the dashboard");
|
||||
logger.info("3. Get your database URL and authentication token");
|
||||
logger.info(
|
||||
p.log.info("📝 Manual Turso Setup Instructions:");
|
||||
p.log.info("1. Visit https://turso.tech and create an account");
|
||||
p.log.info("2. Create a new database from the dashboard");
|
||||
p.log.info("3. Get your database URL and authentication token");
|
||||
p.log.info(
|
||||
"4. Add these credentials to the .env file in packages/server/.env",
|
||||
);
|
||||
logger.info("\nThe .env file has been created with placeholder variables:");
|
||||
logger.info("TURSO_DATABASE_URL=your_database_url");
|
||||
logger.info("TURSO_AUTH_TOKEN=your_auth_token");
|
||||
p.log.info("\nThe .env file has been created with placeholder variables:");
|
||||
p.log.info("TURSO_DATABASE_URL=your_database_url");
|
||||
p.log.info("TURSO_AUTH_TOKEN=your_auth_token");
|
||||
}
|
||||
|
||||
export async function setupTurso(projectDir: string) {
|
||||
const spinner = ora();
|
||||
p.intro("Setting up Turso...");
|
||||
|
||||
const platform = os.platform();
|
||||
const isMac = platform === "darwin";
|
||||
const canInstallCLI = platform !== "win32";
|
||||
|
||||
try {
|
||||
if (!canInstallCLI) {
|
||||
logger.warn("\nAutomatic Turso setup is not supported on Windows.");
|
||||
p.log.warn("Automatic Turso setup is not supported on Windows.");
|
||||
await writeEnvFile(projectDir);
|
||||
displayManualSetupInstructions();
|
||||
return;
|
||||
@@ -112,78 +108,68 @@ export async function setupTurso(projectDir: string) {
|
||||
const isCliInstalled = await isTursoInstalled();
|
||||
|
||||
if (!isCliInstalled) {
|
||||
const shouldInstall = await confirm({
|
||||
message: chalk.blue.bold("🔧 Would you like to install Turso CLI?"),
|
||||
default: true,
|
||||
}).catch((error) => {
|
||||
spinner.stop();
|
||||
throw error;
|
||||
const shouldInstall = await p.confirm({
|
||||
message: "Would you like to install Turso CLI?",
|
||||
});
|
||||
|
||||
if (p.isCancel(shouldInstall)) {
|
||||
p.cancel("Operation cancelled");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (!shouldInstall) {
|
||||
await writeEnvFile(projectDir);
|
||||
displayManualSetupInstructions();
|
||||
return;
|
||||
}
|
||||
|
||||
await installTursoCLI(isMac, spinner);
|
||||
await installTursoCLI(isMac);
|
||||
}
|
||||
|
||||
const isLoggedIn = await isTursoLoggedIn();
|
||||
if (!isLoggedIn) {
|
||||
await loginToTurso(spinner);
|
||||
await loginToTurso();
|
||||
}
|
||||
|
||||
const defaultDbName = path.basename(projectDir);
|
||||
|
||||
let dbName = await input({
|
||||
message: chalk.blue.bold("💾 Enter database name:"),
|
||||
default: defaultDbName,
|
||||
}).catch((error) => {
|
||||
spinner.stop();
|
||||
throw error;
|
||||
});
|
||||
|
||||
let success = false;
|
||||
let dbName = "";
|
||||
let suggestedName = path.basename(projectDir);
|
||||
|
||||
while (!success) {
|
||||
const dbNameResponse = await p.text({
|
||||
message: "Enter database name:",
|
||||
defaultValue: suggestedName,
|
||||
});
|
||||
|
||||
if (p.isCancel(dbNameResponse)) {
|
||||
p.cancel("Operation cancelled");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
dbName = dbNameResponse as string;
|
||||
const spinner = p.spinner();
|
||||
|
||||
try {
|
||||
console.log();
|
||||
spinner.start(`Creating Turso database "${dbName}"...`);
|
||||
const config = await createTursoDatabase(dbName);
|
||||
await writeEnvFile(projectDir, config);
|
||||
spinner.succeed("Turso database configured successfully!");
|
||||
spinner.stop("Turso database configured successfully!");
|
||||
success = true;
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message === "DATABASE_EXISTS") {
|
||||
spinner.warn(`Database "${dbName}" already exists`);
|
||||
dbName = await input({
|
||||
message: "Please enter a different database name:",
|
||||
default: `${dbName}-${Math.floor(Math.random() * 1000)}`,
|
||||
}).catch((error) => {
|
||||
spinner.stop();
|
||||
throw error;
|
||||
});
|
||||
spinner.stop(`Database "${dbName}" already exists`);
|
||||
suggestedName = `${dbName}-${Math.floor(Math.random() * 1000)}`;
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p.outro("Turso setup completed successfully!");
|
||||
} catch (error) {
|
||||
spinner.stop();
|
||||
|
||||
if (
|
||||
error instanceof Error &&
|
||||
(error.name === "ExitPromptError" ||
|
||||
error.message.includes("User force closed"))
|
||||
) {
|
||||
logger.warn("\nTurso setup cancelled");
|
||||
await writeEnvFile(projectDir);
|
||||
displayManualSetupInstructions();
|
||||
return;
|
||||
}
|
||||
|
||||
logger.error("Error during Turso setup:", error);
|
||||
p.log.error(`Error during Turso setup: ${error}`);
|
||||
await writeEnvFile(projectDir);
|
||||
displayManualSetupInstructions();
|
||||
p.outro("Setup completed with manual configuration required.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
import { checkbox, confirm, input, select } from "@inquirer/prompts";
|
||||
import {
|
||||
cancel,
|
||||
confirm,
|
||||
group,
|
||||
intro,
|
||||
isCancel,
|
||||
multiselect,
|
||||
outro,
|
||||
select,
|
||||
spinner,
|
||||
text,
|
||||
} from "@clack/prompts";
|
||||
import chalk from "chalk";
|
||||
import { Command } from "commander";
|
||||
import { DEFAULT_CONFIG } from "./consts";
|
||||
@@ -11,6 +22,7 @@ import type {
|
||||
ProjectFeature,
|
||||
} from "./types";
|
||||
import { generateReproducibleCommand } from "./utils/generate-reproducible-command";
|
||||
import { getUserPkgManager } from "./utils/get-package-manager";
|
||||
import { getVersion } from "./utils/get-version";
|
||||
import { logger } from "./utils/logger";
|
||||
|
||||
@@ -25,88 +37,110 @@ const program = new Command();
|
||||
async function gatherConfig(
|
||||
flags: Partial<ProjectConfig>,
|
||||
): Promise<ProjectConfig> {
|
||||
const config: ProjectConfig = {
|
||||
projectName: "",
|
||||
database: "libsql",
|
||||
auth: true,
|
||||
features: [],
|
||||
const result = await group({
|
||||
projectName: () =>
|
||||
text({
|
||||
message: "📝 Project name",
|
||||
placeholder: "my-better-t-app",
|
||||
validate: (value) => {
|
||||
if (!value) return "Project name is required";
|
||||
},
|
||||
}),
|
||||
database: () =>
|
||||
!flags.database
|
||||
? select<ProjectDatabase>({
|
||||
message: "💾 Select database",
|
||||
options: [
|
||||
{
|
||||
value: "libsql",
|
||||
label: "libSQL",
|
||||
hint: "✨ (Recommended) - Turso's embedded SQLite database",
|
||||
},
|
||||
{
|
||||
value: "postgres",
|
||||
label: "PostgreSQL",
|
||||
hint: "🐘 Traditional relational database",
|
||||
},
|
||||
],
|
||||
})
|
||||
: Promise.resolve(flags.database),
|
||||
auth: () =>
|
||||
flags.auth === undefined
|
||||
? confirm({
|
||||
message: "🔐 Add authentication with Better-Auth?",
|
||||
})
|
||||
: Promise.resolve(flags.auth),
|
||||
features: () =>
|
||||
!flags.features
|
||||
? multiselect<ProjectFeature>({
|
||||
message: "🎯 Select additional features",
|
||||
options: [
|
||||
{
|
||||
value: "docker",
|
||||
label: "Docker setup",
|
||||
hint: "🐳 Containerize your application",
|
||||
},
|
||||
{
|
||||
value: "github-actions",
|
||||
label: "GitHub Actions",
|
||||
hint: "⚡ CI/CD workflows",
|
||||
},
|
||||
{
|
||||
value: "SEO",
|
||||
label: "Basic SEO setup",
|
||||
hint: "🔍 Search engine optimization configuration",
|
||||
},
|
||||
],
|
||||
})
|
||||
: Promise.resolve(flags.features),
|
||||
packageManager: async () => {
|
||||
const detectedPackageManager = getUserPkgManager();
|
||||
|
||||
const useDetected = await confirm({
|
||||
message: `📦 Use detected package manager (${detectedPackageManager})?`,
|
||||
});
|
||||
|
||||
if (useDetected) return detectedPackageManager;
|
||||
|
||||
return select<PackageManager>({
|
||||
message: "📦 Select package manager",
|
||||
options: [
|
||||
{ value: "npm", label: "npm", hint: "Node Package Manager" },
|
||||
{
|
||||
value: "yarn",
|
||||
label: "yarn",
|
||||
hint: "Fast, reliable, and secure dependency management",
|
||||
},
|
||||
{
|
||||
value: "pnpm",
|
||||
label: "pnpm",
|
||||
hint: "Fast, disk space efficient package manager",
|
||||
},
|
||||
{
|
||||
value: "bun",
|
||||
label: "bun",
|
||||
hint: "All-in-one JavaScript runtime & toolkit",
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
projectName: result.projectName as string,
|
||||
database: (result.database as ProjectDatabase) ?? "libsql",
|
||||
auth: (result.auth as boolean) ?? true,
|
||||
features: (result.features as ProjectFeature[]) ?? [],
|
||||
git: flags.git ?? true,
|
||||
packageManager: (result.packageManager as PackageManager) ?? "npm",
|
||||
};
|
||||
|
||||
config.projectName =
|
||||
flags.projectName ??
|
||||
(await input({
|
||||
message: chalk.blue.bold("📝 Project name:"),
|
||||
default: "my-better-t-app",
|
||||
}));
|
||||
|
||||
console.log();
|
||||
|
||||
if (flags.database) {
|
||||
config.database = flags.database;
|
||||
} else {
|
||||
config.database = await select<ProjectDatabase>({
|
||||
message: chalk.blue.bold("💾 Select database:"),
|
||||
choices: [
|
||||
{
|
||||
value: "libsql",
|
||||
name: chalk.green("libSQL"),
|
||||
description: chalk.dim(
|
||||
"✨ (Recommended) - Turso's embedded SQLite database",
|
||||
),
|
||||
},
|
||||
{
|
||||
value: "postgres",
|
||||
name: chalk.yellow("PostgreSQL"),
|
||||
description: chalk.dim("🐘 Traditional relational database"),
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
console.log();
|
||||
|
||||
config.auth =
|
||||
flags.auth ??
|
||||
(await confirm({
|
||||
message: chalk.blue.bold("🔐 Add authentication with Better-Auth?"),
|
||||
default: true,
|
||||
}));
|
||||
|
||||
console.log();
|
||||
|
||||
if (flags.features) {
|
||||
config.features = flags.features;
|
||||
} else {
|
||||
config.features = await checkbox<ProjectFeature>({
|
||||
message: chalk.blue.bold("🎯 Select additional features:"),
|
||||
choices: [
|
||||
{
|
||||
value: "docker",
|
||||
name: chalk.cyan("Docker setup"),
|
||||
description: chalk.dim("🐳 Containerize your application"),
|
||||
},
|
||||
{
|
||||
value: "github-actions",
|
||||
name: chalk.magenta("GitHub Actions"),
|
||||
description: chalk.dim("⚡ CI/CD workflows"),
|
||||
},
|
||||
{
|
||||
value: "SEO",
|
||||
name: chalk.green("Basic SEO setup"),
|
||||
description: chalk.dim("🔍 Search engine optimization configuration"),
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const s = spinner();
|
||||
try {
|
||||
renderTitle();
|
||||
logger.info(chalk.bold(" Creating a new Better-T Stack project...\n"));
|
||||
intro(chalk.bold("Creating a new Better-T Stack project"));
|
||||
program
|
||||
.name("create-better-t-stack")
|
||||
.description("Create a new Better-T Stack project")
|
||||
@@ -161,7 +195,7 @@ async function main() {
|
||||
: await gatherConfig(flagConfig);
|
||||
|
||||
if (options.yes) {
|
||||
logger.info(chalk.blue.bold("\n📦 Using default configuration:"));
|
||||
s.start("Using default configuration");
|
||||
const colorizedConfig = {
|
||||
projectName: chalk.green(config.projectName),
|
||||
database: chalk.yellow(config.database),
|
||||
@@ -195,25 +229,26 @@ async function main() {
|
||||
chalk.dim("└─") + chalk.blue(" Git Init: ") + colorizedConfig.git,
|
||||
);
|
||||
console.log();
|
||||
s.stop("Configuration loaded");
|
||||
}
|
||||
|
||||
await createProject(config);
|
||||
|
||||
logger.info("\n📋 To reproduce this setup, run:");
|
||||
logger.success(chalk.cyan(generateReproducibleCommand(config)));
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
(error.name === "ExitPromptError" ||
|
||||
error.message.includes("User force closed"))
|
||||
) {
|
||||
console.log("\n");
|
||||
logger.warn("Operation cancelled");
|
||||
process.exit(0);
|
||||
}
|
||||
console.log();
|
||||
console.log(
|
||||
chalk.dim("🔄 You can reproduce this setup with the following command:"),
|
||||
);
|
||||
console.log();
|
||||
console.log(chalk.dim(" ") + generateReproducibleCommand(config));
|
||||
console.log();
|
||||
|
||||
logger.error("An unexpected error occurred:", error);
|
||||
process.exit(1);
|
||||
outro("Project created successfully! 🎉");
|
||||
} catch (error) {
|
||||
s.stop("Failed");
|
||||
if (error instanceof Error) {
|
||||
cancel("An unexpected error occurred");
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export type ProjectConfig = {
|
||||
git: boolean;
|
||||
database: ProjectDatabase;
|
||||
auth: boolean;
|
||||
packageManager?: PackageManager;
|
||||
packageManager: PackageManager;
|
||||
features: ProjectFeature[];
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user