refactor(git.ts): remove unused code and simplify getDiff function
feat(git.ts): add message for excluded lock files in getDiff function
This commit is contained in:
Generated
-1
@@ -61,7 +61,6 @@
|
|||||||
},
|
},
|
||||||
"node_modules/@clack/prompts/node_modules/is-unicode-supported": {
|
"node_modules/@clack/prompts/node_modules/is-unicode-supported": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"extraneous": true,
|
|
||||||
"inBundle": true,
|
"inBundle": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
+17
-38
@@ -9,13 +9,9 @@ export const assertGitRepo = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const showSomeFilesExcludedMessage = (files: string[]) => {
|
// const excludeBigFilesFromDiff = ['*-lock.*', '*.lock'].map(
|
||||||
outro(
|
// (file) => `:(exclude)${file}`
|
||||||
`Some files are .lock files which are excluded by default as it's too big, commit it yourself, don't waste your api tokens. \n${files
|
// );
|
||||||
.filter((file) => file.includes('.lock') || file.includes('-lock.'))
|
|
||||||
.join('\n')}`
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getStagedFiles = async (): Promise<string[]> => {
|
export const getStagedFiles = async (): Promise<string[]> => {
|
||||||
const { stdout: files } = await execa('git', [
|
const { stdout: files } = await execa('git', [
|
||||||
@@ -26,15 +22,6 @@ export const getStagedFiles = async (): Promise<string[]> => {
|
|||||||
|
|
||||||
if (!files) return [];
|
if (!files) return [];
|
||||||
|
|
||||||
const excludedFiles = files
|
|
||||||
.split('\n')
|
|
||||||
.filter(Boolean)
|
|
||||||
.filter((file) => file.includes('.lock') || file.includes('-lock.'));
|
|
||||||
|
|
||||||
if (excludedFiles.length === files.split('\n').length) {
|
|
||||||
showSomeFilesExcludedMessage(files.split('\n'));
|
|
||||||
}
|
|
||||||
|
|
||||||
return files.split('\n').sort();
|
return files.split('\n').sort();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -50,41 +37,33 @@ export const getChangedFiles = async (): Promise<string[]> => {
|
|||||||
(file) => !!file
|
(file) => !!file
|
||||||
);
|
);
|
||||||
|
|
||||||
const filesWithoutLocks = files.filter(
|
return files.sort();
|
||||||
(file) => !file.includes('.lock') && !file.includes('-lock.')
|
|
||||||
);
|
|
||||||
|
|
||||||
if (files.length !== filesWithoutLocks.length) {
|
|
||||||
showSomeFilesExcludedMessage(files);
|
|
||||||
}
|
|
||||||
|
|
||||||
return filesWithoutLocks.sort();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const gitAdd = async ({ files }: { files: string[] }) => {
|
export const gitAdd = async ({ files }: { files: string[] }) => {
|
||||||
const filteredFiles = files.filter(
|
|
||||||
(file) => !file.includes('.lock') && !file.includes('-lock.')
|
|
||||||
);
|
|
||||||
|
|
||||||
const gitAddSpinner = spinner();
|
const gitAddSpinner = spinner();
|
||||||
gitAddSpinner.start('Adding files to commit');
|
gitAddSpinner.start('Adding files to commit');
|
||||||
await execa('git', ['add', ...filteredFiles]);
|
await execa('git', ['add', ...files]);
|
||||||
gitAddSpinner.stop('Done');
|
gitAddSpinner.stop('Done');
|
||||||
|
|
||||||
if (filteredFiles.length !== files.length) {
|
|
||||||
showSomeFilesExcludedMessage(files);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getDiff = async ({ files }: { files: string[] }) => {
|
export const getDiff = async ({ files }: { files: string[] }) => {
|
||||||
|
const lockFiles = files.filter(
|
||||||
|
(file) => file.includes('.lock') || file.includes('-lock.')
|
||||||
|
);
|
||||||
|
|
||||||
|
if (lockFiles.length) {
|
||||||
|
outro(
|
||||||
|
`Some files are '.lock' files which are excluded by default from 'git diff'. No commit messages are generated for this files:\n${lockFiles.join(
|
||||||
|
'\n'
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const filesWithoutLocks = files.filter(
|
const filesWithoutLocks = files.filter(
|
||||||
(file) => !file.includes('.lock') && !file.includes('-lock.')
|
(file) => !file.includes('.lock') && !file.includes('-lock.')
|
||||||
);
|
);
|
||||||
|
|
||||||
if (filesWithoutLocks.length !== files.length) {
|
|
||||||
showSomeFilesExcludedMessage(files);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { stdout: diff } = await execa('git', [
|
const { stdout: diff } = await execa('git', [
|
||||||
'diff',
|
'diff',
|
||||||
'--staged',
|
'--staged',
|
||||||
|
|||||||
Reference in New Issue
Block a user