auto git commit during if git init is true

This commit is contained in:
Aman Varshney
2025-06-29 02:20:17 +05:30
parent 161121c425
commit 3ae5ab9782
6 changed files with 46 additions and 37 deletions

View File

@@ -0,0 +1,5 @@
---
"create-better-t-stack": patch
---
auto git commit if git init is true

View File

@@ -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,

View File

@@ -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<void> {
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"}`;
}

View File

@@ -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")

View File

@@ -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<void> {
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}`);
}
}

View File

@@ -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",
},