@alleyinteractive/changelog-extractor 0.3.0 → 0.4.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alleyinteractive/changelog-extractor",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "description": "Parse and extract structured information from Keep a Changelog formatted changelogs",
6
6
  "main": "src/parser.js",
package/src/cli.js CHANGED
@@ -20,6 +20,7 @@ function printUsage() {
20
20
  Usage: npx @alleyinteractive/changelog-extractor [options]
21
21
 
22
22
  Options:
23
+ --format <type> Output format (default: "json"). Options: dump, text, json.
23
24
  -f, --file <path> Path to changelog file (default: CHANGELOG.md)
24
25
  -v, --version <ver> Specific version to extract (e.g., "1.14.0" or "v1.14.0")
25
26
  Leave empty to return all versions
@@ -64,6 +65,20 @@ if (versionIndex !== -1 && args[versionIndex + 1]) {
64
65
 
65
66
  const version = versionArg
66
67
 
68
+ // Parse format option.
69
+ let format = 'json'
70
+ const formatIndex = args.findIndex((arg) => arg === '--format')
71
+ if (formatIndex !== -1 && args[formatIndex + 1]) {
72
+ format = args[formatIndex + 1].toLowerCase()
73
+ }
74
+
75
+ if (!['json', 'dump', 'text'].includes(format)) {
76
+ console.error(
77
+ `āŒ Error: Invalid format "${format}". Valid options are: json, dump, text.`
78
+ )
79
+ process.exit(1)
80
+ }
81
+
67
82
  // Read changelog file
68
83
  const changelogPath = path.resolve(process.cwd(), changelogFile)
69
84
 
@@ -86,18 +101,28 @@ try {
86
101
  process.exit(0)
87
102
  }
88
103
 
104
+ // Default JSON output.
105
+ if (format === 'json') {
106
+ process.stdout.write(JSON.stringify(results, null, 2) + '\n')
107
+ process.exit(0)
108
+ }
109
+
89
110
  // Parse changelog
90
- console.log(`šŸ“– Parsing: ${changelogPath}`)
91
- console.log(`šŸŽÆ Version: ${versionArg || 'all versions'}`)
92
- console.log('')
111
+ if (format === 'dump') {
112
+ console.log(`šŸ“– Parsing: ${changelogPath}`)
113
+ console.log(`šŸŽÆ Version: ${versionArg || 'all versions'}`)
114
+ console.log('')
115
+ }
93
116
 
94
117
  if (results.length === 0) {
95
118
  console.log('āš ļø No changelog entries found')
96
119
  process.exit(1)
97
120
  }
98
121
 
99
- console.log(`āœ… Found ${results.length} version(s)\n`)
100
- console.log('─'.repeat(80))
122
+ if (format === 'dump') {
123
+ console.log(`āœ… Found ${results.length} version(s)\n`)
124
+ console.log('─'.repeat(80))
125
+ }
101
126
 
102
127
  // Pretty print results
103
128
  results.forEach((entry, index) => {
@@ -126,10 +151,11 @@ try {
126
151
  }
127
152
  })
128
153
 
129
- // Output JSON at the end
130
- console.log('\n' + '═'.repeat(80))
131
- console.log('\nšŸ“‹ JSON Output:\n')
132
- console.log(JSON.stringify(results, null, 2))
154
+ if (format === 'dump') {
155
+ console.log('\n' + '═'.repeat(80))
156
+ console.log('\nšŸ“‹ JSON Output:\n')
157
+ process.stdout.write(JSON.stringify(results, null, 2) + '\n')
158
+ }
133
159
  } catch (error) {
134
160
  console.error('āŒ Error parsing changelog:', error.message)
135
161
  process.exit(1)
package/src/parser.js CHANGED
@@ -94,8 +94,9 @@ export function parseChangelog(changelogContent, version = null) {
94
94
  let currentSectionContent = []
95
95
  let generalContent = [] // Content without section headers
96
96
 
97
- // Regex to match version headers: ## v1.14.0 or ## v1.14.0 - 2024-04-29
98
- const versionRegex = /^##\s+v?(\d+\.\d+\.\d+(?:-[^\s]+)?)\s*(?:-\s*(.*))?$/
97
+ // Regex to match version headers: ## v1.14.0, ## [1.14.0] - 2024-04-29, or ## 2024-04-29
98
+ const versionRegex =
99
+ /^##\s+\[?v?(\d+\.\d+\.\d+(?:-[^\s\]]+)?|\d{4}-\d{2}-\d{2})\]?\s*(?:-\s*(.*))?$/
99
100
  // Regex to match section headers: ### Added, ### Changed, etc.
100
101
  const sectionRegex = /^###\s+(.+)$/
101
102