Skip to content

Commit

Permalink
feat(explorer): add worlds.json as default arg (#3059)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <[email protected]>
  • Loading branch information
karooolis and holic authored Aug 23, 2024
1 parent 04c675c commit b3e3289
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/explorer/bin/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const port = argv.port || process.env.PORT || 13690;
const chainId = argv.chainId || process.env.CHAIN_ID || 31337;
const env = argv.env || process.env.NODE_ENV || "production";
const indexerDatabase = argv.indexerDatabase || process.env.INDEXER_DATABASE || "indexer.db";
const worldsFile = argv.worldsFile || process.env.WORLDS_FILE || null;
const worldsFile = argv.worldsFile || process.env.WORLDS_FILE || "worlds.json";

let worldAddress = argv.worldAddress || process.env.WORLD_ADDRESS || null;
let explorerProcess: ChildProcess;
Expand Down Expand Up @@ -93,17 +93,19 @@ process.on("SIGINT", () => {
});

async function main() {
if (!worldsFile && !worldAddress) {
throw new Error(
"Neither worldsFile nor worldAddress provided. Use --worldsFile or --worldAddress to specify a world.",
);
}

if (worldsFile) {
// If world address is not provided, try to read it from worlds.json
if (!worldAddress) {
worldAddress = await readWorldsJson();
watchWorldsJson();

// If world address is still not found, throw an error
if (!worldAddress) {
throw new Error(
`No world address found in "${worldsFile}" file. Either run \`mud deploy\` to create one or provide one with \`--worldAddress\`.`,
);
}
}

watchWorldsJson();
await startExplorer();
}

Expand Down

0 comments on commit b3e3289

Please sign in to comment.