@logickernel/agileflow 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +22 -17
  3. package/src/utils.js +35 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logickernel/agileflow",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Automatic semantic versioning and changelog generation based on conventional commits",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -34,6 +34,6 @@
34
34
  "type": "git",
35
35
  "url": "git@code.logickernel.com:kernel/agileflow.git"
36
36
  },
37
- "author": "",
37
+ "author": "Víctor H. Valle <victor.valle@logickernel.com>",
38
38
  "license": "ISC"
39
39
  }
package/src/index.js CHANGED
@@ -38,24 +38,32 @@ function parseArgs(args) {
38
38
 
39
39
  /**
40
40
  * Displays version info to the console.
41
- * @param {{currentVersion: string|null, nextVersion: string|null, commits: Array, changelog: string}} info
42
- * @param {boolean} quiet - Only output the next version
41
+ * @param {{currentVersion: string|null, newVersion: string|null, commits: Array, changelog: string}} info
42
+ * @param {boolean} quiet - Only output the new version
43
43
  */
44
44
  function displayVersionInfo(info, quiet) {
45
- const { currentVersion, nextVersion, commits, changelog } = info;
45
+ const { currentVersion, newVersion, commits, changelog } = info;
46
46
 
47
47
  if (quiet) {
48
- if (nextVersion) {
49
- console.log(nextVersion);
48
+ if (newVersion) {
49
+ console.log(newVersion);
50
50
  }
51
51
  return;
52
52
  }
53
53
 
54
- console.log(`Current version: ${currentVersion || 'none'}`);
55
- console.log(`Next version: ${nextVersion || 'no bump needed'}`);
56
- console.log(`Commits since current version: ${commits.length}`);
54
+
55
+ // List commits
56
+ console.log(`Commits since current version (${commits.length}):`);
57
+ for (const commit of commits) {
58
+ const subject = commit.message.split('\n')[0].trim();
59
+ const shortHash = commit.hash.substring(0, 7);
60
+ console.log(` ${shortHash} ${subject}`);
61
+ }
62
+
63
+ console.log(`\nCurrent version: ${currentVersion || 'none'}`);
64
+ console.log(`New version: ${newVersion || 'no bump needed'}`);
57
65
  if (changelog) {
58
- console.log(`\nChangelog:\n${changelog}`);
66
+ console.log(`\nChangelog:\n\n${changelog}`);
59
67
  }
60
68
  }
61
69
 
@@ -71,10 +79,7 @@ async function handlePushCommand(pushType, options) {
71
79
  displayVersionInfo(info, options.quiet);
72
80
 
73
81
  // Skip push if no version bump needed
74
- if (!info.nextVersion) {
75
- if (!options.quiet) {
76
- console.log('\nNo version bump needed. Skipping tag creation.');
77
- }
82
+ if (!info.newVersion) {
78
83
  return;
79
84
  }
80
85
 
@@ -93,16 +98,16 @@ async function handlePushCommand(pushType, options) {
93
98
  }
94
99
 
95
100
  // Create tag message from changelog
96
- const tagMessage = info.changelog || info.nextVersion;
101
+ const tagMessage = info.changelog || info.newVersion;
97
102
 
98
103
  if (!options.quiet) {
99
- console.log(`\nCreating tag ${info.nextVersion}...`);
104
+ console.log(`\nCreating tag ${info.newVersion}...`);
100
105
  }
101
106
 
102
- await pushModule.pushTag(info.nextVersion, tagMessage);
107
+ await pushModule.pushTag(info.newVersion, tagMessage);
103
108
 
104
109
  if (!options.quiet) {
105
- console.log(`Tag ${info.nextVersion} created and pushed successfully.`);
110
+ console.log(`Tag ${info.newVersion} created and pushed successfully.`);
106
111
  }
107
112
  }
108
113
 
package/src/utils.js CHANGED
@@ -67,6 +67,21 @@ const TYPE_ORDER = ['feat', 'fix', 'perf', 'refactor', 'style', 'test', 'docs',
67
67
  const PATCH_TYPES = ['fix', 'perf', 'refactor', 'test', 'build', 'ci', 'revert'];
68
68
  const SEMVER_PATTERN = /^v(\d+)\.(\d+)\.(\d+)(-[a-zA-Z0-9.-]+)?$/;
69
69
 
70
+ // Friendly header names for changelog
71
+ const TYPE_HEADERS = {
72
+ feat: 'Features:',
73
+ fix: 'Fixes:',
74
+ perf: 'Performance:',
75
+ refactor: 'Refactors:',
76
+ style: 'Style:',
77
+ test: 'Tests:',
78
+ docs: 'Documentation:',
79
+ build: 'Build:',
80
+ ci: 'CI:',
81
+ chore: 'Chores:',
82
+ revert: 'Reverts:',
83
+ };
84
+
70
85
  /**
71
86
  * Fetches tags from remote (non-destructive) if a remote is configured.
72
87
  * @returns {boolean} True if tags were fetched, false if using local tags only
@@ -242,6 +257,16 @@ function analyzeCommitsForVersioning(commits) {
242
257
  return { hasBreaking, hasFeat, hasPatchTypes, commitsByType };
243
258
  }
244
259
 
260
+ /**
261
+ * Capitalizes the first letter of a string.
262
+ * @param {string} str - The string to capitalize
263
+ * @returns {string} Capitalized string
264
+ */
265
+ function capitalize(str) {
266
+ if (!str) return str;
267
+ return str.charAt(0).toUpperCase() + str.slice(1);
268
+ }
269
+
245
270
  /**
246
271
  * Generates changelog entries for a commit type section.
247
272
  * @param {Array} commits - Commits of this type
@@ -272,21 +297,21 @@ function generateTypeChangelog(commits) {
272
297
  const lines = [];
273
298
  for (const entry of noScope) {
274
299
  const ref = entry.issueRef ? ` ${entry.issueRef}` : '';
275
- lines.push(`- ${entry.description}${ref}`);
300
+ lines.push(`- ${capitalize(entry.description)}${ref}`);
276
301
  }
277
302
  for (const scope of Object.keys(byScope).sort()) {
278
303
  for (const entry of byScope[scope]) {
279
304
  const ref = entry.issueRef ? ` ${entry.issueRef}` : '';
280
- lines.push(`- **${scope}**: ${entry.description}${ref}`);
305
+ lines.push(`- ${scope}: ${capitalize(entry.description)}${ref}`);
281
306
  }
282
307
  }
283
308
  return lines;
284
309
  }
285
310
 
286
311
  /**
287
- * Calculates the next version and generates a changelog.
312
+ * Calculates the new version and generates a changelog.
288
313
  * @param {{latestVersion: string|null, commits: Array}} expandedInfo
289
- * @returns {{nextVersion: string|null, changelog: string}}
314
+ * @returns {{newVersion: string|null, changelog: string}}
290
315
  */
291
316
  function calculateNextVersionAndChangelog(expandedInfo) {
292
317
  const { latestVersion, commits } = expandedInfo;
@@ -294,7 +319,7 @@ function calculateNextVersionAndChangelog(expandedInfo) {
294
319
  const analysis = analyzeCommitsForVersioning(commits);
295
320
 
296
321
  const bump = determineVersionBumpType(analysis, current.major === 0);
297
- const nextVersion = applyVersionBump(current, bump);
322
+ const newVersion = applyVersionBump(current, bump);
298
323
 
299
324
  // Generate changelog
300
325
  const changelogLines = [];
@@ -302,7 +327,7 @@ function calculateNextVersionAndChangelog(expandedInfo) {
302
327
  const typeCommits = analysis.commitsByType[type];
303
328
  if (!typeCommits?.length) continue;
304
329
 
305
- changelogLines.push(`### ${type}`);
330
+ changelogLines.push(TYPE_HEADERS[type] || `${capitalize(type)}:`);
306
331
  changelogLines.push(...generateTypeChangelog(typeCommits));
307
332
  changelogLines.push('');
308
333
  }
@@ -311,7 +336,7 @@ function calculateNextVersionAndChangelog(expandedInfo) {
311
336
  changelogLines.pop();
312
337
  }
313
338
 
314
- return { nextVersion, changelog: changelogLines.join('\n') };
339
+ return { newVersion, changelog: changelogLines.join('\n') };
315
340
  }
316
341
 
317
342
  /**
@@ -357,7 +382,7 @@ function getAllBranchCommits(branch) {
357
382
 
358
383
  /**
359
384
  * Processes version information for the current branch.
360
- * @returns {Promise<{currentVersion: string|null, nextVersion: string|null, commits: Array, changelog: string}>}
385
+ * @returns {Promise<{currentVersion: string|null, newVersion: string|null, commits: Array, changelog: string}>}
361
386
  */
362
387
  async function processVersionInfo() {
363
388
  ensureGitRepo();
@@ -367,11 +392,11 @@ async function processVersionInfo() {
367
392
  const allCommits = getAllBranchCommits(branch);
368
393
  const expandedInfo = expandCommitInfo(allCommits);
369
394
  const { latestVersion, commits } = expandedInfo;
370
- const { nextVersion, changelog } = calculateNextVersionAndChangelog(expandedInfo);
395
+ const { newVersion, changelog } = calculateNextVersionAndChangelog(expandedInfo);
371
396
 
372
397
  return {
373
398
  currentVersion: latestVersion,
374
- nextVersion,
399
+ newVersion,
375
400
  commits,
376
401
  changelog,
377
402
  };