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)) {
|
||||
const { stdout } = await execa('git', ['commit', '-m', commitMessage, ...extraArgs]);
|
||||
const { stdout } = await execa('git', [
|
||||
'commit',
|
||||
'-m',
|
||||
commitMessage,
|
||||
...extraArgs
|
||||
]);
|
||||
|
||||
outro(`${chalk.green('✔')} successfully committed`);
|
||||
|
||||
@@ -83,8 +88,10 @@ ${chalk.grey('——————————————————')}`
|
||||
} else outro(`${chalk.gray('✖')} process cancelled`);
|
||||
};
|
||||
|
||||
|
||||
export async function commit(extraArgs=[], isStageAllFlag = false) {
|
||||
export async function commit(
|
||||
extraArgs: string[] = [],
|
||||
isStageAllFlag: Boolean = false
|
||||
) {
|
||||
if (isStageAllFlag) {
|
||||
const changedFiles = await getChangedFiles();
|
||||
|
||||
@@ -123,7 +130,6 @@ export async function commit(extraArgs=[], isStageAllFlag = false) {
|
||||
isStageAllAndCommitConfirmedByUser &&
|
||||
!isCancel(isStageAllAndCommitConfirmedByUser)
|
||||
) {
|
||||
|
||||
await commit(extraArgs, true);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -153,7 +159,10 @@ export async function commit(extraArgs=[], isStageAllFlag = false) {
|
||||
);
|
||||
|
||||
const [, generateCommitError] = await trytm(
|
||||
generateCommitMessageFromGitDiff(await getDiff({ files: stagedFiles }), extraArgs)
|
||||
generateCommitMessageFromGitDiff(
|
||||
await getDiff({ files: stagedFiles }),
|
||||
extraArgs
|
||||
)
|
||||
);
|
||||
|
||||
if (generateCommitError) {
|
||||
|
||||
+7
-5
@@ -20,23 +20,24 @@ export const getOpenCommitIgnore = (): Ignore => {
|
||||
|
||||
try {
|
||||
ig.add(readFileSync('.opencommitignore').toString().split('\n'));
|
||||
} catch(e) {}
|
||||
} catch (e) {}
|
||||
|
||||
return ig;
|
||||
}
|
||||
};
|
||||
|
||||
export const getStagedFiles = async (): Promise<string[]> => {
|
||||
const { stdout: files } = await execa('git', [
|
||||
'diff',
|
||||
'--name-only',
|
||||
'--cached',
|
||||
'--cached'
|
||||
]);
|
||||
|
||||
if (!files) return [];
|
||||
|
||||
const filesList = files.split('\n');
|
||||
|
||||
|
||||
const ig = getOpenCommitIgnore();
|
||||
const allowedFiles = filesList.filter(file => !ig.ignores(file));
|
||||
const allowedFiles = filesList.filter((file) => !ig.ignores(file));
|
||||
|
||||
if (!allowedFiles) return [];
|
||||
|
||||
@@ -85,6 +86,7 @@ export const getDiff = async ({ files }: { files: string[] }) => {
|
||||
const { stdout: diff } = await execa('git', [
|
||||
'diff',
|
||||
'--staged',
|
||||
'--',
|
||||
...filesWithoutLocks
|
||||
]);
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ export function mergeStrings(arr: string[], maxStringLength: number): string[] {
|
||||
currentItem = item;
|
||||
}
|
||||
}
|
||||
|
||||
mergedArr.push(currentItem);
|
||||
|
||||
return mergedArr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user