MCPcopy
hub / github.com/wooorm/starry-night / list

Function list

script/list.js:57–240  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

55}
56
57async function list() {
58 const base = new URL(import.meta.url)
59 const infoFolder = new URL('info/', base)
60
61 const scopes = new Set(
62 all.map(function (d) {
63 return d.scopeName
64 })
65 )
66 const grammarsBody = await readOrFetch(
67 new URL('grammars.yml', base),
68 new URL(
69 'https://raw.githubusercontent.com/github-linguist/linguist/master/grammars.yml'
70 )
71 )
72 assert.ok(grammarsBody, 'expected grammars')
73 /** @type {Record<string, ReadonlyArray<string>>} */
74 const grammars = parseYaml(grammarsBody)
75 await fs.mkdir(infoFolder, {recursive: true})
76 /** @type {Map<string, string>} */
77 const scopeToVendor = new Map()
78 /** @type {Map<string, Array<string>>} */
79 const vendorToScope = new Map()
80
81 const prefix = 'vendor/grammars/'
82
83 const rawVendors = Object.keys(grammars).filter(function (vendor) {
84 if (!vendor.startsWith(prefix)) {
85 console.warn('ignoring funky vendor `%s`', vendor)
86 return false
87 }
88
89 return true
90 })
91
92 for (const rawVendor of rawVendors) {
93 const packagedScopes = grammars[rawVendor]
94
95 for (const scopeName of packagedScopes) {
96 if (!scopes.has(scopeName)) {
97 // Not used by any of the main grammars, or its dependencies.
98 continue
99 }
100
101 const vendor = rawVendor.slice(prefix.length).replace(/\/.*$/, '')
102 let vendorToScopes = vendorToScope.get(vendor)
103 if (vendorToScopes) {
104 vendorToScopes.push(scopeName)
105 } else {
106 vendorToScopes = [scopeName]
107 vendorToScope.set(vendor, vendorToScopes)
108 }
109
110 scopeToVendor.set(scopeName, vendor)
111 }
112 }
113
114 /** @type {Array<string>} */

Callers 1

list.jsFile · 0.85

Calls 1

readOrFetchFunction · 0.85

Tested by

no test coverage detected