Skip to content

Commit 47bc1a9

Browse files
authored
Merge pull request #25 from ribeirogab/release/v0.2.0
feat: enhance exclude file handling for git diff in generate-commit module
2 parents f767ad8 + 8f2bec9 commit 47bc1a9

File tree

6 files changed

+47
-6
lines changed

6 files changed

+47
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "commitfy",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"main": "lib/index.js",
55
"repository": "https://github.com/ribeirogab/commitfy.git",
66
"author": "ribeirogab <[email protected]>",

src/commands/generate-commit.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,16 @@ export class GenerateCommit {
157157
process.exit(0);
158158
}
159159

160-
const diff = await this.processUtils.exec('git diff --cached', {
161-
showStdout: false,
162-
});
160+
const excludeParams = this.appUtils.ignoreFiles
161+
.map((file) => `':(exclude)${file}'`)
162+
.join(' ');
163+
164+
const diff = await this.processUtils.exec(
165+
`git diff --cached ${excludeParams}`,
166+
{
167+
showStdout: false,
168+
},
169+
);
163170

164171
if (!diff) {
165172
this.appUtils.logger.error('No changes to commit.');

src/commands/help.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ export class Help {
2222
{ path: '~/.commitfy', description: 'Directory for all configs.' },
2323
{
2424
path: '~/.commitfy/.env',
25-
description: 'File for environment variables.',
25+
description: 'Environment variables and configurations.',
26+
},
27+
{
28+
path: '~/.commitfy/.commitfyignore',
29+
description:
30+
'Ignoring specific files and directories (`.commitfyignore` can be created in your Git repository).',
2631
},
2732
];
2833

@@ -35,7 +40,7 @@ export class Help {
3540
console.log('\nDirectories and files:');
3641

3742
directoriesAndFiles.forEach(({ path, description }) => {
38-
console.log(` ${path.padEnd(25)} ${description}`);
43+
console.log(` ${path.padEnd(30)} ${description}`);
3944
});
4045

4146
console.log('\nProviders:');

src/interfaces/utils/app.utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type LoggerFunction = (
1111

1212
export interface AppUtils {
1313
projectConfigDirectory: string;
14+
ignoreFiles: string[];
1415
envFilePath: string;
1516
version: string;
1617
name: string;

src/utils/app.utils.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export class AppUtils implements AppUtilsInterface {
1515
'.env',
1616
);
1717

18+
public readonly ignoreFilePath = path.resolve(
19+
this.projectConfigDirectory,
20+
'.commitfyignore',
21+
);
22+
1823
public readonly logger: AppUtilsInterface['logger'] = {
1924
error: (message, ...params) =>
2025
console.error(`${this.name}:`, message, ...params),
@@ -29,6 +34,14 @@ export class AppUtils implements AppUtilsInterface {
2934
if (!fs.existsSync(this.projectConfigDirectory)) {
3035
fs.mkdirSync(this.projectConfigDirectory);
3136
}
37+
38+
if (!fs.existsSync(this.ignoreFilePath)) {
39+
fs.writeFileSync(
40+
this.ignoreFilePath,
41+
['package-lock.json', 'yarn.lock', 'node_modules'].join('\n'),
42+
'utf-8',
43+
);
44+
}
3245
}
3346

3447
public get name() {
@@ -39,6 +52,20 @@ export class AppUtils implements AppUtilsInterface {
3952
return this.packageJson.version;
4053
}
4154

55+
public get ignoreFiles(): string[] {
56+
if (fs.existsSync('.commitfyignore')) {
57+
return fs
58+
.readFileSync('.commitfyignore', 'utf-8')
59+
.split('\n')
60+
.filter((line) => line.trim() !== '');
61+
}
62+
63+
return fs
64+
.readFileSync(this.ignoreFilePath, 'utf-8')
65+
.split('\n')
66+
.filter((line) => line.trim() !== '');
67+
}
68+
4269
private get packageJson(): { version: string; name: string } {
4370
return JSON.parse(fs.readFileSync(PACKAGE_JSON_PATH, 'utf-8'));
4471
}

tests/fakes/utils/app.utils.fake.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const ENV_FILE_PATH = path.join(TEMP_DIRECTORY, '.env');
77

88
export const makeAppUtilsFake = () =>
99
({
10+
ignoreFiles: ['package-lock.json', 'yarn.lock', 'node_modules'],
1011
projectConfigDirectory: TEMP_DIRECTORY,
1112
envFilePath: ENV_FILE_PATH,
1213
version: '1.0.0',

0 commit comments

Comments
 (0)