📄 metadata/scripts/update¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 3 |
| 📦 Imports | 14 |
| 📊 Variables & Constants | 1 |
| ⚡ Async/Await Patterns | 3 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/metadata/scripts/update.ts
📦 Imports¶
| Name | Source |
|---|---|
PackageIndexes |
@vueuse/metadata |
VueUseFunction |
@vueuse/metadata |
VueUsePackage |
@vueuse/metadata |
existsSync |
node:fs |
join |
node:path |
relative |
node:path |
resolve |
node:path |
fileURLToPath |
node:url |
matter |
gray-matter |
Git |
simple-git |
glob |
tinyglobby |
ecosystemFunctions |
../../../meta/ecosystem-functions |
packages |
../../../meta/packages |
getCategories |
../utils |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
DOCS_URL |
"https://vueuse.org" |
const | 'https://vueuse.org' |
✓ |
Async/Await Patterns¶
| Type | Function | Await Expressions | Promise Chains |
|---|---|---|---|
| async-function | listFunctions |
glob('', { onlyDirectories: true, cwd: dir, ignore: [ '_', 'dist', 'node_mo... | none |
| async-function | readMetadata |
listFunctions(dir), Promise.all(functions.map(async (fnName) => { const mdPat... | Promise.all |
| async-function | run |
readMetadata(), fs.writeFile(join(DIR_PACKAGE, 'index.json'), `${JSON.stringi... | none |
Functions¶
listFunctions(dir: string, ignore: string[]): Promise<any>¶
Parameters:
dirstringignorestring[]
Returns: Promise<any>
Calls:
glob (from tinyglobby)files.sortfiles.mappath.endsWithpath.slice
Code
readMetadata(): Promise<PackageIndexes>¶
Returns: Promise<PackageIndexes>
Calls:
join (from node:path)listFunctionsrelative(DIR_ROOT, dir).replacePromise.allfunctions.mapgit.rawexistsSync (from node:fs)indexes.functions.pushfs.readFilematter (from gray-matter)alias.split(',').map(s => s.trim()).filtervariants.split(',').map(s => s.trim()).filterutils.split(',').map(s => s.trim()).filterrelated.split(',').map(s => s.trim()).filterArray.isArrayrelated.map(s => s.trim()).filtermd // normalize newlines .replace(/\r\n/g, '\n') // remove ::: tip blocks .replace(/(:{3,}(?=[^:\n]*\n))[^\n]*\n[\s\S]*?\1 *(?=\n)/g, '') // remove headers .matchdescription.trim/^[A-Z][A-Z]/.testdescription.charAt(0).toLowerCasedescription.slice['core', 'shared'].includesdescription.includesindexes.functions.sorta.name.localeComparegetCategories (from ../utils)indexes.functions.forEachfn.related.forEachindexes.functions.findtarget.related.includestarget.related.pushfn.related?.sort
Internal Comments:
Code
export async function readMetadata() {
const indexes: PackageIndexes = {
packages: {},
categories: [],
functions: [
...ecosystemFunctions,
],
}
for (const info of packages) {
if (info.utils)
continue
const dir = join(DIR_SRC, info.name)
const functions = await listFunctions(dir)
const pkg: VueUsePackage = {
...info,
dir: relative(DIR_ROOT, dir).replace(/\\/g, '/'),
docs: info.addon ? `${DOCS_URL}/${info.name}/README.html` : undefined,
}
indexes.packages[info.name] = pkg
await Promise.all(functions.map(async (fnName) => {
const mdPath = join(dir, fnName, 'index.md')
const tsPath = join(dir, fnName, 'index.ts')
const fn: VueUseFunction = {
name: fnName,
package: pkg.name,
lastUpdated: +await git.raw(['log', '-1', '--format=%at', tsPath]) * 1000,
}
if (existsSync(join(dir, fnName, 'component.ts')))
fn.component = true
if (existsSync(join(dir, fnName, 'directive.ts')))
fn.directive = true
if (!existsSync(mdPath)) {
fn.internal = true
indexes.functions.push(fn)
return
}
fn.docs = `${DOCS_URL}/${pkg.name}/${fnName}/`
const mdRaw = await fs.readFile(mdPath, 'utf-8')
const { content: md, data: frontmatter } = matter(mdRaw)
const category = frontmatter.category
let alias = frontmatter.alias
if (typeof alias === 'string')
alias = alias.split(',').map(s => s.trim()).filter(Boolean)
let variants = frontmatter.variants
if (typeof variants === 'string')
variants = variants.split(',').map(s => s.trim()).filter(Boolean)
let utils = frontmatter.utils
if (typeof utils === 'string')
utils = utils.split(',').map(s => s.trim()).filter(Boolean)
let related = frontmatter.related
if (typeof related === 'string')
related = related.split(',').map(s => s.trim()).filter(Boolean)
else if (Array.isArray(related))
related = related.map(s => s.trim()).filter(Boolean)
let description = (
md
// normalize newlines
.replace(/\r\n/g, '\n')
// remove ::: tip blocks
.replace(/(:{3,}(?=[^:\n]*\n))[^\n]*\n[\s\S]*?\1 *(?=\n)/g, '')
// remove headers
.match(/#(?=\s).*\n+(.+?)(?:, |\. |\n|\.\n)/) || []
)[1] || ''
description = description.trim()
// convert description to leading lowercase, except for abbv.
if (!/^[A-Z][A-Z]/.test(description))
description = description.charAt(0).toLowerCase() + description.slice(1)
fn.category = ['core', 'shared'].includes(pkg.name) ? category : `@${pkg.display}`
fn.description = description
if (description.includes('DEPRECATED') || frontmatter.deprecated)
fn.deprecated = true
if (alias?.length)
fn.alias = alias
if (variants?.length)
fn.variants = variants
if (utils?.length)
fn.utils = utils
if (related?.length)
fn.related = related
if (pkg.submodules)
fn.importPath = `${pkg.name}/${fn.name}`
indexes.functions.push(fn)
}))
}
indexes.functions.sort((a, b) => a.name.localeCompare(b.name))
indexes.categories = getCategories(indexes.functions)
// interop related
indexes.functions.forEach((fn) => {
if (!fn.related)
return
fn.related.forEach((name) => {
const target = indexes.functions.find(f => f.name === name)
if (!target)
throw new Error(`Unknown related function: ${name}`)
if (!target.related)
target.related = []
if (!target.related.includes(fn.name))
target.related.push(fn.name)
})
})
indexes.functions.forEach(fn => fn.related?.sort())
return indexes
}
run(): Promise<void>¶
Returns: Promise<void>
Calls:
readMetadatafs.writeFilejoin (from node:path)JSON.stringify
Code
Generated by Syntax Scribe