@webiny/cli 6.0.0-alpha.5 → 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 (50) hide show
  1. package/README.md +10 -6
  2. package/bin.js +9 -97
  3. package/files/duplicates.json +1 -1
  4. package/files/references.json +1 -1
  5. package/index.js +2 -4
  6. package/package.json +16 -56
  7. package/commands/about/getDatabaseSetup.js +0 -45
  8. package/commands/about/getNpmVersion.js +0 -5
  9. package/commands/about/getNpxVersion.js +0 -5
  10. package/commands/about/getPulumiVersions.js +0 -43
  11. package/commands/about/getYarnVersion.js +0 -5
  12. package/commands/about/index.js +0 -97
  13. package/commands/index.js +0 -21
  14. package/commands/run/index.js +0 -38
  15. package/commands/telemetry/index.js +0 -31
  16. package/commands/upgrade/index.js +0 -108
  17. package/commands/wcp/hooks.js +0 -133
  18. package/commands/wcp/index.js +0 -8
  19. package/commands/wcp/login.js +0 -228
  20. package/commands/wcp/logout.js +0 -28
  21. package/commands/wcp/project.js +0 -203
  22. package/commands/wcp/utils/getProjectEnvironment.js +0 -120
  23. package/commands/wcp/utils/getUser.js +0 -100
  24. package/commands/wcp/utils/getWcpOrgProjectId.js +0 -9
  25. package/commands/wcp/utils/getWcpPat.js +0 -5
  26. package/commands/wcp/utils/getWcpProjectId.js +0 -3
  27. package/commands/wcp/utils/index.js +0 -19
  28. package/commands/wcp/utils/setProjectId.js +0 -44
  29. package/commands/wcp/utils/setWcpPat.js +0 -5
  30. package/commands/wcp/utils/updateUserLastActiveOn.js +0 -28
  31. package/commands/wcp/whoami.js +0 -43
  32. package/context.js +0 -137
  33. package/files/README.md +0 -1
  34. package/index.d.ts +0 -5
  35. package/regions.d.ts +0 -6
  36. package/regions.js +0 -30
  37. package/types.d.ts +0 -234
  38. package/utils/PluginsContainer.js +0 -49
  39. package/utils/createProjectApplicationWorkspace.js +0 -16
  40. package/utils/getProject.js +0 -48
  41. package/utils/getProjectApplication.js +0 -83
  42. package/utils/importModule.js +0 -43
  43. package/utils/index.d.ts +0 -28
  44. package/utils/index.js +0 -28
  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
  49. package/utils/sleep.js +0 -3
  50. package/utils/sleepSync.js +0 -8
@@ -1,228 +0,0 @@
1
- const open = require("open");
2
- const { GraphQLClient } = require("graphql-request");
3
- const { setProjectId, setWcpPat } = require("./utils");
4
- const { sleep } = require("../../utils");
5
- const chalk = require("chalk");
6
- const { getWcpGqlApiUrl, getWcpAppUrl } = require("@webiny/wcp");
7
-
8
- // 120 retries * 2000ms interval = 4 minutes until the command returns an error.
9
- const LOGIN_RETRIES_COUNT = 30;
10
- const LOGIN_RETRIES_INTERVAL = 2000;
11
-
12
- const USER_PAT_FIELDS = /* GraphQL */ `
13
- fragment UserPatFields on UserPat {
14
- name
15
- meta
16
- token
17
- expiresOn
18
- user {
19
- email
20
- }
21
- }
22
- `;
23
-
24
- const GENERATE_USER_PAT = /* GraphQL */ `
25
- mutation GenerateUserPat {
26
- users {
27
- generateUserPat
28
- }
29
- }
30
- `;
31
-
32
- const GET_USER_PAT = /* GraphQL */ `
33
- ${USER_PAT_FIELDS}
34
- query GetUserPat($token: ID!) {
35
- users {
36
- getUserPat(token: $token) {
37
- ...UserPatFields
38
- }
39
- }
40
- }
41
- `;
42
-
43
- const CREATE_USER_PAT = /* GraphQL */ `
44
- ${USER_PAT_FIELDS}
45
- mutation CreateUserPat($expiresIn: Int, $token: ID, $data: CreateUserPatDataInput) {
46
- users {
47
- createUserPat(expiresIn: $expiresIn, token: $token, data: $data) {
48
- ...UserPatFields
49
- }
50
- }
51
- }
52
- `;
53
-
54
- module.exports.command = () => ({
55
- type: "cli-command",
56
- name: "cli-command-wcp-login",
57
- create({ yargs, context }) {
58
- yargs.command(
59
- "login [pat]",
60
- `Log in to the Webiny Control Panel`,
61
- yargs => {
62
- yargs.example("$0 login");
63
- yargs.positional("pat", {
64
- describe: `Personal access token (PAT)`,
65
- type: "string"
66
- });
67
- yargs.option("debug", {
68
- describe: `Turn on debug logs`,
69
- type: "boolean"
70
- });
71
- yargs.option("debug-level", {
72
- default: 1,
73
- describe: `Set the debug logs verbosity level`,
74
- type: "number"
75
- });
76
- },
77
- async ({ debug, debugLevel, pat: patFromParams }) => {
78
- const graphQLClient = new GraphQLClient(getWcpGqlApiUrl());
79
-
80
- let pat;
81
-
82
- if (patFromParams) {
83
- try {
84
- graphQLClient.setHeaders({ authorization: patFromParams });
85
- pat = await graphQLClient
86
- .request(GET_USER_PAT, { token: patFromParams })
87
- .then(({ users }) => users.getUserPat);
88
-
89
- // If we've received a PAT that has expiration, let's create a long-lived PAT.
90
- // We don't want to have our users interrupted because of an expired PAT.
91
- if (pat.expiresOn) {
92
- pat = await graphQLClient
93
- .request(CREATE_USER_PAT, { data: { meta: pat.meta } })
94
- .then(({ users }) => users.createUserPat);
95
- }
96
- } catch (e) {
97
- if (debug) {
98
- context.debug(
99
- `Could not use the provided %s PAT because of the following error:`,
100
- patFromParams
101
- );
102
- console.debug(e);
103
- }
104
-
105
- throw new Error(
106
- `Invalid PAT received. Please try again or login manually via the ${context.error.hl(
107
- "yarn webiny login"
108
- )} command.`
109
- );
110
- }
111
- } else {
112
- const generatedPat = await graphQLClient
113
- .request(GENERATE_USER_PAT)
114
- .then(({ users }) => users.generateUserPat);
115
-
116
- const queryParams = `pat=${generatedPat}&pat_name=${encodeURIComponent(
117
- "Webiny CLI"
118
- )}&ref=cli`;
119
- const openUrl = `${getWcpAppUrl()}/login/cli?${queryParams}`;
120
-
121
- debug && context.debug(`Opening %s...`, openUrl);
122
- await open(openUrl);
123
-
124
- const graphql = {
125
- variables: { token: generatedPat },
126
- headers: {
127
- Authorization: generatedPat
128
- }
129
- };
130
-
131
- graphQLClient.setHeaders(graphql.headers);
132
-
133
- let retries = 0;
134
- const result = await new Promise(resolve => {
135
- const interval = setInterval(async () => {
136
- retries++;
137
- if (retries > LOGIN_RETRIES_COUNT) {
138
- clearInterval(interval);
139
- resolve(null);
140
- }
141
-
142
- try {
143
- const pat = await graphQLClient
144
- .request(GET_USER_PAT, graphql.variables)
145
- .then(({ users }) => users.getUserPat);
146
-
147
- clearInterval(interval);
148
- resolve(pat);
149
- } catch (e) {
150
- // Do nothing.
151
- if (debug) {
152
- context.debug(
153
- `Could not login. Will try again in ${LOGIN_RETRIES_INTERVAL}ms.`
154
- );
155
- if (debugLevel > 1) {
156
- context.debug("GraphQL Request: ");
157
- console.log(JSON.stringify(graphql, null, 2));
158
- }
159
- if (debugLevel > 2) {
160
- context.debug(e.message);
161
- }
162
- }
163
- }
164
- }, LOGIN_RETRIES_INTERVAL);
165
- });
166
-
167
- if (!result) {
168
- throw new Error(
169
- `Could not login. Did you complete the sign in / sign up process at ${getWcpAppUrl()}?`
170
- );
171
- }
172
-
173
- pat = result;
174
- }
175
-
176
- setWcpPat(pat.token);
177
-
178
- console.log(
179
- `${chalk.green("✔")} You've successfully logged in to Webiny Control Panel.`
180
- );
181
-
182
- let projectInitialized = Boolean(
183
- context.project.config.id || process.env.WCP_PROJECT_ID
184
- );
185
-
186
- // If we have `orgId` and `projectId` in PAT's metadata, let's immediately link the project.
187
- if (pat.meta && pat.meta.orgId && pat.meta.projectId) {
188
- await sleep();
189
-
190
- console.log();
191
-
192
- const { orgId, projectId } = pat.meta;
193
-
194
- const id = `${orgId}/${projectId}`;
195
- console.log(`Project ${chalk.green(id)} detected. Linking...`);
196
-
197
- await sleep();
198
-
199
- await setProjectId({
200
- project: context.project,
201
- orgId,
202
- projectId
203
- });
204
-
205
- console.log(`Project ${context.success.hl(id)} linked successfully.`);
206
- projectInitialized = true;
207
- }
208
-
209
- await sleep();
210
-
211
- console.log();
212
- console.log(chalk.bold("Next Steps"));
213
-
214
- if (!projectInitialized) {
215
- console.log(
216
- `‣ link your project via the ${chalk.green(
217
- "yarn webiny project link"
218
- )} command`
219
- );
220
- }
221
-
222
- console.log(
223
- `‣ deploy your project via the ${chalk.green("yarn webiny deploy")} command`
224
- );
225
- }
226
- );
227
- }
228
- });
@@ -1,28 +0,0 @@
1
- const { setWcpPat } = require("./utils");
2
-
3
- module.exports.command = () => ({
4
- type: "cli-command",
5
- name: "cli-command-wcp-logout",
6
- create({ yargs }) {
7
- yargs.command(
8
- "logout",
9
- `Log out from the Webiny Control Panel`,
10
- yargs => {
11
- yargs.example("$0 logout");
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 () => {
23
- setWcpPat(null);
24
- console.log(`You've successfully logged out from Webiny Control Panel.`);
25
- }
26
- );
27
- }
28
- });
@@ -1,203 +0,0 @@
1
- const open = require("open");
2
- const inquirer = require("inquirer");
3
- const chalk = require("chalk");
4
- const { getUser, WCP_APP_URL, setProjectId } = require("./utils");
5
- const { sleep } = require("../../utils");
6
-
7
- module.exports.command = () => [
8
- {
9
- type: "cli-command",
10
- name: "cli-command-wcp-project",
11
- create({ yargs, context }) {
12
- yargs.command(
13
- ["project <command>"],
14
- `Webiny project-related commands`,
15
- projectCommand => {
16
- projectCommand.command(
17
- "link",
18
- `Link a Webiny project with Webiny Control Panel (WCP)`,
19
- command => {
20
- yargs.option("debug", {
21
- describe: `Turn on debug logs`,
22
- type: "boolean"
23
- });
24
- yargs.option("debug-level", {
25
- default: 1,
26
- describe: `Set the debug logs verbosity level`,
27
- type: "number"
28
- });
29
- command.example("$0 project link");
30
- },
31
- () => handler({ context })
32
- );
33
-
34
- projectCommand.command(
35
- "init",
36
- `Initialize a Webiny project (deprecated, please use the link command instead)`,
37
- command => {
38
- yargs.option("debug", {
39
- describe: `Turn on debug logs`,
40
- type: "boolean"
41
- });
42
- yargs.option("debug-level", {
43
- default: 1,
44
- describe: `Set the debug logs verbosity level`,
45
- type: "number"
46
- });
47
- command.example("$0 project init");
48
- },
49
- () => handler({ context })
50
- );
51
- }
52
- );
53
- }
54
- }
55
- ];
56
-
57
- const handler = async ({ context }) => {
58
- // Check login.
59
- const user = await getUser();
60
-
61
- // User already linked a project?
62
- const { id: orgProjectId } = context.project.config;
63
- if (orgProjectId) {
64
- const [, projectId] = orgProjectId.split("/");
65
- const project = user.projects.find(item => item.id === projectId);
66
- if (project) {
67
- console.log(`Your ${chalk.green(orgProjectId)} project has already been linked.`);
68
-
69
- const prompt = inquirer.createPromptModule();
70
- const { proceed } = await prompt({
71
- name: "proceed",
72
- message: "Would you like to re-initialize it?",
73
- type: "confirm",
74
- default: false
75
- });
76
-
77
- if (!proceed) {
78
- return;
79
- }
80
-
81
- console.log();
82
- }
83
- }
84
-
85
- // Get user's organizations.
86
- if (!user.orgs.length) {
87
- console.log(
88
- "It seems you're not part of any organization. Please log in to Webiny Control Panel and create one."
89
- );
90
-
91
- const prompt = inquirer.createPromptModule();
92
- const { proceed } = await prompt({
93
- name: "proceed",
94
- message: "Would you like to do that now?",
95
- type: "confirm",
96
- default: false
97
- });
98
-
99
- if (proceed) {
100
- await open(WCP_APP_URL);
101
- }
102
- return;
103
- }
104
-
105
- let selectedOrg;
106
- if (user.orgs.length === 1) {
107
- selectedOrg = user.orgs[0];
108
- } else {
109
- console.log("It seems you're part of multiple organizations. ");
110
- const choices = user.orgs.map(item => ({
111
- name: item.name,
112
- value: item
113
- }));
114
-
115
- const prompt = inquirer.createPromptModule();
116
- selectedOrg = await prompt({
117
- name: "org",
118
- message: "Select organization:",
119
- type: "list",
120
- choices,
121
- default: choices[0].value
122
- }).then(result => result.org);
123
- }
124
-
125
- const orgProjects = user.projects.filter(item => item.org.id === selectedOrg.id);
126
-
127
- // Get user's projects.
128
- if (!orgProjects.length) {
129
- console.log(
130
- `It seems there are no projects created within the ${chalk.green(
131
- selectedOrg.name
132
- )} organization.`
133
- );
134
-
135
- const prompt = inquirer.createPromptModule();
136
- const { proceed } = await prompt({
137
- name: "proceed",
138
- message: "Would you like to create one now?",
139
- type: "confirm",
140
- default: false
141
- });
142
-
143
- if (proceed) {
144
- await open(WCP_APP_URL);
145
- }
146
- return;
147
- }
148
-
149
- let selectedProject;
150
- if (orgProjects.length === 1) {
151
- selectedProject = user.projects[0];
152
- } else {
153
- console.log(
154
- `It seems there are multiple projects created within the ${chalk.green(
155
- selectedOrg.name
156
- )} organization.`
157
- );
158
- const choices = orgProjects.map(item => ({
159
- name: item.name,
160
- value: item
161
- }));
162
- const prompt = inquirer.createPromptModule();
163
- selectedProject = await prompt({
164
- name: "project",
165
- message: "Select project:",
166
- type: "list",
167
- choices,
168
- default: choices[0].value
169
- }).then(result => result.project);
170
- }
171
-
172
- const orgId = selectedOrg.id,
173
- projectId = selectedProject.id;
174
-
175
- await sleep();
176
- console.log();
177
-
178
- console.log(`Initializing ${context.success.hl(selectedProject.name)} project...`);
179
-
180
- await sleep();
181
-
182
- // Assign the necessary IDs into root `webiny.project.ts` project file.
183
- await setProjectId({
184
- project: context.project,
185
- orgId,
186
- projectId
187
- });
188
-
189
- console.log(
190
- `${chalk.green("✔")} Project ${context.success.hl(
191
- selectedProject.name
192
- )} linked successfully.`
193
- );
194
-
195
- await sleep();
196
-
197
- console.log();
198
- console.log(chalk.bold("Next Steps"));
199
-
200
- console.log(`‣ deploy your project via the ${chalk.green("yarn webiny deploy")} command`);
201
- };
202
-
203
- 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
- };