Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "commitfy",
"version": "0.1.0",
"version": "0.2.0",
"main": "lib/index.js",
"repository": "https://github.com/ribeirogab/commitfy.git",
"author": "ribeirogab <ribeirogabx@gmail.com>",
Expand Down
13 changes: 10 additions & 3 deletions src/commands/generate-commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,16 @@ export class GenerateCommit {
process.exit(0);
}

const diff = await this.processUtils.exec('git diff --cached', {
showStdout: false,
});
const excludeParams = this.appUtils.ignoreFiles
.map((file) => `':(exclude)${file}'`)
.join(' ');

const diff = await this.processUtils.exec(
`git diff --cached ${excludeParams}`,
{
showStdout: false,
},
);

if (!diff) {
this.appUtils.logger.error('No changes to commit.');
Expand Down
9 changes: 7 additions & 2 deletions src/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ export class Help {
{ path: '~/.commitfy', description: 'Directory for all configs.' },
{
path: '~/.commitfy/.env',
description: 'File for environment variables.',
description: 'Environment variables and configurations.',
},
{
path: '~/.commitfy/.commitfyignore',
description:
'Ignoring specific files and directories (`.commitfyignore` can be created in your Git repository).',
},
];

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

directoriesAndFiles.forEach(({ path, description }) => {
console.log(` ${path.padEnd(25)} ${description}`);
console.log(` ${path.padEnd(30)} ${description}`);
});

console.log('\nProviders:');
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/utils/app.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type LoggerFunction = (

export interface AppUtils {
projectConfigDirectory: string;
ignoreFiles: string[];
envFilePath: string;
version: string;
name: string;
Expand Down
27 changes: 27 additions & 0 deletions src/utils/app.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export class AppUtils implements AppUtilsInterface {
'.env',
);

public readonly ignoreFilePath = path.resolve(
this.projectConfigDirectory,
'.commitfyignore',
);

public readonly logger: AppUtilsInterface['logger'] = {
error: (message, ...params) =>
console.error(`${this.name}:`, message, ...params),
Expand All @@ -29,6 +34,14 @@ export class AppUtils implements AppUtilsInterface {
if (!fs.existsSync(this.projectConfigDirectory)) {
fs.mkdirSync(this.projectConfigDirectory);
}

if (!fs.existsSync(this.ignoreFilePath)) {
fs.writeFileSync(
this.ignoreFilePath,
['package-lock.json', 'yarn.lock', 'node_modules'].join('\n'),
'utf-8',
);
}
}

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

public get ignoreFiles(): string[] {
if (fs.existsSync('.commitfyignore')) {
return fs
.readFileSync('.commitfyignore', 'utf-8')
.split('\n')
.filter((line) => line.trim() !== '');
}

return fs
.readFileSync(this.ignoreFilePath, 'utf-8')
.split('\n')
.filter((line) => line.trim() !== '');
}

private get packageJson(): { version: string; name: string } {
return JSON.parse(fs.readFileSync(PACKAGE_JSON_PATH, 'utf-8'));
}
Expand Down
1 change: 1 addition & 0 deletions tests/fakes/utils/app.utils.fake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const ENV_FILE_PATH = path.join(TEMP_DIRECTORY, '.env');

export const makeAppUtilsFake = () =>
({
ignoreFiles: ['package-lock.json', 'yarn.lock', 'node_modules'],
projectConfigDirectory: TEMP_DIRECTORY,
envFilePath: ENV_FILE_PATH,
version: '1.0.0',
Expand Down