@alleyinteractive/changelog-extractor 0.3.0 → 0.4.0

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/README.md +16 -4
  2. package/package.json +1 -1
  3. package/src/cli.js +35 -9
package/README.md CHANGED
@@ -21,8 +21,6 @@ as both a **GitHub Action** and a **CLI tool**.
21
21
 
22
22
  #### Extract All Versions
23
23
 
24
- ### Extract All Versions
25
-
26
24
  By default, the action returns all versions in the changelog:
27
25
 
28
26
  ```yaml
@@ -36,7 +34,7 @@ By default, the action returns all versions in the changelog:
36
34
  echo '${{ fromJson(steps.changelog.outputs.result)[0].contents }}'
37
35
  ```
38
36
 
39
- ### Extract Specific Version
37
+ #### Extract Specific Version
40
38
 
41
39
  ```yaml
42
40
  - name: Extract v1.14.0 Changelog
@@ -47,7 +45,7 @@ By default, the action returns all versions in the changelog:
47
45
  version: '1.14.0' # or 'v1.14.0'
48
46
  ```
49
47
 
50
- ### Create Release from Latest Version
48
+ #### Create Release from Latest Version
51
49
 
52
50
  ```yaml
53
51
  name: Release
@@ -141,6 +139,20 @@ npm install -g @alleyinteractive/changelog-extractor
141
139
  changelog-extractor
142
140
  ```
143
141
 
142
+ By default, the CLI outputs JSON to stdout. You can also specify other output
143
+ formats using the `--format` option:
144
+
145
+ ```bash
146
+ # JSON output (default)
147
+ npx @alleyinteractive/changelog-extractor --format json
148
+
149
+ # Pretty-printed dump
150
+ npx @alleyinteractive/changelog-extractor --format dump
151
+
152
+ # Plain text output
153
+ npx @alleyinteractive/changelog-extractor --format text
154
+ ```
155
+
144
156
  ## Supported Changelog Format
145
157
 
146
158
  This action parses changelogs following the
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.0",
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)