feat(mod_commit): Add CLI UI helpers and improve commit workflow with progress, recommendations and summary

This commit is contained in:
2025-10-23 23:44:38 +00:00
parent a41e3d5d2c
commit 0d3b10bd00
5 changed files with 290 additions and 25 deletions

View File

@@ -4,6 +4,7 @@ import * as plugins from './mod.plugins.js';
import * as paths from '../paths.js';
import { logger } from '../gitzone.logging.js';
import * as helpers from './mod.helpers.js';
import * as ui from './mod.ui.js';
export const run = async (argvArg: any) => {
if (argvArg.format) {
@@ -11,7 +12,8 @@ export const run = async (argvArg: any) => {
await formatMod.run();
}
logger.log('info', `gathering facts...`);
ui.printHeader('🔍 Analyzing repository changes...');
const aidoc = new plugins.tsdoc.AiDoc();
await aidoc.start();
@@ -19,16 +21,12 @@ export const run = async (argvArg: any) => {
await aidoc.stop();
logger.log(
'info',
`---------
Next recommended commit would be:
===========
-> ${nextCommitObject.recommendedNextVersion}:
-> ${nextCommitObject.recommendedNextVersionLevel}(${nextCommitObject.recommendedNextVersionScope}): ${nextCommitObject.recommendedNextVersionMessage}
===========
`,
);
ui.printRecommendation({
recommendedNextVersion: nextCommitObject.recommendedNextVersion,
recommendedNextVersionLevel: nextCommitObject.recommendedNextVersionLevel,
recommendedNextVersionScope: nextCommitObject.recommendedNextVersionScope,
recommendedNextVersionMessage: nextCommitObject.recommendedNextVersionMessage,
});
const commitInteract = new plugins.smartinteract.SmartInteract();
commitInteract.addQuestions([
{
@@ -70,20 +68,30 @@ export const run = async (argvArg: any) => {
}
})();
logger.log('info', `OK! Creating commit with message '${commitString}'`);
ui.printHeader('✨ Creating Semantic Commit');
ui.printCommitMessage(commitString);
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash',
sourceFilePaths: [],
});
logger.log('info', `Baking commitinfo into code ...`);
// Determine total steps (6 if pushing, 5 if not)
const totalSteps = answerBucket.getAnswerFor('pushToOrigin') && !(process.env.CI === 'true') ? 6 : 5;
let currentStep = 0;
// Step 1: Baking commitinfo
currentStep++;
ui.printStep(currentStep, totalSteps, '🔧 Baking commit info into code', 'in-progress');
const commitInfo = new plugins.commitinfo.CommitInfo(
paths.cwd,
commitVersionType,
);
await commitInfo.writeIntoPotentialDirs();
ui.printStep(currentStep, totalSteps, '🔧 Baking commit info into code', 'done');
logger.log('info', `Writing changelog.md ...`);
// Step 2: Writing changelog
currentStep++;
ui.printStep(currentStep, totalSteps, '📄 Generating changelog.md', 'in-progress');
let changelog = nextCommitObject.changelog;
changelog = changelog.replaceAll(
'{{nextVersion}}',
@@ -110,23 +118,54 @@ export const run = async (argvArg: any) => {
changelog,
plugins.path.join(paths.cwd, `changelog.md`),
);
ui.printStep(currentStep, totalSteps, '📄 Generating changelog.md', 'done');
logger.log('info', `Staging files for commit:`);
// Step 3: Staging files
currentStep++;
ui.printStep(currentStep, totalSteps, '📦 Staging files', 'in-progress');
await smartshellInstance.exec(`git add -A`);
ui.printStep(currentStep, totalSteps, '📦 Staging files', 'done');
// Step 4: Creating commit
currentStep++;
ui.printStep(currentStep, totalSteps, '💾 Creating git commit', 'in-progress');
await smartshellInstance.exec(`git commit -m "${commitString}"`);
ui.printStep(currentStep, totalSteps, '💾 Creating git commit', 'done');
// Detect project type and bump version accordingly
// Step 5: Bumping version
currentStep++;
const projectType = await helpers.detectProjectType();
await helpers.bumpProjectVersion(projectType, commitVersionType);
const newVersion = await helpers.bumpProjectVersion(projectType, commitVersionType, currentStep, totalSteps);
// Step 6: Push to remote (optional)
const currentBranch = await helpers.detectCurrentBranch();
if (
answerBucket.getAnswerFor('pushToOrigin') &&
!(process.env.CI === 'true')
) {
// Detect current branch instead of hardcoding "master"
const currentBranch = await helpers.detectCurrentBranch();
currentStep++;
ui.printStep(currentStep, totalSteps, `🚀 Pushing to origin/${currentBranch}`, 'in-progress');
await smartshellInstance.exec(`git push origin ${currentBranch} --follow-tags`);
ui.printStep(currentStep, totalSteps, `🚀 Pushing to origin/${currentBranch}`, 'done');
}
console.log(''); // Add spacing before summary
// Get commit SHA for summary
const commitShaResult = await smartshellInstance.exec('git rev-parse --short HEAD');
const commitSha = commitShaResult.stdout.trim();
// Print final summary
ui.printSummary({
projectType,
branch: currentBranch,
commitType: answerBucket.getAnswerFor('commitType'),
commitScope: answerBucket.getAnswerFor('commitScope'),
commitMessage: answerBucket.getAnswerFor('commitDescription'),
newVersion: newVersion,
commitSha: commitSha,
pushed: answerBucket.getAnswerFor('pushToOrigin') && !(process.env.CI === 'true'),
});
};
const createCommitStringFromAnswerBucket = (