@webiny/cli 0.0.0-mt-2 → 0.0.0-unstable.06b2ede40f

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 (50) hide show
  1. package/README.md +1 -1
  2. package/bin.js +94 -27
  3. package/commands/about/getDatabaseSetup.js +45 -0
  4. package/commands/about/getNpmVersion.js +5 -0
  5. package/commands/about/getNpxVersion.js +5 -0
  6. package/commands/about/getPulumiVersions.js +43 -0
  7. package/commands/about/getYarnVersion.js +5 -0
  8. package/commands/about/index.js +97 -0
  9. package/commands/index.js +9 -1
  10. package/commands/run/index.js +12 -4
  11. package/commands/telemetry/index.js +9 -9
  12. package/commands/upgrade/index.js +6 -5
  13. package/commands/wcp/hooks.js +133 -0
  14. package/commands/wcp/index.js +8 -0
  15. package/commands/wcp/login.js +228 -0
  16. package/commands/wcp/logout.js +28 -0
  17. package/commands/wcp/project.js +203 -0
  18. package/commands/wcp/utils/getProjectEnvironment.js +120 -0
  19. package/commands/wcp/utils/getUser.js +100 -0
  20. package/commands/wcp/utils/getWcpOrgProjectId.js +9 -0
  21. package/commands/wcp/utils/getWcpPat.js +5 -0
  22. package/commands/wcp/utils/getWcpProjectId.js +3 -0
  23. package/commands/wcp/utils/index.js +19 -0
  24. package/commands/wcp/utils/setProjectId.js +44 -0
  25. package/commands/wcp/utils/setWcpPat.js +5 -0
  26. package/commands/wcp/utils/updateUserLastActiveOn.js +28 -0
  27. package/commands/wcp/whoami.js +43 -0
  28. package/context.js +3 -3
  29. package/files/README.md +1 -0
  30. package/files/duplicates.json +1 -0
  31. package/files/references.json +1 -0
  32. package/index.d.ts +5 -0
  33. package/index.js +5 -0
  34. package/package.json +22 -15
  35. package/regions.d.ts +6 -0
  36. package/regions.js +30 -0
  37. package/types.d.ts +120 -35
  38. package/utils/createProjectApplicationWorkspace.js +16 -0
  39. package/utils/ensureSameWebinyPackageVersions.js +99 -0
  40. package/utils/getProjectApplication.js +27 -7
  41. package/utils/index.d.ts +28 -0
  42. package/utils/index.js +13 -2
  43. package/utils/loadEnvVariables.js +63 -0
  44. package/utils/log.js +15 -17
  45. package/utils/sendEvent.js +2 -6
  46. package/utils/sleep.js +3 -0
  47. package/utils/sleepSync.js +8 -0
  48. package/utils/suppressPunycodeWarnings.js +7 -0
  49. package/CHANGELOG.md +0 -2896
  50. package/cli.js +0 -107
package/README.md CHANGED
@@ -4,4 +4,4 @@
4
4
  [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
5
5
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
6
6
 
7
- A pluggable tool to run commands within a Webiny project.
7
+ A pluggable tool to run commands within a Webiny project.
package/bin.js CHANGED
@@ -1,36 +1,103 @@
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, "^12 || ^14")) {
11
- console.error(
12
- chalk.red(
13
- "You are running Node " +
14
- currentNodeVersion +
15
- ".\n" +
16
- "Webiny requires Node ^12 or ^14. \n" +
17
- "Please update your version of Node."
18
- )
19
- );
20
- process.exit(1);
21
- }
6
+ // Ensure system requirements are met.
7
+ require("@webiny/system-requirements").ensureSystemRequirements();
8
+
9
+ // Detect different Webiny package versions.
10
+ require("./utils/ensureSameWebinyPackageVersions").ensureSameWebinyPackageVersions();
11
+
12
+ const yargs = require("yargs");
13
+
14
+ // Disable help processing until after plugins are imported.
15
+ yargs.help(false);
16
+
17
+ // Loads environment variables from multiple sources.
18
+ require("./utils/loadEnvVariables");
19
+
20
+ const { blue, red, bold, bgYellow } = require("chalk");
21
+ const context = require("./context");
22
+ const { createCommands } = require("./commands");
23
+
24
+ yargs
25
+ .usage("Usage: $0 <command> [options]")
26
+ .demandCommand(1)
27
+ .recommendCommands()
28
+ .scriptName("webiny")
29
+ .epilogue(
30
+ `To find more information, docs and tutorials, see ${blue("https://www.webiny.com/docs")}.`
31
+ )
32
+ .epilogue(`Want to contribute? ${blue("https://github.com/webiny/webiny-js")}.`)
33
+ .fail(function (msg, error, yargs) {
34
+ if (msg) {
35
+ if (msg.includes("Not enough non-option arguments")) {
36
+ console.log();
37
+ context.error(red("Command was not invoked as expected!"));
38
+ context.info(
39
+ `Some non-optional arguments are missing. See the usage examples printed below.`
40
+ );
41
+ console.log();
42
+ yargs.showHelp();
43
+ return;
44
+ }
45
+
46
+ if (msg.includes("Missing required argument")) {
47
+ const args = msg
48
+ .split(":")[1]
49
+ .split(",")
50
+ .map(v => v.trim());
51
+
52
+ console.log();
53
+ context.error(red("Command was not invoked as expected!"));
54
+ context.info(
55
+ `Missing required argument(s): ${args
56
+ .map(arg => red(arg))
57
+ .join(", ")}. See the usage examples printed below.`
58
+ );
59
+ console.log();
60
+ yargs.showHelp();
61
+ return;
62
+ }
63
+ console.log();
64
+ context.error(red("Command execution was aborted!"));
65
+ context.error(msg);
66
+ console.log();
22
67
 
23
- try {
24
- const { stdout } = await execa("yarn", ["--version"]);
25
- if (!semver.satisfies(stdout, "^2||^3")) {
26
- console.error(chalk.red(`"@webiny/cli" requires yarn ^2 or ^3 to be installed!`));
27
68
  process.exit(1);
28
69
  }
29
- } catch (err) {
30
- console.error(chalk.red(`"@webiny/cli" requires yarn ^2 or ^3 to be installed!`));
31
- console.log(`Please visit https://yarnpkg.com/ to install "yarn".`);
70
+
71
+ console.log();
72
+ // Unfortunately, yargs doesn't provide passed args here, so we had to do it via process.argv.
73
+ const debugEnabled = process.argv.includes("--debug");
74
+ if (debugEnabled) {
75
+ context.debug(error);
76
+ } else {
77
+ context.error(error.message);
78
+ }
79
+
80
+ const gracefulError = error.cause?.gracefulError;
81
+ if (gracefulError instanceof Error) {
82
+ console.log();
83
+ console.log(bgYellow(bold("💡 How can I resolve this?")));
84
+ console.log(gracefulError.message);
85
+ }
86
+
87
+ const plugins = context.plugins.byType("cli-command-error");
88
+ for (let i = 0; i < plugins.length; i++) {
89
+ const plugin = plugins[i];
90
+ plugin.handle({
91
+ error,
92
+ context
93
+ });
94
+ }
95
+
32
96
  process.exit(1);
33
- }
97
+ });
34
98
 
35
- require("./cli");
99
+ (async () => {
100
+ await createCommands(yargs, context);
101
+ // Enable help and run the CLI.
102
+ yargs.help().argv;
36
103
  })();
@@ -0,0 +1,45 @@
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
+ };
@@ -0,0 +1,5 @@
1
+ const { SystemRequirements } = require("@webiny/system-requirements");
2
+
3
+ module.exports.getNpmVersion = async () => {
4
+ return SystemRequirements.getNpmVersion();
5
+ };
@@ -0,0 +1,5 @@
1
+ const { SystemRequirements } = require("@webiny/system-requirements");
2
+
3
+ module.exports.getNpxVersion = async () => {
4
+ return SystemRequirements.getNpxVersion();
5
+ };
@@ -0,0 +1,43 @@
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
+ };
@@ -0,0 +1,5 @@
1
+ const { SystemRequirements } = require("@webiny/system-requirements");
2
+
3
+ module.exports.getYarnVersion = async () => {
4
+ return SystemRequirements.getYarnVersion();
5
+ };
@@ -0,0 +1,97 @@
1
+ const NO_VALUE = "-";
2
+ const { isCI } = require("ci-info");
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 CHANGED
@@ -1,9 +1,17 @@
1
+ const about = require("./about");
1
2
  const run = require("./run");
2
3
  const telemetry = require("./telemetry");
3
4
  const upgrade = require("./upgrade");
4
5
 
5
6
  module.exports.createCommands = async (yargs, context) => {
6
- context.plugins.register(run, telemetry, upgrade);
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
+ }
7
15
 
8
16
  await context.loadUserPlugins();
9
17
 
@@ -1,6 +1,3 @@
1
- const camelCase = require("camelcase");
2
- const findUp = require("find-up");
3
-
4
1
  module.exports = {
5
2
  type: "cli-command",
6
3
  name: "cli-command-run",
@@ -15,10 +12,21 @@ module.exports = {
15
12
  });
16
13
  },
17
14
  async argv => {
15
+ const camelCase = require("camelcase");
16
+ const findUp = require("find-up");
17
+ const path = require("path");
18
+
18
19
  const configFile = findUp.sync(["webiny.config.ts", "webiny.config.js"]);
19
- const config = context.import(configFile);
20
+ let config = context.import(configFile);
20
21
 
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
+
22
30
  if (config.commands && typeof config.commands[command] === "function") {
23
31
  return await config.commands[command]({ ...argv }, context);
24
32
  }
@@ -1,16 +1,15 @@
1
- const telemetry = require("@webiny/telemetry/cli");
2
-
3
1
  module.exports = {
4
2
  type: "cli-command",
5
3
  name: "cli-command-telemetry",
6
4
  create({ yargs, context }) {
7
5
  yargs.command("enable-telemetry", "Enable anonymous telemetry.", async () => {
6
+ const telemetry = require("@webiny/telemetry/cli");
7
+
8
8
  telemetry.enable();
9
9
  await telemetry.sendEvent({ event: "enable-telemetry" });
10
10
  context.info(
11
- `Webiny telemetry is now ${context.info.hl(
12
- "enabled"
13
- )}! Thank you for helping us in making Webiny better!`
11
+ `Webiny telemetry is now %s! Thank you for helping us in making Webiny better!`,
12
+ "enabled"
14
13
  );
15
14
  context.info(
16
15
  `For more information, please visit the following link: https://www.webiny.com/telemetry.`
@@ -18,13 +17,14 @@ module.exports = {
18
17
  });
19
18
 
20
19
  yargs.command("disable-telemetry", "Disable anonymous telemetry.", async () => {
20
+ const telemetry = require("@webiny/telemetry/cli");
21
+
21
22
  await telemetry.sendEvent({ event: "disable-telemetry" });
22
23
  telemetry.disable();
23
- context.info(`Webiny telemetry is now ${context.info.hl("disabled")}!`);
24
+ context.info(`Webiny telemetry is now %s!`, "disabled");
24
25
  context.info(
25
- `Note that, in order to complete the process, you will also need to re-deploy your project, using the ${context.info.hl(
26
- "yarn webiny deploy"
27
- )} command.`
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
28
  );
29
29
  });
30
30
  }
@@ -1,7 +1,3 @@
1
- const { red } = require("chalk");
2
- const execa = require("execa");
3
- const semver = require("semver");
4
-
5
1
  module.exports = [
6
2
  {
7
3
  type: "cli-command",
@@ -29,6 +25,10 @@ module.exports = [
29
25
  });
30
26
  },
31
27
  async argv => {
28
+ const { red } = require("chalk");
29
+ const execa = require("execa");
30
+ const semver = require("semver");
31
+
32
32
  if (!argv.skipChecks) {
33
33
  // Before doing any upgrading, there must not be any active changes in the current branch.
34
34
  let gitStatus = "";
@@ -70,7 +70,8 @@ module.exports = [
70
70
  const npx = execa("npx", command, {
71
71
  env: {
72
72
  FORCE_COLOR: true
73
- }
73
+ },
74
+ stdin: process.stdin
74
75
  });
75
76
 
76
77
  npx.stdout.on("data", data => {
@@ -0,0 +1,133 @@
1
+ const { encrypt, decrypt } = require("@webiny/wcp");
2
+ const { getUser, getProjectEnvironment, updateUserLastActiveOn } = require("./utils");
3
+
4
+ /**
5
+ * The two environment variables we set via these hooks are the following:
6
+ * - WCP_PROJECT_ENVIRONMENT - contains encrypted data about the deployed project environment
7
+ * - WCP_PROJECT_ENVIRONMENT_API_KEY - for easier access, we also set the API key
8
+ */
9
+
10
+ /**
11
+ * There are multiple ways the hooks below prepare the WCP-enabled project for deployment.
12
+ * 1. If `WCP_PROJECT_ENVIRONMENT` metadata env var is defined, we decrypt it, retrieve the
13
+ * API key from it, and assign it as the `WCP_PROJECT_ENVIRONMENT_API_KEY` env var.
14
+ * 2. If `WCP_PROJECT_ENVIRONMENT_API_KEY` env var is defined, then we use that as the
15
+ * project environment API key. We use that to load the project environment data
16
+ * and to also assign the `WCP_PROJECT_ENVIRONMENT` metadata env var.
17
+ * 3. If none of the above is defined, we retrieve (or create) the project environment,
18
+ * retrieve its API key and again assign it as `WCP_PROJECT_ENVIRONMENT_API_KEY` env var.
19
+ * As in 2), we also assign the `WCP_PROJECT_ENVIRONMENT` metadata env var.
20
+ */
21
+
22
+ let projectEnvironment;
23
+
24
+ const getEnvironmentHookHandler = async (args, context) => {
25
+ // If the project isn't linked with WCP, do nothing.
26
+ const wcpProjectId = context.project.config.id || process.env.WCP_PROJECT_ID;
27
+ if (!wcpProjectId) {
28
+ return;
29
+ }
30
+
31
+ // For development purposes, we allow setting the WCP_PROJECT_ENVIRONMENT env var directly.
32
+ if (process.env.WCP_PROJECT_ENVIRONMENT) {
33
+ // If we have WCP_PROJECT_ENVIRONMENT env var, we set the WCP_PROJECT_ENVIRONMENT_API_KEY too.
34
+ const decryptedProjectEnvironment = decrypt(process.env.WCP_PROJECT_ENVIRONMENT);
35
+ process.env.WCP_PROJECT_ENVIRONMENT_API_KEY = decryptedProjectEnvironment.apiKey;
36
+ return;
37
+ }
38
+
39
+ // The `id` has the orgId/projectId structure, for example `my-org-x/my-project-y`.
40
+ const [orgId, projectId] = wcpProjectId.split("/");
41
+
42
+ const apiKey = process.env.WCP_PROJECT_ENVIRONMENT_API_KEY;
43
+
44
+ let projectEnvironment;
45
+ if (apiKey) {
46
+ projectEnvironment = await getProjectEnvironment({ apiKey });
47
+ } else {
48
+ const isValidId = orgId && projectId;
49
+ if (!isValidId) {
50
+ throw new Error(
51
+ `It seems the project ID, specified in "webiny.project.ts" file, is invalid.`
52
+ );
53
+ }
54
+
55
+ // If there is no API key, that means we need to retrieve the currently logged-in user.
56
+ const user = await getUser();
57
+ const project = user.projects.find(item => item.id === projectId);
58
+ if (!project) {
59
+ throw new Error(
60
+ `It seems you don't belong to the current project or the current project has been deleted.`
61
+ );
62
+ }
63
+
64
+ projectEnvironment = await getProjectEnvironment({
65
+ orgId,
66
+ projectId,
67
+ userId: user.id,
68
+ environmentId: args.env
69
+ });
70
+ }
71
+
72
+ if (projectEnvironment.org.id !== orgId) {
73
+ throw new Error(
74
+ `Cannot proceed with the deployment because the "${projectEnvironment.name}" project environment doesn't belong to the "${orgId}" organization. Please check your WCP project ID (currently set to "${wcpProjectId}").`
75
+ );
76
+ }
77
+
78
+ if (projectEnvironment.project.id !== projectId) {
79
+ throw new Error(
80
+ `Cannot proceed with the deployment because the "${projectEnvironment.name}" project environment doesn't belong to the "${wcpProjectId}" project. Please check your WCP project ID (currently set to "${wcpProjectId}").`
81
+ );
82
+ }
83
+
84
+ if (projectEnvironment && projectEnvironment.status !== "enabled") {
85
+ throw new Error(
86
+ `Cannot proceed with the deployment because the "${projectEnvironment.name}" project environment has been disabled.`
87
+ );
88
+ }
89
+
90
+ // Assign `WCP_PROJECT_ENVIRONMENT` and `WCP_PROJECT_ENVIRONMENT_API_KEY`
91
+ const wcpProjectEnvironment = {
92
+ id: projectEnvironment.id,
93
+ apiKey: projectEnvironment.apiKey,
94
+ org: { id: projectEnvironment.org.id },
95
+ project: { id: projectEnvironment.project.id }
96
+ };
97
+
98
+ process.env.WCP_PROJECT_ENVIRONMENT = encrypt(wcpProjectEnvironment);
99
+ process.env.WCP_PROJECT_ENVIRONMENT_API_KEY = projectEnvironment.apiKey;
100
+ };
101
+
102
+ const updateLastActiveOnHookHandler = async () => {
103
+ if (!projectEnvironment) {
104
+ return;
105
+ }
106
+
107
+ // Is this a user environment? If so, let's update his "last active" field.
108
+ if (projectEnvironment.user) {
109
+ await updateUserLastActiveOn();
110
+ }
111
+ };
112
+
113
+ // Export hooks plugins for deploy and watch commands.
114
+ module.exports = () => [
115
+ // Deploy hook handlers.
116
+ {
117
+ type: "hook-before-deploy",
118
+ name: "hook-before-deploy-environment-get-environment",
119
+ hook: getEnvironmentHookHandler
120
+ },
121
+ {
122
+ type: "hook-before-deploy",
123
+ name: "hook-before-deploy-update-last-active-on",
124
+ hook: updateLastActiveOnHookHandler
125
+ },
126
+
127
+ // Watch hook handlers.
128
+ {
129
+ type: "hook-before-watch",
130
+ name: "hook-before-watch-environment-get-environment",
131
+ hook: getEnvironmentHookHandler
132
+ }
133
+ ];
@@ -0,0 +1,8 @@
1
+ const { command: login } = require("./login");
2
+ const { command: logout } = require("./logout");
3
+ const { command: whoami } = require("./whoami");
4
+ const { command: project } = require("./project");
5
+
6
+ const hooks = require("./hooks");
7
+
8
+ module.exports = [login(), logout(), whoami(), project(), hooks()];