-
Notifications
You must be signed in to change notification settings - Fork 8
Feat: Add Solana Kit Client Generation Script #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,5 @@ test-ledger | |
| test-programs/* | ||
| .goki/ | ||
| yarn-error.log | ||
| .idea | ||
| .idea | ||
| clients/ | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||||||||||||||||||||||||||||||||||||||
| import { createFromRoot } from "codama"; | ||||||||||||||||||||||||||||||||||||||||||
| import { rootNodeFromAnchor } from "@codama/nodes-from-anchor"; | ||||||||||||||||||||||||||||||||||||||||||
| import { renderVisitor as renderJavaScriptVisitor } from "@codama/renderers-js"; | ||||||||||||||||||||||||||||||||||||||||||
| import fs from "fs"; | ||||||||||||||||||||||||||||||||||||||||||
| import path from "path"; | ||||||||||||||||||||||||||||||||||||||||||
| import { fileURLToPath } from "url"; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const __filename = fileURLToPath(import.meta.url); | ||||||||||||||||||||||||||||||||||||||||||
| const __dirname = path.dirname(__filename); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const anchorIdl = JSON.parse( | ||||||||||||||||||||||||||||||||||||||||||
| fs.readFileSync( | ||||||||||||||||||||||||||||||||||||||||||
| new URL("../target/idl/gpl_session.json", import.meta.url), | ||||||||||||||||||||||||||||||||||||||||||
| "utf8" | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for missing or invalid IDL file. The script will crash with an unhelpful error if the IDL file doesn't exist or isn't valid JSON. This typically happens when 🛡️ Proposed fix with error handling+try {
const anchorIdl = JSON.parse(
fs.readFileSync(
new URL("../target/idl/gpl_session.json", import.meta.url),
"utf8"
)
);
+} catch (error) {
+ console.error("Error: Could not read IDL file. Have you run 'anchor build' first?");
+ console.error(error.message);
+ process.exit(1);
+}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const codama = createFromRoot(rootNodeFromAnchor(anchorIdl)); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const jsClient = path.join(__dirname, "..", "clients", "gpl_session"); | ||||||||||||||||||||||||||||||||||||||||||
| codama.accept(renderJavaScriptVisitor(path.join(jsClient, "src", "generated"))); | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider adding error handling and user feedback. The Codama generation may fail if the output directory doesn't exist or if there are issues with the IDL structure. Adding try-catch and console feedback would improve the developer experience. ♻️ Proposed enhancement with error handling and logging+console.log("Generating Solana Kit client from IDL...");
+
+try {
const codama = createFromRoot(rootNodeFromAnchor(anchorIdl));
const jsClient = path.join(__dirname, "..", "clients", "gpl_session");
+ console.log(`Output directory: ${path.join(jsClient, "src", "generated")}`);
+
codama.accept(renderJavaScriptVisitor(path.join(jsClient, "src", "generated")));
+
+ console.log("✓ Client generation completed successfully!");
+} catch (error) {
+ console.error("Error: Client generation failed");
+ console.error(error.message);
+ process.exit(1);
+}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add prerequisite steps to the SDK generation documentation.
The documentation doesn't mention that users must first run
anchor buildto generate the IDL file, and should runyarn installto install dependencies. Without these prerequisites, the script will fail.📝 Proposed documentation enhancement
🤖 Prompt for AI Agents