diff --git a/packages/cli/src/contracts/LibDeploy.ejs b/packages/cli/src/contracts/LibDeploy.ejs index 5e5310fc40..3f0f2bb6d1 100644 --- a/packages/cli/src/contracts/LibDeploy.ejs +++ b/packages/cli/src/contracts/LibDeploy.ejs @@ -25,6 +25,13 @@ import { <%= component %>, ID as <%= component %>ID } from "components/<%- compo import { <%= system.name %>, ID as <%= system.name %>ID } from "systems/<%- system.name %>.sol"; <% }); -%> +<% if (libs.length > 0) { -%> +// Init Libraries (requires 'libraries=...' remapping in project's remappings.txt) +<% libs.forEach(({name}) => { -%> +import { <%= name %> } from "libraries/<%- name %>.sol"; +<% }); -%> +<% } -%> + struct DeployResult { IWorld world; address deployer; @@ -100,5 +107,9 @@ library LibDeploy { <% } -%> console.log(address(system)); <% });-%> + +<% libs.forEach(({name, func}) => { -%> + if(init) <%= name -%>.<%= func ?? 'init' -%>(world); +<% }); -%> } } diff --git a/packages/cli/src/utils/codegen.ts b/packages/cli/src/utils/codegen.ts index 1cfc2aeefc..2f110eb1a1 100644 --- a/packages/cli/src/utils/codegen.ts +++ b/packages/cli/src/utils/codegen.ts @@ -17,6 +17,9 @@ export async function generateLibDeploy(configPath: string, out: string, systems // Parse config const config = JSON.parse(await readFile(configPath, { encoding: "utf8" })); + // Init libs are optional + config.libs ??= []; + // Filter systems if (systems) { const systemsArray = Array.isArray(systems) ? systems : [systems];