From 8493f88f8db972ef2a7c1caa49f8231c60ed2ba5 Mon Sep 17 00:00:00 2001 From: dk1a Date: Thu, 25 Apr 2024 14:17:52 +0300 Subject: [PATCH] feat(cli): add user-specified PostDeploy forge options (#2703) Co-authored-by: Kevin Ingersoll --- .changeset/three-zoos-laugh.md | 5 +++++ packages/cli/src/commands/dev-contracts.ts | 1 + packages/cli/src/runDeploy.ts | 3 ++- packages/cli/src/utils/postDeploy.ts | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/three-zoos-laugh.md diff --git a/.changeset/three-zoos-laugh.md b/.changeset/three-zoos-laugh.md new file mode 100644 index 0000000000..40a38a4dd4 --- /dev/null +++ b/.changeset/three-zoos-laugh.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/cli": patch +--- + +Added a `--forgeScriptOptions` flag to deploy and dev commands to allow passing in additional CLI flags to `forge script` command. diff --git a/packages/cli/src/commands/dev-contracts.ts b/packages/cli/src/commands/dev-contracts.ts index 53c5572693..025622aaa4 100644 --- a/packages/cli/src/commands/dev-contracts.ts +++ b/packages/cli/src/commands/dev-contracts.ts @@ -16,6 +16,7 @@ const devOptions = { rpc: deployOptions.rpc, configPath: deployOptions.configPath, alwaysRunPostDeploy: deployOptions.alwaysRunPostDeploy, + forgeScriptOptions: deployOptions.forgeScriptOptions, worldAddress: deployOptions.worldAddress, }; diff --git a/packages/cli/src/runDeploy.ts b/packages/cli/src/runDeploy.ts index 07a6868307..9a47b5c42c 100644 --- a/packages/cli/src/runDeploy.ts +++ b/packages/cli/src/runDeploy.ts @@ -37,6 +37,7 @@ export const deployOptions = { type: "boolean", desc: "Always run PostDeploy.s.sol after each deploy (including during upgrades). By default, PostDeploy.s.sol is only run once after a new world is deployed.", }, + forgeScriptOptions: { type: "string", description: "Options to pass to forge script PostDeploy.s.sol" }, salt: { type: "string", desc: "The deployment salt to use. Defaults to a random salt.", @@ -113,7 +114,7 @@ in your contracts directory to use the default anvil private key.`, withWorldProxy: configV2.deploy.useProxy, }); if (opts.worldAddress == null || opts.alwaysRunPostDeploy) { - await postDeploy(config.postDeployScript, worldDeploy.address, rpc, profile); + await postDeploy(config.postDeployScript, worldDeploy.address, rpc, profile, opts.forgeScriptOptions); } console.log(chalk.green("Deployment completed in", (Date.now() - startTime) / 1000, "seconds")); diff --git a/packages/cli/src/utils/postDeploy.ts b/packages/cli/src/utils/postDeploy.ts index 72f276460b..de0c2e2390 100644 --- a/packages/cli/src/utils/postDeploy.ts +++ b/packages/cli/src/utils/postDeploy.ts @@ -10,7 +10,10 @@ export async function postDeploy( worldAddress: string, rpc: string, profile: string | undefined, + forgeOptions: string | undefined, ): Promise { + // TODO: make this more robust as it is likely to fail for any args that have a space in them + const userOptions = forgeOptions?.replaceAll("\\", "").split(" ") ?? []; const postDeployPath = path.join(await getScriptDirectory(), postDeployScript + ".s.sol"); if (!existsSync(postDeployPath)) { console.log(`No script at ${postDeployPath}, skipping post deploy hook`); @@ -37,6 +40,7 @@ export async function postDeploy( "--rpc-url", rpc, "-vvv", + ...userOptions, ], { profile: profile,