-
Notifications
You must be signed in to change notification settings - Fork 222
feat: add gen-deploy cli to generate deploy.json #295
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,56 @@ | ||
| import type { Arguments, CommandBuilder } from "yargs"; | ||
| import { spawnSync } from "node:child_process"; | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import chalk from "chalk"; | ||
|
|
||
| import {readdirSync} from 'fs'; | ||
| type Options = { | ||
| components: string; | ||
| systems: string; | ||
| outdir: string; | ||
| }; | ||
|
|
||
| export const command = "gen-deploy"; | ||
| export const desc = | ||
| "generate deploy.json from smart contracts"; | ||
|
|
||
| export const builder: CommandBuilder<Options, Options> = (yargs) => | ||
| yargs.options({ | ||
| components: { type: "string", default: "./src/components", desc: "path to components dir" }, | ||
| systems: { type: "string", default: "./src/systems", desc: "path to systems dir" }, | ||
| outdir: { type: "string", default: "./deploy.json",desc: "output path" }, | ||
| }); | ||
|
|
||
| export const handler = async (args: Arguments<Options>): Promise<void> => { | ||
| const depployJson:any= {}; | ||
| const { components, systems, outdir } = args; | ||
| console.log("procesing..."); | ||
| const comp = readdirSync(components); | ||
|
|
||
| const comps = comp.map(function(e) { | ||
| e = e.replace('.sol',''); | ||
| return e; | ||
| }); | ||
| depployJson.components = comps | ||
|
|
||
| const sys = readdirSync(systems).filter(c => c.includes(".sol")); | ||
| const syss = sys.map(function(e) { | ||
| const route = path.resolve(systems, e); | ||
| // give write access to any components that each system touch. even if it not actaully write | ||
| const out = spawnSync("forge",["flatten" ,route]); | ||
| const flatCode = out.stdout.toString() | ||
| const used = comps.filter(c => flatCode.includes(c)) | ||
| return { | ||
| "name": e.replace(".sol",""), | ||
| "writeAccess": used | ||
| }; | ||
| }); | ||
| depployJson.systems = syss | ||
|
|
||
| const deployJsonStr = JSON.stringify(depployJson, undefined, 4); | ||
| fs.writeFileSync(outdir, deployJsonStr, 'utf8'); | ||
| console.log("write output to", outdir) | ||
| console.warn(chalk.yellow.bold("Warning: this function may grant more write access than necessary. It is recommended to manually remove any unnecessary permissions.")) | ||
| process.exit(0); | ||
| }; | ||
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.
Btw this would include components that the system doesn't actually write to, not that I have a better solution in mind
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.
Regex the
setfunction?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.
That was my 1st thought actually, but set is called on the variable, which can have any name. And even if you account for that, a library may have some func which uses set, but the system doesnt use that func.
I've been trying some stuff with solidity-parser, but it's not rly gonna help here (imports make things very complicated)
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.
I can think of 2 ways.
Uh oh!
There was an error while loading. Please reload this page.
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.
Another option I could suggest: parse e.g.
@custom:ecsc TestComponent; but neitherforge inspect, norsolidity-parsercan do that. So I guess you'd needsolc's devdoc json output. Seems complicated, but still way easier than writing a function parser.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.
added warning msg :)