From 8da3c59dde629b4b9d13cff32f45b21a5578211d Mon Sep 17 00:00:00 2001 From: Will Cory Date: Mon, 16 Sep 2024 12:25:48 -0700 Subject: [PATCH] :bug: Fix: Accidentally deleted bin folder (#1435) ## Description _Concise description of proposed changes_ ## Testing Explain the quality checks that have been done on the code changes ## Additional Information - [ ] I read the [contributing docs](../docs/contributing.md) (if this is your first contribution) Your ENS/address: ## Summary by CodeRabbit - **New Features** - Restored the essential `bin` folder for proper application functionality. - Introduced a command-line interface (CLI) tool for generating TypeScript types from Solidity contracts, enhancing development efficiency. - Added a `gen` command to facilitate type generation based on user-defined patterns. - **Bug Fixes** - Addressed the issue of missing binaries by reinstating the deleted `bin` folder. Co-authored-by: William Cory --- .changeset/shiny-bulldogs-sniff.md | 5 ++ tevm/bin/tevm.js | 83 ++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 .changeset/shiny-bulldogs-sniff.md create mode 100755 tevm/bin/tevm.js diff --git a/.changeset/shiny-bulldogs-sniff.md b/.changeset/shiny-bulldogs-sniff.md new file mode 100644 index 0000000000..bb966d9a97 --- /dev/null +++ b/.changeset/shiny-bulldogs-sniff.md @@ -0,0 +1,5 @@ +--- +"tevm": patch +--- + +Fixed accidentally deleted bin folder diff --git a/tevm/bin/tevm.js b/tevm/bin/tevm.js new file mode 100755 index 0000000000..9a7273286f --- /dev/null +++ b/tevm/bin/tevm.js @@ -0,0 +1,83 @@ +#!/usr/bin/env node +import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'; +import { access, mkdir, readFile, stat, writeFile } from 'node:fs/promises'; +import path from 'node:path'; +import { Command } from 'commander'; +import { bundler } from '@tevm/base-bundler'; +import { createCache } from '@tevm/bundler-cache'; +import { loadConfig } from '@tevm/config'; +import { runSync } from 'effect/Effect'; +import { glob } from 'glob'; +// @ts-expect-error +import * as solc from 'solc'; + +/** + * @typedef {import('@tevm/base-bundler').FileAccessObject} FileAccessObject + */ + +/** @type {FileAccessObject} */ +const fao = { + existsSync: existsSync, + readFile: readFile, + readFileSync: readFileSync, + writeFileSync: writeFileSync, + statSync, + stat, + mkdirSync, + mkdir, + writeFile, + exists: async (path) => { + try { + await access(path); + return true; + } catch (e) { + return false; + } + }, +}; + +/** + * Generate types from Solidity contracts. + * + * @param {string} cwd - The current working directory. + * @param {string[]} include - The glob pattern to include Solidity files. + */ +const generate = (cwd, include) => { + console.log('Generating types from contracts...', { dir: cwd, include }); + const files = glob.sync(include, { cwd }); + if (files.length === 0) { + throw new Error('No files found'); + } + files.forEach(async (file) => { + const fileName = file.split('/').at(-1); + const fileDir = file.split('/').slice(0, -1).join('/'); + const config = runSync(loadConfig(cwd)); + const solcCache = createCache(config.cacheDir, fao, cwd); + const plugin = bundler(config, console, fao, solc, solcCache); + const tsContent = await plugin.resolveTsModule(`./${file}`, cwd, false, true); + await writeFile(path.join(fileDir, `${fileName}.ts`), tsContent.code); + }); +}; + +// Initialize Commander +const program = new Command(); + +program + .name('tevm') + .description('TEVM CLI') + .version('1.0.0'); + +program + .command('gen') + .description('Generate types from Solidity contracts. If files in in .s.sol it will also compile bytecode') + .argument('', 'Glob pattern to include Solidity files') + .option('-c, --config ', 'Path to the configuration file', process.cwd()) + .action((include, options) => { + const cwd = options.config || process.cwd(); + const includePattern = include.split(','); + generate(cwd, includePattern); + }); + +// Parse the arguments +program.parse(process.argv); +