From cb7960d32daa77ac27fda186ecec9eccbf92b497 Mon Sep 17 00:00:00 2001 From: Mark H <70579116+mark-dr@users.noreply.github.com> Date: Wed, 5 Apr 2023 12:31:25 +0100 Subject: [PATCH 1/2] Use path.join instead of string concatenation --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index d8a4d5e..f7e369b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -97,7 +97,7 @@ export interface Options { // Note: Only works if the git repository folder matches tsconfig folder const getGitStatus = (dir: string) => new Promise((resolve) => { const dirPath = path.dirname(dir); - return exec(`git --git-dir="${dirPath + "\\.git"}" --work-tree="${dirPath}" status --porcelain`, (err, stdout) => { + return exec(`git --git-dir="${path.join(dirPath, ".git")}" --work-tree="${dirPath}" status --porcelain`, (err, stdout) => { if (err) { throw new Error(err.message); } From 3eec215b3a72cd184c543ec9803933d3cb4a7965 Mon Sep 17 00:00:00 2001 From: Mark H <70579116+mark-dr@users.noreply.github.com> Date: Wed, 5 Apr 2023 12:32:23 +0100 Subject: [PATCH 2/2] Don't call git status if ignoreGitStatus is set --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index f7e369b..9ebe58d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -112,7 +112,7 @@ export const checkOptions = async (opt: Options): Promise<[string[], string[]]> // Check git status if the write flag was provided and the output folder is the same as the project folder // Do not allow overwriting files with previous changes on them unless --ignoreGitStatus flag was provided - if (opt.write && path.dirname(opt.tsconfig) === opt.outputFolder) { + if (opt.write && path.dirname(opt.tsconfig) === opt.outputFolder && !opt.ignoreGitStatus) { let isModified = false; const status = await (getGitStatus(opt.tsconfig)); const splitStatus = status.split(/\r?\n/); @@ -120,7 +120,7 @@ export const checkOptions = async (opt: Options): Promise<[string[], string[]]> const re = /[MARCD?]\s(package).+?(json)/g isModified = splitStatus.length && splitStatus[0] !== '' ? !(splitStatus.filter((text) => { return text.match(re) }).length === splitStatus.length) : false; } - if (isModified && !opt.ignoreGitStatus) { + if (isModified) { throw new Error(`Please provide the --ignoreGitStatus flag if you are sure you'ld like to override your exisiting changes`); } }