@webiny/cli 6.0.0-beta.0 → 6.0.0-rc.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.
Files changed (48) hide show
  1. package/README.md +10 -6
  2. package/bin.js +10 -33
  3. package/files/duplicates.json +1 -0
  4. package/files/references.json +1 -0
  5. package/index.js +2 -2
  6. package/package.json +16 -55
  7. package/utils/ensureSameWebinyPackageVersions.js +99 -0
  8. package/utils/suppressPunycodeWarnings.js +7 -0
  9. package/cli.js +0 -93
  10. package/commands/about/getDatabaseSetup.js +0 -45
  11. package/commands/about/getNpmVersion.js +0 -10
  12. package/commands/about/getNpxVersion.js +0 -10
  13. package/commands/about/getPulumiVersions.js +0 -43
  14. package/commands/about/getYarnVersion.js +0 -10
  15. package/commands/about/index.js +0 -97
  16. package/commands/index.js +0 -21
  17. package/commands/run/index.js +0 -38
  18. package/commands/telemetry/index.js +0 -31
  19. package/commands/upgrade/index.js +0 -108
  20. package/commands/wcp/hooks.js +0 -133
  21. package/commands/wcp/index.js +0 -8
  22. package/commands/wcp/login.js +0 -227
  23. package/commands/wcp/logout.js +0 -28
  24. package/commands/wcp/project.js +0 -202
  25. package/commands/wcp/utils/getProjectEnvironment.js +0 -120
  26. package/commands/wcp/utils/getUser.js +0 -100
  27. package/commands/wcp/utils/getWcpOrgProjectId.js +0 -9
  28. package/commands/wcp/utils/getWcpPat.js +0 -5
  29. package/commands/wcp/utils/getWcpProjectId.js +0 -3
  30. package/commands/wcp/utils/index.js +0 -21
  31. package/commands/wcp/utils/setProjectId.js +0 -44
  32. package/commands/wcp/utils/setWcpPat.js +0 -5
  33. package/commands/wcp/utils/sleep.js +0 -1
  34. package/commands/wcp/utils/updateUserLastActiveOn.js +0 -28
  35. package/commands/wcp/whoami.js +0 -43
  36. package/context.js +0 -137
  37. package/index.d.ts +0 -3
  38. package/types.d.ts +0 -172
  39. package/utils/PluginsContainer.js +0 -49
  40. package/utils/createProjectApplicationWorkspace.js +0 -16
  41. package/utils/getProject.js +0 -48
  42. package/utils/getProjectApplication.js +0 -83
  43. package/utils/importModule.js +0 -43
  44. package/utils/index.js +0 -24
  45. package/utils/loadEnvVariables.js +0 -63
  46. package/utils/localStorage.js +0 -44
  47. package/utils/log.js +0 -67
  48. package/utils/sendEvent.js +0 -11
package/index.js CHANGED
@@ -1,3 +1,3 @@
1
- const context = require("./context");
1
+ import { GracefulError } from "@webiny/cli-core";
2
2
 
3
- module.exports.cli = context;
3
+ export { GracefulError };
package/package.json CHANGED
@@ -1,69 +1,30 @@
1
1
  {
2
2
  "name": "@webiny/cli",
3
- "version": "6.0.0-beta.0",
3
+ "version": "6.0.0-rc.0",
4
+ "type": "module",
4
5
  "main": "index.js",
5
- "bin": {
6
- "webiny": "./bin.js"
7
- },
8
6
  "repository": {
9
7
  "type": "git",
10
- "url": "https://github.com/webiny/webiny-js.git",
11
- "directory": "packages/cli"
8
+ "url": "https://github.com/webiny/webiny-js.git"
9
+ },
10
+ "bin": {
11
+ "webiny": "./bin.js"
12
12
  },
13
- "author": "Pavel Denisjuk <pavel@webiny.com>",
14
- "description": "A tool to bootstrap a Webiny project.",
13
+ "description": "A command line interface (CLI) for managing Webiny projects.",
14
+ "license": "MIT",
15
15
  "dependencies": {
16
- "@webiny/telemetry": "6.0.0-beta.0",
17
- "@webiny/wcp": "6.0.0-beta.0",
18
- "boolean": "3.2.0",
19
- "camelcase": "5.3.1",
20
- "chalk": "4.1.2",
21
- "dotenv": "8.6.0",
16
+ "@webiny/cli-core": "6.0.0-rc.0",
17
+ "@webiny/system-requirements": "6.0.0-rc.0",
22
18
  "execa": "5.1.1",
23
- "fast-glob": "3.2.12",
24
- "find-up": "5.0.0",
25
- "fs-extra": "9.1.0",
26
- "graphql-request": "3.7.0",
27
- "inquirer": "7.3.3",
28
- "is-ci": "3.0.1",
29
- "ncp": "2.0.0",
30
- "open": "8.4.0",
31
- "pirates": "4.0.5",
32
- "semver": "7.5.4",
33
- "ts-morph": "11.0.3",
34
- "typescript": "4.7.4",
35
- "uniqid": "5.4.0",
36
- "yargs": "17.6.2"
19
+ "tsx": "4.21.0"
20
+ },
21
+ "devDependencies": {
22
+ "@types/lodash": "4.17.23",
23
+ "@webiny/build-tools": "6.0.0-rc.0"
37
24
  },
38
- "license": "MIT",
39
25
  "publishConfig": {
40
26
  "access": "public",
41
27
  "directory": "."
42
28
  },
43
- "adio": {
44
- "ignoreDirs": [
45
- "/create/template/",
46
- "/node_modules/",
47
- "/dist/"
48
- ],
49
- "ignore": {
50
- "src": [
51
- "@webiny/project-utils",
52
- "@webiny/api-file-manager",
53
- "@webiny/cli-plugin-deploy-pulumi",
54
- "@webiny/api",
55
- "@webiny/handler-client",
56
- "@webiny/api-elasticsearch",
57
- "@webiny/api-tenancy",
58
- "@webiny/api-security",
59
- "@webiny/api-i18n",
60
- "@webiny/api-i18n-content",
61
- "@webiny/api-page-builder",
62
- "@webiny/api-prerendering-service",
63
- "@webiny/api-form-builder",
64
- "@webiny/api-headless-cms"
65
- ]
66
- }
67
- },
68
- "gitHead": "aa8dbfbbd5ad13ec271adba6f2431e02991a300f"
29
+ "gitHead": "0f2aa699f4642e550ab62c96fcd050e8d02345c9"
69
30
  }
@@ -0,0 +1,99 @@
1
+ const execa = require("execa");
2
+ const logger = require("./log");
3
+
4
+ const DEBUG_FLAG = "--debug";
5
+ const usingDebugFlag = process.argv.includes(DEBUG_FLAG);
6
+
7
+ const SKIP_WEBINY_VERSIONS_CHECK_FLAG = "--no-package-versions-check";
8
+ const skippingWebinyVersionsCheck = process.argv.includes(SKIP_WEBINY_VERSIONS_CHECK_FLAG);
9
+
10
+ function listWebinyPackageVersions() {
11
+ const { stdout } = execa.sync("yarn", ["info", "@webiny/*", "--name-only", "--all", "--json"], {
12
+ encoding: "utf-8"
13
+ });
14
+
15
+ // Each line is a JSON string, so parse them individually
16
+ const lines = stdout
17
+ .trim()
18
+ .split("\n")
19
+ .map(line => JSON.parse(line));
20
+
21
+ const versionMap = new Map();
22
+
23
+ for (const entry of lines) {
24
+ // An example entry: "@webiny/cli@npm:5.42.3"
25
+ const match = entry.match(/^(@webiny\/[^@]+)@npm:(.+)$/);
26
+ if (!match) {
27
+ continue;
28
+ }
29
+
30
+ const [, pkg, version] = match;
31
+ if (!versionMap.has(pkg)) {
32
+ versionMap.set(pkg, new Set());
33
+ }
34
+
35
+ versionMap.get(pkg).add(version);
36
+ }
37
+
38
+ return versionMap;
39
+ }
40
+
41
+ function ensureSameWebinyPackageVersions() {
42
+ // Just in case, we want to allow users to skip the check.
43
+ if (skippingWebinyVersionsCheck) {
44
+ return;
45
+ }
46
+
47
+ let webinyVersions;
48
+ try {
49
+ webinyVersions = listWebinyPackageVersions();
50
+ } catch (e) {
51
+ const message = ["Failed to inspect Webiny package versions."];
52
+
53
+ if (!usingDebugFlag) {
54
+ message.push(
55
+ `For more information, try running with ${logger.warning.hl(DEBUG_FLAG)}.`
56
+ );
57
+ }
58
+
59
+ message.push("Learn more: https://webiny.link/webiny-package-versions-check");
60
+
61
+ logger.warning(message.join(" "));
62
+ if (usingDebugFlag) {
63
+ logger.debug(e);
64
+ }
65
+
66
+ console.log();
67
+ return;
68
+ }
69
+
70
+ let hasMismatch = false;
71
+ const mismatchedPackages = [];
72
+ for (const [pkg, versions] of webinyVersions.entries()) {
73
+ if (versions.size > 1) {
74
+ hasMismatch = true;
75
+ mismatchedPackages.push([pkg, versions]);
76
+ }
77
+ }
78
+
79
+ if (hasMismatch) {
80
+ const message = [
81
+ "The following Webiny packages have mismatched versions:",
82
+ "",
83
+ ...mismatchedPackages.map(([pkg, versions]) => {
84
+ return `‣ ${pkg}: ${Array.from(versions).join(", ")}`;
85
+ }),
86
+ "",
87
+ `Please ensure all Webiny packages are using the same version. If you think this is a mistake, you can also skip this check by appending the ${logger.error.hl(
88
+ SKIP_WEBINY_VERSIONS_CHECK_FLAG
89
+ )} flag. Learn more: https://webiny.link/webiny-package-versions-check`
90
+ ];
91
+
92
+ logger.error(message.join("\n"));
93
+ process.exit(1);
94
+ }
95
+ }
96
+
97
+ module.exports = {
98
+ ensureSameWebinyPackageVersions
99
+ };
@@ -0,0 +1,7 @@
1
+ const originalConsoleError = console.error;
2
+ console.error = (message, ...args) => {
3
+ if (typeof message === "string" && message.includes("punycode")) {
4
+ return;
5
+ }
6
+ originalConsoleError.call(console, message, ...args);
7
+ };
package/cli.js DELETED
@@ -1,93 +0,0 @@
1
- #!/usr/bin/env node
2
- const yargs = require("yargs");
3
-
4
- // Disable help processing until after plugins are imported.
5
- yargs.help(false);
6
-
7
- // Loads environment variables from multiple sources.
8
- require("./utils/loadEnvVariables");
9
-
10
- const { blue, red, bold, bgYellow } = require("chalk");
11
- const context = require("./context");
12
- const { createCommands } = require("./commands");
13
-
14
- yargs
15
- .usage("Usage: $0 <command> [options]")
16
- .demandCommand(1)
17
- .recommendCommands()
18
- .scriptName("webiny")
19
- .epilogue(
20
- `To find more information, docs and tutorials, see ${blue("https://www.webiny.com/docs")}.`
21
- )
22
- .epilogue(`Want to contribute? ${blue("https://github.com/webiny/webiny-js")}.`)
23
- .fail(function (msg, error, yargs) {
24
- if (msg) {
25
- if (msg.includes("Not enough non-option arguments")) {
26
- console.log();
27
- context.error(red("Command was not invoked as expected!"));
28
- context.info(
29
- `Some non-optional arguments are missing. See the usage examples printed below.`
30
- );
31
- console.log();
32
- yargs.showHelp();
33
- return;
34
- }
35
-
36
- if (msg.includes("Missing required argument")) {
37
- const args = msg
38
- .split(":")[1]
39
- .split(",")
40
- .map(v => v.trim());
41
-
42
- console.log();
43
- context.error(red("Command was not invoked as expected!"));
44
- context.info(
45
- `Missing required argument(s): ${args
46
- .map(arg => red(arg))
47
- .join(", ")}. See the usage examples printed below.`
48
- );
49
- console.log();
50
- yargs.showHelp();
51
- return;
52
- }
53
- console.log();
54
- context.error(red("Command execution was aborted!"));
55
- context.error(msg);
56
- console.log();
57
-
58
- process.exit(1);
59
- }
60
-
61
- console.log();
62
- // Unfortunately, yargs doesn't provide passed args here, so we had to do it via process.argv.
63
- const debugEnabled = process.argv.includes("--debug");
64
- if (debugEnabled) {
65
- context.debug(error);
66
- } else {
67
- context.error(error.message);
68
- }
69
-
70
- const gracefulError = error.cause?.gracefulError;
71
- if (gracefulError instanceof Error) {
72
- console.log();
73
- console.log(bgYellow(bold("💡 How can I resolve this?")));
74
- console.log(gracefulError.message);
75
- }
76
-
77
- const plugins = context.plugins.byType("cli-command-error");
78
- for (let i = 0; i < plugins.length; i++) {
79
- const plugin = plugins[i];
80
- plugin.handle({
81
- error,
82
- context
83
- });
84
- }
85
-
86
- process.exit(1);
87
- });
88
-
89
- (async () => {
90
- await createCommands(yargs, context);
91
- // Enable help and run the CLI.
92
- yargs.help().argv;
93
- })();
@@ -1,45 +0,0 @@
1
- const { getProject } = require("@webiny/cli/utils");
2
- const path = require("path");
3
- const fs = require("fs");
4
-
5
- const DATABASE_SETUPS = {
6
- DDB: "ddb",
7
- DDB_ES: "ddb-es",
8
- DDB_OS: "ddb-os"
9
- };
10
-
11
- const DATABASE_SETUPS_LABELS = {
12
- [DATABASE_SETUPS.DDB]: "Amazon DynamoDB",
13
- [DATABASE_SETUPS.DDB_ES]: "Amazon DynamoDB + Amazon Elasticsearch Service",
14
- [DATABASE_SETUPS.DDB_OS]: "Amazon DynamoDB + Amazon OpenSearch Service"
15
- };
16
-
17
- // In order to get the database setup, we check for existence of `elasticSearch`
18
- // or `openSearch` strings within the `apps/core/webiny.application.ts` file.
19
- const getDatabaseSetup = () => {
20
- const project = getProject();
21
- const webinyAppTsPath = path.join(project.root, "apps", "core", "webiny.application.ts");
22
-
23
- const webinyAppTs = fs.readFileSync(webinyAppTsPath, "utf8");
24
- if (webinyAppTs.includes("elasticSearch")) {
25
- return "ddb-es";
26
- }
27
-
28
- if (webinyAppTs.includes("openSearch")) {
29
- return "ddb-os";
30
- }
31
-
32
- return "ddb";
33
- };
34
-
35
- const getDatabaseSetupLabel = () => {
36
- const setup = getDatabaseSetup();
37
- return DATABASE_SETUPS_LABELS[setup];
38
- };
39
-
40
- module.exports = {
41
- getDatabaseSetup,
42
- getDatabaseSetupLabel,
43
- DATABASE_SETUPS,
44
- DATABASE_SETUPS_LABELS
45
- };
@@ -1,10 +0,0 @@
1
- const execa = require("execa");
2
-
3
- module.exports.getNpmVersion = async () => {
4
- try {
5
- const { stdout } = await execa("npm", ["--version"]);
6
- return stdout;
7
- } catch (err) {
8
- return "";
9
- }
10
- };
@@ -1,10 +0,0 @@
1
- const execa = require("execa");
2
-
3
- module.exports.getNpxVersion = async () => {
4
- try {
5
- const { stdout } = await execa("npx", ["--version"]);
6
- return stdout;
7
- } catch (err) {
8
- return "";
9
- }
10
- };
@@ -1,43 +0,0 @@
1
- const execa = require("execa");
2
-
3
- module.exports.getPulumiVersions = async () => {
4
- let pulumi, pulumiAws;
5
-
6
- try {
7
- {
8
- const { stdout } = await execa("yarn", [
9
- "info",
10
- "@pulumi/pulumi",
11
- "-A",
12
- "-R",
13
- "--name-only",
14
- "--json"
15
- ]);
16
-
17
- const match = stdout.match(/npm:(.*?)"/);
18
- if (match) {
19
- pulumi = match[1];
20
- }
21
- }
22
-
23
- {
24
- const { stdout } = await execa("yarn", [
25
- "info",
26
- "@pulumi/aws",
27
- "-A",
28
- "-R",
29
- "--name-only",
30
- "--json"
31
- ]);
32
-
33
- const match = stdout.match(/npm:(.*?)"/);
34
- if (match) {
35
- pulumiAws = match[1];
36
- }
37
- }
38
- } catch (err) {
39
- return "";
40
- }
41
-
42
- return [pulumi, pulumiAws];
43
- };
@@ -1,10 +0,0 @@
1
- const execa = require("execa");
2
-
3
- module.exports.getYarnVersion = async () => {
4
- try {
5
- const { stdout } = await execa("yarn", ["--version"]);
6
- return stdout;
7
- } catch (err) {
8
- return "";
9
- }
10
- };
@@ -1,97 +0,0 @@
1
- const NO_VALUE = "-";
2
- const isCI = require("is-ci");
3
-
4
- const getData = async context => {
5
- const { getUser } = require("../wcp/utils");
6
- const { getNpxVersion } = require("./getNpxVersion");
7
- const { getNpmVersion } = require("./getNpmVersion");
8
- const { getPulumiVersions } = require("./getPulumiVersions");
9
- const { getYarnVersion } = require("./getYarnVersion");
10
- const { getDatabaseSetupLabel } = require("./getDatabaseSetup");
11
-
12
- const [pulumiVersion, pulumiAwsVersion] = await getPulumiVersions();
13
-
14
- const wcpProjectId = process.env.WCP_PROJECT_ID;
15
- const wcpUser = await getUser().catch(() => null);
16
- const wcpUsingProjectEnvironmentApiKey = Boolean(process.env.WCP_ENVIRONMENT_API_KEY);
17
-
18
- return [
19
- {
20
- sectionName: "Webiny Project",
21
- data: {
22
- Name: context.project.name,
23
- Version: context.version,
24
- "Database Setup": getDatabaseSetupLabel(),
25
- "Debug Enabled": process.env.DEBUG === "true" ? "Yes" : "No",
26
- "Feature Flags": process.env.WEBINY_FEATURE_FLAGS || "N/A"
27
- }
28
- },
29
- {
30
- sectionName: "Webiny Control Panel (WCP)",
31
- data: {
32
- "Project ID": wcpProjectId,
33
- User: wcpUser?.email || "N/A",
34
- "Using Project Environment API Key": wcpUsingProjectEnvironmentApiKey ? "Yes" : "No"
35
- }
36
- },
37
- {
38
- sectionName: "Host",
39
- data: {
40
- OS: `${process.platform} (${process.arch})`,
41
- "Node.js": process.version,
42
- NPM: await getNpmVersion(),
43
- NPX: await getNpxVersion(),
44
- Yarn: await getYarnVersion(),
45
- "Is CI": isCI ? "Yes" : "No"
46
- }
47
- },
48
- {
49
- sectionName: "Pulumi",
50
- data: {
51
- "@pulumi/pulumi": pulumiVersion,
52
- "@pulumi/aws": pulumiAwsVersion,
53
- "Secrets Provider": process.env.PULUMI_SECRETS_PROVIDER,
54
- "Using Password": process.env.PULUMI_CONFIG_PASSPHRASE ? "Yes" : "No"
55
- }
56
- }
57
- ];
58
- };
59
-
60
- module.exports = {
61
- type: "cli-command",
62
- name: "cli-command-about",
63
- create({ yargs, context }) {
64
- yargs.command(
65
- "about",
66
- `Prints out information helpful for debugging purposes.`,
67
- yargs => {
68
- yargs.option("json", {
69
- describe: "Emit output as JSON.",
70
- type: "boolean",
71
- default: false
72
- });
73
- },
74
- async yargs => {
75
- const data = await getData(context);
76
-
77
- if (yargs.json) {
78
- console.log(JSON.stringify(data, null, 2));
79
- return;
80
- }
81
-
82
- data.forEach(({ sectionName, data }, index) => {
83
- if (index > 0) {
84
- console.log();
85
- }
86
-
87
- const { bold } = require("chalk");
88
- console.log(bold(sectionName));
89
-
90
- Object.keys(data).forEach(key => {
91
- console.log(key.padEnd(36), data[key] || NO_VALUE);
92
- });
93
- });
94
- }
95
- );
96
- }
97
- };
package/commands/index.js DELETED
@@ -1,21 +0,0 @@
1
- const about = require("./about");
2
- const run = require("./run");
3
- const telemetry = require("./telemetry");
4
- const upgrade = require("./upgrade");
5
-
6
- module.exports.createCommands = async (yargs, context) => {
7
- context.plugins.register(about, run, telemetry, upgrade);
8
-
9
- try {
10
- const wcp = require("./wcp");
11
- context.plugins.register(wcp);
12
- } catch {
13
- // Skip WCP command
14
- }
15
-
16
- await context.loadUserPlugins();
17
-
18
- context.plugins.byType("cli-command").forEach(plugin => {
19
- plugin.create({ yargs, context });
20
- });
21
- };
@@ -1,38 +0,0 @@
1
- module.exports = {
2
- type: "cli-command",
3
- name: "cli-command-run",
4
- create({ yargs, context }) {
5
- yargs.command(
6
- "run <command> [options]",
7
- `Run command defined in webiny.config.{js,ts}.\nNote: run from folder containing webiny.config.{js,ts} file.`,
8
- yargs => {
9
- yargs.positional("command", {
10
- describe: `Command to run in webiny.config.{js,ts}`,
11
- type: "string"
12
- });
13
- },
14
- async argv => {
15
- const camelCase = require("camelcase");
16
- const findUp = require("find-up");
17
- const path = require("path");
18
-
19
- const configFile = findUp.sync(["webiny.config.ts", "webiny.config.js"]);
20
- let config = context.import(configFile);
21
-
22
- const command = camelCase(argv.command);
23
- if (typeof config === "function") {
24
- config = config({
25
- options: { ...argv, cwd: path.dirname(configFile) },
26
- context
27
- });
28
- }
29
-
30
- if (config.commands && typeof config.commands[command] === "function") {
31
- return await config.commands[command]({ ...argv }, context);
32
- }
33
-
34
- throw Error(`Command "${command}" is not defined in "${configFile}"!`);
35
- }
36
- );
37
- }
38
- };
@@ -1,31 +0,0 @@
1
- module.exports = {
2
- type: "cli-command",
3
- name: "cli-command-telemetry",
4
- create({ yargs, context }) {
5
- yargs.command("enable-telemetry", "Enable anonymous telemetry.", async () => {
6
- const telemetry = require("@webiny/telemetry/cli");
7
-
8
- telemetry.enable();
9
- await telemetry.sendEvent({ event: "enable-telemetry" });
10
- context.info(
11
- `Webiny telemetry is now %s! Thank you for helping us in making Webiny better!`,
12
- "enabled"
13
- );
14
- context.info(
15
- `For more information, please visit the following link: https://www.webiny.com/telemetry.`
16
- );
17
- });
18
-
19
- yargs.command("disable-telemetry", "Disable anonymous telemetry.", async () => {
20
- const telemetry = require("@webiny/telemetry/cli");
21
-
22
- await telemetry.sendEvent({ event: "disable-telemetry" });
23
- telemetry.disable();
24
- context.info(`Webiny telemetry is now %s!`, "disabled");
25
- context.info(
26
- `Note that, in order to complete the process, you will also need to re-deploy your project, using the %s command.`,
27
- "yarn webiny deploy"
28
- );
29
- });
30
- }
31
- };