-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 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: <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: William Cory <[email protected]>
- Loading branch information
1 parent
f487e83
commit 8da3c59
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"tevm": patch | ||
--- | ||
|
||
Fixed accidentally deleted bin folder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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('<include>', 'Glob pattern to include Solidity files') | ||
.option('-c, --config <path>', '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); | ||
|