@webiny/cli 0.0.0-unstable.de38392959 → 0.0.0-unstable.df7a8bb475

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 -54
  7. package/utils/ensureSameWebinyPackageVersions.js +99 -0
  8. package/utils/suppressPunycodeWarnings.js +7 -0
  9. package/cli.js +0 -86
  10. package/commands/about/getNpxVersion.js +0 -10
  11. package/commands/about/getPulumiVersions.js +0 -43
  12. package/commands/about/getYarnVersion.js +0 -10
  13. package/commands/about/index.js +0 -93
  14. package/commands/index.js +0 -21
  15. package/commands/run/index.js +0 -38
  16. package/commands/telemetry/index.js +0 -29
  17. package/commands/upgrade/index.js +0 -108
  18. package/commands/wcp/hooks.js +0 -133
  19. package/commands/wcp/index.js +0 -8
  20. package/commands/wcp/login.js +0 -227
  21. package/commands/wcp/logout.js +0 -28
  22. package/commands/wcp/project.js +0 -202
  23. package/commands/wcp/utils/getProjectEnvironment.js +0 -120
  24. package/commands/wcp/utils/getUser.js +0 -100
  25. package/commands/wcp/utils/getWcpOrgProjectId.js +0 -9
  26. package/commands/wcp/utils/getWcpPat.js +0 -5
  27. package/commands/wcp/utils/getWcpProjectId.js +0 -3
  28. package/commands/wcp/utils/index.js +0 -21
  29. package/commands/wcp/utils/setProjectId.js +0 -44
  30. package/commands/wcp/utils/setWcpPat.js +0 -5
  31. package/commands/wcp/utils/sleep.js +0 -1
  32. package/commands/wcp/utils/updateUserLastActiveOn.js +0 -28
  33. package/commands/wcp/whoami.js +0 -43
  34. package/context.js +0 -137
  35. package/index.d.ts +0 -3
  36. package/types.d.ts +0 -113
  37. package/utils/PluginsContainer.js +0 -49
  38. package/utils/createProjectApplicationWorkspace.js +0 -16
  39. package/utils/getApiProjectApplicationFolder.js +0 -12
  40. package/utils/getProject.js +0 -48
  41. package/utils/getProjectApplication.js +0 -87
  42. package/utils/importModule.js +0 -43
  43. package/utils/index.d.ts +0 -1
  44. package/utils/index.js +0 -26
  45. package/utils/loadEnvVariables.js +0 -54
  46. package/utils/localStorage.js +0 -44
  47. package/utils/log.js +0 -67
  48. package/utils/sendEvent.js +0 -15
@@ -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
- });
package/context.js DELETED
@@ -1,137 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const { importModule, getProject, PluginsContainer, log, localStorage, noop } = require("./utils");
4
-
5
- const project = getProject();
6
-
7
- if (!project) {
8
- console.log(
9
- `🚨 Couldn't locate "webiny.project.js"! Webiny CLI relies on that file to find the root of a Webiny project.`
10
- );
11
- process.exit(1);
12
- }
13
-
14
- class Context {
15
- constructor() {
16
- this.loadedEnvFiles = {};
17
-
18
- this.version = require("./package.json").version;
19
- this.project = project;
20
-
21
- // Check if `projectName` was injected properly.
22
- if (this.project.name === "[PROJECT_NAME]") {
23
- console.log(
24
- [
25
- "",
26
- "🚨 IMPORTANT 🚨",
27
- "Looks like your project was not bootstrapped correctly! We recommend creating a new project from scratch.",
28
- "If you see errors during project creation, please report them to us:",
29
- "🔗 Github:\thttps://github.com/webiny/webiny-js",
30
- "🔗 Slack:\thttps://www.webiny.com/slack",
31
- ""
32
- ].join("\n")
33
- );
34
- process.exit(1);
35
- }
36
-
37
- this.plugins = new PluginsContainer();
38
-
39
- this.localStorage = localStorage();
40
-
41
- this.onExitCallbacks = [];
42
-
43
- let onExitProcessed = false;
44
- process.on("SIGINT", async () => {
45
- if (onExitProcessed) {
46
- return;
47
- }
48
-
49
- onExitProcessed = true;
50
-
51
- for (let i = 0; i < this.onExitCallbacks.length; i++) {
52
- await this.onExitCallbacks[i]("SIGINT");
53
- }
54
-
55
- process.exit(1);
56
- });
57
- }
58
-
59
- onExit(callback) {
60
- this.onExitCallbacks.push(callback);
61
- }
62
-
63
- import(name) {
64
- return importModule(name);
65
- }
66
-
67
- async loadUserPlugins() {
68
- if (this.project.config.cli) {
69
- let plugins = this.project.config.cli.plugins || [];
70
- if (typeof plugins === "function") {
71
- plugins = await plugins();
72
- }
73
-
74
- this.plugins.register(
75
- ...plugins.map(plugin => {
76
- if (typeof plugin === "string") {
77
- let loadedPlugin;
78
- try {
79
- loadedPlugin = require(path.join(this.project.root, plugin)); // Try loading the package from the project's root
80
- } catch {
81
- // If it fails, perhaps the user still has the package installed somewhere locally...
82
- loadedPlugin = require(plugin);
83
- }
84
- return loadedPlugin;
85
- }
86
- return plugin;
87
- })
88
- );
89
- }
90
- }
91
-
92
- log = log.log;
93
- info = log.info;
94
- success = log.success;
95
- debug = process.argv.some(v => v.match("--debug")) ? log.debug : noop;
96
- warning = log.warning;
97
- error = log.error;
98
-
99
- resolve(...dir) {
100
- return path.resolve(this.project.root, ...dir);
101
- }
102
-
103
- replaceProjectRoot(path) {
104
- return path.replace(this.project.root, "<projectRoot>").replace(/\\/g, "/");
105
- }
106
-
107
- /**
108
- * Uses `dotenv` lib to load env files, by accepting a simple file path.
109
- * @param filePath
110
- * @param debug
111
- * @returns {Promise<void>}
112
- */
113
- async loadEnv(filePath, { debug = false } = {}) {
114
- if (this.loadedEnvFiles[filePath]) {
115
- return;
116
- }
117
-
118
- if (!fs.existsSync(filePath)) {
119
- debug && this.debug(`No environment file found on %s.`, filePath);
120
- return;
121
- }
122
-
123
- try {
124
- require("dotenv").config({ path: filePath });
125
- debug && this.success(`Loaded environment variables from ${filePath}.`);
126
- this.loadedEnvFiles[filePath] = true;
127
- } catch (err) {
128
- if (debug) {
129
- this.error(`Could not load env variables from ${filePath}:`);
130
- this.error(err.message);
131
- console.log();
132
- }
133
- }
134
- }
135
- }
136
-
137
- module.exports = new Context();
package/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { CliContext } from "./types";
2
-
3
- export declare const cli: CliContext;
package/types.d.ts DELETED
@@ -1,113 +0,0 @@
1
- /**
2
- * Rename file to types.ts when switching the package to Typescript.
3
- */
4
-
5
- /**
6
- * A simplified plugins container interface, used specifically within the Webiny CLI.
7
- * Not in relation with "@webiny/plugins" package.
8
- */
9
- export interface PluginsContainer {
10
- byType<T extends Plugin>(type: T["type"]): T[];
11
- byName<T extends Plugin>(name: T["name"]): T;
12
- }
13
-
14
- /**
15
- * A simplified plugin interface, used specifically within the Webiny CLI.
16
- * Not in relation with "@webiny/plugins" package.
17
- */
18
- export interface Plugin {
19
- type: string;
20
- name?: string;
21
- [key: string]: any;
22
- }
23
-
24
- interface Project {
25
- /**
26
- * Name of the project.
27
- */
28
- name: string;
29
- /**
30
- * Configurations.
31
- */
32
- config: Record<string, any>;
33
- /**
34
- * Root path of the project.
35
- */
36
- root: string;
37
- }
38
-
39
- /**
40
- * A type that represents the logging method.
41
- */
42
- interface Log {
43
- (...args: any): string;
44
- hl: (...args: any) => string;
45
- highlight: (...args: any) => string;
46
- }
47
-
48
- /**
49
- * Interface representing the CLI Context.
50
- */
51
- export interface CliContext {
52
- /**
53
- * All registered plugins.
54
- */
55
- plugins: PluginsContainer;
56
- /**
57
- * All the environment variables.
58
- */
59
- loadedEnvFiles: Record<string, any>;
60
- /**
61
- * Version of the Webiny CLI.
62
- */
63
- version: string;
64
- /**
65
- * Project information.
66
- */
67
- project: Project;
68
- /**
69
- * Trigger given callback on SIGINT.
70
- */
71
- onExit: (cb: () => any) => void;
72
- /**
73
- * Import a given module.
74
- */
75
- import: (module: string) => Promise<void>;
76
- /**
77
- * Regular logging.
78
- */
79
- log: Log;
80
- /**
81
- * Info logging.
82
- */
83
- info: Log;
84
- /**
85
- * Success logging.
86
- */
87
- success: Log;
88
- /**
89
- * Debug logging.
90
- */
91
- debug: Log;
92
- /**
93
- * Warnings logging.
94
- */
95
- warning: Log;
96
- /**
97
- * Errors logging.
98
- */
99
- error: Log;
100
- /**
101
- * Resolve given dir or dirs against project root path.
102
- */
103
- resolve: (dir: string) => string;
104
-
105
- /**
106
- * Provides a way to store some meta data in the project's local ".webiny/cli.json" file.
107
- * Only trivial data should be passed here, specific to the current project.
108
- */
109
- localStorage: {
110
- set: (key: string, value: string) => Record<string, any>;
111
- get: (key: string) => any;
112
- };
113
- }
@@ -1,49 +0,0 @@
1
- const uniqid = require("uniqid");
2
-
3
- // Since the Webiny CLI can rely on "@webiny/plugins" package (chicken-egg problem), then
4
- // we need to make a copy of its PluginsContainer class. We removed all of the extra
5
- // features that are in reality not needed for the Webiny CLI.
6
- const assign = (plugins, target) => {
7
- for (let i = 0; i < plugins.length; i++) {
8
- const plugin = plugins[i];
9
- if (Array.isArray(plugin)) {
10
- assign(plugin, target);
11
- continue;
12
- }
13
-
14
- let name = plugin._name || plugin.name;
15
- if (!name) {
16
- plugin.name = name = uniqid(plugin.type + "-");
17
- }
18
-
19
- target[name] = plugin;
20
- }
21
- };
22
-
23
- module.exports = class PluginsContainer {
24
- plugins = {};
25
- constructor(...args) {
26
- this.register(...args);
27
- }
28
-
29
- byName(name) {
30
- return this.plugins[name];
31
- }
32
-
33
- byType(type) {
34
- const plugins = this.findByType(type);
35
- return Array.from(plugins);
36
- }
37
-
38
- findByType(type) {
39
- return Object.values(this.plugins).filter(pl => pl.type === type);
40
- }
41
-
42
- register(...args) {
43
- assign(args, this.plugins);
44
- }
45
-
46
- unregister(name) {
47
- delete this.plugins[name];
48
- }
49
- };