MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / docsPlugins

Function docsPlugins

Bunoshfile.js:46–118  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44 * Generate documentation for plugins: each plugin gets a dedicated page plus an overview index.
45 */
46export 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`---
88permalink: /plugins/${name}
89editLink: false
90sidebar: auto
91title: ${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`

Callers 2

docsFunction · 0.70
defFunction · 0.70

Calls 7

ensureDirFunction · 0.85
sayFunction · 0.85
replaceInFileFunction · 0.85
filterMethod · 0.80
pushMethod · 0.80
pluginMarkDownFileFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected