|
| 1 | +const fs = require('fs') |
| 2 | +const path = require('path') |
| 3 | + |
| 4 | +let modulesPath = path.join(__dirname, 'modules.json') |
| 5 | +if (!fs.existsSync(modulesPath)) { |
| 6 | + const alternativePath = path.join(__dirname, 'documentation', 'modules.json') |
| 7 | + if (fs.existsSync(alternativePath)) { |
| 8 | + modulesPath = alternativePath |
| 9 | + } else { |
| 10 | + process.exit(1) |
| 11 | + } |
| 12 | +} |
| 13 | + |
| 14 | +let modules |
| 15 | +try { |
| 16 | + modules = JSON.parse(fs.readFileSync(modulesPath, 'utf8')) |
| 17 | +} catch { |
| 18 | + process.exit(1) |
| 19 | +} |
| 20 | +if (!Array.isArray(modules)) process.exit(1) |
| 21 | + |
| 22 | +function toFolderName(name) { |
| 23 | + return String(name) |
| 24 | + .toLowerCase() |
| 25 | + .replace(/[^a-z0-9]+/g, '_') |
| 26 | + .replace(/^_+|_+$/g, '') |
| 27 | +} |
| 28 | + |
| 29 | +for (const mod of modules) { |
| 30 | + const id = mod.uniqueID || '' |
| 31 | + if (!id) continue |
| 32 | + |
| 33 | + const folder = toFolderName(mod.name || id) |
| 34 | + |
| 35 | + const readmePath = path.join(__dirname, folder, 'README.md') |
| 36 | + if (!fs.existsSync(readmePath)) continue |
| 37 | + |
| 38 | + const outputDir = path.join(__dirname, 'documentation', 'docs', 'modules', folder) |
| 39 | + fs.mkdirSync(outputDir, { recursive: true }) |
| 40 | + |
| 41 | + fs.copyFileSync(readmePath, path.join(outputDir, 'about.md')) |
| 42 | +} |
| 43 | + |
| 44 | +console.log('README.md files copied as about.md.') |
0 commit comments