solgen
Version:
A TypeScript SDK generator for Solana IDL - Automatically generates type definitions, account interfaces, and instruction builders
5 lines • 2.36 kB
JavaScript
;var s=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var D=(i,t)=>{for(var n in t)s(i,n,{get:t[n],enumerable:!0})},h=(i,t,n,d)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of f(t))!p.call(i,a)&&a!==n&&s(i,a,{get:()=>t[a],enumerable:!(d=c(t,a))||d.enumerable});return i};var w=i=>h(s({},"__esModule",{value:!0}),i);var R={};D(R,{genProgramId:()=>P});module.exports=w(R);var o=require("ts-morph");function P(i,t,n,d){var g,u;let a=null;"metadata"in t&&"address"in t.metadata&&(a=t.metadata.address);let e=i.addSourceFileAtPathIfExists(d("programId.ts"));e===void 0&&a===null&&n===null&&console.warn("\nWARNING: program ID not found in the IDL nor provided with the `--program-id` flag. Edit the generated `programId.ts` file manually to return the correct program ID!\n");let r=(u=(g=e==null?void 0:e.getVariableDeclaration("PROGRAM_ID"))==null?void 0:g.getInitializer())==null?void 0:u.getText(),m="new PublicKey(/* edit this to return the correct program ID */)";r===m&&(r=void 0),r===void 0&&(r=m,n?r="PROGRAM_ID_CLI":a&&(r="PROGRAM_ID_IDL"));let l=e==null?void 0:e.getImportDeclarations().map(I=>I.getText());e=i.createSourceFile(d("programId.ts"),"",{overwrite:!0}),l===void 0||l.length===0?e.addImportDeclaration({namedImports:["PublicKey"],moduleSpecifier:"@solana/web3.js"}):e.addStatements(l),a&&(e.addStatements([`
`,"// Program ID defined in the provided IDL. Do not edit, it will get overwritten."]),e.addVariableStatement({declarationKind:o.VariableDeclarationKind.Const,declarations:[{name:"PROGRAM_ID_IDL",initializer:`new PublicKey("${a}")`}],isExported:!0})),n&&(e.addStatements([`
`,"// Program ID passed with the cli --program-id flag when running the code generator. Do not edit, it will get overwritten."]),e.addVariableStatement({declarationKind:o.VariableDeclarationKind.Const,declarations:[{name:"PROGRAM_ID_CLI",initializer:`new PublicKey("${n}")`}],isExported:!0})),e.addStatements([`
`,"// This constant will not get overwritten on subsequent code generations and it's safe to modify it's value."]),e.addVariableStatement({isExported:!0,declarationKind:o.VariableDeclarationKind.Const,declarations:[{name:"PROGRAM_ID",type:"PublicKey",initializer:r}]})}0&&(module.exports={genProgramId});
//# sourceMappingURL=programId.js.map