diff --git a/packages/create/src/git.ts b/packages/create/src/git.ts new file mode 100644 index 0000000..87c76f6 --- /dev/null +++ b/packages/create/src/git.ts @@ -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; +}