Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Empty file added lib/idl/accounts.ts
Empty file.
Empty file added lib/idl/errors.ts
Empty file.
Empty file added lib/idl/instructions.ts
Empty file.
55 changes: 55 additions & 0 deletions lib/idl/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Idl } from "@project-serum/anchor"
import * as fs from "fs"
import * as path from "path"
import { Project } from "ts-morph"
import { program } from "commander"

import { generateAccounts } from "./accounts"
import { generateErrors } from "./errors"
import { generateInstructions } from "./instructions"
import { generateProgramId } from "./programId"
import { generateTypes } from "./types"



function main() {
program
.description(
)
.argument("idl", "file path")
Comment thread
OmkarAcharekar marked this conversation as resolved.
Outdated
.argument("out", "output")
.option(
"programid",
"program ID"
)
.parse()


function outPath(filePath: string) {
Comment thread
OmkarAcharekar marked this conversation as resolved.
Outdated
return path.join(out, filePath)
}

const idlPath = program.args[0]
const out = program.args[1]
const programIdOpt: string | null = program.opts().programId || null

const pathOrStdin = idlPath === "-" ? 0 : idlPath
Comment thread
OmkarAcharekar marked this conversation as resolved.
Outdated
const idl = JSON.parse(fs.readFileSync(pathOrStdin, "utf-8")) as Idl

const project = new Project()

console.log("generating programId")
generateProgramId(project, idl, programIdOpt, outPath)
console.log("generating errors")
generateErrors(project, idl, outPath)
console.log("generating instructions")
generateInstructions(project, idl, outPath)
console.log("generating types")
generateTypes(project, idl, outPath)
console.log("generating accounts")
generateAccounts(project, idl, outPath)

console.log("writing in the files")
project.save()
}

Empty file added lib/idl/programId.ts
Empty file.
Empty file added lib/idl/types.ts
Empty file.