@latticexyz/cli 2.0.0-next.12 → 2.0.0-next.13

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/src/mud.ts CHANGED
@@ -1,39 +1,45 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import yargs from "yargs";
4
- import { hideBin } from "yargs/helpers";
5
- import { commands } from "./commands";
6
- import { logError } from "./utils/errors";
7
-
8
3
  // Load .env file into process.env
9
4
  import * as dotenv from "dotenv";
10
- import chalk from "chalk";
11
5
  dotenv.config();
12
6
 
13
- yargs(hideBin(process.argv))
14
- // Explicit name to display in help (by default it's the entry file, which may not be "mud" for e.g. ts-node)
15
- .scriptName("mud")
16
- // Use the commands directory to scaffold
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(commands as any)
19
- // Enable strict mode.
20
- .strict()
21
- // Custom error handler
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
- }
29
- console.log("");
30
- // Even though `.fail` type says we should get an `Error`, this can sometimes be undefined
31
- if (err != null) {
32
- logError(err);
7
+ async function run() {
8
+ // Import everything else async so they can pick up env vars in .env
9
+ const { default: yargs } = await import("yargs");
10
+ const { default: chalk } = await import("chalk");
11
+ const { hideBin } = await import("yargs/helpers");
12
+ const { logError } = await import("./utils/errors");
13
+ const { commands } = await import("./commands");
14
+
15
+ yargs(hideBin(process.argv))
16
+ // Explicit name to display in help (by default it's the entry file, which may not be "mud" for e.g. ts-node)
17
+ .scriptName("mud")
18
+ // Use the commands directory to scaffold
19
+ // command array overload isn't typed, see https://github.com/yargs/yargs/blob/main/docs/advanced.md#esm-hierarchy
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ .command(commands as any)
22
+ // Enable strict mode.
23
+ .strict()
24
+ // Custom error handler
25
+ .fail((msg, err) => {
26
+ console.error(chalk.red(msg));
27
+ if (msg.includes("Missing required argument")) {
28
+ console.log(
29
+ chalk.yellow(`Run 'pnpm mud ${process.argv[2]} --help' for a list of available and required arguments.`)
30
+ );
31
+ }
33
32
  console.log("");
34
- }
33
+ // Even though `.fail` type says we should get an `Error`, this can sometimes be undefined
34
+ if (err != null) {
35
+ logError(err);
36
+ console.log("");
37
+ }
38
+
39
+ process.exit(1);
40
+ })
41
+ // Useful aliases.
42
+ .alias({ h: "help" }).argv;
43
+ }
35
44
 
36
- process.exit(1);
37
- })
38
- // Useful aliases.
39
- .alias({ h: "help" }).argv;
45
+ run();