-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add build command (#1990)
Co-authored-by: alvarius <alvarius@lattice.xyz>
- Loading branch information
Showing
12 changed files
with
104 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"@latticexyz/cli": minor | ||
--- | ||
|
||
Added a `mud build` command that generates table libraries, system interfaces, and typed ABIs. |
This file contains 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
This file contains 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
This file contains 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,44 @@ | ||
import { existsSync, readFileSync, writeFileSync } from "node:fs"; | ||
import path from "node:path"; | ||
import { tablegen } from "@latticexyz/store/codegen"; | ||
import { worldgen } from "@latticexyz/world/node"; | ||
import { StoreConfig } from "@latticexyz/store"; | ||
import { WorldConfig } from "@latticexyz/world"; | ||
import { forge, getForgeConfig, getRemappings } from "@latticexyz/common/foundry"; | ||
import { getExistingContracts } from "./utils/getExistingContracts"; | ||
import { debug as parentDebug } from "./debug"; | ||
import { execa } from "execa"; | ||
|
||
const debug = parentDebug.extend("runDeploy"); | ||
|
||
type BuildOptions = { | ||
foundryProfile?: string; | ||
srcDir: string; | ||
config: StoreConfig & WorldConfig; | ||
}; | ||
|
||
export async function build({ | ||
config, | ||
srcDir, | ||
foundryProfile = process.env.FOUNDRY_PROFILE, | ||
}: BuildOptions): Promise<void> { | ||
const outPath = path.join(srcDir, config.codegenDirectory); | ||
const remappings = await getRemappings(foundryProfile); | ||
await Promise.all([tablegen(config, outPath, remappings), worldgen(config, getExistingContracts(srcDir), outPath)]); | ||
|
||
// TODO remove when https://github.com/foundry-rs/foundry/issues/6241 is resolved | ||
const forgeConfig = await getForgeConfig(foundryProfile); | ||
if (forgeConfig.cache) { | ||
const cacheFilePath = path.join(forgeConfig.cache_path, "solidity-files-cache.json"); | ||
if (existsSync(cacheFilePath)) { | ||
debug("Unsetting cached content hash of IWorld.sol to force it to regenerate"); | ||
const solidityFilesCache = JSON.parse(readFileSync(cacheFilePath, "utf8")); | ||
const worldInterfacePath = path.join(outPath, "world", "IWorld.sol"); | ||
solidityFilesCache["files"][worldInterfacePath]["contentHash"] = ""; | ||
writeFileSync(cacheFilePath, JSON.stringify(solidityFilesCache, null, 2)); | ||
} | ||
} | ||
|
||
await forge(["build"], { profile: foundryProfile }); | ||
await execa("mud", ["abi-ts"], { stdio: "inherit" }); | ||
} |
This file contains 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,36 @@ | ||
import type { CommandModule } from "yargs"; | ||
import { loadConfig } from "@latticexyz/config/node"; | ||
import { StoreConfig } from "@latticexyz/store"; | ||
import { WorldConfig } from "@latticexyz/world"; | ||
|
||
import { getSrcDirectory } from "@latticexyz/common/foundry"; | ||
import { build } from "../build"; | ||
|
||
type Options = { | ||
configPath?: string; | ||
profile?: string; | ||
}; | ||
|
||
const commandModule: CommandModule<Options, Options> = { | ||
command: "build", | ||
|
||
describe: "Build contracts and generate MUD artifacts (table libraries, world interface, ABI)", | ||
|
||
builder(yargs) { | ||
return yargs.options({ | ||
configPath: { type: "string", desc: "Path to the config file" }, | ||
profile: { type: "string", desc: "The foundry profile to use" }, | ||
}); | ||
}, | ||
|
||
async handler({ configPath, profile }) { | ||
const config = (await loadConfig(configPath)) as StoreConfig & WorldConfig; | ||
const srcDir = await getSrcDirectory(); | ||
|
||
await build({ config, srcDir, foundryProfile: profile }); | ||
|
||
process.exit(0); | ||
}, | ||
}; | ||
|
||
export default commandModule; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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