UNPKG

@cosmwasm/ts-codegen

Version:

@cosmwasm/ts-codegen converts your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.

66 lines (65 loc) 2.12 kB
import { ContractInfo, IContext, UtilMapping } from '@cosmwasm/ts-codegen-ast'; import { BuilderFile, BuilderFileType, TSBuilder } from '../builder'; /** * IBuilderPlugin is a common plugin that render generated code. */ export interface IBuilderPlugin { /** * a mapping of utils will be used in generated code. */ utils: UtilMapping; builder?: TSBuilder; setBuilder(builder: TSBuilder): void; /** * prop to indicate to execute the render function in the lifecycle of main process or after */ readonly lifecycle: 'main' | 'after'; defaultContractName?: string; /** * render generated cdoe. * @param name the name of contract * @param contractInfo contract * @param outPath the path of generated code. * @returns info of generated files. */ render(outPath: string, name?: string, contractInfo?: ContractInfo): Promise<BuilderFile[]>; } /** * BuilderPluginBase enable ts-codegen users implement their own plugins by only implement a few functions. */ export declare abstract class BuilderPluginBase<TOpt extends { enabled?: boolean; }> implements IBuilderPlugin { builder?: TSBuilder; options: TOpt; utils: UtilMapping; /** * prop to indicate to execute the render function in the lifecycle of main process or after */ lifecycle: 'main' | 'after'; defaultContractName?: string; constructor(opts?: TOpt, builder?: TSBuilder); setBuilder(builder: TSBuilder): void; render(outPath: string, name?: string, contractInfo?: ContractInfo): Promise<BuilderFile[]>; /** * init context here * @param contract * @param options */ abstract initContext(contract: ContractInfo, options?: TOpt): IContext; /** * render generated code here. * @param name * @param context */ abstract doRender(name: string, context: IContext): Promise<{ type: BuilderFileType; pluginType?: string; localname: string; body: any[]; }[]>; /** * get default options */ getDefaultOptions(opts: TOpt): any; }