@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/README.md +16 -4
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/cli.js +35 -9
- package/src/parser.js +3 -2
package/package.json
CHANGED
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
100
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
|
98
|
-
const versionRegex =
|
|
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
|
|