feat(create): optional git init and initial commit

Made-with: Cursor
This commit is contained in:
zuiidea
2026-04-14 22:33:01 +08:00
parent 3e630785bb
commit 56943a3a95
+22
View File
@@ -0,0 +1,22 @@
import { spawnSync } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
export function tryGitInit(root: string, enabled: boolean): boolean {
if (!enabled) {
const gitDir = path.join(root, ".git");
if (fs.existsSync(gitDir)) {
fs.rmSync(gitDir, { recursive: true, force: true });
}
return false;
}
const init = spawnSync("git", ["init"], { cwd: root, stdio: "ignore" });
if (init.status !== 0) return false;
spawnSync("git", ["add", "-A"], { cwd: root, stdio: "ignore" });
spawnSync(
"git",
["commit", "-m", "chore: initial commit from create-antd-admin"],
{ cwd: root, stdio: "ignore" }
);
return true;
}