@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,19 +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
-
10
- module.exports = {
11
- getUser,
12
- getProjectEnvironment,
13
- updateUserLastActiveOn,
14
- setProjectId,
15
- setWcpPat,
16
- getWcpPat,
17
- getWcpProjectId,
18
- getWcpOrgProjectId
19
- };
@@ -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,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/files/README.md DELETED
@@ -1 +0,0 @@
1
- Do not manually create files in this folder. This folder is used to store the files that are generated by the CLI.
package/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import {CliContext} from "./types";
2
-
3
- export * from "./regions"
4
-
5
- export declare const cli: CliContext;
package/regions.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export interface RegionValue {
2
- name: string;
3
- value: string;
4
- }
5
-
6
- export declare const regions: RegionValue[];
package/regions.js DELETED
@@ -1,30 +0,0 @@
1
- const regions = [
2
- { value: "us-east-1", name: "us-east-1 (US East, N. Virginia)" },
3
- { value: "us-east-2", name: "us-east-2 (US East, Ohio)" },
4
- { value: "us-west-1", name: "us-west-1 (US West, N. California)" },
5
- { value: "us-west-2", name: "us-west-2 (US West, Oregon)" },
6
- { value: "ca-central-1", name: "ca-central-1 (Canada, Central)" },
7
- { value: "eu-central-1", name: "eu-central-1 (EU, Frankfurt)" },
8
- { value: "eu-west-1", name: "eu-west-1 (EU, Ireland)" },
9
- { value: "eu-west-2", name: "eu-west-2 (EU, London)" },
10
- /**
11
- * This was commented out because cognito was not available in this region in 2021.
12
- * TODO - uncomment and test it out
13
- */
14
- /*{ value: "eu-south-1", name: "eu-south-1 (EU, Milan)" },*/
15
- { value: "eu-west-3", name: "eu-west-3 (EU, Paris)" },
16
- { value: "eu-north-1", name: "eu-north-1 (EU, Stockholm)" },
17
- { value: "af-south-1", name: "af-south-1 (Africa, Cape Town)" },
18
- { value: "ap-east-1", name: "ap-east-1 (Asia Pacific, Hong Kong)" },
19
- { value: "ap-south-1", name: "ap-south-1 (Asia Pacific, Mumbai)" },
20
- { value: "ap-northeast-2", name: "ap-northeast-2 (Asia Pacific, Seoul)" },
21
- { value: "ap-southeast-1", name: "ap-southeast-1 (Asia Pacific, Singapore)" },
22
- { value: "ap-southeast-2", name: "ap-southeast-2 (Asia Pacific, Sydney)" },
23
- { value: "ap-northeast-1", name: "ap-northeast-1 (Asia Pacific, Tokyo)" },
24
- // { value: "me-south-1", name: "me-south-1 (Middle East, Bahrain)" },
25
- { value: "sa-east-1", name: "sa-east-1 (South America, São Paulo)" }
26
- ];
27
-
28
- module.exports = {
29
- regions
30
- };
package/types.d.ts DELETED
@@ -1,234 +0,0 @@
1
- import type yargs from "yargs";
2
-
3
- /**
4
- * Rename file to types.ts when switching the package to Typescript.
5
- */
6
- export type GenericRecord<K extends PropertyKey = PropertyKey, V = any> = Record<K, V>;
7
-
8
- export type NonEmptyArray<T> = [T, ...T[]];
9
-
10
- /**
11
- * A simplified plugins container interface, used specifically within the Webiny CLI.
12
- * Not in relation with "@webiny/plugins" package.
13
- */
14
- export interface PluginsContainer {
15
- register(...args: any[]): void;
16
- byType<T extends Plugin>(type: T["type"]): T[];
17
-
18
- byName<T extends Plugin>(name: T["name"]): T;
19
- }
20
-
21
- /**
22
- * A simplified plugin interface, used specifically within the Webiny CLI.
23
- * Not in relation with "@webiny/plugins" package.
24
- */
25
- export interface Plugin {
26
- type: string;
27
- name?: string;
28
-
29
- [key: string]: any;
30
- }
31
-
32
- interface Project {
33
- /**
34
- * Name of the project.
35
- */
36
- name: string;
37
- /**
38
- * Configurations.
39
- */
40
- config: {
41
- appAliases: {
42
- [key: string]: string;
43
- }
44
- [key: string]: any;
45
- };
46
- /**
47
- * Root path of the project.
48
- */
49
- root: string;
50
- }
51
-
52
-
53
- export interface IProjectApplicationPackage {
54
- name: string;
55
- paths: {
56
- root: string;
57
- relative: string;
58
- packageJson: string;
59
- config: string;
60
- };
61
- packageJson: Record<string, any>;
62
- get config(): any;
63
- }
64
-
65
- export interface IProjectApplicationConfigCli {
66
- watch?: boolean;
67
- }
68
-
69
- export interface IProjectApplicationConfig {
70
- appAliases?: Record<string, string>;
71
- cli?: IProjectApplicationConfigCli;
72
- [key: string]: unknown
73
- }
74
-
75
- export interface ProjectApplication {
76
- /**
77
- * Unique ID of the project application.
78
- */
79
- id: string;
80
- /**
81
- * Name of the project application.
82
- */
83
- name: string;
84
- /**
85
- * Description of the project application.
86
- */
87
- description: string;
88
- /**
89
- * Type of the project application.
90
- */
91
- type: string;
92
- /**
93
- * Root path of the project application.
94
- */
95
- root: string;
96
- /**
97
- * Commonly used paths.
98
- */
99
- paths: {
100
- relative: string;
101
- absolute: string;
102
- workspace: string;
103
- };
104
- /**
105
- * Project application config (exported via `webiny.application.ts` file).
106
- */
107
- config: IProjectApplicationConfig;
108
- /**
109
- * Project application package.json.
110
- */
111
- project: Project;
112
-
113
- /**
114
- * A list of all the packages in the project application.
115
- */
116
- get packages(): IProjectApplicationPackage[];
117
- }
118
-
119
- /**
120
- * A type that represents the logging method.
121
- */
122
- interface Log {
123
- (...args: any): string;
124
-
125
- hl: (...args: any) => string;
126
- highlight: (...args: any) => string;
127
- }
128
-
129
- /**
130
- * Interface representing the CLI Context.
131
- */
132
- export interface CliContext {
133
- /**
134
- * All registered plugins.
135
- */
136
- plugins: PluginsContainer;
137
- /**
138
- * Load environment variables from a given file.
139
- */
140
- loadEnv(filePath: string, options?: {debug?: boolean}): Promise<void>;
141
- /**
142
- * All the environment variables.
143
- */
144
- loadedEnvFiles: Record<string, any>;
145
- /**
146
- * Version of the Webiny CLI.
147
- */
148
- version: string;
149
- /**
150
- * Project information.
151
- */
152
- project: Project;
153
- /**
154
- * Trigger given callback on SIGINT.
155
- */
156
- onExit: (cb: () => any) => void;
157
- /**
158
- * Import a given module.
159
- */
160
- import: (module: string) => Promise<void>;
161
- /**
162
- * Regular logging.
163
- */
164
- log: Log;
165
- /**
166
- * Info logging.
167
- */
168
- info: Log;
169
- /**
170
- * Success logging.
171
- */
172
- success: Log;
173
- /**
174
- * Debug logging.
175
- */
176
- debug: Log;
177
- /**
178
- * Warnings logging.
179
- */
180
- warning: Log;
181
- /**
182
- * Errors logging.
183
- */
184
- error: Log;
185
- /**
186
- * Resolve given dir or dirs against project root path.
187
- */
188
- resolve: (dir: string) => string;
189
-
190
- /**
191
- * Provides a way to store some metadata in the project's local ".webiny/cli.json" file.
192
- * Only trivial data should be passed here, specific to the current project.
193
- */
194
- localStorage: {
195
- set: (key: string, value: any) => Record<string, any>;
196
- get: (key: string) => any;
197
- };
198
- }
199
-
200
- /**
201
- * Arguments for CliPlugin.create
202
- *
203
- * @category Cli
204
- */
205
- export interface CliCommandPluginArgs {
206
- yargs: typeof yargs;
207
- context: CliContext;
208
- }
209
-
210
- /**
211
- * A plugin defining cli-command type.
212
- *
213
- * @category Plugin
214
- * @category Cli
215
- */
216
- export interface CliCommandPlugin extends Plugin {
217
- type: "cli-command";
218
- name: string;
219
- create: (args: CliCommandPluginArgs) => void;
220
- }
221
-
222
- export interface CliCommandErrorPluginHandleParams {
223
- context: CliContext;
224
- error: Error;
225
- }
226
-
227
- export interface CliCommandErrorPluginHandle {
228
- (params: CliCommandErrorPluginHandleParams):void;
229
- }
230
-
231
- export interface CliCommandErrorPlugin extends Plugin {
232
- type: "cli-command-error";
233
- handle: CliCommandErrorPluginHandle;
234
- }
@@ -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
- };
@@ -1,16 +0,0 @@
1
- const util = require("util");
2
- const fs = require("fs-extra");
3
- const ncpBase = require("ncp");
4
- const ncp = util.promisify(ncpBase.ncp);
5
-
6
- module.exports = async projectApplication => {
7
- if (await fs.pathExists(projectApplication.paths.workspace)) {
8
- await fs.remove(projectApplication.paths.workspace);
9
- }
10
-
11
- await fs.ensureDir(projectApplication.paths.workspace);
12
- await ncp(projectApplication.paths.absolute, projectApplication.paths.workspace);
13
-
14
- // Wait a bit and make sure the files are ready to have its content replaced.
15
- return new Promise(resolve => setTimeout(resolve, 10));
16
- };
@@ -1,48 +0,0 @@
1
- const findUp = require("find-up");
2
- const { dirname } = require("path");
3
- const { importModule } = require("./importModule");
4
-
5
- const projectConfigs = ["webiny.project.js", "webiny.project.ts"];
6
-
7
- function getRoot({ cwd } = {}) {
8
- let root = findUp.sync(projectConfigs, { cwd });
9
- if (root) {
10
- return dirname(root).replace(/\\/g, "/");
11
- }
12
-
13
- // For backwards compatibility
14
- root = findUp.sync("webiny.root.js", { cwd });
15
- if (root) {
16
- return dirname(root).replace(/\\/g, "/");
17
- }
18
-
19
- throw new Error("Couldn't detect Webiny project.");
20
- }
21
-
22
- function getConfig({ cwd } = {}) {
23
- let path = findUp.sync(projectConfigs, { cwd });
24
- if (path) {
25
- return importModule(path);
26
- }
27
-
28
- path = findUp.sync("webiny.root.js", { cwd });
29
- if (path) {
30
- return require(path);
31
- }
32
-
33
- throw new Error("Couldn't detect Webiny project.");
34
- }
35
-
36
- module.exports = args => {
37
- const root = getRoot(args);
38
- return {
39
- get name() {
40
- // Check "projectName" for backwards compatibility.
41
- return process.env.WEBINY_PROJECT_NAME || this.config.projectName || this.config.name;
42
- },
43
- root,
44
- get config() {
45
- return getConfig(args);
46
- }
47
- };
48
- };