MCPcopy
hub / github.com/codeceptjs/CodeceptJS / docsPlugins

Function docsPlugins

runok.cjs:49–123  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

replaceInFileFunction · 0.85
filterMethod · 0.80
logMethod · 0.80
pushMethod · 0.80
lineMethod · 0.80
pluginMarkDownFileFunction · 0.70
toStringMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected