mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
auto git commit during if git init is true
This commit is contained in:
5
.changeset/purple-wings-notice.md
Normal file
5
.changeset/purple-wings-notice.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"create-better-t-stack": patch
|
||||
---
|
||||
|
||||
auto git commit if git init is true
|
||||
@@ -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,
|
||||
|
||||
34
apps/cli/src/helpers/project-generation/git.ts
Normal file
34
apps/cli/src/helpers/project-generation/git.ts
Normal 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"}`;
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
@@ -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}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user