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.

32 lines (31 loc) 1.4 kB
import { sync as mkdirp } from 'mkdirp'; import { basename, dirname, extname, join } from 'path'; import { contractContextBase, contractContextBaseShortHandCtor, contractsContextTSX, baseClient, } from '../helpers'; import { writeContentToFile } from '../utils/files'; import { header } from '../utils/header'; const write = (outPath, file, content, varname) => { const outFile = join(outPath, file); mkdirp(dirname(outFile)); writeContentToFile(outPath, header + content, outFile); return { type: 'plugin', pluginType: 'helper', contract: varname ?? basename(file, extname(file)), localname: file, filename: outFile, }; }; export const createHelpers = (input, builderContext) => { const files = []; // Always generate baseClient.ts since InterchainJS interfaces are needed by all clients files.push(write(input.outPath, 'baseClient.ts', baseClient)); if (input.options?.useContractsHook?.enabled && Object.keys(builderContext.providers)?.length) { const useShorthandCtor = input.options?.useShorthandCtor; files.push(write(input.outPath, 'contractContextBase.ts', useShorthandCtor ? contractContextBaseShortHandCtor : contractContextBase)); files.push(write(input.outPath, 'contracts-context.tsx', contractsContextTSX, 'contractsContext')); } return files; };