()
| 44 | * Generate documentation for plugins: each plugin gets a dedicated page plus an overview index. |
| 45 | */ |
| 46 | export async function docsPlugins() { |
| 47 | task.stopOnFailures() |
| 48 | ensureDir('docs/plugins') |
| 49 | |
| 50 | const files = fs.readdirSync('lib/plugin').filter(f => path.extname(f) === '.js') |
| 51 | |
| 52 | const sharedPartials = fs.readdirSync('docs/shared').filter(f => path.extname(f) === '.mustache') |
| 53 | const sharedPlaceholders = sharedPartials.map(file => `{{ ${path.basename(file, '.mustache')} }}`) |
| 54 | const sharedTemplates = sharedPartials.map(file => fs.readFileSync(`docs/shared/${file}`).toString()).map(template => `\n\n\n${template}`) |
| 55 | |
| 56 | const index = [] |
| 57 | |
| 58 | for (const file of files) { |
| 59 | const name = path.basename(file, '.js') |
| 60 | say(`Writing documentation for ${name} plugin`) |
| 61 | |
| 62 | await shell`npx documentation build lib/plugin/${file} -o ${pluginMarkDownFile(name)} ${documentjsCliArgs}` |
| 63 | |
| 64 | replaceInFile(pluginMarkDownFile(name), cfg => { |
| 65 | cfg.replace(/\(optional, default.*?\)/gm, '') |
| 66 | cfg.replace(/\\*/gm, '') |
| 67 | }) |
| 68 | |
| 69 | replaceInFile(pluginMarkDownFile(name), cfg => { |
| 70 | for (const i in sharedPlaceholders) { |
| 71 | cfg.replace(sharedPlaceholders[i], sharedTemplates[i]) |
| 72 | } |
| 73 | }) |
| 74 | |
| 75 | const lines = fs.readFileSync(pluginMarkDownFile(name)).toString().split('\n') |
| 76 | const headingAt = lines.findIndex(l => l.startsWith('## ')) |
| 77 | const summary = [] |
| 78 | for (let i = headingAt + 1; i < lines.length; i++) { |
| 79 | const line = lines[i].trim() |
| 80 | if (!summary.length && !line) continue |
| 81 | if (summary.length && (!line || line.startsWith('#') || line.startsWith('```'))) break |
| 82 | summary.push(line) |
| 83 | } |
| 84 | index.push({ name, summary: summary.join(' ').trim() }) |
| 85 | |
| 86 | await writeToFile(pluginMarkDownFile(name), line => { |
| 87 | line`--- |
| 88 | permalink: /plugins/${name} |
| 89 | editLink: false |
| 90 | sidebar: auto |
| 91 | title: ${name} |
| 92 | --- |
| 93 | |
| 94 | ` |
| 95 | line.fromFile(pluginMarkDownFile(name)) |
| 96 | }) |
| 97 | } |
| 98 | |
| 99 | await writeToFile('docs/plugins.md', line => { |
| 100 | line`---` |
| 101 | line`permalink: /plugins` |
| 102 | line`editLink: false` |
| 103 | line`sidebar: auto` |
no test coverage detected