Skip to content

Commit

Permalink
feat(cli): add user-specified PostDeploy forge options (#2703)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <kingersoll@gmail.com>
  • Loading branch information
dk1a and holic committed Apr 25, 2024
1 parent fce741b commit 8493f88
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .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.
1 change: 1 addition & 0 deletions packages/cli/src/commands/dev-contracts.ts
Expand Up @@ -16,6 +16,7 @@ const devOptions = {
rpc: deployOptions.rpc,
configPath: deployOptions.configPath,
alwaysRunPostDeploy: deployOptions.alwaysRunPostDeploy,
forgeScriptOptions: deployOptions.forgeScriptOptions,
worldAddress: deployOptions.worldAddress,
};

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/runDeploy.ts
Expand Up @@ -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.",
Expand Down Expand Up @@ -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"));

Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/utils/postDeploy.ts
Expand Up @@ -10,7 +10,10 @@ export async function postDeploy(
worldAddress: string,
rpc: string,
profile: string | undefined,
forgeOptions: string | undefined,
): Promise<void> {
// 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`);
Expand All @@ -37,6 +40,7 @@ export async function postDeploy(
"--rpc-url",
rpc,
"-vvv",
...userOptions,
],
{
profile: profile,
Expand Down

0 comments on commit 8493f88

Please sign in to comment.