@latticexyz/cli 2.0.0-alpha.75 → 2.0.0-alpha.78

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.
@@ -1,5 +1,5 @@
1
- import { R as RequireKeys, b as StringForUnion, E as ExtractUserTypes, S as StoreUserConfig, a as StoreConfig } from '../parseStoreConfig-05533795.js';
2
- export { h as EnumsConfig, F as FullSchemaConfig, d as SchemaConfig, c as ShorthandSchemaConfig, a as StoreConfig, S as StoreUserConfig, T as TableConfig, f as TablesConfig, p as parseStoreConfig, s as storeConfig, i as zEnumsConfig, z as zSchemaConfig, j as zStoreConfig, e as zTableConfig, g as zTablesConfig } from '../parseStoreConfig-05533795.js';
1
+ import { R as RequireKeys, b as StringForUnion, E as ExtractUserTypes, S as StoreUserConfig, a as StoreConfig } from '../parseStoreConfig-8aa69ac9.js';
2
+ export { h as EnumsConfig, F as FullSchemaConfig, d as SchemaConfig, c as ShorthandSchemaConfig, a as StoreConfig, S as StoreUserConfig, T as TableConfig, f as TablesConfig, p as parseStoreConfig, s as storeConfig, i as zEnumsConfig, z as zSchemaConfig, j as zStoreConfig, e as zTableConfig, g as zTablesConfig } from '../parseStoreConfig-8aa69ac9.js';
3
3
  import { z, RefinementCtx } from 'zod';
4
4
  import '@latticexyz/schema-type';
5
5
 
@@ -17,6 +17,7 @@ declare function loadStoreConfig(configPath?: string): Promise<{
17
17
  namespace: string;
18
18
  storeImportPath: string;
19
19
  userTypesPath: string;
20
+ codegenDirectory: string;
20
21
  }>;
21
22
 
22
23
  type SystemUserConfig = {
@@ -27,7 +27,7 @@ import {
27
27
  zUserEnum,
28
28
  zValueName,
29
29
  zWorldConfig
30
- } from "../chunk-S7JI7355.js";
30
+ } from "../chunk-MN3HYFJK.js";
31
31
  import {
32
32
  getDuplicates,
33
33
  parseStaticArray,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { MUDConfig, MUDUserConfig, ResolvedWorldConfig, WorldUserConfig, loadStoreConfig, loadWorldConfig, mudConfig, parseWorldConfig, resolveTableId, resolveWorldConfig } from './config/index.js';
2
- export { a as StoreConfig, S as StoreUserConfig, p as parseStoreConfig, s as storeConfig } from './parseStoreConfig-05533795.js';
2
+ export { a as StoreConfig, S as StoreUserConfig, p as parseStoreConfig, s as storeConfig } from './parseStoreConfig-8aa69ac9.js';
3
3
  import 'zod';
4
4
  import '@latticexyz/schema-type';
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  resolveTableId,
8
8
  resolveWorldConfig,
9
9
  storeConfig
10
- } from "./chunk-S7JI7355.js";
10
+ } from "./chunk-MN3HYFJK.js";
11
11
  import "./chunk-KPBNUPK6.js";
12
12
  import "./chunk-O6HOO6WA.js";
13
13
  export {
package/dist/mud.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  commands
4
- } from "./chunk-2L44HXDV.js";
5
- import "./chunk-QGY6YXME.js";
4
+ } from "./chunk-TLEAEDUA.js";
5
+ import "./chunk-XUNWAEP7.js";
6
6
  import {
7
7
  logError
8
- } from "./chunk-S7JI7355.js";
8
+ } from "./chunk-MN3HYFJK.js";
9
9
  import {
10
10
  JsonRpcProvider,
11
11
  componentsDir,
@@ -24,7 +24,7 @@ import {
24
24
  getSrcDirectory,
25
25
  getTestDirectory
26
26
  } from "./chunk-FPG73MVN.js";
27
- import "./chunk-MIGVHECZ.js";
27
+ import "./chunk-DO7OWTMM.js";
28
28
  import "./chunk-TPZUS44H.js";
29
29
  import "./chunk-5NC2OON2.js";
30
30
  import "./chunk-KPBNUPK6.js";
package/dist/mud2.js CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  commands
4
- } from "./chunk-2L44HXDV.js";
5
- import "./chunk-QGY6YXME.js";
4
+ } from "./chunk-TLEAEDUA.js";
5
+ import "./chunk-XUNWAEP7.js";
6
6
  import {
7
7
  logError
8
- } from "./chunk-S7JI7355.js";
8
+ } from "./chunk-MN3HYFJK.js";
9
9
  import "./chunk-FFY7VTYB.js";
10
10
  import "./chunk-FPG73MVN.js";
11
- import "./chunk-MIGVHECZ.js";
11
+ import "./chunk-DO7OWTMM.js";
12
12
  import "./chunk-TPZUS44H.js";
13
13
  import "./chunk-5NC2OON2.js";
14
14
  import "./chunk-KPBNUPK6.js";
@@ -219,6 +219,8 @@ type StoreUserConfig<EnumNames extends StringForUnion = StringForUnion, StaticUs
219
219
  tables: TablesConfig<AsDependent<StaticUserTypes>, AsDependent<StaticUserTypes>>;
220
220
  /** Path to the file where common user types will be generated and imported from. Default is "Types" */
221
221
  userTypesPath?: string;
222
+ /** Path to the directory where generated files will be placed. (Default is "codegen") */
223
+ codegenDirectory?: string;
222
224
  };
223
225
  /** Type helper for defining StoreUserConfig */
224
226
  declare function storeConfig<EnumNames extends StringForUnion = never, StaticUserTypes extends ExtractUserTypes<EnumNames> = ExtractUserTypes<EnumNames>>(config: StoreUserConfig<EnumNames, StaticUserTypes>): StoreUserConfig<EnumNames, StaticUserTypes>;
@@ -292,6 +294,7 @@ declare const zStoreConfig: z.ZodEffects<z.ZodObject<{
292
294
  namespace: z.ZodDefault<z.ZodEffects<z.ZodString, string, string>>;
293
295
  storeImportPath: z.ZodDefault<z.ZodString>;
294
296
  userTypesPath: z.ZodDefault<z.ZodString>;
297
+ codegenDirectory: z.ZodDefault<z.ZodString>;
295
298
  enums: z.ZodDefault<z.ZodRecord<z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">, string[], string[]>>>;
296
299
  }, "strip", z.ZodTypeAny, {
297
300
  tables: Record<string, RequireKeys<RequireKeys<{
@@ -307,6 +310,7 @@ declare const zStoreConfig: z.ZodEffects<z.ZodObject<{
307
310
  namespace: string;
308
311
  storeImportPath: string;
309
312
  userTypesPath: string;
313
+ codegenDirectory: string;
310
314
  }, {
311
315
  tables: Record<string, string | {
312
316
  schema: (string | Record<string, string>) & (string | Record<string, string> | undefined);
@@ -320,6 +324,7 @@ declare const zStoreConfig: z.ZodEffects<z.ZodObject<{
320
324
  namespace?: string | undefined;
321
325
  storeImportPath?: string | undefined;
322
326
  userTypesPath?: string | undefined;
327
+ codegenDirectory?: string | undefined;
323
328
  enums?: Record<string, string[]> | undefined;
324
329
  }>, {
325
330
  tables: Record<string, RequireKeys<RequireKeys<{
@@ -335,6 +340,7 @@ declare const zStoreConfig: z.ZodEffects<z.ZodObject<{
335
340
  namespace: string;
336
341
  storeImportPath: string;
337
342
  userTypesPath: string;
343
+ codegenDirectory: string;
338
344
  }, {
339
345
  tables: Record<string, string | {
340
346
  schema: (string | Record<string, string>) & (string | Record<string, string> | undefined);
@@ -348,6 +354,7 @@ declare const zStoreConfig: z.ZodEffects<z.ZodObject<{
348
354
  namespace?: string | undefined;
349
355
  storeImportPath?: string | undefined;
350
356
  userTypesPath?: string | undefined;
357
+ codegenDirectory?: string | undefined;
351
358
  enums?: Record<string, string[]> | undefined;
352
359
  }>;
353
360
  declare function parseStoreConfig(config: unknown): {
@@ -364,6 +371,7 @@ declare function parseStoreConfig(config: unknown): {
364
371
  namespace: string;
365
372
  storeImportPath: string;
366
373
  userTypesPath: string;
374
+ codegenDirectory: string;
367
375
  };
368
376
 
369
377
  export { ExtractUserTypes as E, FullSchemaConfig as F, RequireKeys as R, StoreUserConfig as S, TableConfig as T, StoreConfig as a, StringForUnion as b, ShorthandSchemaConfig as c, SchemaConfig as d, zTableConfig as e, TablesConfig as f, zTablesConfig as g, EnumsConfig as h, zEnumsConfig as i, zStoreConfig as j, parseStoreConfig as p, storeConfig as s, zSchemaConfig as z };
@@ -1,4 +1,4 @@
1
- import { a as StoreConfig } from '../parseStoreConfig-05533795.js';
1
+ import { a as StoreConfig } from '../parseStoreConfig-8aa69ac9.js';
2
2
  import { SchemaType } from '@latticexyz/schema-type';
3
3
  import 'zod';
4
4
 
@@ -16,7 +16,7 @@ import {
16
16
  renderedSolidityHeader,
17
17
  solidityRelativeImportPath,
18
18
  tablegen
19
- } from "../chunk-MIGVHECZ.js";
19
+ } from "../chunk-DO7OWTMM.js";
20
20
  import {
21
21
  getSchemaTypeInfo,
22
22
  getUserTypeInfo,
@@ -1,4 +1,4 @@
1
- import { a as StoreConfig } from '../parseStoreConfig-05533795.js';
1
+ import { a as StoreConfig } from '../parseStoreConfig-8aa69ac9.js';
2
2
  import { SchemaType } from '@latticexyz/schema-type';
3
3
  import 'zod';
4
4
 
@@ -1,7 +1,7 @@
1
1
  import { ZodError, z } from 'zod';
2
2
  import { ValidationError } from 'zod-validation-error';
3
3
  import { MUDConfig } from '../config/index.js';
4
- import '../parseStoreConfig-05533795.js';
4
+ import '../parseStoreConfig-8aa69ac9.js';
5
5
  import '@latticexyz/schema-type';
6
6
 
7
7
  declare function fromZodErrorCustom(error: ZodError, prefix: string): ValidationError;
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  deploy
3
- } from "../chunk-QGY6YXME.js";
3
+ } from "../chunk-XUNWAEP7.js";
4
4
  import {
5
5
  MUDError,
6
6
  NotInsideProjectError,
7
7
  UnrecognizedSystemErrorFactory,
8
8
  fromZodErrorCustom,
9
9
  logError
10
- } from "../chunk-S7JI7355.js";
10
+ } from "../chunk-MN3HYFJK.js";
11
11
  import {
12
12
  anvil,
13
13
  cast,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/cli",
3
- "version": "2.0.0-alpha.75+406a002d",
3
+ "version": "2.0.0-alpha.78+cf5f4bfe",
4
4
  "description": "Command line interface for mud",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  "release": "npm publish --access=public"
28
28
  },
29
29
  "devDependencies": {
30
- "@latticexyz/store": "^2.0.0-alpha.75+406a002d",
30
+ "@latticexyz/store": "^2.0.0-alpha.78+cf5f4bfe",
31
31
  "@types/ejs": "^3.1.1",
32
32
  "@types/glob": "^7.2.0",
33
33
  "@types/node": "^17.0.34",
@@ -40,10 +40,10 @@
40
40
  "dependencies": {
41
41
  "@improbable-eng/grpc-web": "^0.15.0",
42
42
  "@improbable-eng/grpc-web-node-http-transport": "^0.15.0",
43
- "@latticexyz/schema-type": "^2.0.0-alpha.75+406a002d",
44
- "@latticexyz/services": "^2.0.0-alpha.75+406a002d",
45
- "@latticexyz/solecs": "^2.0.0-alpha.75+406a002d",
46
- "@latticexyz/std-contracts": "^2.0.0-alpha.75+406a002d",
43
+ "@latticexyz/schema-type": "^2.0.0-alpha.78+cf5f4bfe",
44
+ "@latticexyz/services": "^2.0.0-alpha.78+cf5f4bfe",
45
+ "@latticexyz/solecs": "^2.0.0-alpha.78+cf5f4bfe",
46
+ "@latticexyz/std-contracts": "^2.0.0-alpha.78+cf5f4bfe",
47
47
  "@solidity-parser/parser": "^0.16.0",
48
48
  "@typechain/ethers-v5": "^10.1.1",
49
49
  "chalk": "^5.0.1",
@@ -70,5 +70,5 @@
70
70
  "zod": "^3.21.4",
71
71
  "zod-validation-error": "^1.0.1"
72
72
  },
73
- "gitHead": "406a002d58cbdb3f65af5bb47a2c7791ac93d5f2"
73
+ "gitHead": "cf5f4bfe0d1d14e70efbf10ebef47d39f39e7239"
74
74
  }
@@ -1,7 +1,8 @@
1
+ import path from "path";
1
2
  import type { CommandModule } from "yargs";
2
3
  import { loadStoreConfig } from "../config/loadStoreConfig.js";
3
- import { getSrcDirectory } from "../utils/foundry.js";
4
4
  import { tablegen } from "../render-solidity/tablegen.js";
5
+ import { getSrcDirectory } from "../utils/index.js";
5
6
 
6
7
  type Options = {
7
8
  configPath?: string;
@@ -19,11 +20,10 @@ const commandModule: CommandModule<Options, Options> = {
19
20
  },
20
21
 
21
22
  async handler({ configPath }) {
22
- const srcDirectory = await getSrcDirectory();
23
-
24
23
  const config = await loadStoreConfig(configPath);
24
+ const srcDir = await getSrcDirectory();
25
25
 
26
- await tablegen(config, srcDirectory);
26
+ await tablegen(config, path.join(srcDir, config.codegenDirectory));
27
27
 
28
28
  process.exit(0);
29
29
  },
@@ -42,11 +42,13 @@ const commandModule: CommandModule<Options, Options> = {
42
42
  const storeConfig = await loadStoreConfig(configPath);
43
43
  const mudConfig = { ...worldConfig, ...storeConfig };
44
44
 
45
+ const outputBaseDirectory = path.join(srcDir, mudConfig.codegenDirectory);
46
+
45
47
  // clear the worldgen directory
46
- if (clean) rmSync(path.join(srcDir, worldConfig.worldgenDirectory), { recursive: true, force: true });
48
+ if (clean) rmSync(path.join(outputBaseDirectory, mudConfig.worldgenDirectory), { recursive: true, force: true });
47
49
 
48
50
  // generate new interfaces
49
- await worldgen(mudConfig, existingContracts, srcDir);
51
+ await worldgen(mudConfig, existingContracts, outputBaseDirectory);
50
52
 
51
53
  process.exit(0);
52
54
  },
@@ -192,6 +192,8 @@ export type StoreUserConfig<
192
192
  tables: TablesConfig<AsDependent<StaticUserTypes>, AsDependent<StaticUserTypes>>;
193
193
  /** Path to the file where common user types will be generated and imported from. Default is "Types" */
194
194
  userTypesPath?: string;
195
+ /** Path to the directory where generated files will be placed. (Default is "codegen") */
196
+ codegenDirectory?: string;
195
197
  };
196
198
 
197
199
  /** Type helper for defining StoreUserConfig */
@@ -211,6 +213,7 @@ const StoreConfigUnrefined = z
211
213
  storeImportPath: z.string().default("@latticexyz/store/src/"),
212
214
  tables: zTablesConfig,
213
215
  userTypesPath: z.string().default("Types"),
216
+ codegenDirectory: z.string().default("codegen"),
214
217
  })
215
218
  .merge(zEnumsConfig);
216
219
 
@@ -0,0 +1,15 @@
1
+ import { renderList, renderedSolidityHeader } from "./common.js";
2
+ import { TableOptions } from "./tableOptions.js";
3
+
4
+ export function renderTableIndex(options: TableOptions[]) {
5
+ return `${renderedSolidityHeader}
6
+
7
+ ${renderList(options, ({ outputPath, tableName, renderOptions: { structName, staticResourceData } }) => {
8
+ const imports = [tableName];
9
+ if (structName) imports.push(structName);
10
+ if (staticResourceData) imports.push(`${tableName}TableId`);
11
+
12
+ return `import { ${imports.join(", ")} } from "./${outputPath}";`;
13
+ })}
14
+ `;
15
+ }
@@ -4,9 +4,17 @@ import { getTableOptions } from "./tableOptions.js";
4
4
  import { renderTable } from "./renderTable.js";
5
5
  import { renderTypesFromConfig } from "./renderTypesFromConfig.js";
6
6
  import { formatAndWriteSolidity } from "../utils/formatAndWrite.js";
7
+ import { renderTableIndex } from "./renderTableIndex.js";
8
+ import { rmSync } from "fs";
7
9
 
8
10
  export async function tablegen(config: StoreConfig, outputBaseDirectory: string) {
9
11
  const allTableOptions = getTableOptions(config);
12
+
13
+ const uniqueTableDirectories = new Set(allTableOptions.map(({ outputPath }) => path.dirname(outputPath)));
14
+ for (const tableDir of uniqueTableDirectories) {
15
+ rmSync(path.join(outputBaseDirectory, tableDir), { recursive: true, force: true });
16
+ }
17
+
10
18
  // write tables to files
11
19
  for (const { outputPath, renderOptions } of allTableOptions) {
12
20
  const fullOutputPath = path.join(outputBaseDirectory, outputPath);
@@ -20,4 +28,8 @@ export async function tablegen(config: StoreConfig, outputBaseDirectory: string)
20
28
  const output = renderTypesFromConfig(config);
21
29
  formatAndWriteSolidity(output, fullOutputPath, "Generated types file");
22
30
  }
31
+
32
+ const fullOutputPath = path.join(outputBaseDirectory, `Tables.sol`);
33
+ const output = renderTableIndex(allTableOptions);
34
+ formatAndWriteSolidity(output, fullOutputPath, "Generated table index");
23
35
  }