feat: config command (#71)

This commit is contained in:
Hiroki Osame
2023-02-21 22:04:40 +09:00
parent 05f70e344e
commit 0d3f35c135
7 changed files with 275 additions and 190 deletions

39
src/utils/git.ts Normal file
View File

@@ -0,0 +1,39 @@
import { execa } from 'execa';
export const assertGitRepo = async () => {
const { stdout } = await execa('git', ['rev-parse', '--is-inside-work-tree'], { reject: false });
if (stdout !== 'true') {
throw new Error('The current directory must be a Git repository!');
}
};
const excludeFromDiff = [
'package-lock.json',
'yarn.lock',
'pnpm-lock.yaml',
].map(file => `:(exclude)${file}`);
export const getStagedDiff = async () => {
const diffCached = ['diff', '--cached'];
const { stdout: files } = await execa(
'git',
[...diffCached, '--name-only', ...excludeFromDiff],
);
if (!files) {
return;
}
const { stdout: diff } = await execa(
'git',
[...diffCached, ...excludeFromDiff],
);
return {
files: files.split('\n'),
diff,
};
};
export const getDetectedMessage = (files: string[]) => `Detected ${files.length.toLocaleString()} staged file${files.length > 1 ? 's' : ''}`;