MCPcopy Index your code
hub / github.com/primer/react / getComponentStatuses

Function getComponentStatuses

script/component-status-project/build.ts:21–54  ·  view source on GitHub ↗

* Extracts the component status for each file in the given directory. * * @param filenames Array of filenames to read front-matter from * @param dir Absolute path to directory containing files * @returns A promise that resolves to an array containing outcome of file front-matter extraction

(filenames: string[], dir: string)

Source from the content-addressed store, hash-verified

19 * @returns A promise that resolves to an array containing outcome of file front-matter extraction
20 */
21function getComponentStatuses(filenames: string[], dir: string) {
22 const promises: Promise<ComponentStatus | null>[] = []
23
24 const handleCallback = (
25 filename: string,
26 resolve: (value: ComponentStatus | null) => void,
27 reject: (value: unknown) => void,
28 ) => {
29 fs.readFile(path.resolve(dir, filename), 'utf-8', (err, content) => {
30 if (err) return reject(err)
31
32 if (fm.test(content)) {
33 const {
34 attributes: {title, status},
35 } = fm(content)
36
37 if (status) {
38 return resolve({[title]: status})
39 }
40 }
41
42 resolve(null)
43 })
44 }
45
46 for (const filename of filenames) {
47 const promise: Promise<ComponentStatus | null> = new Promise((resolve, reject) => {
48 return handleCallback(filename, resolve, reject)
49 })
50 promises.push(promise)
51 }
52
53 return Promise.all(promises)
54}
55
56/**
57 * Orchestrates the process of reading component status for each file in the given directory.

Callers 1

readFilesFunction · 0.85

Calls 1

handleCallbackFunction · 0.85

Tested by

no test coverage detected