mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
fix inconsistent flag behaviour
This commit is contained in:
@@ -24,7 +24,10 @@ export async function createProject(options: ProjectConfig) {
|
||||
spinner.succeed();
|
||||
console.log();
|
||||
|
||||
const initGit = await confirm({
|
||||
let shouldInitGit = options.git;
|
||||
|
||||
if (!options.yes && shouldInitGit) {
|
||||
shouldInitGit = await confirm({
|
||||
message: chalk.blue.bold("🔄 Initialize a git repository?"),
|
||||
default: true,
|
||||
}).catch((error) => {
|
||||
@@ -32,19 +35,18 @@ export async function createProject(options: ProjectConfig) {
|
||||
console.log();
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
if (initGit) {
|
||||
if (shouldInitGit) {
|
||||
spinner.start("Initializing git repository...");
|
||||
await $`git init ${projectDir}`;
|
||||
spinner.succeed();
|
||||
console.log();
|
||||
}
|
||||
|
||||
let packageManager = options.packageManager;
|
||||
|
||||
if (!packageManager) {
|
||||
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(
|
||||
@@ -57,9 +59,7 @@ export async function createProject(options: ProjectConfig) {
|
||||
throw error;
|
||||
});
|
||||
|
||||
if (useDetectedPackageManager) {
|
||||
packageManager = detectedPackageManager;
|
||||
} else {
|
||||
if (!useDetectedPackageManager) {
|
||||
console.log();
|
||||
packageManager = await select<PackageManager>({
|
||||
message: chalk.blue.bold("📦 Select package manager:"),
|
||||
@@ -96,8 +96,6 @@ export async function createProject(options: ProjectConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
console.log();
|
||||
|
||||
const installDeps = await confirm({
|
||||
message: chalk.blue.bold(
|
||||
`📦 Install dependencies using ${chalk.cyan(packageManager)}?`,
|
||||
@@ -114,16 +112,16 @@ export async function createProject(options: ProjectConfig) {
|
||||
spinner.start(`📦 Installing dependencies using ${packageManager}...`);
|
||||
switch (packageManager ?? DEFAULT_CONFIG.packageManager) {
|
||||
case "npm":
|
||||
await $`npm install ${projectDir}`;
|
||||
await $`cd ${projectDir} && npm install`;
|
||||
break;
|
||||
case "yarn":
|
||||
await $`yarn install ${projectDir}`;
|
||||
await $`cd ${projectDir} && yarn install`;
|
||||
break;
|
||||
case "pnpm":
|
||||
await $`pnpm install ${projectDir}`;
|
||||
await $`cd ${projectDir} && pnpm install`;
|
||||
break;
|
||||
case "bun":
|
||||
await $`bun install ${projectDir}`;
|
||||
await $`cd ${projectDir} && bun install`;
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unsupported package manager");
|
||||
|
||||
@@ -103,6 +103,7 @@ export async function setupTurso(projectDir: string) {
|
||||
|
||||
try {
|
||||
if (!canInstallCLI) {
|
||||
logger.warn("\nAutomatic Turso setup is not supported on Windows.");
|
||||
await writeEnvFile(projectDir);
|
||||
displayManualSetupInstructions();
|
||||
return;
|
||||
|
||||
@@ -30,7 +30,7 @@ async function gatherConfig(
|
||||
database: "libsql",
|
||||
auth: true,
|
||||
features: [],
|
||||
git: true,
|
||||
git: flags.git ?? true,
|
||||
};
|
||||
|
||||
config.projectName =
|
||||
@@ -119,6 +119,7 @@ async function main() {
|
||||
.option("--docker", "Include Docker setup")
|
||||
.option("--github-actions", "Include GitHub Actions")
|
||||
.option("--seo", "Include SEO setup")
|
||||
.option("--no-git", "Skip git initialization")
|
||||
.option(
|
||||
"--package-manager <type>",
|
||||
"Package manager to use (npm, yarn, pnpm, or bun)",
|
||||
@@ -133,6 +134,7 @@ async function main() {
|
||||
database: options.database as ProjectDatabase,
|
||||
auth: options.auth,
|
||||
packageManager: options.packageManager as PackageManager,
|
||||
git: options.git ?? true,
|
||||
features: [
|
||||
...(options.docker ? ["docker"] : []),
|
||||
...(options.githubActions ? ["github-actions"] : []),
|
||||
@@ -141,7 +143,21 @@ async function main() {
|
||||
};
|
||||
|
||||
const config = options.yes
|
||||
? DEFAULT_CONFIG
|
||||
? {
|
||||
...DEFAULT_CONFIG,
|
||||
yes: true,
|
||||
projectName: projectDirectory ?? DEFAULT_CONFIG.projectName,
|
||||
database: options.database ?? DEFAULT_CONFIG.database,
|
||||
auth: options.auth ?? DEFAULT_CONFIG.auth,
|
||||
git: options.git ?? DEFAULT_CONFIG.git,
|
||||
packageManager:
|
||||
options.packageManager ?? DEFAULT_CONFIG.packageManager,
|
||||
features: [
|
||||
...(options.docker ? ["docker"] : []),
|
||||
...(options.githubActions ? ["github-actions"] : []),
|
||||
...(options.seo ? ["SEO"] : []),
|
||||
] as ProjectFeature[],
|
||||
}
|
||||
: await gatherConfig(flagConfig);
|
||||
|
||||
if (options.yes) {
|
||||
|
||||
@@ -3,6 +3,7 @@ export type ProjectFeature = "docker" | "github-actions" | "SEO";
|
||||
export type ProjectDatabase = "libsql" | "postgres";
|
||||
|
||||
export type ProjectConfig = {
|
||||
yes?: boolean;
|
||||
projectName: string;
|
||||
git: boolean;
|
||||
database: ProjectDatabase;
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import chalk from "chalk";
|
||||
import { DEFAULT_CONFIG } from "../consts";
|
||||
import type { ProjectConfig } from "../types";
|
||||
import { getUserPkgManager } from "./get-package-manager";
|
||||
|
||||
export function generateReproducibleCommand(config: ProjectConfig): string {
|
||||
const flags: string[] = [];
|
||||
const defaultPackageManager = getUserPkgManager();
|
||||
|
||||
if (config.database !== DEFAULT_CONFIG.database) {
|
||||
flags.push(chalk.cyan(`--database ${config.database}`));
|
||||
@@ -15,9 +13,13 @@ export function generateReproducibleCommand(config: ProjectConfig): string {
|
||||
flags.push(chalk.yellow("--no-auth"));
|
||||
}
|
||||
|
||||
if (!config.git) {
|
||||
flags.push(chalk.red("--no-git"));
|
||||
}
|
||||
|
||||
if (
|
||||
config.packageManager &&
|
||||
config.packageManager !== defaultPackageManager
|
||||
config.packageManager !== DEFAULT_CONFIG.packageManager
|
||||
) {
|
||||
flags.push(chalk.magenta(`--package-manager ${config.packageManager}`));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user