UNPKG

git-release-manager

Version:

A tool to generate release notes from git commit history

87 lines 3.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommitManager = void 0; const simple_git_1 = require("simple-git"); class CommitManager { constructor() { this.git = (0, simple_git_1.simpleGit)(); } async stageAll() { await this.git.add('.'); } async stageFiles(files) { await this.git.add(files); } async createCommit(options, config) { var _a; try { const commitOptions = {}; if (options.stage) { if (options.stage == 'all') { await this.stageAll(); } else if (options.stage == 'any') { commitOptions['--allow-empty'] = null; } else { await this.stageFiles(options.stage); } } else { commitOptions['--allow-empty'] = null; } // Prepare commit message parts const commitMessage = []; if (options.type && options.scope) { commitMessage.push(`${options.type}(${options.scope}): ${options.message}`); } else if (options.type) { commitMessage.push(`${options.type}: ${options.message}`); } else { commitMessage.push((_a = options.message) !== null && _a !== void 0 ? _a : 'No commit message provided'); } if (options.body) { commitMessage.push(`\n\n${options.body.join('\n')}`); } if (options.breaking) { commitMessage.push(`\n\nBREAKING CHANGE: ${options.breaking}`); } // Convert commit options to an array format: if (options.noVerify) commitOptions['--no-verify'] = null; if (options.sign) commitOptions['--sign'] = null; // if (options.amend) commitOptions['--amend'] = null; // Execute commit await this.git.commit(commitMessage.join(''), commitOptions); // // Optionally push changes // if (options.push) { // await this.git.push(config.remote || 'origin', config.branch || 'main') // } } catch (error) { console.error('Error:', error instanceof Error ? error.message : String(error)); process.exit(1); } } async listCommits(options, config) { try { const count = typeof options.count === 'number' ? options.count : 1; const log = await this.git.log({ maxCount: count }); log.all.forEach(commit => { console.log(`Commit: ${commit.hash}`); console.log(`Author: ${commit.author_name} <${commit.author_email}>`); console.log(`Date: ${commit.date}`); console.log(`Message: ${commit.message}`); console.log('---'); }); } catch (error) { console.error('Error listing commits:', error instanceof Error ? error.message : String(error)); process.exit(1); } } } exports.CommitManager = CommitManager; //# sourceMappingURL=CommitManager.js.map