MCPcopy Index your code
hub / github.com/github/docs / getDeepDataByDir

Function getDeepDataByDir

lib/get-data.js:33–54  ·  view source on GitHub ↗
(dottedPath, dir)

Source from the content-addressed store, hash-verified

31// Doesn't need to be memoized because it's used by getDataKeysByLanguage
32// which is already memoized.
33function getDeepDataByDir(dottedPath, dir) {
34 const fullPath = ['data']
35 const split = dottedPath.split(/\./g)
36 fullPath.push(...split)
37
38 const things = {}
39 const relPath = fullPath.join(path.sep)
40 for (const dirent of getDirents(dir, relPath)) {
41 if (dirent.name === 'README.md') continue
42 const key = dirent.isDirectory() ? dirent.name : dirent.name.replace(/\.yml$/, '') // e.g. '3-5' or '0-rc2'
43 if (dirent.isDirectory()) {
44 things[key] = getDeepDataByDir(`${dottedPath}.${key}`, dir)
45 } else if (dirent.name.endsWith('.yml')) {
46 things[key] = getYamlContent(dir, path.join(relPath, dirent.name))
47 } else if (dirent.name.endsWith('.md')) {
48 things[key] = getMarkdownContent(dir, path.join(relPath, dirent.name))
49 } else {
50 throw new Error(`don't know how to read '${dirent.name}'`)
51 }
52 }
53 return things
54}
55
56function getDirents(root, relPath) {
57 const filePath = root ? path.join(root, relPath) : relPath

Callers 1

get-data.jsFile · 0.85

Calls 1

getDirentsFunction · 0.85

Tested by

no test coverage detected