UNPKG

@dethcrypto/eth-sdk

Version:

🛠 Generate type-safe, lightweight SDK for your Ethereum smart contracts

32 lines • 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateSdk = void 0; const path_1 = require("path"); const generateTsClient_1 = require("./generateTsClient"); const transpileClient_1 = require("./transpileClient"); async function generateSdk(ctx) { var _a, _b; const { cliArgs: { workingDirPath }, config: { contracts, outputPath, typechainFlags }, fs, } = ctx; await fs.ensureDir(outputPath); await copyStaticFiles(ctx); const abisRoot = (0, path_1.join)(workingDirPath, 'abis'); const outputToAbiRelativePath = (0, path_1.relative)(outputPath, abisRoot).replace(/\\/g, '/'); const randomTmpDir = await fs.tmpDir('eth-sdk'); const shapedFlag = { discriminateTypes: (_a = typechainFlags === null || typechainFlags === void 0 ? void 0 : typechainFlags.discriminateTypes) !== null && _a !== void 0 ? _a : false, alwaysGenerateOverloads: (_b = typechainFlags === null || typechainFlags === void 0 ? void 0 : typechainFlags.alwaysGenerateOverloads) !== null && _b !== void 0 ? _b : false, environment: undefined, }; if ((typechainFlags === null || typechainFlags === void 0 ? void 0 : typechainFlags.tsNocheck) != null) { shapedFlag.tsNocheck = typechainFlags.tsNocheck; } await (0, generateTsClient_1.generateTsClient)(contracts, abisRoot, randomTmpDir, outputToAbiRelativePath, fs, shapedFlag); await (0, transpileClient_1.transpileClient)(randomTmpDir, outputPath, fs); } exports.generateSdk = generateSdk; async function copyStaticFiles({ fs, config }) { const staticDir = (0, path_1.join)(__dirname, '../../static'); const dir = await fs.readDir(staticDir); await Promise.all(dir.map((file) => fs.copy((0, path_1.join)(staticDir, file), (0, path_1.join)(config.outputPath, file)))); } //# sourceMappingURL=index.js.map