Home / Function/ gen() — supabase Function Reference

gen() — supabase Function Reference

Architecture documentation for the gen() function in legacy.ts from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  797c645c_8063_cca7_a388_c741cda42c70["gen()"]
  0b86162b_2365_7a34_3bb2_7ad0c85ff06e["generateDocsIndexPage()"]
  797c645c_8063_cca7_a388_c741cda42c70 -->|calls| 0b86162b_2365_7a34_3bb2_7ad0c85ff06e
  f39b2b6c_7375_59c7_6b63_addaa94ee4b5["writeToDisk()"]
  797c645c_8063_cca7_a388_c741cda42c70 -->|calls| f39b2b6c_7375_59c7_6b63_addaa94ee4b5
  a3173402_f4d8_1383_032d_81ae491658db["extractTsDocNode()"]
  797c645c_8063_cca7_a388_c741cda42c70 -->|calls| a3173402_f4d8_1383_032d_81ae491658db
  c1960e9a_fc3b_1e0f_4af2_e5f580cc6ae4["tsDocCommentToMdComment()"]
  797c645c_8063_cca7_a388_c741cda42c70 -->|calls| c1960e9a_fc3b_1e0f_4af2_e5f580cc6ae4
  581af71e_3755_92c5_9fd6_e723079c8291["getDescriptionFromDefinition()"]
  797c645c_8063_cca7_a388_c741cda42c70 -->|calls| 581af71e_3755_92c5_9fd6_e723079c8291
  14e4383e_4bea_97d2_4205_13a2c645473d["Page()"]
  797c645c_8063_cca7_a388_c741cda42c70 -->|calls| 14e4383e_4bea_97d2_4205_13a2c645473d
  05d8312f_d822_2922_b652_a232d77d6bd8["generateParameters()"]
  797c645c_8063_cca7_a388_c741cda42c70 -->|calls| 05d8312f_d822_2922_b652_a232d77d6bd8
  c37ec867_efed_0cde_e502_6f46856f7ff2["generateSpotlight()"]
  797c645c_8063_cca7_a388_c741cda42c70 -->|calls| c37ec867_efed_0cde_e502_6f46856f7ff2
  7db7dd94_03dc_aa14_65f0_43138306a148["generateExamples()"]
  797c645c_8063_cca7_a388_c741cda42c70 -->|calls| 7db7dd94_03dc_aa14_65f0_43138306a148
  style 797c645c_8063_cca7_a388_c741cda42c70 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/docs/generator/legacy.ts lines 27–79

export default async function gen(inputFileName: string, outputDir: string) {
  const docSpec = yaml.load(fs.readFileSync(inputFileName, 'utf8'))
  const defRef = docSpec.info.definition ? fs.readFileSync(docSpec.info.definition, 'utf8') : '{}'

  const definition = JSON.parse(defRef)
  const id = docSpec.info.id
  const allLanguages = docSpec.info.libraries
  const pages = Object.entries(docSpec.functions).map(([name, x]: [string, OpenRef.Page]) => ({
    ...x,
    pageName: name,
  }))

  // Index Page
  const indexFilename = outputDir + `/index.mdx`
  const index = generateDocsIndexPage(docSpec, inputFileName)
  await writeToDisk(indexFilename, index)
  console.log('The index was saved: ', indexFilename)

  // Generate Pages
  pages.forEach(async (pageSpec: OpenRef.Page) => {
    try {
      // get the slug from common-client-libs.yml
      const slug = flattenedCommonDocSpecJson.find((item) => item.id === pageSpec.id).slug

      const hasTsRef = pageSpec['$ref'] || null
      const tsDefinition = hasTsRef && extractTsDocNode(hasTsRef, definition)
      if (hasTsRef && !tsDefinition) throw new Error('Definition not found: ' + hasTsRef)

      const description =
        pageSpec.description || tsDocCommentToMdComment(getDescriptionFromDefinition(tsDefinition))

      // Create page
      const content = Page({
        slug: slug,
        id: pageSpec.id,
        specFileName: docSpec.info.specUrl || inputFileName,
        title: pageSpec.title || pageSpec.pageName,
        description,
        parameters: hasTsRef ? generateParameters(tsDefinition) : '',
        spotlight: generateSpotlight(id, pageSpec['examples'] || [], allLanguages),
        examples: generateExamples(id, pageSpec['examples'] || [], allLanguages),
        notes: pageSpec.notes,
      })
      //console.log({ slug })
      // Write to disk
      const dest = outputDir + `/${slug}.mdx`
      await writeToDisk(dest, content)
      console.log('Saved: ', dest)
    } catch (error) {
      console.error(error)
    }
  })
}

Subdomains

Frequently Asked Questions

What does gen() do?
gen() is a function in the supabase codebase.
What does gen() call?
gen() calls 9 function(s): Page, extractTsDocNode, generateDocsIndexPage, generateExamples, generateParameters, generateSpotlight, getDescriptionFromDefinition, tsDocCommentToMdComment, and 1 more.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free