diff --git a/package.json b/package.json index b6045e9d..bf2c4138 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "superplate-cli", - "version": "1.19.0", + "version": "1.20.0", "description": "The frontend boilerplate with superpowers", "license": "MIT", "repository": { diff --git a/src/Helper/git/index.ts b/src/Helper/git/index.ts index 44fd39f8..d9f3b190 100644 --- a/src/Helper/git/index.ts +++ b/src/Helper/git/index.ts @@ -32,4 +32,36 @@ export const GitHelper = { throw new Error(e instanceof Error ? e.message : (e as string)); } }, + CanGitInit: async (root: string): Promise => { + const [isGit, isHg] = await Promise.all([ + isInGitRepository(root), + isInMercurialRepository(root), + ]); + + return !isGit && !isHg; + }, }; + +async function isInGitRepository(root: string): Promise { + try { + await promisify(exec)("git rev-parse --is-inside-work-tree", { + cwd: root, + }); + return true; + } catch (_) { + // + } + return false; +} + +async function isInMercurialRepository(root: string): Promise { + try { + await promisify(exec)("hg --cwd . root", { + cwd: root, + }); + return true; + } catch (_) { + // + } + return false; +} diff --git a/src/saofile.ts b/src/saofile.ts index cdd7a492..e25c0122 100644 --- a/src/saofile.ts +++ b/src/saofile.ts @@ -3,6 +3,7 @@ import { extendBase, getPluginsArray, get_potential_package_managers, + GitHelper, handleIgnore, mergeBabel, mergeJSONFiles, @@ -404,7 +405,10 @@ const saoConfig: GeneratorConfig = { * Git init and install packages */ if (!debug) { - saoInstance.gitInit(); + const canGitInit = await GitHelper.CanGitInit(saoInstance.outDir); + if (canGitInit) { + saoInstance.gitInit(); + } await saoInstance.npmInstall({ npmClient: npmClient, installArgs: ["--silent"],