Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .changeset/free-schools-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@evolution-sdk/evolution": patch
---

add blueprint module
212 changes: 212 additions & 0 deletions docs/app/tools/blueprint-codegen/blueprint-codegen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
'use client'

import { useState } from 'react'
import { Blueprint } from "@evolution-sdk/evolution"
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock'

const { PlutusBlueprint, generateTypeScript, createCodegenConfig } = Blueprint

export function BlueprintCodegen() {
const [blueprintJson, setBlueprintJson] = useState("")
const [generatedCode, setGeneratedCode] = useState<string>("")
const [error, setError] = useState<string | null>(null)
const [optionStyle, setOptionStyle] = useState<'NullOr' | 'UndefinedOr' | 'Union'>('UndefinedOr')
const [moduleStrategy, setModuleStrategy] = useState<'flat' | 'namespaced'>('namespaced')
const [forceVariant, setForceVariant] = useState(true)

const generateTypes = async () => {
setError(null)
setGeneratedCode("")

try {
const cleanJson = blueprintJson.trim()

if (!cleanJson) {
setError('Please enter a Plutus Blueprint JSON')
return
}

// Parse the JSON
const plutusJson = JSON.parse(cleanJson)

// Create config
const config = createCodegenConfig({
optionStyle,
moduleStrategy,
forceVariant,
useSuspend: false,
useRelativeRefs: true,
emptyConstructorStyle: "Literal",
})

// Generate TypeScript code
const code = generateTypeScript(plutusJson, config)

setGeneratedCode(code)
} catch (err) {
console.error('Generation error:', err)
setError(err instanceof Error ? err.message : 'Failed to generate types from blueprint')
}
}

const downloadCode = () => {
if (!generatedCode) return

const blob = new Blob([generatedCode], { type: 'text/typescript' })
const url = URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = 'generated-types.ts'
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
URL.revokeObjectURL(url)
}

const copyToClipboard = async () => {
if (!generatedCode) return

try {
await navigator.clipboard.writeText(generatedCode)
} catch (err) {
console.error('Failed to copy:', err)
}
}

return (
<div className="max-w-6xl mx-auto space-y-6">
<div className="rounded-lg border bg-card text-card-foreground shadow-sm">
<div className="p-6 space-y-6">
<div className="flex items-center justify-between">
<div className="space-y-1">
<h3 className="text-2xl font-semibold tracking-tight">Blueprint Input</h3>
<p className="text-sm text-muted-foreground">Paste your plutus.json blueprint</p>
</div>
</div>

<div className="space-y-4">
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
<div className="space-y-2">
<label htmlFor="option-style" className="text-sm font-medium leading-none">
Option Style
</label>
<select
id="option-style"
value={optionStyle}
onChange={(e) => setOptionStyle(e.target.value as any)}
className="flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring"
>
<option value="UndefinedOr">UndefinedOr</option>
<option value="NullOr">NullOr</option>
<option value="Union">Union</option>
</select>
</div>

<div className="space-y-2">
<label htmlFor="module-strategy" className="text-sm font-medium leading-none">
Module Strategy
</label>
<select
id="module-strategy"
value={moduleStrategy}
onChange={(e) => setModuleStrategy(e.target.value as any)}
className="flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring"
>
<option value="namespaced">Namespaced</option>
<option value="flat">Flat</option>
</select>
</div>

<div className="space-y-2">
<label htmlFor="force-variant" className="text-sm font-medium leading-none">
Force Variant
</label>
<div className="flex items-center h-10">
<input
id="force-variant"
type="checkbox"
checked={forceVariant}
onChange={(e) => setForceVariant(e.target.checked)}
className="h-4 w-4 rounded border-input"
/>
<label htmlFor="force-variant" className="ml-2 text-sm text-muted-foreground">
Use Variant for all unions
</label>
</div>
</div>
</div>

<div className="space-y-2">
<label htmlFor="blueprint-json" className="text-sm font-medium leading-none">
Blueprint JSON
</label>
<textarea
id="blueprint-json"
value={blueprintJson}
onChange={(e) => setBlueprintJson(e.target.value)}
placeholder="Paste your plutus.json content here..."
className="flex min-h-[200px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm font-mono resize-y focus:outline-none focus:ring-2 focus:ring-ring"
/>
</div>

<button
onClick={generateTypes}
className="sm:w-auto w-full inline-flex items-center justify-center rounded-md text-sm font-medium h-9 px-6 py-2 bg-zinc-700 text-white hover:bg-zinc-600 active:bg-zinc-500 transition-all cursor-pointer shadow-sm hover:shadow"
>
Generate Types
</button>
</div>
</div>
</div>

{error && (
<div className="rounded-lg border bg-card text-card-foreground shadow-sm">
<div className="p-6">
<div className="flex gap-3">
<svg className="h-5 w-5 text-destructive shrink-0 mt-0.5" viewBox="0 0 20 20" fill="currentColor">
<path fillRule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clipRule="evenodd" />
</svg>
<div className="flex-1 min-w-0 space-y-2">
<p className="text-sm font-medium text-destructive">Error generating types</p>
<pre className="text-xs text-muted-foreground whitespace-pre-wrap break-words overflow-wrap-anywhere font-mono">{error}</pre>
</div>
</div>
</div>
</div>
)}

{generatedCode && (
<div className="rounded-lg border bg-card text-card-foreground shadow-sm">
<div className="p-6 space-y-3">
<div className="flex items-center justify-between">
<h4 className="text-sm font-semibold">Generated TypeScript</h4>
<div className="flex gap-2">
<button
onClick={copyToClipboard}
className="inline-flex items-center justify-center rounded-md text-sm font-medium h-8 px-3 py-1 bg-zinc-700 text-white hover:bg-zinc-600 active:bg-zinc-500 transition-all cursor-pointer shadow-sm"
>
Copy
</button>
<button
onClick={downloadCode}
className="inline-flex items-center justify-center rounded-md text-sm font-medium h-8 px-3 py-1 bg-zinc-700 text-white hover:bg-zinc-600 active:bg-zinc-500 transition-all cursor-pointer shadow-sm"
>
Download
</button>
</div>
</div>
<div className="max-h-[600px] overflow-y-auto">
<DynamicCodeBlock lang="ts" code={generatedCode} />
</div>
</div>
</div>
)}

<div className="pt-4 border-t border-border/50">
<p className="text-xs text-center text-muted-foreground">
Questions or feedback? <a href="https://github.com/IntersectMBO/evolution-sdk/issues" target="_blank" rel="noopener noreferrer" className="text-primary hover:underline">Start a discussion on GitHub</a>
</p>
</div>
</div>
)
}
21 changes: 21 additions & 0 deletions docs/app/tools/blueprint-codegen/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { BlueprintCodegen } from "./blueprint-codegen"
import type { Metadata } from 'next'

export const metadata: Metadata = {
title: 'Blueprint Codegen | Evolution SDK',
description: 'Generate TypeScript types from Plutus Blueprint (plutus.json)',
}

export default function BlueprintCodegenPage() {
return (
<div className="container mx-auto px-4 py-8 max-w-6xl">
<div className="mb-8">
<h1 className="text-4xl font-bold mb-4">Blueprint Type Generator</h1>
<p className="text-muted-foreground text-lg">
Generate TypeScript TSchema definitions from your Plutus Blueprint (plutus.json). Paste your blueprint JSON below to generate type-safe TypeScript code.
</p>
</div>
<BlueprintCodegen />
</div>
)
}
5 changes: 5 additions & 0 deletions docs/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import { Card, Cards } from 'fumadocs-ui/components/card'
description="Decode CBOR transaction hex into readable JSON format"
href="/tools/tx-decoder"
/>
<Card
title="Blueprint Codegen"
description="Generate TypeScript types from Plutus Blueprint JSON"
href="/tools/blueprint-codegen"
/>
<Card
title="Examples"
description="Explore real-world examples and common patterns"
Expand Down
Loading