@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
@@ -1,202 +0,0 @@
1
- const open = require("open");
2
- const inquirer = require("inquirer");
3
- const chalk = require("chalk");
4
- const { getUser, WCP_APP_URL, setProjectId, sleep } = require("./utils");
5
-
6
- module.exports.command = () => [
7
- {
8
- type: "cli-command",
9
- name: "cli-command-wcp-project",
10
- create({ yargs, context }) {
11
- yargs.command(
12
- ["project <command>"],
13
- `Webiny project-related commands`,
14
- projectCommand => {
15
- projectCommand.command(
16
- "link",
17
- `Link a Webiny project with Webiny Control Panel (WCP)`,
18
- command => {
19
- yargs.option("debug", {
20
- describe: `Turn on debug logs`,
21
- type: "boolean"
22
- });
23
- yargs.option("debug-level", {
24
- default: 1,
25
- describe: `Set the debug logs verbosity level`,
26
- type: "number"
27
- });
28
- command.example("$0 project link");
29
- },
30
- () => handler({ context })
31
- );
32
-
33
- projectCommand.command(
34
- "init",
35
- `Initialize a Webiny project (deprecated, please use the link command instead)`,
36
- command => {
37
- yargs.option("debug", {
38
- describe: `Turn on debug logs`,
39
- type: "boolean"
40
- });
41
- yargs.option("debug-level", {
42
- default: 1,
43
- describe: `Set the debug logs verbosity level`,
44
- type: "number"
45
- });
46
- command.example("$0 project init");
47
- },
48
- () => handler({ context })
49
- );
50
- }
51
- );
52
- }
53
- }
54
- ];
55
-
56
- const handler = async ({ context }) => {
57
- // Check login.
58
- const user = await getUser();
59
-
60
- // User already linked a project?
61
- const { id: orgProjectId } = context.project.config;
62
- if (orgProjectId) {
63
- const [, projectId] = orgProjectId.split("/");
64
- const project = user.projects.find(item => item.id === projectId);
65
- if (project) {
66
- console.log(`Your ${chalk.green(orgProjectId)} project has already been linked.`);
67
-
68
- const prompt = inquirer.createPromptModule();
69
- const { proceed } = await prompt({
70
- name: "proceed",
71
- message: "Would you like to re-initialize it?",
72
- type: "confirm",
73
- default: false
74
- });
75
-
76
- if (!proceed) {
77
- return;
78
- }
79
-
80
- console.log();
81
- }
82
- }
83
-
84
- // Get user's organizations.
85
- if (!user.orgs.length) {
86
- console.log(
87
- "It seems you're not part of any organization. Please log in to Webiny Control Panel and create one."
88
- );
89
-
90
- const prompt = inquirer.createPromptModule();
91
- const { proceed } = await prompt({
92
- name: "proceed",
93
- message: "Would you like to do that now?",
94
- type: "confirm",
95
- default: false
96
- });
97
-
98
- if (proceed) {
99
- await open(WCP_APP_URL);
100
- }
101
- return;
102
- }
103
-
104
- let selectedOrg;
105
- if (user.orgs.length === 1) {
106
- selectedOrg = user.orgs[0];
107
- } else {
108
- console.log("It seems you're part of multiple organizations. ");
109
- const choices = user.orgs.map(item => ({
110
- name: item.name,
111
- value: item
112
- }));
113
-
114
- const prompt = inquirer.createPromptModule();
115
- selectedOrg = await prompt({
116
- name: "org",
117
- message: "Select organization:",
118
- type: "list",
119
- choices,
120
- default: choices[0].value
121
- }).then(result => result.org);
122
- }
123
-
124
- const orgProjects = user.projects.filter(item => item.org.id === selectedOrg.id);
125
-
126
- // Get user's projects.
127
- if (!orgProjects.length) {
128
- console.log(
129
- `It seems there are no projects created within the ${chalk.green(
130
- selectedOrg.name
131
- )} organization.`
132
- );
133
-
134
- const prompt = inquirer.createPromptModule();
135
- const { proceed } = await prompt({
136
- name: "proceed",
137
- message: "Would you like to create one now?",
138
- type: "confirm",
139
- default: false
140
- });
141
-
142
- if (proceed) {
143
- await open(WCP_APP_URL);
144
- }
145
- return;
146
- }
147
-
148
- let selectedProject;
149
- if (orgProjects.length === 1) {
150
- selectedProject = user.projects[0];
151
- } else {
152
- console.log(
153
- `It seems there are multiple projects created within the ${chalk.green(
154
- selectedOrg.name
155
- )} organization.`
156
- );
157
- const choices = orgProjects.map(item => ({
158
- name: item.name,
159
- value: item
160
- }));
161
- const prompt = inquirer.createPromptModule();
162
- selectedProject = await prompt({
163
- name: "project",
164
- message: "Select project:",
165
- type: "list",
166
- choices,
167
- default: choices[0].value
168
- }).then(result => result.project);
169
- }
170
-
171
- const orgId = selectedOrg.id,
172
- projectId = selectedProject.id;
173
-
174
- await sleep();
175
- console.log();
176
-
177
- console.log(`Initializing ${context.success.hl(selectedProject.name)} project...`);
178
-
179
- await sleep();
180
-
181
- // Assign the necessary IDs into root `webiny.project.ts` project file.
182
- await setProjectId({
183
- project: context.project,
184
- orgId,
185
- projectId
186
- });
187
-
188
- console.log(
189
- `${chalk.green("✔")} Project ${context.success.hl(
190
- selectedProject.name
191
- )} linked successfully.`
192
- );
193
-
194
- await sleep();
195
-
196
- console.log();
197
- console.log(chalk.bold("Next Steps"));
198
-
199
- console.log(`‣ deploy your project via the ${chalk.green("yarn webiny deploy")} command`);
200
- };
201
-
202
- module.exports.handler = handler;
@@ -1,120 +0,0 @@
1
- const { localStorage, log } = require("@webiny/cli/utils");
2
- const { request } = require("graphql-request");
3
- const { getWcpGqlApiUrl } = require("@webiny/wcp");
4
-
5
- const ENVIRONMENT_FIELDS = /* GraphQL */ `
6
- fragment EnvironmentFields on Environment {
7
- id
8
- status
9
- name
10
- apiKey
11
- org {
12
- id
13
- name
14
- }
15
- project {
16
- id
17
- name
18
- }
19
- user {
20
- id
21
- email
22
- }
23
- }
24
- `;
25
-
26
- const CREATE_ENVIRONMENT = /* GraphQL */ `
27
- ${ENVIRONMENT_FIELDS}
28
- mutation CreateEnvironment(
29
- $orgId: ID!
30
- $projectId: ID!
31
- $userId: ID
32
- $data: CreateEnvironmentDataInput!
33
- ) {
34
- projects {
35
- createEnvironment(orgId: $orgId, projectId: $projectId, userId: $userId, data: $data) {
36
- ...EnvironmentFields
37
- }
38
- }
39
- }
40
- `;
41
-
42
- const GET_ENVIRONMENT = /* GraphQL */ `
43
- ${ENVIRONMENT_FIELDS}
44
- query GetEnvironment(
45
- $environmentId: ID
46
- $orgId: ID
47
- $projectId: ID
48
- $userId: ID
49
- $apiKey: String
50
- ) {
51
- projects {
52
- getEnvironment(
53
- environmentId: $environmentId
54
- orgId: $orgId
55
- projectId: $projectId
56
- userId: $userId
57
- apiKey: $apiKey
58
- ) {
59
- ...EnvironmentFields
60
- }
61
- }
62
- }
63
- `;
64
-
65
- module.exports.getProjectEnvironment = async ({
66
- orgId,
67
- projectId,
68
- userId,
69
- environmentId,
70
- apiKey
71
- }) => {
72
- if (apiKey) {
73
- return request(getWcpGqlApiUrl(), GET_ENVIRONMENT, { apiKey })
74
- .then(response => response.projects.getEnvironment)
75
- .catch(() => {
76
- throw new Error(
77
- `It seems the API key you provided is incorrect or disabled. Please double check the API key and try again.`
78
- );
79
- });
80
- }
81
-
82
- const pat = localStorage().get("wcpPat");
83
- if (!pat) {
84
- throw new Error(
85
- `It seems you are not logged in. Please login using the ${log.error.hl(
86
- "webiny login"
87
- )} command.`
88
- );
89
- }
90
-
91
- const headers = { authorization: pat };
92
- return request(
93
- getWcpGqlApiUrl(),
94
- GET_ENVIRONMENT,
95
- {
96
- orgId,
97
- projectId,
98
- userId,
99
- environmentId,
100
- apiKey
101
- },
102
- headers
103
- )
104
- .then(async response => response.projects.getEnvironment)
105
- .catch(() => {
106
- return request(
107
- getWcpGqlApiUrl(),
108
- CREATE_ENVIRONMENT,
109
- {
110
- orgId,
111
- projectId,
112
- userId,
113
- data: {
114
- name: environmentId
115
- }
116
- },
117
- headers
118
- ).then(async response => response.projects.createEnvironment);
119
- });
120
- };
@@ -1,100 +0,0 @@
1
- const { log } = require("@webiny/cli/utils");
2
- const { request } = require("graphql-request");
3
- const { getWcpPat } = require("./getWcpPat");
4
- const { getWcpGqlApiUrl } = require("@webiny/wcp");
5
-
6
- const GET_CURRENT_USER = /* GraphQL */ `
7
- query GetUser {
8
- users {
9
- getCurrentUser {
10
- id
11
- email
12
- firstName
13
- lastName
14
- }
15
- }
16
- }
17
- `;
18
-
19
- const LIST_ORGS = /* GraphQL */ `
20
- query ListOrgs {
21
- orgs {
22
- listOrgs {
23
- data {
24
- id
25
- name
26
- }
27
- }
28
- }
29
- }
30
- `;
31
-
32
- const LIST_PROJECTS = /* GraphQL */ `
33
- query ListProjects($orgId: ID!) {
34
- projects {
35
- listProjects(orgId: $orgId) {
36
- data {
37
- id
38
- name
39
- org {
40
- id
41
- name
42
- }
43
- }
44
- }
45
- }
46
- }
47
- `;
48
-
49
- let user;
50
- module.exports.getUser = async () => {
51
- if (user) {
52
- return user;
53
- }
54
-
55
- const pat = getWcpPat();
56
- if (!pat) {
57
- throw new Error(
58
- `It seems you are not logged into your WCP project. Please log in using the ${log.error.hl(
59
- "yarn webiny login"
60
- )} command. If you are not using WCP, make sure you don't have an "id" property in your "webiny.project.ts" file.`
61
- );
62
- }
63
-
64
- try {
65
- const headers = { authorization: pat };
66
- user = await request(getWcpGqlApiUrl(), GET_CURRENT_USER, {}, headers).then(
67
- async response => {
68
- const user = response.users.getCurrentUser;
69
-
70
- const orgs = await request(getWcpGqlApiUrl(), LIST_ORGS, {}, headers).then(
71
- async response => {
72
- const orgs = response.orgs.listOrgs.data;
73
- for (let i = 0; i < orgs.length; i++) {
74
- const org = orgs[i];
75
- org.projects = await request(
76
- getWcpGqlApiUrl(),
77
- LIST_PROJECTS,
78
- { orgId: org.id },
79
- headers
80
- ).then(response => response.projects.listProjects.data);
81
- }
82
- return orgs;
83
- }
84
- );
85
-
86
- const projects = orgs.map(org => org.projects).flat();
87
-
88
- return { ...user, orgs, projects };
89
- }
90
- );
91
- } catch {
92
- throw new Error(
93
- `It seems the personal access token is incorrect or does not exist. Please log out and log in again using the ${log.error.hl(
94
- "yarn webiny login"
95
- )} command.`
96
- );
97
- }
98
-
99
- return user;
100
- };
@@ -1,9 +0,0 @@
1
- const { getWcpProjectId } = require("./getWcpProjectId");
2
-
3
- module.exports.getWcpOrgProjectId = context => {
4
- const id = getWcpProjectId(context);
5
- if (typeof id === "string") {
6
- return id.split("/");
7
- }
8
- return [];
9
- };
@@ -1,5 +0,0 @@
1
- const { localStorage } = require("@webiny/cli/utils");
2
-
3
- module.exports.getWcpPat = wcpPat => {
4
- return localStorage().get("wcpPat", wcpPat);
5
- };
@@ -1,3 +0,0 @@
1
- module.exports.getWcpProjectId = context => {
2
- return context?.project?.config?.id || process.env.WCP_PROJECT_ID || "";
3
- };
@@ -1,21 +0,0 @@
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
- const { sleep } = require("./sleep");
10
-
11
- module.exports = {
12
- getUser,
13
- getProjectEnvironment,
14
- updateUserLastActiveOn,
15
- setProjectId,
16
- setWcpPat,
17
- getWcpPat,
18
- getWcpProjectId,
19
- getWcpOrgProjectId,
20
- sleep
21
- };
@@ -1,44 +0,0 @@
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
- };
@@ -1,5 +0,0 @@
1
- const { localStorage } = require("@webiny/cli/utils");
2
-
3
- module.exports.setWcpPat = wcpPat => {
4
- localStorage().set("wcpPat", wcpPat);
5
- };
@@ -1 +0,0 @@
1
- module.exports.sleep = () => new Promise(resolve => setTimeout(resolve, 1500));
@@ -1,28 +0,0 @@
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
- };
@@ -1,43 +0,0 @@
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
- });