-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Fix: Accidentally deleted bin folder #1435
Merged
roninjin10
merged 1 commit into
main
from
09-16-_bug_fix_accidentally_deleted_bin_folder
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider improvements to enhance performance, error handling, and logging.
The
generate
function is responsible for generating TypeScript types from Solidity contracts. While the overall logic is sound, there are a few areas that could be improved:Performance: The function uses synchronous file operations, which may block the execution until all files are processed. Consider using asynchronous file operations to improve performance and avoid blocking the execution.
Error Handling: The function relies on various external dependencies and file operations. It would be beneficial to add proper error handling for potential issues with file access, configuration loading, or Solidity compilation. This would help identify and troubleshoot any problems that may arise during the generation process.
Logging and Progress Tracking: The function currently logs the current working directory and include pattern at the beginning. However, it would be helpful to provide more detailed logging or progress tracking throughout the generation process. This would give better visibility into the progress and status of the type generation for each file.