@@ -30,6 +30,78 @@ function getFileExtension(filename) {
3030 return filename . slice ( ( ( filename . lastIndexOf ( "." ) - 1 ) >>> 0 ) + 2 ) ;
3131}
3232
33+ function formatChangelogEntry ( versionData ) {
34+ const changes = [ ] ;
35+
36+ if ( versionData . added ) {
37+ changes . push ( `**Added:**` ) ;
38+ changes . push ( versionData . added ) ;
39+ changes . push ( "" ) ;
40+ }
41+
42+ if ( versionData . changed ) {
43+ changes . push ( `**Changed:**` ) ;
44+ changes . push ( versionData . changed ) ;
45+ changes . push ( "" ) ;
46+ }
47+
48+ if ( versionData . fixed ) {
49+ changes . push ( `**Fixed:**` ) ;
50+ changes . push ( versionData . fixed ) ;
51+ }
52+
53+ return changes ;
54+ }
55+
56+ function getLatestChangelog ( version ) {
57+ const changelogPath = path . join ( __dirname , "CHANGELOG.json" ) ;
58+ if ( ! fs . existsSync ( changelogPath ) ) {
59+ return null ;
60+ }
61+
62+ try {
63+ const changelogContent = fs . readFileSync ( changelogPath , "utf-8" ) ;
64+ const changelog = JSON . parse ( changelogContent ) ;
65+
66+ if ( ! changelog [ version ] ) {
67+ return null ;
68+ }
69+
70+ const changes = formatChangelogEntry ( changelog [ version ] ) ;
71+ return changes . length > 0 ? changes . join ( "\n" ) : null ;
72+ } catch ( e ) {
73+ return null ;
74+ }
75+ }
76+
77+ function getAllChangelogs ( ) {
78+ const changelogPath = path . join ( __dirname , "CHANGELOG.json" ) ;
79+ if ( ! fs . existsSync ( changelogPath ) ) {
80+ return null ;
81+ }
82+
83+ try {
84+ const changelogContent = fs . readFileSync ( changelogPath , "utf-8" ) ;
85+ const changelog = JSON . parse ( changelogContent ) ;
86+
87+ // Sort versions in descending order (newest first)
88+ const versions = Object . keys ( changelog ) . sort ( ( a , b ) => {
89+ const aParts = a . split ( "." ) . map ( Number ) ;
90+ const bParts = b . split ( "." ) . map ( Number ) ;
91+ for ( let i = 0 ; i < 4 ; i ++ ) {
92+ if ( aParts [ i ] !== bParts [ i ] ) {
93+ return bParts [ i ] - aParts [ i ] ;
94+ }
95+ }
96+ return 0 ;
97+ } ) ;
98+
99+ return { changelog, versions } ;
100+ } catch ( e ) {
101+ return null ;
102+ }
103+ }
104+
33105const __dirname = path . resolve ( "../" ) ;
34106
35107function getCoverImage ( ) {
@@ -85,6 +157,16 @@ export default async function generateDocumentation() {
85157 readme . push ( "<br>" ) ;
86158 readme . push ( `<sub> [See all releases](${ githubUrl } /releases) </sub> <br>` ) ;
87159
160+ // Add changelog section if CHANGELOG.json exists
161+ const latestChangelog = getLatestChangelog ( config . version ) ;
162+ if ( latestChangelog ) {
163+ readme . push ( "" ) ;
164+ readme . push ( `#### What's New in ${ config . version } ` ) ;
165+ readme . push ( latestChangelog ) ;
166+ readme . push ( "" ) ;
167+ readme . push ( `<sub>[View full changelog](#changelog)</sub>` ) ;
168+ }
169+
88170 readme . push ( "" ) ;
89171 readme . push ( "---" ) ;
90172 readme . push ( `<b><u>Author:</u></b> ${ config . author } <br>` ) ;
@@ -269,6 +351,27 @@ export default async function generateDocumentation() {
269351 } ) ;
270352 readme . push ( `` ) ;
271353
354+ // Add full changelog section if CHANGELOG.json exists
355+ const allChangelogs = getAllChangelogs ( ) ;
356+ if ( allChangelogs ) {
357+ readme . push ( `` ) ;
358+ readme . push ( `---` ) ;
359+ readme . push ( `## Changelog` ) ;
360+ readme . push ( `` ) ;
361+
362+ allChangelogs . versions . forEach ( ( version ) => {
363+ const versionData = allChangelogs . changelog [ version ] ;
364+ readme . push ( `### Version ${ version } ` ) ;
365+ readme . push ( `` ) ;
366+
367+ const formattedChanges = formatChangelogEntry ( versionData ) ;
368+ formattedChanges . forEach ( ( line ) => readme . push ( line ) ) ;
369+
370+ readme . push ( `---` ) ;
371+ readme . push ( `` ) ;
372+ } ) ;
373+ }
374+
272375 fs . writeFileSync ( path . join ( __dirname , "README.md" ) , readme . join ( "\n" ) ) ;
273376
274377 chalkUtils . success ( "README.md generated successfully" ) ;
0 commit comments