#!/usr/bin/env node
/**
* Generate API documentation for all packages using TypeDoc
* Agent 2: API Reference Generator
*/
import { execSync } from 'child_process'
import fs from 'fs/promises'
import path from 'path'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const rootDir = path.resolve(__dirname, '..')
// Package categories aligned with navigation structure
const packageCategories = {
'Core & Infrastructure': [
'packages/core',
'packages/shared',
'packages/infrastructure'
],
'DeFi Protocols': [
'packages/defi'
],
'Wallets & Identity': [
'packages/wallets'
],
'Trading & CEX': [
'packages/trading'
],
'Market Data': [
'packages/market-data'
],
'NFT & Gaming': [
'packages/nft'
],
'AI Agents': [
'packages/agents'
],
'Automation': [
'packages/automation'
],
'Generators': [
'packages/generators'
],
'Integrations': [
'packages/integrations'
],
'Security': [
'packages/security'
],
'Novel Primitives': [
'packages/novel'
],
'Payments': [
'packages/payments'
],
'Marketplace': [
'packages/marketplace'
],
'Credits System': [
'packages/credits'
],
'Agent Wallet': [
'packages/agent-wallet'
],
'Dashboard': [
'packages/dashboard'
]
}
async function main() {
console.log('π§ Agent 2: API Reference Generator')
console.log('=' .repeat(80))
// Step 1: Check if typedoc is installed
console.log('\nπ¦ Installing TypeDoc...')
try {
execSync('pnpm add -D typedoc typedoc-plugin-markdown', {
cwd: rootDir,
stdio: 'inherit'
})
} catch (error) {
console.error('β Failed to install TypeDoc')
process.exit(1)
}
// Step 2: Generate API documentation
console.log('\nπ Generating API documentation...')
try {
execSync('pnpm typedoc --options typedoc.json', {
cwd: rootDir,
stdio: 'inherit'
})
console.log('β
API documentation generated')
} catch (error) {
console.error('β οΈ TypeDoc generation completed with warnings')
}
// Step 3: Create category index pages
console.log('\nπ Creating category index pages...')
const apiDir = path.join(rootDir, 'docs/content/reference/api')
for (const [category, packages] of Object.entries(packageCategories)) {
const categorySlug = category.toLowerCase().replace(/[^a-z0-9]+/g, '-')
const indexPath = path.join(apiDir, `${categorySlug}.mdx`)
const content = `---
title: ${category} API Reference
description: API documentation for ${category} packages
category: api-reference
keywords: [api, ${categorySlug}, reference]
published: true
---
# ${category} API Reference
Auto-generated API documentation for ${category} packages in Universal Crypto MCP.
## Packages
${packages.map(pkg => {
const pkgName = pkg.split('/').pop()
return `- [${pkgName}](./modules/${pkgName}.md)`
}).join('\n')}
## Overview
This section contains comprehensive API documentation for all ${category} packages, including:
- Classes and interfaces
- Function signatures
- Type definitions
- Usage examples
- Source code links
## Navigation
Use the sidebar to browse through individual package documentation.
---
*This documentation is auto-generated from TypeScript source code using TypeDoc.*
`
await fs.writeFile(indexPath, content, 'utf-8')
console.log(`β
Created ${categorySlug}.mdx`)
}
// Step 4: Create main API reference index
console.log('\nπ Creating main API reference index...')
const mainIndexPath = path.join(apiDir, 'index.mdx')
const mainIndexContent = `---
title: API Reference
description: Complete API documentation for Universal Crypto MCP
category: reference
keywords: [api, documentation, reference, typescript]
published: true
---
# API Reference
**Auto-generated TypeScript API documentation** for all Universal Crypto MCP packages.
## Package Categories
${Object.keys(packageCategories).map(category => {
const categorySlug = category.toLowerCase().replace(/[^a-z0-9]+/g, '-')
return `### [${category}](./${categorySlug}.md)
Documentation for ${packageCategories[category].length} package${packageCategories[category].length > 1 ? 's' : ''}`
}).join('\n\n')}
## Using the API Reference
### Search
Use the search bar to find specific classes, functions, or types.
### Navigation
- Browse by **category** using the links above
- Use the **sidebar** for detailed navigation
- Click **source code links** to view implementation
### Code Examples
Most API entries include usage examples. Look for:
- \`@example\` tags in documentation
- Links to full examples in the repository
## Key Packages
### Core & Infrastructure
- **[@nirholas/universal-crypto-mcp](./modules/core.md)** - Core MCP server functionality
- **[@nirholas/shared](./modules/shared.md)** - Shared utilities and types
### DeFi
- **[@nirholas/defi](./modules/defi.md)** - DeFi protocol integrations (Uniswap, Aave, Compound, etc.)
### Payments
- **[@nirholas/marketplace](./modules/marketplace.md)** - AI Service Marketplace
- **[@nirholas/credits](./modules/credits.md)** - Credit purchase system
- **[@nirholas/agent-wallet](./modules/agent-wallet.md)** - Agent wallet SDK
### Wallets
- **[@nirholas/wallets](./modules/wallets.md)** - Multi-chain wallet management
### Trading
- **[@nirholas/trading](./modules/trading.md)** - CEX integrations and trading bots
### Market Data
- **[@nirholas/market-data](./modules/market-data.md)** - 17+ data sources
## Documentation Standards
All packages follow consistent documentation patterns:
\`\`\`typescript
/**
* Brief description of the function
*
* @param param1 - Description of parameter
* @param param2 - Description of parameter
* @returns Description of return value
*
* @example
* \`\`\`typescript
* const result = myFunction('value1', 'value2')
* console.log(result)
* \`\`\`
*
* @see {@link RelatedClass} for related functionality
*/
export function myFunction(param1: string, param2: string): Result {
// implementation
}
\`\`\`
## Contributing
When adding new APIs:
1. Add JSDoc comments to all exported members
2. Include \`@example\` tags with working code
3. Link related APIs using \`@see\` tags
4. Run \`pnpm generate:api-docs\` to regenerate
## Support
- π [Main Documentation](/docs)
- π¬ [Discord Community](https://discord.gg/universal-crypto-mcp)
- π [Report API Issues](https://github.com/nirholas/universal-crypto-mcp/issues)
---
*This API reference is automatically generated from TypeScript source code using [TypeDoc](https://typedoc.org/).*
*Last updated: ${new Date().toISOString().split('T')[0]}*
`
await fs.writeFile(mainIndexPath, mainIndexContent, 'utf-8')
console.log('β
Created index.mdx')
// Step 5: Generate search index
console.log('\nπ Building search index...')
// This would integrate with the search system from lib/docs/search.ts
console.log('βΉοΈ Search index will be built at runtime from MDX files')
console.log('\n' + '='.repeat(80))
console.log('β
Agent 2: API Reference Generation Complete!')
console.log(`\nπ Generated documentation for ${Object.keys(packageCategories).length} categories`)
console.log(`π Output: docs/content/reference/api/`)
console.log(`\nπ Next: Run website dev server to preview API docs`)
}
main().catch(console.error)