PluginProbe
MONEI Payments for WooCommerce / trunk
MONEI Payments for WooCommerce vtrunk
7.3.3 7.3.2 7.3.1 7.3.0 7.2.4 7.2.3 7.2.2 7.2.0 7.2.1 7.1.3 2.1.0 3.0.0 3.1.0 3.1.1 4.0.0 4.1.0 4.1.1 4.2.0 4.2.1 5.0 5.1.0 5.1.1 5.1.2 5.2.2 5.2.3 All 87 releases
monei / scripts / sort-changelog.js

sort-changelog.js in MONEI Payments for WooCommerce trunk, at scripts/sort-changelog.js

112 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 #!/usr/bin/env node
2
3 /**
4 * Sort CHANGELOG.md versions by date (newest first)
5 */
6
7 /* eslint-disable no-console */
8
9 const fs = require( 'fs' );
10 const path = require( 'path' );
11
12 const changelogPath = path.join( process.cwd(), 'CHANGELOG.md' );
13 const content = fs.readFileSync( changelogPath, 'utf8' );
14
15 // Split into header and versions
16 const lines = content.split( '\n' );
17 const headerLines = [];
18 const versionSections = [];
19
20 let currentVersion = null;
21 let currentLines = [];
22
23 for ( const line of lines ) {
24 // Match version headers like "## 6.3.12 (2025-10-01)" or "## <small>6.3.12 (2025-10-01)</small>"
25 const versionMatch = line.match(
26 /^##\s+(?:<small>)?(\d+\.\d+\.\d+)\s+\(([^)]+)\)(?:<\/small>)?/
27 );
28
29 if ( versionMatch ) {
30 // Save previous version if exists
31 if ( currentVersion ) {
32 versionSections.push( {
33 version: currentVersion.version,
34 date: currentVersion.date,
35 header: currentVersion.header,
36 lines: currentLines,
37 } );
38 }
39
40 // Start new version
41 currentVersion = {
42 version: versionMatch[ 1 ],
43 date: versionMatch[ 2 ],
44 header: line,
45 };
46 currentLines = [];
47 } else if ( currentVersion ) {
48 // Add to current version body
49 currentLines.push( line );
50 } else {
51 // Before first version (header)
52 headerLines.push( line );
53 }
54 }
55
56 // Save last version
57 if ( currentVersion ) {
58 versionSections.push( {
59 version: currentVersion.version,
60 date: currentVersion.date,
61 header: currentVersion.header,
62 lines: currentLines,
63 } );
64 }
65
66 // Sort versions by date (newest first)
67 versionSections.sort( ( a, b ) => {
68 const dateA = new Date( a.date );
69 const dateB = new Date( b.date );
70
71 if ( dateB - dateA !== 0 ) {
72 return dateB - dateA; // Newest first
73 }
74
75 // If same date, sort by version number (highest first)
76 const partsA = a.version.split( '.' ).map( Number );
77 const partsB = b.version.split( '.' ).map( Number );
78
79 for ( let i = 0; i < 3; i++ ) {
80 if ( partsB[ i ] !== partsA[ i ] ) {
81 return partsB[ i ] - partsA[ i ];
82 }
83 }
84
85 return 0;
86 } );
87
88 // Rebuild file
89 const output = [
90 ...headerLines,
91 ...versionSections.flatMap( ( section ) => [
92 section.header,
93 ...section.lines,
94 ] ),
95 ].join( '\n' );
96
97 fs.writeFileSync( changelogPath, output );
98
99 console.log( '�
100 CHANGELOG.md sorted successfully!' );
101 console.log( `📦 Total versions: ${ versionSections.length }` );
102 console.log(
103 `�
104 Newest: ${ versionSections[ 0 ].version } (${ versionSections[ 0 ].date })`
105 );
106 console.log(
107 `�
108 Oldest: ${ versionSections[ versionSections.length - 1 ].version } (${
109 versionSections[ versionSections.length - 1 ].date
110 })`
111 );
112