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

Function docsHelpers

Bunoshfile.js:230–328  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

228 * Generate documentation pages for all bundled helpers.
229 */
230export async function docsHelpers() {
231 task.stopOnFailures()
232 const files = fs.readdirSync('lib/helper').filter(f => path.extname(f) === '.js')
233 ensureDir('docs/build')
234
235 const ignoreList = ['Polly', 'MockRequest']
236
237 const partials = fs.readdirSync('docs/webapi').filter(f => path.extname(f) === '.mustache')
238 const placeholders = partials.map(file => `{{> ${path.basename(file, '.mustache')} }}`)
239 const templates = partials
240 .map(file => fs.readFileSync(`docs/webapi/${file}`).toString())
241 .map(template =>
242 template
243 .replace(/^/gm, ' * ')
244 .replace(/^/, '\n')
245 .replace(/\s*\* /, ''),
246 )
247
248 const sharedPartials = fs.readdirSync('docs/shared').filter(f => path.extname(f) === '.mustache')
249 const sharedPlaceholders = sharedPartials.map(file => `{{ ${path.basename(file, '.mustache')} }}`)
250 const sharedTemplates = sharedPartials.map(file => fs.readFileSync(`docs/shared/${file}`).toString()).map(template => `\n\n\n${template}`)
251
252 for (const file of files) {
253 const name = path.basename(file, '.js')
254 if (ignoreList.indexOf(name) >= 0) continue
255 say(`Writing documentation for ${name}`)
256 copyFile(`lib/helper/${file}`, `docs/build/${file}`)
257 replaceInFile(`docs/build/${file}`, cfg => {
258 for (const i in placeholders) {
259 cfg.replace(placeholders[i], templates[i])
260 }
261 cfg.replace(/CodeceptJS.LocatorOrString\?/g, '(string | object)?')
262 cfg.replace(/LocatorOrString\?/g, '(string | object)?')
263 cfg.replace(/CodeceptJS.LocatorOrString/g, 'string | object')
264 cfg.replace(/LocatorOrString/g, 'string | object')
265 cfg.replace(/CodeceptJS.StringOrSecret/g, 'string | object')
266
267 cfg.replace(/^import\s+([^'"`\s{]+)\s+from\s+['"`]([^'"`]+)['"`]/gm, "const $1 = require('$2')")
268 cfg.replace(/^import\s*\{\s*([^}]+)\s*\}\s*from\s+['"`]([^'"`]+)['"`]/gm, (match, imports, importPath) => {
269 if (imports.includes(' as ')) {
270 const parts = imports.split(',').map(i => i.trim())
271 const assignments = parts.map(part => {
272 if (part.includes(' as ')) {
273 const [original, alias] = part.split(' as ').map(s => s.trim())
274 return `const ${alias} = require('${importPath}').${original}`
275 }
276 return `const ${part} = require('${importPath}').${part}`
277 })
278 return assignments.join(';\n')
279 }
280 return `const { ${imports} } = require('${importPath}')`
281 })
282 cfg.replace(/^import\s+\*\s+as\s+([^'"`]+)\s+from\s+['"`]([^'"`]+)['"`]/gm, "const $1 = require('$2')")
283
284 cfg.replace(/^export\s*\{\s*([^}]+)\s+as\s+default\s*\}/gm, 'module.exports = $1')
285 cfg.replace(/^export\s+default\s+(.+)/gm, 'module.exports = $1')
286 cfg.replace(/^export\s*\{\s*([^}]+)\s*\}/gm, 'module.exports = { $1 }')
287 cfg.replace(/^export\s+(class|function|const|let|var)\s+([^\s=]+)/gm, '$1 $2')

Callers 1

docsFunction · 0.70

Calls 8

ensureDirFunction · 0.85
sayFunction · 0.85
replaceInFileFunction · 0.85
filterMethod · 0.80
includesMethod · 0.80
helperMarkDownFileFunction · 0.70
docsAppiumFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected