@latticexyz/cli 2.0.0-alpha.73 → 2.0.0-alpha.76

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.
@@ -703,18 +703,43 @@ function renderTypesFromConfig(config) {
703
703
 
704
704
  // src/render-solidity/tablegen.ts
705
705
  import path3 from "path";
706
+
707
+ // src/render-solidity/renderTableIndex.ts
708
+ function renderTableIndex(options) {
709
+ return `${renderedSolidityHeader}
710
+
711
+ ${renderList(options, ({ outputPath, tableName, renderOptions: { structName, staticResourceData } }) => {
712
+ const imports = [tableName];
713
+ if (structName)
714
+ imports.push(structName);
715
+ if (staticResourceData)
716
+ imports.push(`${tableName}TableId`);
717
+ return `import { ${imports.join(", ")} } from "./${outputPath}";`;
718
+ })}
719
+ `;
720
+ }
721
+
722
+ // src/render-solidity/tablegen.ts
723
+ import { rmSync } from "fs";
706
724
  async function tablegen(config, outputBaseDirectory) {
707
725
  const allTableOptions = getTableOptions(config);
726
+ const uniqueTableDirectories = new Set(allTableOptions.map(({ outputPath }) => path3.dirname(outputPath)));
727
+ for (const tableDir of uniqueTableDirectories) {
728
+ rmSync(path3.join(outputBaseDirectory, tableDir), { recursive: true, force: true });
729
+ }
708
730
  for (const { outputPath, renderOptions } of allTableOptions) {
709
- const fullOutputPath = path3.join(outputBaseDirectory, outputPath);
710
- const output = renderTable(renderOptions);
711
- formatAndWriteSolidity(output, fullOutputPath, "Generated table");
731
+ const fullOutputPath2 = path3.join(outputBaseDirectory, outputPath);
732
+ const output2 = renderTable(renderOptions);
733
+ formatAndWriteSolidity(output2, fullOutputPath2, "Generated table");
712
734
  }
713
735
  if (Object.keys(config.enums).length > 0) {
714
- const fullOutputPath = path3.join(outputBaseDirectory, `${config.userTypesPath}.sol`);
715
- const output = renderTypesFromConfig(config);
716
- formatAndWriteSolidity(output, fullOutputPath, "Generated types file");
736
+ const fullOutputPath2 = path3.join(outputBaseDirectory, `${config.userTypesPath}.sol`);
737
+ const output2 = renderTypesFromConfig(config);
738
+ formatAndWriteSolidity(output2, fullOutputPath2, "Generated types file");
717
739
  }
740
+ const fullOutputPath = path3.join(outputBaseDirectory, `Tables.sol`);
741
+ const output = renderTableIndex(allTableOptions);
742
+ formatAndWriteSolidity(output, fullOutputPath, "Generated table index");
718
743
  }
719
744
 
720
745
  export {
@@ -172,7 +172,8 @@ var StoreConfigUnrefined = z3.object({
172
172
  namespace: zSelector.default(""),
173
173
  storeImportPath: z3.string().default("@latticexyz/store/src/"),
174
174
  tables: zTablesConfig,
175
- userTypesPath: z3.string().default("Types")
175
+ userTypesPath: z3.string().default("Types"),
176
+ codegenDirectory: z3.string().default("codegen")
176
177
  }).merge(zEnumsConfig);
177
178
  var zStoreConfig = StoreConfigUnrefined.superRefine(validateStoreConfig);
178
179
  function parseStoreConfig(config) {