@alleyinteractive/changelog-extractor 0.0.1 → 0.3.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.
package/cli.js DELETED
@@ -1,112 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { parseChangelog } = require('./src/parser');
6
-
7
- /**
8
- * CLI for testing the changelog parser
9
- * Usage: node cli.js [changelog-file] [version]
10
- */
11
-
12
- function printUsage() {
13
- console.log(`
14
- Usage: node cli.js [options] [changelog-file] [version]
15
-
16
- Options:
17
- -l, --list List the count of versions found and exit
18
- -h, --help Show this help message
19
-
20
- Arguments:
21
- changelog-file Path to changelog file (default: CHANGELOG.md)
22
- version Specific version to extract (e.g., "1.14.0" or "v1.14.0")
23
- Leave empty to return all versions (default: all versions)
24
-
25
- Examples:
26
- node cli.js # Parse CHANGELOG.md, extract all versions
27
- node cli.js -l # Count versions in CHANGELOG.md
28
- node cli.js CHANGELOG.md # Same as above
29
- node cli.js CHANGELOG.md 1.14.0 # Extract specific version
30
- node cli.js /tmp/test-changelog.md # Parse specific file, all versions
31
- node cli.js -l /tmp/test-changelog.md # Count versions in specific file
32
- `);
33
- }
34
-
35
- // Parse command line arguments
36
- const args = process.argv.slice(2);
37
-
38
- if (args.includes('--help') || args.includes('-h')) {
39
- printUsage();
40
- process.exit(0);
41
- }
42
-
43
- const listMode = args.includes('-l') || args.includes('--list');
44
- const filteredArgs = args.filter(arg => arg !== '-l' && arg !== '--list');
45
-
46
- const changelogFile = filteredArgs[0] || 'CHANGELOG.md';
47
- const versionArg = filteredArgs[1] || null;
48
- const version = versionArg;
49
-
50
- // Read changelog file
51
- const changelogPath = path.resolve(process.cwd(), changelogFile);
52
-
53
- if (!fs.existsSync(changelogPath)) {
54
- console.error(`āŒ Error: Changelog file not found: ${changelogPath}`);
55
- console.error('\nTip: You can create a test changelog at /tmp/test-changelog.md');
56
- process.exit(1);
57
- }
58
-
59
- const changelogContent = fs.readFileSync(changelogPath, 'utf8');
60
-
61
- try {
62
- const results = parseChangelog(changelogContent, version);
63
-
64
- // List mode: just display count and exit
65
- if (listMode) {
66
- console.log(`${results.length}`);
67
- process.exit(0);
68
- }
69
-
70
- // Parse changelog
71
- console.log(`šŸ“– Parsing: ${changelogPath}`);
72
- console.log(`šŸŽÆ Version: ${versionArg || 'all versions'}`);
73
- console.log('');
74
-
75
- if (results.length === 0) {
76
- console.log('āš ļø No changelog entries found');
77
- process.exit(0);
78
- }
79
-
80
- console.log(`āœ… Found ${results.length} version(s)\n`);
81
- console.log('─'.repeat(80));
82
-
83
- // Pretty print results
84
- results.forEach((entry, index) => {
85
- console.log(`\nšŸ“¦ Version: ${entry.name}`);
86
- console.log(`šŸ“ Sections: ${Object.keys(entry.sections).join(', ') || 'none'}`);
87
- console.log('');
88
-
89
- // Print sections
90
- for (const [sectionName, sectionContent] of Object.entries(entry.sections)) {
91
- console.log(` ### ${sectionName.charAt(0).toUpperCase() + sectionName.slice(1)}`);
92
- console.log('');
93
- // Indent content
94
- const lines = sectionContent.split('\n');
95
- lines.forEach(line => console.log(` ${line}`));
96
- console.log('');
97
- }
98
-
99
- if (index < results.length - 1) {
100
- console.log('─'.repeat(80));
101
- }
102
- });
103
-
104
- // Output JSON at the end
105
- console.log('\n' + '═'.repeat(80));
106
- console.log('\nšŸ“‹ JSON Output:\n');
107
- console.log(JSON.stringify(results, null, 2));
108
-
109
- } catch (error) {
110
- console.error('āŒ Error parsing changelog:', error.message);
111
- process.exit(1);
112
- }