Skip to content
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

feat(cli): mud pull #3171

Merged
merged 18 commits into from
Oct 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
validate config, use config to generate paths
holic committed Sep 13, 2024
commit 30a115b44f01fc1612a6e542c6e738ec2dfa699b
29 changes: 21 additions & 8 deletions packages/cli/src/pull/pull.ts
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import { getResourceIds } from "../deploy/getResourceIds";
import { getFunctions } from "@latticexyz/world/internal";
import { abiToInterface, formatSolidity, formatTypescript } from "@latticexyz/common/codegen";
import { debug } from "./debug";
import { defineWorld } from "@latticexyz/world";

const ignoredNamespaces = new Set(["store", "world", "metadata"]);

@@ -110,7 +111,8 @@ export async function pull({ rootDir, client, worldAddress }: PullOptions) {
}),
);

const config = {
debug("generating config");
const configInput = {
namespaces: Object.fromEntries(
namespaces.map(({ namespace, resourceId: namespaceId }) => {
const namespaceLabel = labels[namespaceId] ?? namespace;
@@ -141,31 +143,42 @@ export async function pull({ rootDir, client, worldAddress }: PullOptions) {
),
};

// use the config before writing it so we make sure its valid
// and because we'll use the default paths to write interfaces
debug("validating config");
const config = defineWorld(configInput);

debug("writing config");
await writeFile(
path.join(rootDir, "mud.config.ts"),
await formatTypescript(`
import { defineWorld } from "@latticexyz/world";

export default defineWorld(${JSON.stringify(config)});
export default defineWorld(${JSON.stringify(configInput)});
`),
);

for (const system of systems.filter((system) => system.abi.length)) {
const interfaceName = `I${system.label}`;
const interfaceFile = `src/namespaces/${system.namespaceLabel}/${interfaceName}.sol`;
const interfaceFile = path.join(
config.sourceDirectory,
"namespaces",
system.namespaceLabel,
`${interfaceName}.sol`,
);

debug("writing system interface", interfaceName, "to", interfaceFile);
const source = abiToInterface({ name: interfaceName, systemId: system.systemId, abi: system.abi });

debug("generating system interface", interfaceName, "to", interfaceFile);
await writeFile(path.join(rootDir, interfaceFile), await formatSolidity(source));
}

const worldAbi = systems.flatMap((system) => system.worldAbi);
if (worldAbi.length) {
const interfaceName = "IWorldSystems";
const interfaceFile = `src/${interfaceName}.sol`;
const source = abiToInterface({ name: interfaceName, abi: worldAbi });
const interfaceFile = path.join(config.sourceDirectory, `${interfaceName}.sol`);

debug("generating world systems interface to", interfaceFile);
debug("writing world systems interface to", interfaceFile);
const source = abiToInterface({ name: interfaceName, abi: worldAbi });
await writeFile(path.join(rootDir, interfaceFile), await formatSolidity(source));
}
}