@webiny/cli 0.0.0-mt-3 → 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
@@ -0,0 +1,19 @@
1
+ const { getUser } = require("./getUser");
2
+ const { getProjectEnvironment } = require("./getProjectEnvironment");
3
+ const { updateUserLastActiveOn } = require("./updateUserLastActiveOn");
4
+ const { setProjectId } = require("./setProjectId");
5
+ const { setWcpPat } = require("./setWcpPat");
6
+ const { getWcpPat } = require("./getWcpPat");
7
+ const { getWcpProjectId } = require("./getWcpProjectId");
8
+ const { getWcpOrgProjectId } = require("./getWcpOrgProjectId");
9
+
10
+ module.exports = {
11
+ getUser,
12
+ getProjectEnvironment,
13
+ updateUserLastActiveOn,
14
+ setProjectId,
15
+ setWcpPat,
16
+ getWcpPat,
17
+ getWcpProjectId,
18
+ getWcpOrgProjectId
19
+ };
@@ -0,0 +1,44 @@
1
+ const path = require("path");
2
+ const tsMorph = require("ts-morph");
3
+ const { log } = require("@webiny/cli/utils");
4
+
5
+ module.exports.setProjectId = async ({ project, orgId, projectId }) => {
6
+ // Assign the necessary IDs into root `webiny.project.ts` project file.
7
+ const webinyProjectPath = path.join(project.root, "webiny.project.ts");
8
+
9
+ const tsMorphProject = new tsMorph.Project();
10
+ tsMorphProject.addSourceFileAtPath(webinyProjectPath);
11
+
12
+ const source = tsMorphProject.getSourceFile(webinyProjectPath);
13
+
14
+ const defaultExport = source.getFirstDescendant(node => {
15
+ if (tsMorph.Node.isExportAssignment(node) === false) {
16
+ return false;
17
+ }
18
+ return node.getText().startsWith("export default ");
19
+ });
20
+
21
+ if (!defaultExport) {
22
+ throw new Error(
23
+ `Could not find the default export in ${log.error.hl("webiny.project.ts")}.`
24
+ );
25
+ }
26
+
27
+ // Get ObjectLiteralExpression within the default export and assign the `id` property to it.
28
+ const exportedObjectLiteral = defaultExport.getFirstDescendant(
29
+ node => tsMorph.Node.isObjectLiteralExpression(node) === true
30
+ );
31
+
32
+ const existingIdProperty = exportedObjectLiteral.getProperty(node => {
33
+ return tsMorph.Node.isPropertyAssignment(node) && node.getName() === "id";
34
+ });
35
+
36
+ const fullId = `${orgId}/${projectId}`;
37
+ if (tsMorph.Node.isPropertyAssignment(existingIdProperty)) {
38
+ existingIdProperty.setInitializer(`"${fullId}"`);
39
+ } else {
40
+ exportedObjectLiteral.insertProperty(0, `id: "${fullId}"`);
41
+ }
42
+
43
+ await tsMorphProject.save();
44
+ };
@@ -0,0 +1,5 @@
1
+ const { localStorage } = require("@webiny/cli/utils");
2
+
3
+ module.exports.setWcpPat = wcpPat => {
4
+ localStorage().set("wcpPat", wcpPat);
5
+ };
@@ -0,0 +1,28 @@
1
+ const { request } = require("graphql-request");
2
+ const { localStorage, log } = require("@webiny/cli/utils");
3
+ const { getWcpGqlApiUrl } = require("@webiny/wcp");
4
+
5
+ const UPDATE_LAST_ACTIVE_TO_NOW = /* GraphQL */ `
6
+ mutation UpdateLastActiveToNow {
7
+ users {
8
+ updateLastActiveToNow {
9
+ id
10
+ lastActiveOn
11
+ }
12
+ }
13
+ }
14
+ `;
15
+
16
+ module.exports.updateUserLastActiveOn = async () => {
17
+ const pat = localStorage().get("wcpPat");
18
+ if (!pat) {
19
+ throw new Error(
20
+ `It seems you are not logged in. Please login using the ${log.error.hl(
21
+ "webiny login"
22
+ )} command.`
23
+ );
24
+ }
25
+
26
+ const headers = { authorization: pat };
27
+ return request(getWcpGqlApiUrl(), UPDATE_LAST_ACTIVE_TO_NOW, {}, headers);
28
+ };
@@ -0,0 +1,43 @@
1
+ const { getUser } = require("./utils");
2
+
3
+ module.exports.command = () => ({
4
+ type: "cli-command",
5
+ name: "cli-command-wcp-whoami",
6
+ create({ yargs, context }) {
7
+ yargs.command(
8
+ "whoami",
9
+ `Display the current logged-in user`,
10
+ yargs => {
11
+ yargs.example("$0 whoami");
12
+ yargs.option("debug", {
13
+ describe: `Turn on debug logs`,
14
+ type: "boolean"
15
+ });
16
+ yargs.option("debug-level", {
17
+ default: 1,
18
+ describe: `Set the debug logs verbosity level`,
19
+ type: "number"
20
+ });
21
+ },
22
+ async ({ debug }) => {
23
+ try {
24
+ const user = await getUser();
25
+ console.log(
26
+ `You are logged in to Webiny Control Panel as ${context.info.hl(
27
+ user.email
28
+ )}.`
29
+ );
30
+ } catch (e) {
31
+ if (debug) {
32
+ context.debug(e);
33
+ }
34
+ throw new Error(
35
+ `It seems you are not logged in. Please login using the ${context.error.hl(
36
+ "webiny login"
37
+ )} command.`
38
+ );
39
+ }
40
+ }
41
+ );
42
+ }
43
+ });
package/context.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const fs = require("fs");
2
2
  const path = require("path");
3
- const { importModule, getProject, PluginsContainer, log, localStorage } = require("./utils");
3
+ const { importModule, getProject, PluginsContainer, log, localStorage, noop } = require("./utils");
4
4
 
5
5
  const project = getProject();
6
6
 
@@ -92,7 +92,7 @@ class Context {
92
92
  log = log.log;
93
93
  info = log.info;
94
94
  success = log.success;
95
- debug = log.debug;
95
+ debug = process.argv.some(v => v.match("--debug")) ? log.debug : noop;
96
96
  warning = log.warning;
97
97
  error = log.error;
98
98
 
@@ -116,7 +116,7 @@ class Context {
116
116
  }
117
117
 
118
118
  if (!fs.existsSync(filePath)) {
119
- debug && this.debug(`No environment file found on ${this.debug.hl(filePath)}.`);
119
+ debug && this.debug(`No environment file found on %s.`, filePath);
120
120
  return;
121
121
  }
122
122
 
@@ -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
+ []