Automatically untrack files implemented by ui modules
This commit is contained in:
parent
1231c92198
commit
e2975503a4
@ -9,6 +9,8 @@ import { dirname as pathDirname } from "path";
|
||||
import { join as pathJoin } from "path";
|
||||
import { existsAsync } from "../tools/fs.existsAsync";
|
||||
import * as fsPr from "fs/promises";
|
||||
import { getIsTrackedByGit } from "../tools/isTrackedByGit";
|
||||
import { untrackFromGit } from "../tools/untrackFromGit";
|
||||
|
||||
export async function command(params: { buildContext: BuildContext }) {
|
||||
const { buildContext } = params;
|
||||
@ -45,8 +47,10 @@ export async function command(params: { buildContext: BuildContext }) {
|
||||
fileRelativePath
|
||||
);
|
||||
|
||||
const doesFileExist = await existsAsync(destFilePath);
|
||||
|
||||
skip_condition: {
|
||||
if (!(await existsAsync(destFilePath))) {
|
||||
if (!doesFileExist) {
|
||||
break skip_condition;
|
||||
}
|
||||
|
||||
@ -61,6 +65,24 @@ export async function command(params: { buildContext: BuildContext }) {
|
||||
return;
|
||||
}
|
||||
|
||||
git_untrack: {
|
||||
if (!destFilePath) {
|
||||
break git_untrack;
|
||||
}
|
||||
|
||||
const isTracked = await getIsTrackedByGit({
|
||||
filePath: destFilePath
|
||||
});
|
||||
|
||||
if (!isTracked) {
|
||||
break git_untrack;
|
||||
}
|
||||
|
||||
await untrackFromGit({
|
||||
filePath: destFilePath
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const dirName = pathDirname(destFilePath);
|
||||
|
||||
|
29
src/bin/tools/isTrackedByGit.ts
Normal file
29
src/bin/tools/isTrackedByGit.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import * as child_process from "child_process";
|
||||
import { dirname as pathDirname, basename as pathBasename } from "path";
|
||||
import { Deferred } from "evt/tools/Deferred";
|
||||
|
||||
export function getIsTrackedByGit(params: { filePath: string }): Promise<boolean> {
|
||||
const { filePath } = params;
|
||||
|
||||
const dIsTracked = new Deferred<boolean>();
|
||||
|
||||
child_process.exec(
|
||||
`git ls-files --error-unmatch ${pathBasename(filePath)}`,
|
||||
{ cwd: pathDirname(filePath) },
|
||||
error => {
|
||||
if (error === null) {
|
||||
dIsTracked.resolve(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (error.code === 1) {
|
||||
dIsTracked.resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
dIsTracked.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
return dIsTracked.pr;
|
||||
}
|
24
src/bin/tools/untrackFromGit.ts
Normal file
24
src/bin/tools/untrackFromGit.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import * as child_process from "child_process";
|
||||
import { dirname as pathDirname, basename as pathBasename } from "path";
|
||||
import { Deferred } from "evt/tools/Deferred";
|
||||
|
||||
export async function untrackFromGit(params: { filePath: string }): Promise<void> {
|
||||
const { filePath } = params;
|
||||
|
||||
const dDone = new Deferred<void>();
|
||||
|
||||
child_process.exec(
|
||||
`git rm --cached ${pathBasename(filePath)}`,
|
||||
{ cwd: pathDirname(filePath) },
|
||||
error => {
|
||||
if (error !== null) {
|
||||
dDone.reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
dDone.resolve();
|
||||
}
|
||||
);
|
||||
|
||||
await dDone.pr;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user