style(commit.ts): format code with prettier
refactor(commit.ts): add types to commit function parameters fix(git.ts): handle empty string returned from getStagedFiles function refactor(mergeStrings.ts): remove unnecessary blank line and add missing semicolon
This commit is contained in:
+14
-5
@@ -60,7 +60,12 @@ ${chalk.grey('——————————————————')}`
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (isCommitConfirmedByUser && !isCancel(isCommitConfirmedByUser)) {
|
if (isCommitConfirmedByUser && !isCancel(isCommitConfirmedByUser)) {
|
||||||
const { stdout } = await execa('git', ['commit', '-m', commitMessage, ...extraArgs]);
|
const { stdout } = await execa('git', [
|
||||||
|
'commit',
|
||||||
|
'-m',
|
||||||
|
commitMessage,
|
||||||
|
...extraArgs
|
||||||
|
]);
|
||||||
|
|
||||||
outro(`${chalk.green('✔')} successfully committed`);
|
outro(`${chalk.green('✔')} successfully committed`);
|
||||||
|
|
||||||
@@ -83,8 +88,10 @@ ${chalk.grey('——————————————————')}`
|
|||||||
} else outro(`${chalk.gray('✖')} process cancelled`);
|
} else outro(`${chalk.gray('✖')} process cancelled`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export async function commit(
|
||||||
export async function commit(extraArgs=[], isStageAllFlag = false) {
|
extraArgs: string[] = [],
|
||||||
|
isStageAllFlag: Boolean = false
|
||||||
|
) {
|
||||||
if (isStageAllFlag) {
|
if (isStageAllFlag) {
|
||||||
const changedFiles = await getChangedFiles();
|
const changedFiles = await getChangedFiles();
|
||||||
|
|
||||||
@@ -123,7 +130,6 @@ export async function commit(extraArgs=[], isStageAllFlag = false) {
|
|||||||
isStageAllAndCommitConfirmedByUser &&
|
isStageAllAndCommitConfirmedByUser &&
|
||||||
!isCancel(isStageAllAndCommitConfirmedByUser)
|
!isCancel(isStageAllAndCommitConfirmedByUser)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
await commit(extraArgs, true);
|
await commit(extraArgs, true);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@@ -153,7 +159,10 @@ export async function commit(extraArgs=[], isStageAllFlag = false) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const [, generateCommitError] = await trytm(
|
const [, generateCommitError] = await trytm(
|
||||||
generateCommitMessageFromGitDiff(await getDiff({ files: stagedFiles }), extraArgs)
|
generateCommitMessageFromGitDiff(
|
||||||
|
await getDiff({ files: stagedFiles }),
|
||||||
|
extraArgs
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (generateCommitError) {
|
if (generateCommitError) {
|
||||||
|
|||||||
+7
-5
@@ -20,23 +20,24 @@ export const getOpenCommitIgnore = (): Ignore => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
ig.add(readFileSync('.opencommitignore').toString().split('\n'));
|
ig.add(readFileSync('.opencommitignore').toString().split('\n'));
|
||||||
} catch(e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
return ig;
|
return ig;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const getStagedFiles = async (): Promise<string[]> => {
|
export const getStagedFiles = async (): Promise<string[]> => {
|
||||||
const { stdout: files } = await execa('git', [
|
const { stdout: files } = await execa('git', [
|
||||||
'diff',
|
'diff',
|
||||||
'--name-only',
|
'--name-only',
|
||||||
'--cached',
|
'--cached'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (!files) return [];
|
||||||
|
|
||||||
const filesList = files.split('\n');
|
const filesList = files.split('\n');
|
||||||
|
|
||||||
|
|
||||||
const ig = getOpenCommitIgnore();
|
const ig = getOpenCommitIgnore();
|
||||||
const allowedFiles = filesList.filter(file => !ig.ignores(file));
|
const allowedFiles = filesList.filter((file) => !ig.ignores(file));
|
||||||
|
|
||||||
if (!allowedFiles) return [];
|
if (!allowedFiles) return [];
|
||||||
|
|
||||||
@@ -85,6 +86,7 @@ export const getDiff = async ({ files }: { files: string[] }) => {
|
|||||||
const { stdout: diff } = await execa('git', [
|
const { stdout: diff } = await execa('git', [
|
||||||
'diff',
|
'diff',
|
||||||
'--staged',
|
'--staged',
|
||||||
|
'--',
|
||||||
...filesWithoutLocks
|
...filesWithoutLocks
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ export function mergeStrings(arr: string[], maxStringLength: number): string[] {
|
|||||||
currentItem = item;
|
currentItem = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mergedArr.push(currentItem);
|
mergedArr.push(currentItem);
|
||||||
|
|
||||||
return mergedArr;
|
return mergedArr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user