@webiny/cli 5.41.4-beta.6 → 5.42.0-beta.0

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/bin.js CHANGED
@@ -1,38 +1,100 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
2
 
4
- const chalk = require("chalk");
5
- const execa = require("execa");
6
- const semver = require("semver");
7
- const currentNodeVersion = process.versions.node;
3
+ // Suppress punycode warnings. This is a known issue which we can't fix.
4
+ require("./utils/suppressPunycodeWarnings");
8
5
 
9
- (async () => {
10
- if (!semver.satisfies(currentNodeVersion, ">=14")) {
11
- console.error(
12
- chalk.red(
13
- [
14
- `You are running Node.js ${currentNodeVersion}, but Webiny requires version 14 or higher.`,
15
- `Please switch to one of the required versions and try again.`,
16
- `For more information, please visit https://www.webiny.com/docs/get-started/install-webiny#prerequisites.`
17
- ].join(" ")
18
- )
19
- );
20
- process.exit(1);
21
- }
6
+ // Ensure system requirements are met.
7
+ require("@webiny/system-requirements").ensureSystemRequirements();
8
+
9
+ const yargs = require("yargs");
10
+
11
+ // Disable help processing until after plugins are imported.
12
+ yargs.help(false);
13
+
14
+ // Loads environment variables from multiple sources.
15
+ require("./utils/loadEnvVariables");
16
+
17
+ const { blue, red, bold, bgYellow } = require("chalk");
18
+ const context = require("./context");
19
+ const { createCommands } = require("./commands");
20
+
21
+ yargs
22
+ .usage("Usage: $0 <command> [options]")
23
+ .demandCommand(1)
24
+ .recommendCommands()
25
+ .scriptName("webiny")
26
+ .epilogue(
27
+ `To find more information, docs and tutorials, see ${blue("https://www.webiny.com/docs")}.`
28
+ )
29
+ .epilogue(`Want to contribute? ${blue("https://github.com/webiny/webiny-js")}.`)
30
+ .fail(function (msg, error, yargs) {
31
+ if (msg) {
32
+ if (msg.includes("Not enough non-option arguments")) {
33
+ console.log();
34
+ context.error(red("Command was not invoked as expected!"));
35
+ context.info(
36
+ `Some non-optional arguments are missing. See the usage examples printed below.`
37
+ );
38
+ console.log();
39
+ yargs.showHelp();
40
+ return;
41
+ }
42
+
43
+ if (msg.includes("Missing required argument")) {
44
+ const args = msg
45
+ .split(":")[1]
46
+ .split(",")
47
+ .map(v => v.trim());
48
+
49
+ console.log();
50
+ context.error(red("Command was not invoked as expected!"));
51
+ context.info(
52
+ `Missing required argument(s): ${args
53
+ .map(arg => red(arg))
54
+ .join(", ")}. See the usage examples printed below.`
55
+ );
56
+ console.log();
57
+ yargs.showHelp();
58
+ return;
59
+ }
60
+ console.log();
61
+ context.error(red("Command execution was aborted!"));
62
+ context.error(msg);
63
+ console.log();
22
64
 
23
- try {
24
- const { stdout } = await execa("yarn", ["--version"]);
25
- if (!semver.satisfies(stdout, ">=3")) {
26
- console.error(chalk.red(`"@webiny/cli" requires yarn 3 or 4!`));
27
65
  process.exit(1);
28
66
  }
29
- } catch (err) {
30
- console.error(chalk.red(`"@webiny/cli" requires yarn 3 or 4!`));
31
- console.log(
32
- `Run ${chalk.blue("yarn set version berry")} to install a compatible version of yarn.`
33
- );
67
+
68
+ console.log();
69
+ // Unfortunately, yargs doesn't provide passed args here, so we had to do it via process.argv.
70
+ const debugEnabled = process.argv.includes("--debug");
71
+ if (debugEnabled) {
72
+ context.debug(error);
73
+ } else {
74
+ context.error(error.message);
75
+ }
76
+
77
+ const gracefulError = error.cause?.gracefulError;
78
+ if (gracefulError instanceof Error) {
79
+ console.log();
80
+ console.log(bgYellow(bold("💡 How can I resolve this?")));
81
+ console.log(gracefulError.message);
82
+ }
83
+
84
+ const plugins = context.plugins.byType("cli-command-error");
85
+ for (let i = 0; i < plugins.length; i++) {
86
+ const plugin = plugins[i];
87
+ plugin.handle({
88
+ error,
89
+ context
90
+ });
91
+ }
92
+
34
93
  process.exit(1);
35
- }
94
+ });
36
95
 
37
- require("./cli");
96
+ (async () => {
97
+ await createCommands(yargs, context);
98
+ // Enable help and run the CLI.
99
+ yargs.help().argv;
38
100
  })();
@@ -1,10 +1,5 @@
1
- const execa = require("execa");
1
+ const { SystemRequirements } = require("@webiny/system-requirements");
2
2
 
3
3
  module.exports.getNpmVersion = async () => {
4
- try {
5
- const { stdout } = await execa("npm", ["--version"]);
6
- return stdout;
7
- } catch (err) {
8
- return "";
9
- }
4
+ return SystemRequirements.getNpmVersion();
10
5
  };
@@ -1,10 +1,5 @@
1
- const execa = require("execa");
1
+ const { SystemRequirements } = require("@webiny/system-requirements");
2
2
 
3
3
  module.exports.getNpxVersion = async () => {
4
- try {
5
- const { stdout } = await execa("npx", ["--version"]);
6
- return stdout;
7
- } catch (err) {
8
- return "";
9
- }
4
+ return SystemRequirements.getNpxVersion();
10
5
  };
@@ -1,10 +1,5 @@
1
- const execa = require("execa");
1
+ const { SystemRequirements } = require("@webiny/system-requirements");
2
2
 
3
3
  module.exports.getYarnVersion = async () => {
4
- try {
5
- const { stdout } = await execa("yarn", ["--version"]);
6
- return stdout;
7
- } catch (err) {
8
- return "";
9
- }
4
+ return SystemRequirements.getYarnVersion();
10
5
  };
@@ -0,0 +1 @@
1
+ Do not manually create files in this folder. This folder is used to store the files that are generated by the CLI.
@@ -0,0 +1 @@
1
+ [{"name":"downshift","versions":[{"version":"3.1.2","files":[{"file":"/packages/app-admin/package.json","types":["dependencies"]}]},{"version":"2.1.5","files":[{"file":"/packages/ui/package.json","types":["dependencies"]}]}]}]