1- const { existsSync , mkdirSync , readFileSync , writeFileSync } = require ( 'fs' ) ;
2- const { join , dirname } = require ( 'path' ) ;
1+ const fs = require ( 'fs' )
2+ const path = require ( 'path' )
33
4- const dataPath = join ( __dirname , 'modules_data.json' ) ;
5- const defPath = join ( __dirname , 'documentation' , 'definitions' , 'module.md' ) ;
6- const outPath = join ( __dirname , 'documentation' , 'modules.md' ) ;
4+ const modulesDataPath = path . join ( __dirname , 'modules_data.json' )
5+ const definitionPath = path . join ( __dirname , 'documentation' , 'definitions' , 'module.md' )
6+ const outputPath = path . join ( __dirname , 'documentation' , 'modules.md' )
77
8- if ( ! existsSync ( dataPath ) ) {
9- console . error ( 'modules_data.json not found, skipping modules.md generation.' ) ;
10- process . exit ( 1 ) ;
8+ if ( ! fs . existsSync ( modulesDataPath ) ) {
9+ console . error ( 'modules_data.json not found, skipping modules.md generation.' )
10+ process . exit ( 1 )
1111}
1212
13- const raw = readFileSync ( dataPath , 'utf8' ) ;
14- const parsed = JSON . parse ( raw ) ;
15- const list = Array . isArray ( parsed ) ? parsed : parsed . modules || [ ] ;
16- const details = existsSync ( defPath ) ? readFileSync ( defPath , 'utf8' ) : parsed . moduleDetails || '' ;
13+ const rawData = fs . readFileSync ( modulesDataPath , 'utf8' )
14+ const parsedData = JSON . parse ( rawData )
15+ const modulesList = Array . isArray ( parsedData ) ? parsedData : parsedData . modules || [ ]
1716
18- const outDir = dirname ( outPath ) ;
19- if ( ! existsSync ( outDir ) ) mkdirSync ( outDir , { recursive : true } ) ;
17+ let details = ''
18+ if ( fs . existsSync ( definitionPath ) ) {
19+ details = fs . readFileSync ( definitionPath , 'utf8' )
20+ } else if ( parsedData . moduleDetails ) {
21+ details = parsedData . moduleDetails
22+ }
23+
24+ function toVersionString ( version ) {
25+ if ( typeof version === 'number' ) {
26+ const major = Math . floor ( version / 10000 )
27+ const minor = Math . floor ( version / 100 ) % 100
28+ const patch = version % 100
29+ return `${ major } .${ minor } .${ patch } `
30+ }
31+ return version
32+ }
33+
34+ let output = ''
35+
36+ for ( const moduleInfo of modulesList ) {
37+ const {
38+ name = '' ,
39+ version = '' ,
40+ description = '' ,
41+ features = [ ] ,
42+ download = '' ,
43+ public_uniqueID = '' ,
44+ } = moduleInfo
2045
21- const toVersion = v => {
22- if ( typeof v === 'number' ) {
23- const major = Math . floor ( v / 10000 ) ;
24- const minor = Math . floor ( v / 100 ) % 100 ;
25- const patch = v % 100 ;
26- return `${ major } .${ minor } .${ patch } ` ;
46+ const versionStr = toVersionString ( version )
47+ const versionLabel = versionStr ? ` ${ versionStr } ` : ''
48+
49+ output += `<h2 align="center">${ name } ${ versionLabel } </h2>\n\n`
50+
51+ if ( description ) {
52+ output += `<p><strong>Description:</strong></p>\n`
53+ output += `<p>${ description } </p>\n\n`
2754 }
28- return v ;
29- } ;
30-
31- let md = '# Optional Modules\n\n' ;
32-
33- for ( const {
34- name = '' ,
35- version = '' ,
36- description = '' ,
37- features = [ ] ,
38- download = '' ,
39- public_uniqueID = ''
40- } of list ) {
41- const ver = toVersion ( version ) ;
42- md += `<h2 align="center">${ name } ${ ver ? ` ${ ver } ` : '' } </h2>\n\n` ;
43- if ( description ) md += `**Description:** ${ description } \n\n` ;
55+
4456 if ( features . length ) {
45- md += '**Features:**\n\n' ;
46- for ( const f of features ) md += `- ${ f } \n` ;
47- md += '\n' ;
57+ output += `<p><strong>Features:</strong></p>\n<ul>\n`
58+ for ( const feature of features ) {
59+ output += ` <li>${ feature } </li>\n`
60+ }
61+ output += `</ul>\n\n`
4862 }
63+
4964 if ( public_uniqueID ) {
50- const base = 'https://liliaframework.github.io/Modules/docs' ;
51- md += `<p align="center"><a href="${ base } /libraries/modules/${ public_uniqueID } .html">Libraries</a> | <a href="${ base } /hooks/modules/${ public_uniqueID } .html">Hooks</a></p>\n\n` ;
65+ const base = 'https://liliaframework.github.io/Modules/docs'
66+ output += `<p><strong>Libraries:</strong> \n`
67+ output += ` <a href="${ base } /libraries/modules/${ public_uniqueID } .html">Access Here</a>\n`
68+ output += `</p>\n\n`
69+ output += `<p><strong>Hooks:</strong> \n`
70+ output += ` <a href="${ base } /hooks/modules/${ public_uniqueID } .html">Access Here</a>\n`
71+ output += `</p>\n\n`
72+ }
73+
74+ if ( download ) {
75+ output += `<p align="center">\n`
76+ output += ` <a href="${ download } ">\n`
77+ output += ` <strong>Download Here</strong>\n`
78+ output += ` </a>\n`
79+ output += `</p>\n\n`
5280 }
53- if ( download ) md += `<h1 align="center"><a href="${ download } ">DOWNLOAD HERE</a></h1>\n\n` ;
5481}
5582
56- md += '---\n\n' + details ;
83+ output += details
5784
58- writeFileSync ( outPath , md ) ;
85+ fs . mkdirSync ( path . dirname ( outputPath ) , { recursive : true } )
86+ fs . writeFileSync ( outputPath , output )
0 commit comments