Skip to content

Commit

Permalink
feat: ox/erc4337 (#39)
Browse files Browse the repository at this point in the history
* wip: checkpoint

* wip: checkpoint

* wip: up

* wip: checkpoint

* wip: checkpoint

* wip: checkpoint

* wip: checkpoint

* wip: checkpoint

* wip: checkpoint
  • Loading branch information
jxom authored Dec 29, 2024
1 parent dbfeb2a commit 23286de
Show file tree
Hide file tree
Showing 14 changed files with 3,665 additions and 41 deletions.
65 changes: 26 additions & 39 deletions scripts/docgen/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
renderNamespaceErrors,
renderNamespaceTypes,
} from './render/apiNamespace.js'
import { createDataLookup, getId } from './utils/model.js'
import { createDataLookup, getId, getPath } from './utils/model.js'
import { namespaceRegex } from './utils/regex.js'
import {
extractNamespaceDocComments,
Expand All @@ -22,11 +22,35 @@ import {
console.log('Generating API docs.')

////////////////////////////////////////////////////////////
/// Load API Model and construct lookup
/// Load API Model
////////////////////////////////////////////////////////////

const fileName = './scripts/docgen/ox.api.json'
const apiPackage = new model.ApiModel().loadPackage(fileName)

////////////////////////////////////////////////////////////
/// Get namespace doc comments
////////////////////////////////////////////////////////////

const exports = getExports()

export let namespaceDocComments: ReturnType<
typeof extractNamespaceDocComments
> = {}
for (const path of Object.values(exports.src)) {
if (!path.endsWith('index.ts')) continue
const comments = extractNamespaceDocComments(
resolve(import.meta.dirname, '../../src', path),
apiPackage,
)
if (!comments) continue
namespaceDocComments = { ...namespaceDocComments, ...comments }
}

////////////////////////////////////////////////////////////
/// Construct lookup
////////////////////////////////////////////////////////////

const dataLookup = createDataLookup(apiPackage)

fs.writeFileSync(
Expand Down Expand Up @@ -57,23 +81,6 @@ for (const member of apiEntryPoint.members) {
namespaces.push(member)
}

////////////////////////////////////////////////////////////
/// Get namespace doc comments
////////////////////////////////////////////////////////////

const exports = getExports()

let namespaceDocComments: ReturnType<typeof extractNamespaceDocComments> = {}
for (const path of Object.values(exports.src)) {
if (!path.endsWith('index.ts')) continue
const comments = extractNamespaceDocComments(
resolve(import.meta.dirname, '../../src', path),
apiPackage,
)
if (!comments) continue
namespaceDocComments = { ...namespaceDocComments, ...comments }
}

////////////////////////////////////////////////////////////
/// Build markdown files
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -290,23 +297,3 @@ for (const namespace of namespaceEntries) {

// biome-ignore lint/suspicious/noConsoleLog:
console.log('Done.')

////////////////////////////////////////////////////////////
/// Helpers
////////////////////////////////////////////////////////////

function sanitizePath(name: string) {
return name.toLowerCase().replaceAll(/-|\s/g, '')
}

function getPath({
entrypointCategory,
category,
}: { entrypointCategory?: string | undefined; category?: string | undefined }) {
const isCore = entrypointCategory === 'Core'
let path = '/'
if (entrypointCategory)
path = `/${isCore ? 'api' : `${sanitizePath(entrypointCategory)}`}`
if (category && !isCore) path += `/${sanitizePath(category)}`
return path
}
25 changes: 23 additions & 2 deletions scripts/docgen/utils/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { readFileSync } from 'node:fs'
import * as model from '@microsoft/api-extractor-model'
import type { DocDeclarationReference } from '@microsoft/tsdoc'

import { namespaceDocComments } from '../build.js'
import { moduleNameRegex, namespaceRegex } from './regex.js'
import { processDocComment, renderDocNode } from './tsdoc.js'

Expand Down Expand Up @@ -160,17 +161,37 @@ export type ResolveDeclarationReference = ReturnType<
typeof createResolveDeclarationReference
>

function sanitizePath(name: string) {
return name.toLowerCase().replaceAll(/-|\s/g, '')
}

export function getPath({
entrypointCategory,
category,
}: { entrypointCategory?: string | undefined; category?: string | undefined }) {
const isCore = entrypointCategory === 'Core'
let path = '/'
if (entrypointCategory)
path = `/${isCore ? 'api' : `${sanitizePath(entrypointCategory)}`}`
if (category && !isCore) path += `/${sanitizePath(category)}`
return path
}

function getLinkForApiItem(item: model.ApiItem) {
const parent = item.parent
if (!parent) throw new Error('Parent not found')

const baseLink = `/api/${parent.displayName}`
const { entrypointCategory, category } =
namespaceDocComments[parent.displayName] || {}
const basePath = getPath({ category, entrypointCategory })

const baseLink = `${basePath === '/' ? '/api' : basePath}/${parent.displayName}`
if (item.kind === model.ApiItemKind.Namespace) return baseLink
if (item.kind === model.ApiItemKind.Function)
return `${baseLink}/${item.displayName}`
if (item.kind === model.ApiItemKind.TypeAlias) {
if (!parent.displayName)
return `/api/${item.displayName}/types#${item.displayName.toLowerCase()}`
return `${basePath}/${item.displayName}/types#${item.displayName.toLowerCase()}`
return `${baseLink}/types#${item.displayName.toLowerCase()}`
}
if (
Expand Down
Loading

0 comments on commit 23286de

Please sign in to comment.