Skip to content

⬅️ Back to Table of Contents

📄 build

📊 Analysis Summary

Metric Count
🔧 Functions 6
📦 Imports 10
📊 Variables & Constants 2
⚡ Async/Await Patterns 2
📐 Interfaces 1
📑 Type Aliases 1

📚 Table of Contents

🛠️ File Location:

📂 packages/skills/build.ts

📦 Imports

Name Source
cpSync node:fs
existsSync node:fs
mkdirSync node:fs
readFileSync node:fs
rmSync node:fs
writeFileSync node:fs
path node:path
fileURLToPath node:url
getTypeDefinition ../../scripts/utils
rewriteFunctionLinks ./rewrite-function-links

Variables & Constants

Name Type Kind Value Exported
SKILL_REFERENCE_DIR "./references" const './references'
EXPLICIT_ONLY_FUNCTIONS Set<string> const new Set([ 'get', 'set', 'toRef', ])

Async/Await Patterns

Type Function Await Expressions Promise Chains
async-function prepareFunctionReferences genFunctionReference(fn.package, fn.name, docPath) none
async-function genFunctionReference getTypeDefinition(pkg, name) none

Functions

r(path: string): string

Parameters:

  • path string

Returns: string

Calls:

  • fileURLToPath (from node:url)
Code
(path: string) => fileURLToPath(new URL(path, import.meta.url))

prepareFunctionReferences(outDir: string, referenceDir: string): Promise<Record<string, FunctionReference[]>>

Parameters:

  • outDir string
  • referenceDir string

Returns: Promise<Record<string, FunctionReference[]>>

Calls:

  • path.join
  • rmSync (from node:fs)
  • mkdirSync (from node:fs)
  • category.startsWith
  • metadata.functions.filter
  • rewriteFunctionLinks (from ./rewrite-function-links)
  • toTitleCase
  • fn.description?.replace
  • referenceDir.replace
  • refs.push
  • existsSync (from node:fs)
  • genFunctionReference
  • writeFileSync (from node:fs)
  • console.warn

Internal Comments:

// Regenerate from scratch so references of removed functions don't linger (x2)

Code
async function prepareFunctionReferences(outDir: string, referenceDir = SKILL_REFERENCE_DIR): Promise<Record<string, FunctionReference[]>> {
  // Regenerate from scratch so references of removed functions don't linger
  const outReferenceDir = path.join(outDir, referenceDir)
  rmSync(outReferenceDir, { recursive: true, force: true })
  mkdirSync(outReferenceDir, { recursive: true })

  const categories: Record<string, FunctionReference[]> = {}

  for (const category of metadata.categoryNames) {
    if (category.startsWith('_'))
      continue

    const refs: FunctionReference[] = []

    const functions = metadata.functions.filter(i => i.category === category && !i.internal)
    for (const fn of functions) {
      const description = rewriteFunctionLinks(toTitleCase(fn.description?.replace(/\|/g, '\\|') ?? ''), `${referenceDir.replace(/^\.\//, '')}/`)

      if (fn.external) {
        refs.push({ name: fn.name, description, reference: fn.external })
        continue
      }

      const docPath = path.join(VUEUSE_ROOT, `packages/${fn.package}/${fn.name}/index.md`)
      if (existsSync(docPath)) {
        const outputPath = path.join(referenceDir, `${fn.name}.md`)
        const docContent = await genFunctionReference(fn.package, fn.name, docPath)
        writeFileSync(path.join(outDir, outputPath), docContent)
        refs.push({ name: fn.name, description, reference: outputPath })
      }
      else {
        console.warn(`Missing doc: ${fn.name}`)
      }
    }

    categories[category] = refs
  }
  return categories
}

prepareFunctionsTable(categories: Record<string, FunctionReference[]>): string

Parameters:

  • categories Record<string, FunctionReference[]>

Returns: string

Calls:

  • Object.entries
  • resolveFunctionInvocation
Code
function prepareFunctionsTable(categories: Record<string, FunctionReference[]>) {
  let table = ''

  for (const [category, functions] of Object.entries(categories)) {
    table += `### ${category}\n\n`
    table += `| Function | Description | Invocation |\n`
    table += `|----------|-------------|------------|\n`

    for (const fn of functions) {
      const invocation = resolveFunctionInvocation(fn.name, category)
      table += `| [\`${fn.name}\`](${fn.reference}) | ${fn.description} | ${invocation} |\n`
    }
    table += `\n`
  }

  return table
}

resolveFunctionInvocation(name: string, category: string): FunctionInvocation

Parameters:

  • name string
  • category string

Returns: FunctionInvocation

Calls:

  • EXPLICIT_ONLY_FUNCTIONS.has
  • category.startsWith
Code
function resolveFunctionInvocation(name: string, category: string): FunctionInvocation {
  if (EXPLICIT_ONLY_FUNCTIONS.has(name)) {
    return 'EXPLICIT_ONLY'
  }
  if (category.startsWith('@')) {
    return 'EXTERNAL'
  }
  return 'AUTO'
}

toTitleCase(str: string): string

Parameters:

  • str string

Returns: string

Calls:

  • first.toUpperCase
  • str.slice
Code
function toTitleCase(str: string): string {
  if (!str)
    return str
  const first = str[0]
  if (first < 'a' || first > 'z')
    return str
  return first.toUpperCase() + str.slice(1)
}

genFunctionReference(pkg: string, name: string, mdPath: string): Promise<string>

Parameters:

  • pkg string
  • name string
  • mdPath string

Returns: Promise<string>

Calls:

  • rewriteFunctionLinks (from ./rewrite-function-links)
  • readFileSync (from node:fs)
  • getTypeDefinition (from ../../scripts/utils)
Code
async function genFunctionReference(pkg: string, name: string, mdPath: string) {
  const md = rewriteFunctionLinks(readFileSync(mdPath, 'utf-8'), './')
  const types = await getTypeDefinition(pkg, name)
  if (types) {
    return `${md}
## Type Declarations

\`\`\`ts
${types}
\`\`\`
`
  }
  return md
}

Interfaces

FunctionReference

Interface Code
interface FunctionReference {
  name: string
  description: string
  reference: string
}

Properties

Name Type Optional Description
name string not shown
description string not shown
reference string not shown

Type Aliases

FunctionInvocation

type FunctionInvocation = 'AUTO' | 'EXTERNAL' | 'EXPLICIT_ONLY';

Generated by Syntax Scribe