@latticexyz/cli 2.0.0-alpha.94 → 2.0.0-indexing-1d07fea9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-LFIOIY67.js +30 -0
- package/dist/chunk-LFIOIY67.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/mud.js +15 -8340
- package/dist/mud.js.map +1 -0
- package/package.json +46 -44
- package/src/commands/deploy.ts +49 -0
- package/src/commands/dev-contracts.ts +176 -0
- package/src/commands/devnode.ts +7 -2
- package/src/commands/faucet.ts +1 -1
- package/src/commands/index.ts +18 -13
- package/src/commands/set-version.ts +99 -36
- package/src/commands/tablegen.ts +5 -4
- package/src/commands/{test-v2.ts → test.ts} +5 -6
- package/src/commands/trace.ts +108 -0
- package/src/commands/tsgen.ts +4 -3
- package/src/commands/worldgen.ts +29 -28
- package/src/index.ts +2 -1
- package/src/modules.d.ts +11 -0
- package/src/mud.ts +10 -4
- package/src/render-ts/recsV1TableOptions.ts +4 -4
- package/src/render-ts/renderRecsV1Tables.ts +3 -3
- package/src/render-ts/schemaTypesToRecsTypeStrings.ts +33 -33
- package/src/render-ts/tsgen.ts +4 -4
- package/src/utils/{deploy-v2.ts → deploy.ts} +207 -123
- package/src/utils/deployHandler.ts +87 -0
- package/src/utils/errors.ts +1 -1
- package/src/utils/getExistingContracts.ts +12 -0
- package/src/utils/index.ts +7 -5
- package/src/utils/printMUD.ts +14 -0
- package/src/utils/worldtypes.ts +21 -0
- package/dist/chunk-6V563IAZ.js +0 -283
- package/dist/chunk-FPG73MVN.js +0 -71
- package/dist/chunk-L4YLJHLJ.js +0 -30
- package/dist/chunk-SKNB74MT.js +0 -726
- package/dist/chunk-T2YHSEJD.js +0 -3842
- package/dist/chunk-VQTZJIFF.js +0 -353
- package/dist/chunk-WZFXLDPK.js +0 -761
- package/dist/chunk-YL4GJLLL.js +0 -26139
- package/dist/index.d.ts +0 -2
- package/dist/mud.d.ts +0 -1
- package/dist/mud2.d.ts +0 -1
- package/dist/mud2.js +0 -25
- package/dist/render-solidity/index.d.ts +0 -171
- package/dist/render-solidity/index.js +0 -49
- package/dist/render-ts/index.d.ts +0 -26
- package/dist/render-ts/index.js +0 -14
- package/dist/utils/deprecated/index.d.ts +0 -76
- package/dist/utils/deprecated/index.js +0 -36
- package/dist/utils/index.d.ts +0 -88
- package/dist/utils/index.js +0 -39
- package/src/commands/deploy-v2.ts +0 -112
- package/src/commands/deprecated/bulkupload.ts +0 -50
- package/src/commands/deprecated/call-system.ts +0 -70
- package/src/commands/deprecated/codegen-libdeploy.ts +0 -29
- package/src/commands/deprecated/deploy-contracts.ts +0 -120
- package/src/commands/deprecated/index.ts +0 -22
- package/src/commands/deprecated/system-types.ts +0 -29
- package/src/commands/deprecated/test.ts +0 -53
- package/src/commands/deprecated/trace.ts +0 -81
- package/src/commands/deprecated/types.ts +0 -33
- package/src/commands/gas-report.ts +0 -219
- package/src/contracts/BulkUpload.sol +0 -174
- package/src/contracts/Deploy.sol +0 -23
- package/src/contracts/LibDeploy.ejs +0 -121
- package/src/contracts/LibDeploy.sol +0 -23
- package/src/contracts/LibDeployStub.sol +0 -23
- package/src/mud2.ts +0 -29
- package/src/render-solidity/common.ts +0 -138
- package/src/render-solidity/field.ts +0 -160
- package/src/render-solidity/index.ts +0 -10
- package/src/render-solidity/record.ts +0 -158
- package/src/render-solidity/renderSystemInterface.ts +0 -31
- package/src/render-solidity/renderTable.ts +0 -164
- package/src/render-solidity/renderTableIndex.ts +0 -15
- package/src/render-solidity/renderTypeHelpers.ts +0 -99
- package/src/render-solidity/renderTypes.ts +0 -19
- package/src/render-solidity/renderTypesFromConfig.ts +0 -13
- package/src/render-solidity/renderWorld.ts +0 -24
- package/src/render-solidity/tableOptions.ts +0 -107
- package/src/render-solidity/tablegen.ts +0 -35
- package/src/render-solidity/types.ts +0 -111
- package/src/render-solidity/userType.ts +0 -131
- package/src/render-solidity/worldgen.ts +0 -59
- package/src/utils/contractToInterface.ts +0 -132
- package/src/utils/deprecated/build.ts +0 -55
- package/src/utils/deprecated/codegen.ts +0 -42
- package/src/utils/deprecated/constants.ts +0 -2
- package/src/utils/deprecated/deploy.ts +0 -111
- package/src/utils/deprecated/exec.ts +0 -18
- package/src/utils/deprecated/findLog.ts +0 -8
- package/src/utils/deprecated/hsr.ts +0 -71
- package/src/utils/deprecated/ids.ts +0 -14
- package/src/utils/deprecated/index.ts +0 -8
- package/src/utils/deprecated/typegen.ts +0 -133
- package/src/utils/execLog.ts +0 -22
- package/src/utils/format.ts +0 -39
- package/src/utils/formatAndWrite.ts +0 -21
- package/src/utils/foundry.ts +0 -103
|
@@ -2,15 +2,19 @@ import chalk from "chalk";
|
|
|
2
2
|
import { existsSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import type { CommandModule } from "yargs";
|
|
5
|
-
import { MUDError } from "@latticexyz/
|
|
6
|
-
import { logError } from "../utils/errors
|
|
5
|
+
import { MUDError } from "@latticexyz/common/errors";
|
|
6
|
+
import { logError } from "../utils/errors";
|
|
7
7
|
import localPackageJson from "../../package.json" assert { type: "json" };
|
|
8
|
+
import glob from "glob";
|
|
8
9
|
|
|
9
10
|
type Options = {
|
|
10
11
|
backup?: boolean;
|
|
11
12
|
force?: boolean;
|
|
12
13
|
restore?: boolean;
|
|
13
14
|
mudVersion?: string;
|
|
15
|
+
tag?: string;
|
|
16
|
+
commit?: string;
|
|
17
|
+
link?: string;
|
|
14
18
|
};
|
|
15
19
|
|
|
16
20
|
const BACKUP_FILE = ".mudbackup";
|
|
@@ -19,7 +23,7 @@ const MUD_PREFIX = "@latticexyz";
|
|
|
19
23
|
const commandModule: CommandModule<Options, Options> = {
|
|
20
24
|
command: "set-version",
|
|
21
25
|
|
|
22
|
-
describe: "
|
|
26
|
+
describe: "Set MUD version in all package.json files and optionally backup the previously installed version",
|
|
23
27
|
|
|
24
28
|
builder(yargs) {
|
|
25
29
|
return yargs.options({
|
|
@@ -29,30 +33,44 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
29
33
|
description: `Backup fails if a "${BACKUP_FILE}" file is found, unless --force is provided`,
|
|
30
34
|
},
|
|
31
35
|
restore: { type: "boolean", description: `Restore the previous MUD versions from "${BACKUP_FILE}"` },
|
|
32
|
-
mudVersion: { alias: "v", type: "string", description: "
|
|
36
|
+
mudVersion: { alias: "v", type: "string", description: "Set MUD to the given version" },
|
|
37
|
+
tag: {
|
|
38
|
+
alias: "t",
|
|
39
|
+
type: "string",
|
|
40
|
+
description: "Set MUD to the latest version with the given tag from npm",
|
|
41
|
+
},
|
|
42
|
+
commit: {
|
|
43
|
+
alias: "c",
|
|
44
|
+
type: "string",
|
|
45
|
+
description: "Set MUD to the version based on a given git commit hash from npm",
|
|
46
|
+
},
|
|
47
|
+
link: { alias: "l", type: "string", description: "Relative path to the local MUD root directory to link" },
|
|
33
48
|
});
|
|
34
49
|
},
|
|
35
50
|
|
|
36
51
|
async handler(options) {
|
|
37
52
|
try {
|
|
38
|
-
|
|
39
|
-
|
|
53
|
+
const mutuallyExclusiveOptions = ["mudVersion", "link", "tag", "commit", "restore"];
|
|
54
|
+
const numMutuallyExclusiveOptions = mutuallyExclusiveOptions.reduce(
|
|
55
|
+
(acc, opt) => (options[opt] ? acc + 1 : acc),
|
|
56
|
+
0
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
if (numMutuallyExclusiveOptions === 0) {
|
|
60
|
+
throw new MUDError(`You need to provide one these options: ${mutuallyExclusiveOptions.join(", ")}`);
|
|
40
61
|
}
|
|
41
62
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
63
|
+
if (numMutuallyExclusiveOptions > 1) {
|
|
64
|
+
throw new MUDError(`These options are mutually exclusive: ${mutuallyExclusiveOptions.join(", ")}`);
|
|
65
|
+
}
|
|
45
66
|
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
const { workspaces } = updatePackageJson(rootPath, options);
|
|
67
|
+
// Resolve the version number from available options like `tag` or `commit`
|
|
68
|
+
options.mudVersion = await resolveVersion(options);
|
|
49
69
|
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
updatePackageJson(filePath, options);
|
|
55
|
-
}
|
|
70
|
+
// Update all package.json below the current working directory (except in node_modules)
|
|
71
|
+
const packageJsons = glob.sync("**/package.json").filter((p) => !p.includes("node_modules"));
|
|
72
|
+
for (const packageJson of packageJsons) {
|
|
73
|
+
updatePackageJson(packageJson, options);
|
|
56
74
|
}
|
|
57
75
|
} catch (e) {
|
|
58
76
|
logError(e);
|
|
@@ -62,12 +80,54 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
62
80
|
},
|
|
63
81
|
};
|
|
64
82
|
|
|
83
|
+
async function resolveVersion(options: Options) {
|
|
84
|
+
// Backwards compatibility to previous behavior of this script where passing "canary" as the version resolved to the latest commit on main
|
|
85
|
+
if (options.mudVersion === "canary") options.tag = "main";
|
|
86
|
+
|
|
87
|
+
let npmResult;
|
|
88
|
+
try {
|
|
89
|
+
console.log(chalk.blue(`Fetching available versions`));
|
|
90
|
+
npmResult = await (await fetch(`https://registry.npmjs.org/${localPackageJson.name}`)).json();
|
|
91
|
+
} catch (e) {
|
|
92
|
+
throw new MUDError(`Could not fetch available MUD versions`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (options.tag) {
|
|
96
|
+
const version = npmResult["dist-tags"][options.tag];
|
|
97
|
+
if (!version) {
|
|
98
|
+
throw new MUDError(`Could not find npm version with tag "${options.tag}"`);
|
|
99
|
+
}
|
|
100
|
+
console.log(chalk.green(`Latest version with tag ${options.tag}: ${version}`));
|
|
101
|
+
return version;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (options.commit) {
|
|
105
|
+
// Find a version with this commit hash
|
|
106
|
+
const commit = options.commit.substring(0, 8); // changesets uses the first 8 characters of the commit hash as version for prereleases/snapshot releases
|
|
107
|
+
const version = Object.keys(npmResult["versions"]).find((v) => (v as string).includes(commit));
|
|
108
|
+
if (!version) {
|
|
109
|
+
throw new MUDError(`Could not find npm version based on commit "${options.commit}"`);
|
|
110
|
+
}
|
|
111
|
+
console.log(chalk.green(`Version from commit ${options.commit}: ${version}`));
|
|
112
|
+
return version;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// If neither a tag nor a commit option is given, return the `mudVersion`
|
|
116
|
+
return options.mudVersion;
|
|
117
|
+
}
|
|
118
|
+
|
|
65
119
|
function updatePackageJson(filePath: string, options: Options): { workspaces?: string[] } {
|
|
66
|
-
const {
|
|
120
|
+
const { restore, force, link } = options;
|
|
121
|
+
let { backup, mudVersion } = options;
|
|
122
|
+
|
|
67
123
|
const backupFilePath = path.join(path.dirname(filePath), BACKUP_FILE);
|
|
124
|
+
const backupFileExists = existsSync(backupFilePath);
|
|
125
|
+
|
|
126
|
+
// Create a backup file for previous MUD versions by default if linking to local MUD
|
|
127
|
+
if (link && !backupFileExists) backup = true;
|
|
68
128
|
|
|
69
129
|
// If `backup` is true and force not set, check if a backup file already exists and throw an error if it does
|
|
70
|
-
if (backup && !force &&
|
|
130
|
+
if (backup && !force && backupFileExists) {
|
|
71
131
|
throw new MUDError(
|
|
72
132
|
`A backup file already exists at ${backupFilePath}.\nUse --force to overwrite it or --restore to restore it.`
|
|
73
133
|
);
|
|
@@ -106,16 +166,14 @@ function updatePackageJson(filePath: string, options: Options): { workspaces?: s
|
|
|
106
166
|
// Update the dependencies
|
|
107
167
|
for (const key in packageJson.dependencies) {
|
|
108
168
|
if (key.startsWith(MUD_PREFIX)) {
|
|
109
|
-
packageJson.dependencies[key] =
|
|
110
|
-
restore && backupJson ? backupJson.dependencies[key] : mudVersion || packageJson.dependencies[key];
|
|
169
|
+
packageJson.dependencies[key] = resolveMudVersion(key, "dependencies");
|
|
111
170
|
}
|
|
112
171
|
}
|
|
113
172
|
|
|
114
173
|
// Update the devDependencies
|
|
115
174
|
for (const key in packageJson.devDependencies) {
|
|
116
175
|
if (key.startsWith(MUD_PREFIX)) {
|
|
117
|
-
packageJson.devDependencies[key] =
|
|
118
|
-
restore && backupJson ? backupJson.devDependencies[key] : mudVersion || packageJson.devDependencies[key];
|
|
176
|
+
packageJson.devDependencies[key] = resolveMudVersion(key, "devDependencies");
|
|
119
177
|
}
|
|
120
178
|
}
|
|
121
179
|
|
|
@@ -134,6 +192,13 @@ function updatePackageJson(filePath: string, options: Options): { workspaces?: s
|
|
|
134
192
|
}
|
|
135
193
|
|
|
136
194
|
return packageJson;
|
|
195
|
+
|
|
196
|
+
function resolveMudVersion(key: string, type: "dependencies" | "devDependencies") {
|
|
197
|
+
if (restore && backupJson) return backupJson[type][key];
|
|
198
|
+
if (link) mudVersion = resolveLinkPath(filePath, link, key);
|
|
199
|
+
if (!mudVersion) return packageJson[type][key];
|
|
200
|
+
return mudVersion;
|
|
201
|
+
}
|
|
137
202
|
}
|
|
138
203
|
|
|
139
204
|
function readPackageJson(path: string): {
|
|
@@ -149,18 +214,6 @@ function readPackageJson(path: string): {
|
|
|
149
214
|
}
|
|
150
215
|
}
|
|
151
216
|
|
|
152
|
-
async function getCanaryVersion(pkg: string) {
|
|
153
|
-
try {
|
|
154
|
-
console.log(chalk.blue("fetching MUD canary version..."));
|
|
155
|
-
const result = await (await fetch(`https://registry.npmjs.org/${pkg}`)).json();
|
|
156
|
-
const canary = result["dist-tags"].canary;
|
|
157
|
-
console.log(chalk.green("MUD canary version:", canary));
|
|
158
|
-
return canary;
|
|
159
|
-
} catch (e) {
|
|
160
|
-
throw new MUDError(`Could not fetch canary version of ${pkg}`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
217
|
function logComparison(prev: Record<string, string>, curr: Record<string, string>) {
|
|
165
218
|
for (const key in prev) {
|
|
166
219
|
if (prev[key] !== curr[key]) {
|
|
@@ -169,4 +222,14 @@ function logComparison(prev: Record<string, string>, curr: Record<string, string
|
|
|
169
222
|
}
|
|
170
223
|
}
|
|
171
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Returns path of the package to link, given a path to a local MUD clone and a package
|
|
227
|
+
*/
|
|
228
|
+
function resolveLinkPath(packageJsonPath: string, mudLinkPath: string, pkg: string) {
|
|
229
|
+
const pkgName = pkg.replace(MUD_PREFIX, "");
|
|
230
|
+
const packageJsonToRootPath = path.relative(path.dirname(packageJsonPath), process.cwd());
|
|
231
|
+
const linkPath = path.join(packageJsonToRootPath, mudLinkPath, "packages", pkgName);
|
|
232
|
+
return "link:" + linkPath;
|
|
233
|
+
}
|
|
234
|
+
|
|
172
235
|
export default commandModule;
|
package/src/commands/tablegen.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import type { CommandModule } from "yargs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { loadConfig } from "@latticexyz/config/node";
|
|
4
|
+
import { StoreConfig } from "@latticexyz/store";
|
|
5
|
+
import { tablegen } from "@latticexyz/store/codegen";
|
|
6
|
+
import { getSrcDirectory } from "@latticexyz/common/foundry";
|
|
6
7
|
|
|
7
8
|
type Options = {
|
|
8
9
|
configPath?: string;
|
|
@@ -20,7 +21,7 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
20
21
|
},
|
|
21
22
|
|
|
22
23
|
async handler({ configPath }) {
|
|
23
|
-
const config = await
|
|
24
|
+
const config = (await loadConfig(configPath)) as StoreConfig;
|
|
24
25
|
const srcDir = await getSrcDirectory();
|
|
25
26
|
|
|
26
27
|
await tablegen(config, path.join(srcDir, config.codegenDirectory));
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import type { CommandModule } from "yargs";
|
|
2
|
-
import {
|
|
3
|
-
import { yDeployOptions } from "./deploy-v2.js";
|
|
4
|
-
import { anvil, forge, getRpcUrl, getTestDirectory } from "../utils/foundry.js";
|
|
2
|
+
import { anvil, forge, getRpcUrl } from "@latticexyz/common/foundry";
|
|
5
3
|
import chalk from "chalk";
|
|
6
4
|
import { rmSync, writeFileSync } from "fs";
|
|
7
|
-
import
|
|
5
|
+
import { yDeployOptions } from "./deploy";
|
|
6
|
+
import { deployHandler, DeployOptions } from "../utils";
|
|
8
7
|
|
|
9
8
|
type Options = DeployOptions & { port?: number; worldAddress?: string; forgeOptions?: string };
|
|
10
9
|
|
|
11
10
|
const WORLD_ADDRESS_FILE = ".mudtest";
|
|
12
11
|
|
|
13
12
|
const commandModule: CommandModule<Options, Options> = {
|
|
14
|
-
command: "test
|
|
13
|
+
command: "test",
|
|
15
14
|
|
|
16
|
-
describe: "Run tests in MUD
|
|
15
|
+
describe: "Run tests in MUD contracts",
|
|
17
16
|
|
|
18
17
|
builder(yargs) {
|
|
19
18
|
return yargs.options({
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "fs";
|
|
2
|
+
import type { CommandModule } from "yargs";
|
|
3
|
+
import { ethers } from "ethers";
|
|
4
|
+
|
|
5
|
+
import { loadConfig } from "@latticexyz/config/node";
|
|
6
|
+
import { MUDError } from "@latticexyz/common/errors";
|
|
7
|
+
import { cast, getRpcUrl, getSrcDirectory } from "@latticexyz/common/foundry";
|
|
8
|
+
import { TableId } from "@latticexyz/common";
|
|
9
|
+
import { StoreConfig } from "@latticexyz/store";
|
|
10
|
+
import { resolveWorldConfig, WorldConfig } from "@latticexyz/world";
|
|
11
|
+
import { IBaseWorld } from "@latticexyz/world/types/ethers-contracts/IBaseWorld";
|
|
12
|
+
import IBaseWorldData from "@latticexyz/world/abi/IBaseWorld.sol/IBaseWorld.json" assert { type: "json" };
|
|
13
|
+
import { getChainId, getExistingContracts } from "../utils";
|
|
14
|
+
|
|
15
|
+
const systemsTableId = new TableId("", "Systems");
|
|
16
|
+
|
|
17
|
+
type Options = {
|
|
18
|
+
tx: string;
|
|
19
|
+
worldAddress?: string;
|
|
20
|
+
configPath?: string;
|
|
21
|
+
profile?: string;
|
|
22
|
+
srcDir?: string;
|
|
23
|
+
rpc?: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const commandModule: CommandModule<Options, Options> = {
|
|
27
|
+
command: "trace",
|
|
28
|
+
|
|
29
|
+
describe: "Display the trace of a transaction",
|
|
30
|
+
|
|
31
|
+
builder(yargs) {
|
|
32
|
+
return yargs.options({
|
|
33
|
+
tx: { type: "string", required: true, description: "Transaction hash to replay" },
|
|
34
|
+
worldAddress: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "World contract address. Defaults to the value from worlds.json, based on rpc's chainId",
|
|
37
|
+
},
|
|
38
|
+
configPath: { type: "string", description: "Path to the config file" },
|
|
39
|
+
profile: { type: "string", description: "The foundry profile to use" },
|
|
40
|
+
srcDir: { type: "string", description: "Source directory. Defaults to foundry src directory." },
|
|
41
|
+
rpc: { type: "string", description: "json rpc endpoint. Defaults to foundry's configured eth_rpc_url" },
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
async handler(args) {
|
|
46
|
+
args.profile ??= process.env.FOUNDRY_PROFILE;
|
|
47
|
+
const { profile } = args;
|
|
48
|
+
args.srcDir ??= await getSrcDirectory(profile);
|
|
49
|
+
args.rpc ??= await getRpcUrl(profile);
|
|
50
|
+
const { tx, configPath, srcDir, rpc } = args;
|
|
51
|
+
|
|
52
|
+
const existingContracts = getExistingContracts(srcDir);
|
|
53
|
+
|
|
54
|
+
// Load the config
|
|
55
|
+
const mudConfig = (await loadConfig(configPath)) as StoreConfig & WorldConfig;
|
|
56
|
+
|
|
57
|
+
const resolvedConfig = resolveWorldConfig(
|
|
58
|
+
mudConfig,
|
|
59
|
+
existingContracts.map(({ basename }) => basename)
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// Get worldAddress either from args or from worldsFile
|
|
63
|
+
const worldAddress = args.worldAddress ?? (await getWorldAddress(mudConfig.worldsFile, rpc));
|
|
64
|
+
|
|
65
|
+
// Create World contract instance from deployed address
|
|
66
|
+
const provider = new ethers.providers.StaticJsonRpcProvider(rpc);
|
|
67
|
+
const WorldContract = new ethers.Contract(worldAddress, IBaseWorldData.abi, provider) as IBaseWorld;
|
|
68
|
+
|
|
69
|
+
// TODO account for multiple namespaces (https://github.com/latticexyz/mud/issues/994)
|
|
70
|
+
const namespace = mudConfig.namespace;
|
|
71
|
+
const names = Object.values(resolvedConfig.systems).map(({ name }) => name);
|
|
72
|
+
|
|
73
|
+
const labels: { name: string; address: string }[] = [];
|
|
74
|
+
for (const name of names) {
|
|
75
|
+
const systemSelector = new TableId(namespace, name);
|
|
76
|
+
// Get the first field of `Systems` table (the table maps system name to its address and other data)
|
|
77
|
+
const address = await WorldContract.getField(systemsTableId.toHex(), [systemSelector.toHex()], 0);
|
|
78
|
+
labels.push({ name, address });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const result = await cast([
|
|
82
|
+
"run",
|
|
83
|
+
"--label",
|
|
84
|
+
`${worldAddress}:World`,
|
|
85
|
+
...labels.map(({ name, address }) => ["--label", `${address}:${name}`]).flat(),
|
|
86
|
+
`${tx}`,
|
|
87
|
+
]);
|
|
88
|
+
console.log(result);
|
|
89
|
+
|
|
90
|
+
process.exit(0);
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export default commandModule;
|
|
95
|
+
|
|
96
|
+
async function getWorldAddress(worldsFile: string, rpc: string) {
|
|
97
|
+
if (existsSync(worldsFile)) {
|
|
98
|
+
const chainId = await getChainId(rpc);
|
|
99
|
+
const deploys = JSON.parse(readFileSync(worldsFile, "utf-8"));
|
|
100
|
+
|
|
101
|
+
if (!deploys[chainId]) {
|
|
102
|
+
throw new MUDError(`chainId ${chainId} is missing in worldsFile "${worldsFile}"`);
|
|
103
|
+
}
|
|
104
|
+
return deploys[chainId].address as string;
|
|
105
|
+
} else {
|
|
106
|
+
throw new MUDError("worldAddress is not specified and worldsFile is missing");
|
|
107
|
+
}
|
|
108
|
+
}
|
package/src/commands/tsgen.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CommandModule } from "yargs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { loadConfig } from "@latticexyz/config/node";
|
|
3
|
+
import { StoreConfig } from "@latticexyz/store";
|
|
4
|
+
import { tsgen } from "../render-ts/tsgen";
|
|
4
5
|
|
|
5
6
|
type Options = {
|
|
6
7
|
configPath: string;
|
|
@@ -22,7 +23,7 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
22
23
|
async handler(args) {
|
|
23
24
|
const { configPath, out } = args;
|
|
24
25
|
|
|
25
|
-
const config = await
|
|
26
|
+
const config = (await loadConfig(configPath)) as StoreConfig;
|
|
26
27
|
|
|
27
28
|
await tsgen(config, out);
|
|
28
29
|
|
package/src/commands/worldgen.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import type { CommandModule } from "yargs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
2
|
+
import { loadConfig } from "@latticexyz/config/node";
|
|
3
|
+
import { StoreConfig } from "@latticexyz/store";
|
|
4
|
+
import { WorldConfig } from "@latticexyz/world";
|
|
5
|
+
import { worldgen } from "@latticexyz/world/node";
|
|
6
|
+
import { getSrcDirectory } from "@latticexyz/common/foundry";
|
|
7
|
+
import path from "path";
|
|
7
8
|
import { rmSync } from "fs";
|
|
9
|
+
import { getExistingContracts } from "../utils";
|
|
8
10
|
|
|
9
11
|
type Options = {
|
|
10
12
|
configPath?: string;
|
|
11
13
|
clean?: boolean;
|
|
14
|
+
srcDir?: string;
|
|
15
|
+
config?: StoreConfig & WorldConfig;
|
|
12
16
|
};
|
|
13
17
|
|
|
14
18
|
const commandModule: CommandModule<Options, Options> = {
|
|
@@ -19,38 +23,35 @@ const commandModule: CommandModule<Options, Options> = {
|
|
|
19
23
|
builder(yargs) {
|
|
20
24
|
return yargs.options({
|
|
21
25
|
configPath: { type: "string", desc: "Path to the config file" },
|
|
22
|
-
clean: {
|
|
26
|
+
clean: {
|
|
27
|
+
type: "boolean",
|
|
28
|
+
desc: "Clear the worldgen directory before generating new interfaces (defaults to true)",
|
|
29
|
+
default: true,
|
|
30
|
+
},
|
|
23
31
|
});
|
|
24
32
|
},
|
|
25
33
|
|
|
26
34
|
async handler(args) {
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
await worldgenHandler(args);
|
|
36
|
+
process.exit(0);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
29
39
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
path,
|
|
33
|
-
basename: basename(path, ".sol"),
|
|
34
|
-
}));
|
|
40
|
+
export async function worldgenHandler(args: Options) {
|
|
41
|
+
const srcDir = args.srcDir ?? (await getSrcDirectory());
|
|
35
42
|
|
|
36
|
-
|
|
37
|
-
const worldConfig = await loadWorldConfig(
|
|
38
|
-
configPath,
|
|
39
|
-
existingContracts.map(({ basename }) => basename)
|
|
40
|
-
);
|
|
41
|
-
const storeConfig = await loadStoreConfig(configPath);
|
|
42
|
-
const mudConfig = { ...worldConfig, ...storeConfig };
|
|
43
|
+
const existingContracts = getExistingContracts(srcDir);
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
// Load the config
|
|
46
|
+
const mudConfig = args.config ?? ((await loadConfig(args.configPath)) as StoreConfig & WorldConfig);
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
if (clean) rmSync(path.join(outputBaseDirectory, mudConfig.worldgenDirectory), { recursive: true, force: true });
|
|
48
|
+
const outputBaseDirectory = path.join(srcDir, mudConfig.codegenDirectory);
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
// clear the worldgen directory
|
|
51
|
+
if (args.clean) rmSync(path.join(outputBaseDirectory, mudConfig.worldgenDirectory), { recursive: true, force: true });
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
53
|
+
// generate new interfaces
|
|
54
|
+
await worldgen(mudConfig, existingContracts, outputBaseDirectory);
|
|
55
|
+
}
|
|
55
56
|
|
|
56
57
|
export default commandModule;
|
package/src/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./render-ts";
|
|
2
|
+
export * from "./utils/deployHandler";
|
package/src/modules.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// adding .js to minimal would break clients down the line because it probably won't get a synthetic default import
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
declare module "protobufjs/minimal" {
|
|
4
|
+
export const configure: any;
|
|
5
|
+
export const util: any;
|
|
6
|
+
export const Reader: any;
|
|
7
|
+
export type Reader = any;
|
|
8
|
+
export const Writer: any;
|
|
9
|
+
export type Writer = any;
|
|
10
|
+
}
|
|
11
|
+
declare module "rollup-plugin-preserve-shebang";
|
package/src/mud.ts
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import yargs from "yargs";
|
|
4
4
|
import { hideBin } from "yargs/helpers";
|
|
5
|
-
import { commands
|
|
6
|
-
import {
|
|
7
|
-
import { logError } from "./utils/errors.js";
|
|
5
|
+
import { commands } from "./commands";
|
|
6
|
+
import { logError } from "./utils/errors";
|
|
8
7
|
|
|
9
8
|
// Load .env file into process.env
|
|
10
9
|
import * as dotenv from "dotenv";
|
|
10
|
+
import chalk from "chalk";
|
|
11
11
|
dotenv.config();
|
|
12
12
|
|
|
13
13
|
yargs(hideBin(process.argv))
|
|
@@ -15,11 +15,17 @@ yargs(hideBin(process.argv))
|
|
|
15
15
|
.scriptName("mud")
|
|
16
16
|
// Use the commands directory to scaffold
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- command array overload isn't typed, see https://github.com/yargs/yargs/blob/main/docs/advanced.md#esm-hierarchy
|
|
18
|
-
.command(
|
|
18
|
+
.command(commands as any)
|
|
19
19
|
// Enable strict mode.
|
|
20
20
|
.strict()
|
|
21
21
|
// Custom error handler
|
|
22
22
|
.fail((msg, err) => {
|
|
23
|
+
console.error(chalk.red(msg));
|
|
24
|
+
if (msg.includes("Missing required argument")) {
|
|
25
|
+
console.log(
|
|
26
|
+
chalk.yellow(`Run 'pnpm mud ${process.argv[2]} --help' for a list of available and required arguments.`)
|
|
27
|
+
);
|
|
28
|
+
}
|
|
23
29
|
console.log("");
|
|
24
30
|
logError(err);
|
|
25
31
|
console.log("");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { StoreConfig } from "@latticexyz/
|
|
2
|
-
import { resolveAbiOrUserType } from "
|
|
3
|
-
import { schemaTypesToRecsTypeStrings } from "./schemaTypesToRecsTypeStrings
|
|
4
|
-
import { RecsV1TableOptions } from "./types
|
|
1
|
+
import { StoreConfig } from "@latticexyz/store";
|
|
2
|
+
import { resolveAbiOrUserType } from "@latticexyz/store/codegen";
|
|
3
|
+
import { schemaTypesToRecsTypeStrings } from "./schemaTypesToRecsTypeStrings";
|
|
4
|
+
import { RecsV1TableOptions } from "./types";
|
|
5
5
|
|
|
6
6
|
export function getRecsV1TableOptions(config: StoreConfig): RecsV1TableOptions {
|
|
7
7
|
const tableOptions = [];
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { RecsV1TableOptions } from "./types
|
|
1
|
+
import { RecsV1TableOptions } from "./types";
|
|
2
2
|
|
|
3
3
|
export function renderRecsV1Tables(options: RecsV1TableOptions) {
|
|
4
4
|
const { tables } = options;
|
|
5
5
|
|
|
6
6
|
return `/* Autogenerated file. Do not edit manually. */
|
|
7
7
|
|
|
8
|
-
import { TableId } from "@latticexyz/
|
|
8
|
+
import { TableId } from "@latticexyz/common";
|
|
9
9
|
import { defineComponent, Type as RecsType, World } from "@latticexyz/recs";
|
|
10
10
|
|
|
11
11
|
export function defineContractComponents(world: World) {
|
|
@@ -24,7 +24,7 @@ function renderDefineComponent(table: RecsV1TableOptions["tables"][number]) {
|
|
|
24
24
|
return defineComponent(world, {
|
|
25
25
|
${table.fields.map(({ name, recsTypeString }) => `${name}: ${recsTypeString},`).join("")}
|
|
26
26
|
}, {
|
|
27
|
-
metadata: { contractId: tableId.
|
|
27
|
+
metadata: { contractId: tableId.toHex(), tableId: tableId.toString() },
|
|
28
28
|
});
|
|
29
29
|
})()
|
|
30
30
|
`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SchemaType } from "@latticexyz/schema-type";
|
|
1
|
+
import { SchemaType } from "@latticexyz/schema-type/deprecated";
|
|
2
2
|
|
|
3
3
|
export const schemaTypesToRecsTypeStrings: Record<SchemaType, string> = {
|
|
4
4
|
[SchemaType.UINT8]: "RecsType.Number",
|
|
@@ -163,38 +163,38 @@ export const schemaTypesToRecsTypeStrings: Record<SchemaType, string> = {
|
|
|
163
163
|
[SchemaType.INT240_ARRAY]: "RecsType.BigIntArray",
|
|
164
164
|
[SchemaType.INT248_ARRAY]: "RecsType.BigIntArray",
|
|
165
165
|
[SchemaType.INT256_ARRAY]: "RecsType.BigIntArray",
|
|
166
|
-
[SchemaType.BYTES1_ARRAY]: "RecsType.
|
|
167
|
-
[SchemaType.BYTES2_ARRAY]: "RecsType.
|
|
168
|
-
[SchemaType.BYTES3_ARRAY]: "RecsType.
|
|
169
|
-
[SchemaType.BYTES4_ARRAY]: "RecsType.
|
|
170
|
-
[SchemaType.BYTES5_ARRAY]: "RecsType.
|
|
171
|
-
[SchemaType.BYTES6_ARRAY]: "RecsType.
|
|
172
|
-
[SchemaType.BYTES7_ARRAY]: "RecsType.
|
|
173
|
-
[SchemaType.BYTES8_ARRAY]: "RecsType.
|
|
174
|
-
[SchemaType.BYTES9_ARRAY]: "RecsType.
|
|
175
|
-
[SchemaType.BYTES10_ARRAY]: "RecsType.
|
|
176
|
-
[SchemaType.BYTES11_ARRAY]: "RecsType.
|
|
177
|
-
[SchemaType.BYTES12_ARRAY]: "RecsType.
|
|
178
|
-
[SchemaType.BYTES13_ARRAY]: "RecsType.
|
|
179
|
-
[SchemaType.BYTES14_ARRAY]: "RecsType.
|
|
180
|
-
[SchemaType.BYTES15_ARRAY]: "RecsType.
|
|
181
|
-
[SchemaType.BYTES16_ARRAY]: "RecsType.
|
|
182
|
-
[SchemaType.BYTES17_ARRAY]: "RecsType.
|
|
183
|
-
[SchemaType.BYTES18_ARRAY]: "RecsType.
|
|
184
|
-
[SchemaType.BYTES19_ARRAY]: "RecsType.
|
|
185
|
-
[SchemaType.BYTES20_ARRAY]: "RecsType.
|
|
186
|
-
[SchemaType.BYTES21_ARRAY]: "RecsType.
|
|
187
|
-
[SchemaType.BYTES22_ARRAY]: "RecsType.
|
|
188
|
-
[SchemaType.BYTES23_ARRAY]: "RecsType.
|
|
189
|
-
[SchemaType.BYTES24_ARRAY]: "RecsType.
|
|
190
|
-
[SchemaType.BYTES25_ARRAY]: "RecsType.
|
|
191
|
-
[SchemaType.BYTES26_ARRAY]: "RecsType.
|
|
192
|
-
[SchemaType.BYTES27_ARRAY]: "RecsType.
|
|
193
|
-
[SchemaType.BYTES28_ARRAY]: "RecsType.
|
|
194
|
-
[SchemaType.BYTES29_ARRAY]: "RecsType.
|
|
195
|
-
[SchemaType.BYTES30_ARRAY]: "RecsType.
|
|
196
|
-
[SchemaType.BYTES31_ARRAY]: "RecsType.
|
|
197
|
-
[SchemaType.BYTES32_ARRAY]: "RecsType.
|
|
166
|
+
[SchemaType.BYTES1_ARRAY]: "RecsType.StringArray",
|
|
167
|
+
[SchemaType.BYTES2_ARRAY]: "RecsType.StringArray",
|
|
168
|
+
[SchemaType.BYTES3_ARRAY]: "RecsType.StringArray",
|
|
169
|
+
[SchemaType.BYTES4_ARRAY]: "RecsType.StringArray",
|
|
170
|
+
[SchemaType.BYTES5_ARRAY]: "RecsType.StringArray",
|
|
171
|
+
[SchemaType.BYTES6_ARRAY]: "RecsType.StringArray",
|
|
172
|
+
[SchemaType.BYTES7_ARRAY]: "RecsType.StringArray",
|
|
173
|
+
[SchemaType.BYTES8_ARRAY]: "RecsType.StringArray",
|
|
174
|
+
[SchemaType.BYTES9_ARRAY]: "RecsType.StringArray",
|
|
175
|
+
[SchemaType.BYTES10_ARRAY]: "RecsType.StringArray",
|
|
176
|
+
[SchemaType.BYTES11_ARRAY]: "RecsType.StringArray",
|
|
177
|
+
[SchemaType.BYTES12_ARRAY]: "RecsType.StringArray",
|
|
178
|
+
[SchemaType.BYTES13_ARRAY]: "RecsType.StringArray",
|
|
179
|
+
[SchemaType.BYTES14_ARRAY]: "RecsType.StringArray",
|
|
180
|
+
[SchemaType.BYTES15_ARRAY]: "RecsType.StringArray",
|
|
181
|
+
[SchemaType.BYTES16_ARRAY]: "RecsType.StringArray",
|
|
182
|
+
[SchemaType.BYTES17_ARRAY]: "RecsType.StringArray",
|
|
183
|
+
[SchemaType.BYTES18_ARRAY]: "RecsType.StringArray",
|
|
184
|
+
[SchemaType.BYTES19_ARRAY]: "RecsType.StringArray",
|
|
185
|
+
[SchemaType.BYTES20_ARRAY]: "RecsType.StringArray",
|
|
186
|
+
[SchemaType.BYTES21_ARRAY]: "RecsType.StringArray",
|
|
187
|
+
[SchemaType.BYTES22_ARRAY]: "RecsType.StringArray",
|
|
188
|
+
[SchemaType.BYTES23_ARRAY]: "RecsType.StringArray",
|
|
189
|
+
[SchemaType.BYTES24_ARRAY]: "RecsType.StringArray",
|
|
190
|
+
[SchemaType.BYTES25_ARRAY]: "RecsType.StringArray",
|
|
191
|
+
[SchemaType.BYTES26_ARRAY]: "RecsType.StringArray",
|
|
192
|
+
[SchemaType.BYTES27_ARRAY]: "RecsType.StringArray",
|
|
193
|
+
[SchemaType.BYTES28_ARRAY]: "RecsType.StringArray",
|
|
194
|
+
[SchemaType.BYTES29_ARRAY]: "RecsType.StringArray",
|
|
195
|
+
[SchemaType.BYTES30_ARRAY]: "RecsType.StringArray",
|
|
196
|
+
[SchemaType.BYTES31_ARRAY]: "RecsType.StringArray",
|
|
197
|
+
[SchemaType.BYTES32_ARRAY]: "RecsType.StringArray",
|
|
198
198
|
[SchemaType.BOOL_ARRAY]: "RecsType.T", // no boolean array
|
|
199
199
|
[SchemaType.ADDRESS_ARRAY]: "RecsType.StringArray",
|
|
200
200
|
[SchemaType.BYTES]: "RecsType.String",
|
package/src/render-ts/tsgen.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { StoreConfig } from "@latticexyz/
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { StoreConfig } from "@latticexyz/store";
|
|
3
|
+
import { formatAndWriteTypescript } from "@latticexyz/common/codegen";
|
|
4
|
+
import { getRecsV1TableOptions } from "../render-ts/recsV1TableOptions";
|
|
5
|
+
import { renderRecsV1Tables } from "../render-ts/renderRecsV1Tables";
|
|
6
6
|
|
|
7
7
|
export async function tsgen(config: StoreConfig, outDirectory: string) {
|
|
8
8
|
const fullOutputPath = path.join(outDirectory, `contractComponents.ts`);
|