diff --git a/package.json b/package.json index ea26042..ef8e904 100644 --- a/package.json +++ b/package.json @@ -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 ", diff --git a/src/commands/generate-commit.ts b/src/commands/generate-commit.ts index 20da944..91fe61e 100644 --- a/src/commands/generate-commit.ts +++ b/src/commands/generate-commit.ts @@ -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.'); diff --git a/src/commands/help.ts b/src/commands/help.ts index f0e3f42..8e1f8c4 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -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).', }, ]; @@ -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:'); diff --git a/src/interfaces/utils/app.utils.ts b/src/interfaces/utils/app.utils.ts index ac0a437..e4c5ec9 100644 --- a/src/interfaces/utils/app.utils.ts +++ b/src/interfaces/utils/app.utils.ts @@ -11,6 +11,7 @@ type LoggerFunction = ( export interface AppUtils { projectConfigDirectory: string; + ignoreFiles: string[]; envFilePath: string; version: string; name: string; diff --git a/src/utils/app.utils.ts b/src/utils/app.utils.ts index 884b283..00cbda1 100644 --- a/src/utils/app.utils.ts +++ b/src/utils/app.utils.ts @@ -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), @@ -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() { @@ -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')); } diff --git a/tests/fakes/utils/app.utils.fake.ts b/tests/fakes/utils/app.utils.fake.ts index 61b4185..cc3899a 100644 --- a/tests/fakes/utils/app.utils.fake.ts +++ b/tests/fakes/utils/app.utils.fake.ts @@ -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',