diff --git a/.changeset/purple-wings-notice.md b/.changeset/purple-wings-notice.md new file mode 100644 index 0000000..7a225c7 --- /dev/null +++ b/.changeset/purple-wings-notice.md @@ -0,0 +1,5 @@ +--- +"create-better-t-stack": patch +--- + +auto git commit if git init is true diff --git a/apps/cli/src/helpers/project-generation/create-project.ts b/apps/cli/src/helpers/project-generation/create-project.ts index 34aa53f..c4d37b4 100644 --- a/apps/cli/src/helpers/project-generation/create-project.ts +++ b/apps/cli/src/helpers/project-generation/create-project.ts @@ -15,9 +15,10 @@ import { } from "../setup/runtime-setup"; import { createReadme } from "./create-readme"; import { setupEnvironmentVariables } from "./env-setup"; +import { initializeGit } from "./git"; import { installDependencies } from "./install-dependencies"; import { displayPostInstallInstructions } from "./post-installation"; -import { initializeGit, updatePackageConfigurations } from "./project-config"; +import { updatePackageConfigurations } from "./project-config"; import { copyBaseTemplate, handleExtras, @@ -75,8 +76,6 @@ export async function createProject(options: ProjectConfig) { await writeBtsConfig(options); - await initializeGit(projectDir, options.git); - log.success("Project template successfully scaffolded!"); if (options.install) { @@ -87,6 +86,8 @@ export async function createProject(options: ProjectConfig) { await generateCloudflareWorkerTypes(options); } + await initializeGit(projectDir, options.git); + displayPostInstallInstructions({ ...options, depsInstalled: options.install, diff --git a/apps/cli/src/helpers/project-generation/git.ts b/apps/cli/src/helpers/project-generation/git.ts new file mode 100644 index 0000000..21ceccf --- /dev/null +++ b/apps/cli/src/helpers/project-generation/git.ts @@ -0,0 +1,34 @@ +import { log } from "@clack/prompts"; +import { $ } from "execa"; +import pc from "picocolors"; + +export async function initializeGit( + projectDir: string, + useGit: boolean, +): Promise { + if (!useGit) return; + + const gitVersionResult = await $({ + cwd: projectDir, + reject: false, + stderr: "pipe", + })`git --version`; + + if (gitVersionResult.exitCode !== 0) { + log.warn(pc.yellow("Git is not installed")); + return; + } + + const result = await $({ + cwd: projectDir, + reject: false, + stderr: "pipe", + })`git init`; + + if (result.exitCode !== 0) { + throw new Error(`Git initialization failed: ${result.stderr}`); + } + + await $({ cwd: projectDir })`git add -A`; + await $({ cwd: projectDir })`git commit -m ${"Initial commit"}`; +} diff --git a/apps/cli/src/helpers/project-generation/post-installation.ts b/apps/cli/src/helpers/project-generation/post-installation.ts index d7b0792..98feaba 100644 --- a/apps/cli/src/helpers/project-generation/post-installation.ts +++ b/apps/cli/src/helpers/project-generation/post-installation.ts @@ -48,9 +48,7 @@ export function displayPostInstallInstructions( ? getNativeInstructions(isConvex) : ""; const pwaInstructions = - addons?.includes("pwa") && - (frontend?.includes("react-router") || - frontend?.includes("tanstack-router")) + addons?.includes("pwa") && frontend?.includes("react-router") ? getPwaInstructions() : ""; const starlightInstructions = addons?.includes("starlight") diff --git a/apps/cli/src/helpers/project-generation/project-config.ts b/apps/cli/src/helpers/project-generation/project-config.ts index e4fc9a7..620874f 100644 --- a/apps/cli/src/helpers/project-generation/project-config.ts +++ b/apps/cli/src/helpers/project-generation/project-config.ts @@ -1,8 +1,7 @@ import path from "node:path"; import { log } from "@clack/prompts"; -import { $, execa } from "execa"; +import { execa } from "execa"; import fs from "fs-extra"; -import pc from "picocolors"; import type { ProjectConfig } from "../../types"; export async function updatePackageConfigurations( @@ -268,31 +267,3 @@ async function updateConvexPackageJson( await fs.writeJson(convexPackageJsonPath, convexPackageJson, { spaces: 2 }); } - -export async function initializeGit( - projectDir: string, - useGit: boolean, -): Promise { - if (!useGit) return; - - const gitVersionResult = await $({ - cwd: projectDir, - reject: false, - stderr: "pipe", - })`git --version`; - - if (gitVersionResult.exitCode !== 0) { - log.warn(pc.yellow("Git is not installed")); - return; - } - - const result = await $({ - cwd: projectDir, - reject: false, - stderr: "pipe", - })`git init`; - - if (result.exitCode !== 0) { - throw new Error(`Git initialization failed: ${result.stderr}`); - } -} diff --git a/bun.lock b/bun.lock index dab267a..15d99b2 100644 --- a/bun.lock +++ b/bun.lock @@ -14,7 +14,7 @@ }, "apps/cli": { "name": "create-better-t-stack", - "version": "2.22.6", + "version": "2.22.8", "bin": { "create-better-t-stack": "dist/index.js", },