Skip to content

Commit 8245d18

Browse files
fix inconsistent flag behaviour
1 parent 50e336c commit 8245d18

File tree

5 files changed

+46
-28
lines changed

5 files changed

+46
-28
lines changed

apps/cli/src/helpers/create-project.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,29 @@ export async function createProject(options: ProjectConfig) {
2424
spinner.succeed();
2525
console.log();
2626

27-
const initGit = await confirm({
28-
message: chalk.blue.bold("🔄 Initialize a git repository?"),
29-
default: true,
30-
}).catch((error) => {
31-
spinner.stop();
32-
console.log();
33-
throw error;
34-
});
27+
let shouldInitGit = options.git;
28+
29+
if (!options.yes && shouldInitGit) {
30+
shouldInitGit = await confirm({
31+
message: chalk.blue.bold("🔄 Initialize a git repository?"),
32+
default: true,
33+
}).catch((error) => {
34+
spinner.stop();
35+
console.log();
36+
throw error;
37+
});
38+
}
3539

36-
if (initGit) {
40+
if (shouldInitGit) {
3741
spinner.start("Initializing git repository...");
3842
await $`git init ${projectDir}`;
3943
spinner.succeed();
40-
console.log();
4144
}
4245

43-
let packageManager = options.packageManager;
44-
45-
if (!packageManager) {
46-
const detectedPackageManager = getUserPkgManager();
46+
const detectedPackageManager = getUserPkgManager();
47+
let packageManager = options.packageManager ?? detectedPackageManager;
4748

49+
if (!options.yes) {
4850
const useDetectedPackageManager = await confirm({
4951
message: chalk.blue.bold(
5052
`📦 Use detected package manager (${chalk.cyan(
@@ -57,9 +59,7 @@ export async function createProject(options: ProjectConfig) {
5759
throw error;
5860
});
5961

60-
if (useDetectedPackageManager) {
61-
packageManager = detectedPackageManager;
62-
} else {
62+
if (!useDetectedPackageManager) {
6363
console.log();
6464
packageManager = await select<PackageManager>({
6565
message: chalk.blue.bold("📦 Select package manager:"),
@@ -96,8 +96,6 @@ export async function createProject(options: ProjectConfig) {
9696
}
9797
}
9898

99-
console.log();
100-
10199
const installDeps = await confirm({
102100
message: chalk.blue.bold(
103101
`📦 Install dependencies using ${chalk.cyan(packageManager)}?`,
@@ -114,16 +112,16 @@ export async function createProject(options: ProjectConfig) {
114112
spinner.start(`📦 Installing dependencies using ${packageManager}...`);
115113
switch (packageManager ?? DEFAULT_CONFIG.packageManager) {
116114
case "npm":
117-
await $`npm install ${projectDir}`;
115+
await $`cd ${projectDir} && npm install`;
118116
break;
119117
case "yarn":
120-
await $`yarn install ${projectDir}`;
118+
await $`cd ${projectDir} && yarn install`;
121119
break;
122120
case "pnpm":
123-
await $`pnpm install ${projectDir}`;
121+
await $`cd ${projectDir} && pnpm install`;
124122
break;
125123
case "bun":
126-
await $`bun install ${projectDir}`;
124+
await $`cd ${projectDir} && bun install`;
127125
break;
128126
default:
129127
throw new Error("Unsupported package manager");

apps/cli/src/helpers/db-setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export async function setupTurso(projectDir: string) {
103103

104104
try {
105105
if (!canInstallCLI) {
106+
logger.warn("\nAutomatic Turso setup is not supported on Windows.");
106107
await writeEnvFile(projectDir);
107108
displayManualSetupInstructions();
108109
return;

apps/cli/src/index.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async function gatherConfig(
3030
database: "libsql",
3131
auth: true,
3232
features: [],
33-
git: true,
33+
git: flags.git ?? true,
3434
};
3535

3636
config.projectName =
@@ -119,6 +119,7 @@ async function main() {
119119
.option("--docker", "Include Docker setup")
120120
.option("--github-actions", "Include GitHub Actions")
121121
.option("--seo", "Include SEO setup")
122+
.option("--no-git", "Skip git initialization")
122123
.option(
123124
"--package-manager <type>",
124125
"Package manager to use (npm, yarn, pnpm, or bun)",
@@ -133,6 +134,7 @@ async function main() {
133134
database: options.database as ProjectDatabase,
134135
auth: options.auth,
135136
packageManager: options.packageManager as PackageManager,
137+
git: options.git ?? true,
136138
features: [
137139
...(options.docker ? ["docker"] : []),
138140
...(options.githubActions ? ["github-actions"] : []),
@@ -141,7 +143,21 @@ async function main() {
141143
};
142144

143145
const config = options.yes
144-
? DEFAULT_CONFIG
146+
? {
147+
...DEFAULT_CONFIG,
148+
yes: true,
149+
projectName: projectDirectory ?? DEFAULT_CONFIG.projectName,
150+
database: options.database ?? DEFAULT_CONFIG.database,
151+
auth: options.auth ?? DEFAULT_CONFIG.auth,
152+
git: options.git ?? DEFAULT_CONFIG.git,
153+
packageManager:
154+
options.packageManager ?? DEFAULT_CONFIG.packageManager,
155+
features: [
156+
...(options.docker ? ["docker"] : []),
157+
...(options.githubActions ? ["github-actions"] : []),
158+
...(options.seo ? ["SEO"] : []),
159+
] as ProjectFeature[],
160+
}
145161
: await gatherConfig(flagConfig);
146162

147163
if (options.yes) {

apps/cli/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type ProjectFeature = "docker" | "github-actions" | "SEO";
33
export type ProjectDatabase = "libsql" | "postgres";
44

55
export type ProjectConfig = {
6+
yes?: boolean;
67
projectName: string;
78
git: boolean;
89
database: ProjectDatabase;

apps/cli/src/utils/generate-reproducible-command.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import chalk from "chalk";
22
import { DEFAULT_CONFIG } from "../consts";
33
import type { ProjectConfig } from "../types";
4-
import { getUserPkgManager } from "./get-package-manager";
54

65
export function generateReproducibleCommand(config: ProjectConfig): string {
76
const flags: string[] = [];
8-
const defaultPackageManager = getUserPkgManager();
97

108
if (config.database !== DEFAULT_CONFIG.database) {
119
flags.push(chalk.cyan(`--database ${config.database}`));
@@ -15,9 +13,13 @@ export function generateReproducibleCommand(config: ProjectConfig): string {
1513
flags.push(chalk.yellow("--no-auth"));
1614
}
1715

16+
if (!config.git) {
17+
flags.push(chalk.red("--no-git"));
18+
}
19+
1820
if (
1921
config.packageManager &&
20-
config.packageManager !== defaultPackageManager
22+
config.packageManager !== DEFAULT_CONFIG.packageManager
2123
) {
2224
flags.push(chalk.magenta(`--package-manager ${config.packageManager}`));
2325
}

0 commit comments

Comments
 (0)