Skip to content

Commit 4560a45

Browse files
committed
Update scrap_modules.js
1 parent ae62944 commit 4560a45

File tree

1 file changed

+41
-55
lines changed

1 file changed

+41
-55
lines changed

scrap_modules.js

Lines changed: 41 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,58 @@
1-
const fs = require('fs');
2-
const path = require('path');
3-
const modulesDataPath = path.join(__dirname, 'modules_data.json');
4-
const definitionPath = path.join(__dirname, 'documentation', 'definitions', 'module.md');
5-
const outputPath = path.join(__dirname, 'documentation', 'modules.md');
1+
const { existsSync, mkdirSync, readFileSync, writeFileSync } = require('fs');
2+
const { join, dirname } = require('path');
63

7-
const outputDir = path.dirname(outputPath);
8-
if (!fs.existsSync(outputDir)) {
9-
fs.mkdirSync(outputDir, { recursive: true });
10-
}
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');
117

12-
if (!fs.existsSync(modulesDataPath)) {
8+
if (!existsSync(dataPath)) {
139
console.error('modules_data.json not found, skipping modules.md generation.');
1410
process.exit(1);
1511
}
1612

17-
const rawData = fs.readFileSync(modulesDataPath, 'utf8');
18-
const parsedData = JSON.parse(rawData);
19-
const modulesList = Array.isArray(parsedData) ? parsedData : parsedData.modules || [];
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 || '';
2017

21-
let details = '';
22-
if (fs.existsSync(definitionPath)) {
23-
details = fs.readFileSync(definitionPath, 'utf8');
24-
} else if (parsedData.moduleDetails) {
25-
details = parsedData.moduleDetails;
26-
} else {
27-
console.warn(`${definitionPath} not found and no moduleDetails in JSON.`);
28-
}
18+
const outDir = dirname(outPath);
19+
if (!existsSync(outDir)) mkdirSync(outDir, { recursive: true });
2920

30-
function toVersionString(version) {
31-
if (typeof version === 'number') {
32-
const major = Math.floor(version / 10000);
33-
const minor = Math.floor(version / 100) % 100;
34-
const patch = version % 100;
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;
3526
return `${major}.${minor}.${patch}`;
3627
}
37-
return version;
38-
}
39-
40-
let output = '# Optional Modules\n\n';
41-
42-
for (const module of modulesList) {
43-
const {
44-
name = '',
45-
version = '',
46-
description = '',
47-
features = [],
48-
download = '',
49-
public_uniqueID = '',
50-
} = module;
51-
const versionStr = toVersionString(version);
52-
const versionLabel = versionStr ? ` ${versionStr}` : '';
53-
output += `<h2 align="center">${name}${versionLabel}</h2>\n\n`;
54-
if (description) output += `**Description:** ${description}\n\n`;
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`;
5544
if (features.length) {
56-
output += '**Features:**\n\n';
57-
for (const feature of features) output += `- ${feature}\n`;
58-
output += '\n';
45+
md += '**Features:**\n\n';
46+
for (const f of features) md += `- ${f}\n`;
47+
md += '\n';
5948
}
6049
if (public_uniqueID) {
6150
const base = 'https://liliaframework.github.io/Modules/docs';
62-
const libs = `${base}/libraries/modules/${public_uniqueID}.html`;
63-
const hooks = `${base}/hooks/modules/${public_uniqueID}.html`;
64-
output += `<p align="center"><a href="${libs}">Libraries</a> | <a href="${hooks}">Hooks</a></p>\n\n`;
65-
}
66-
if (download) {
67-
output += `<h1 align="center"><a href="${download}">DOWNLOAD HERE</a></h1>\n\n`;
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`;
6852
}
53+
if (download) md += `<h1 align="center"><a href="${download}">DOWNLOAD HERE</a></h1>\n\n`;
6954
}
7055

71-
output += '---\n\n' + details;
72-
fs.writeFileSync(outputPath, output);
56+
md += '---\n\n' + details;
57+
58+
writeFileSync(outPath, md);

0 commit comments

Comments
 (0)