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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions components/GeneratePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,32 @@ export function GeneratePanel({ idl, programId }: GeneratePanelProps) {
</p>
</>
)}
{language === "dart" && (
<>
<Step
n={1}
text="Unzip the download. The output is a folder of Dart sources with a top-level barrel file that re-exports the instructions, PDAs, errors, and program constants."
/>
<Step
n={2}
text="Copy the folder into your Dart or Flutter project's lib/, then add the solana_kit packages the generated code imports (solana_kit_addresses, solana_kit_instructions, solana_kit_codecs_*, and meta) to your pubspec.yaml and fetch them:"
>
<Code>{`dart pub get`}</Code>
</Step>
<Step
n={3}
text="Import the barrel file and use the exported instruction builders, account/PDA helpers, and program constants."
>
<Code>{`import 'generated/${programName}.dart';`}</Code>
</Step>
<p className="text-zinc-600 pt-1">
Generated as native <span className="text-zinc-500">Dart</span>{" "}
sources targeting the solana_kit SDK. No pubspec.yaml is emitted
— add the solana_kit dependencies to your project manifest
yourself.
</p>
</>
)}
</div>
</div>
</div>
Expand Down
20 changes: 20 additions & 0 deletions lib/codama-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import JSZip from "jszip";
import fs from "fs";
import path from "path";
import { randomUUID } from "crypto";
import { createRequire } from "module";

// codama-renderers-dart@0.4.x mispublishes its exports map: the `import` condition
// points at a .mjs absent from the tarball. Load the working CJS build via require.
// Anchor on cwd rather than import.meta.url so this also compiles under the CJS test build.
const renderDart: typeof import("codama-renderers-dart").renderVisitor =
createRequire(path.join(process.cwd(), "package.json"))(
"codama-renderers-dart"
).renderVisitor;
import type { Language } from "./codama-types";
import { assertLanguageSupportedForIdl } from "./codama-compat";
import { getCodamaRootNode, getIdlProgramName } from "./idl-utils";
Expand Down Expand Up @@ -87,6 +96,17 @@ export async function generateFromIdl(
);
break;
}
case "dart": {
const dartDir = path.join(tmpDir, `${programName}-dart-client`);
fs.mkdirSync(dartDir, { recursive: true });
codama.accept(
renderDart(dartDir, {
formatCode: false,
deleteFolderBeforeRendering: false,
})
);
break;
}
default:
throw new Error(`Unknown language: ${language}`);
}
Expand Down
7 changes: 6 additions & 1 deletion lib/codama-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Language = "typescript" | "typescript-umi" | "rust" | "go";
export type Language = "typescript" | "typescript-umi" | "rust" | "go" | "dart";

export const LANGUAGES: { id: Language; label: string; description: string }[] =
[
Expand All @@ -22,4 +22,9 @@ export const LANGUAGES: { id: Language; label: string; description: string }[] =
label: "Go",
description: "Native Go client",
},
{
id: "dart",
label: "Dart",
description: "Native Dart client (solana_kit)",
},
];
1 change: 1 addition & 0 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const nextConfig: NextConfig = {
"@codama/renderers-js-umi",
"@codama/renderers-rust",
"@codama/renderers-go",
"codama-renderers-dart",
"memfs",
],

Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@solana/kit": "^7.0.0",
"@vercel/analytics": "^2.0.1",
"codama": "^1.9.0",
"codama-renderers-dart": "^0.4.1",
"jszip": "^3.10.1",
"next": "^16.2.10",
"pako": "^3.0.1",
Expand Down
Loading