@webiny/cli 0.0.0-unstable.fcdad0bc61 → 0.0.0-unstable.fdd9228b5d

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.
package/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
- import { CliContext } from "./types";
1
+ import {CliContext} from "./types";
2
+
3
+ export * from "./regions"
2
4
 
3
5
  export declare const cli: CliContext;
package/index.js CHANGED
@@ -1,3 +1,5 @@
1
1
  const context = require("./context");
2
+ const regions = require("./regions");
2
3
 
3
4
  module.exports.cli = context;
5
+ module.exports.regions = regions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/cli",
3
- "version": "0.0.0-unstable.fcdad0bc61",
3
+ "version": "0.0.0-unstable.fdd9228b5d",
4
4
  "main": "index.js",
5
5
  "bin": {
6
6
  "webiny": "./bin.js"
@@ -13,26 +13,28 @@
13
13
  "author": "Pavel Denisjuk <pavel@webiny.com>",
14
14
  "description": "A tool to bootstrap a Webiny project.",
15
15
  "dependencies": {
16
- "@webiny/telemetry": "0.0.0-unstable.fcdad0bc61",
17
- "@webiny/wcp": "0.0.0-unstable.fcdad0bc61",
18
- "boolean": "3.1.4",
19
- "camelcase": "5.3.1",
16
+ "@webiny/system-requirements": "0.0.0-unstable.fdd9228b5d",
17
+ "@webiny/telemetry": "0.0.0-unstable.fdd9228b5d",
18
+ "@webiny/wcp": "0.0.0-unstable.fdd9228b5d",
19
+ "boolean": "3.2.0",
20
+ "camelcase": "6.3.0",
20
21
  "chalk": "4.1.2",
21
- "dotenv": "8.2.0",
22
+ "ci-info": "4.2.0",
23
+ "dotenv": "8.6.0",
22
24
  "execa": "5.1.1",
23
- "fast-glob": "3.2.7",
25
+ "fast-glob": "3.2.12",
24
26
  "find-up": "5.0.0",
25
- "fs-extra": "9.1.0",
27
+ "fs-extra": "11.2.0",
26
28
  "graphql-request": "3.7.0",
27
- "inquirer": "7.3.3",
29
+ "inquirer": "8.2.6",
28
30
  "ncp": "2.0.0",
29
- "open": "8.4.0",
30
- "pirates": "4.0.5",
31
- "semver": "7.3.8",
31
+ "open": "8.4.2",
32
+ "pirates": "4.0.6",
33
+ "semver": "7.6.3",
32
34
  "ts-morph": "11.0.3",
33
- "typescript": "4.7.4",
35
+ "typescript": "5.3.3",
34
36
  "uniqid": "5.4.0",
35
- "yargs": "17.6.0"
37
+ "yargs": "17.7.2"
36
38
  },
37
39
  "license": "MIT",
38
40
  "publishConfig": {
@@ -64,5 +66,5 @@
64
66
  ]
65
67
  }
66
68
  },
67
- "gitHead": "40d639c3665e384a5e2d26674d43ce26f3295e8c"
69
+ "gitHead": "fdd9228b5d2636463e8a34b6e0d26eea1e29c01d"
68
70
  }
package/regions.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export interface RegionValue {
2
+ name: string;
3
+ value: string;
4
+ }
5
+
6
+ export declare const regions: RegionValue[];
package/regions.js ADDED
@@ -0,0 +1,30 @@
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 CHANGED
@@ -1,13 +1,20 @@
1
+ import type yargs from "yargs";
2
+
1
3
  /**
2
4
  * Rename file to types.ts when switching the package to Typescript.
3
5
  */
6
+ export type GenericRecord<K extends PropertyKey = PropertyKey, V = any> = Record<K, V>;
7
+
8
+ export type NonEmptyArray<T> = [T, ...T[]];
4
9
 
5
10
  /**
6
11
  * A simplified plugins container interface, used specifically within the Webiny CLI.
7
12
  * Not in relation with "@webiny/plugins" package.
8
13
  */
9
14
  export interface PluginsContainer {
15
+ register(...args: any[]): void;
10
16
  byType<T extends Plugin>(type: T["type"]): T[];
17
+
11
18
  byName<T extends Plugin>(name: T["name"]): T;
12
19
  }
13
20
 
@@ -18,6 +25,7 @@ export interface PluginsContainer {
18
25
  export interface Plugin {
19
26
  type: string;
20
27
  name?: string;
28
+
21
29
  [key: string]: any;
22
30
  }
23
31
 
@@ -29,18 +37,91 @@ interface Project {
29
37
  /**
30
38
  * Configurations.
31
39
  */
32
- config: Record<string, any>;
40
+ config: {
41
+ appAliases: {
42
+ [key: string]: string;
43
+ }
44
+ [key: string]: any;
45
+ };
33
46
  /**
34
47
  * Root path of the project.
35
48
  */
36
49
  root: string;
37
50
  }
38
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
+
39
119
  /**
40
120
  * A type that represents the logging method.
41
121
  */
42
122
  interface Log {
43
123
  (...args: any): string;
124
+
44
125
  hl: (...args: any) => string;
45
126
  highlight: (...args: any) => string;
46
127
  }
@@ -53,6 +134,10 @@ export interface CliContext {
53
134
  * All registered plugins.
54
135
  */
55
136
  plugins: PluginsContainer;
137
+ /**
138
+ * Load environment variables from a given file.
139
+ */
140
+ loadEnv(filePath: string, options?: {debug?: boolean}): Promise<void>;
56
141
  /**
57
142
  * All the environment variables.
58
143
  */
@@ -103,11 +188,47 @@ export interface CliContext {
103
188
  resolve: (dir: string) => string;
104
189
 
105
190
  /**
106
- * Provides a way to store some meta data in the project's local ".webiny/cli.json" file.
191
+ * Provides a way to store some metadata in the project's local ".webiny/cli.json" file.
107
192
  * Only trivial data should be passed here, specific to the current project.
108
193
  */
109
194
  localStorage: {
110
- set: (key: string, value: string) => Record<string, any>;
195
+ set: (key: string, value: any) => Record<string, any>;
111
196
  get: (key: string) => any;
112
197
  };
113
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
+ }
@@ -0,0 +1,99 @@
1
+ const execa = require("execa");
2
+ const logger = require("./log");
3
+
4
+ const DEBUG_FLAG = "--debug";
5
+ const usingDebugFlag = process.argv.includes(DEBUG_FLAG);
6
+
7
+ const SKIP_WEBINY_VERSIONS_CHECK_FLAG = "--no-package-versions-check";
8
+ const skippingWebinyVersionsCheck = process.argv.includes(SKIP_WEBINY_VERSIONS_CHECK_FLAG);
9
+
10
+ function listWebinyPackageVersions() {
11
+ const { stdout } = execa.sync("yarn", ["info", "@webiny/*", "--name-only", "--all", "--json"], {
12
+ encoding: "utf-8"
13
+ });
14
+
15
+ // Each line is a JSON string, so parse them individually
16
+ const lines = stdout
17
+ .trim()
18
+ .split("\n")
19
+ .map(line => JSON.parse(line));
20
+
21
+ const versionMap = new Map();
22
+
23
+ for (const entry of lines) {
24
+ // An example entry: "@webiny/cli@npm:5.42.3"
25
+ const match = entry.match(/^(@webiny\/[^@]+)@npm:(.+)$/);
26
+ if (!match) {
27
+ continue;
28
+ }
29
+
30
+ const [, pkg, version] = match;
31
+ if (!versionMap.has(pkg)) {
32
+ versionMap.set(pkg, new Set());
33
+ }
34
+
35
+ versionMap.get(pkg).add(version);
36
+ }
37
+
38
+ return versionMap;
39
+ }
40
+
41
+ function ensureSameWebinyPackageVersions() {
42
+ // Just in case, we want to allow users to skip the check.
43
+ if (skippingWebinyVersionsCheck) {
44
+ return;
45
+ }
46
+
47
+ let webinyVersions;
48
+ try {
49
+ webinyVersions = listWebinyPackageVersions();
50
+ } catch (e) {
51
+ const message = ["Failed to inspect Webiny package versions."];
52
+
53
+ if (!usingDebugFlag) {
54
+ message.push(
55
+ `For more information, try running with ${logger.warning.hl(DEBUG_FLAG)}.`
56
+ );
57
+ }
58
+
59
+ message.push("Learn more: https://webiny.link/webiny-package-versions-check");
60
+
61
+ logger.warning(message.join(" "));
62
+ if (usingDebugFlag) {
63
+ logger.debug(e);
64
+ }
65
+
66
+ console.log();
67
+ return;
68
+ }
69
+
70
+ let hasMismatch = false;
71
+ const mismatchedPackages = [];
72
+ for (const [pkg, versions] of webinyVersions.entries()) {
73
+ if (versions.size > 1) {
74
+ hasMismatch = true;
75
+ mismatchedPackages.push([pkg, versions]);
76
+ }
77
+ }
78
+
79
+ if (hasMismatch) {
80
+ const message = [
81
+ "The following Webiny packages have mismatched versions:",
82
+ "",
83
+ ...mismatchedPackages.map(([pkg, versions]) => {
84
+ return `‣ ${pkg}: ${Array.from(versions).join(", ")}`;
85
+ }),
86
+ "",
87
+ `Please ensure all Webiny packages are using the same version. If you think this is a mistake, you can also skip this check by appending the ${logger.error.hl(
88
+ SKIP_WEBINY_VERSIONS_CHECK_FLAG
89
+ )} flag. Learn more: https://webiny.link/webiny-package-versions-check`
90
+ ];
91
+
92
+ logger.error(message.join("\n"));
93
+ process.exit(1);
94
+ }
95
+ }
96
+
97
+ module.exports = {
98
+ ensureSameWebinyPackageVersions
99
+ };
@@ -43,16 +43,10 @@ module.exports = args => {
43
43
  projectAppRelativePath
44
44
  );
45
45
 
46
- // If we're missing the `pulumi` property in the `applicationConfig` object, that
47
- // means we're dealing with an old project application where all of the Pulumi code is
48
- // located in user's project. New projects applications have this code abstracted away.
49
- const type = applicationConfig.pulumi ? "v5-workspaces" : "v5";
50
-
51
46
  return {
52
47
  id,
53
48
  name,
54
49
  description,
55
- type,
56
50
  root: projectAppRootPath,
57
51
  paths: {
58
52
  relative: projectAppRelativePath,
@@ -72,6 +66,8 @@ module.exports = args => {
72
66
  return {
73
67
  name: packageJson.name,
74
68
  paths: {
69
+ absolute: dirname(config),
70
+ relative: relative(project.root, dirPath),
75
71
  root: dirname(config),
76
72
  packageJson: join(dirPath, "package.json"),
77
73
  config
package/utils/index.d.ts CHANGED
@@ -1 +1,28 @@
1
- export function getApiProjectApplicationFolder(project: Record<string, any>): boolean;
1
+ import { Project, ProjectApplication } from "../types";
2
+
3
+ export interface IGetProjectParams {
4
+ cwd: string;
5
+ }
6
+
7
+ export declare function getProject(params?: IGetProjectParams): Project;
8
+
9
+ export interface IGetProjectApplicationParams {
10
+ cwd: string;
11
+ }
12
+
13
+ export declare function getProjectApplication(
14
+ params: IGetProjectApplicationParams
15
+ ): ProjectApplication;
16
+
17
+ export declare function sendEvent(event: string, properties?: Record<string, any>): Promise<void>;
18
+
19
+ export declare function sleepSync(ms?: number): void;
20
+
21
+ export declare const log: {
22
+ log: ((...args: any[]) => void) & { hl: (message: string) => string };
23
+ info: ((...args: any[]) => void) & { hl: (message: string) => string };
24
+ success: ((...args: any[]) => void) & { hl: (message: string) => string };
25
+ debug: ((...args: any[]) => void) & { hl: (message: string) => string };
26
+ warning: ((...args: any[]) => void) & { hl: (message: string) => string };
27
+ error: ((...args: any[]) => void) & { hl: (message: string) => string };
28
+ };
package/utils/index.js CHANGED
@@ -2,11 +2,12 @@ const { importModule } = require("./importModule");
2
2
  const createProjectApplicationWorkspace = require("./createProjectApplicationWorkspace");
3
3
  const getProject = require("./getProject");
4
4
  const getProjectApplication = require("./getProjectApplication");
5
- const getApiProjectApplicationFolder = require("./getApiProjectApplicationFolder");
6
5
  const localStorage = require("./localStorage");
7
6
  const log = require("./log");
8
7
  const sendEvent = require("./sendEvent");
9
8
  const PluginsContainer = require("./PluginsContainer");
9
+ const sleep = require("./sleep");
10
+ const sleepSync = require("./sleepSync");
10
11
 
11
12
  const noop = () => {
12
13
  // Do nothing.
@@ -14,7 +15,6 @@ const noop = () => {
14
15
 
15
16
  module.exports = {
16
17
  createProjectApplicationWorkspace,
17
- getApiProjectApplicationFolder,
18
18
  getProject,
19
19
  getProjectApplication,
20
20
  importModule,
@@ -22,5 +22,7 @@ module.exports = {
22
22
  log,
23
23
  noop,
24
24
  sendEvent,
25
- PluginsContainer
25
+ PluginsContainer,
26
+ sleep,
27
+ sleepSync
26
28
  };
@@ -0,0 +1,63 @@
1
+ const path = require("path");
2
+ const yargs = require("yargs");
3
+ const log = require("./log");
4
+ const getProject = require("./getProject");
5
+ const { boolean } = require("boolean");
6
+
7
+ // Load environment variables from following sources:
8
+ // - `webiny.project.ts` file
9
+ // - `.env` file
10
+ // - `.env.{PASSED_ENVIRONMENT}` file
11
+
12
+ const project = getProject();
13
+
14
+ // `webiny.project.ts` file.
15
+ // Environment variables defined via the `env` property.
16
+ if (project.config.env) {
17
+ Object.assign(process.env, project.config.env);
18
+ }
19
+
20
+ // `.env.{PASSED_ENVIRONMENT}` and `.env` files.
21
+ let paths = [path.join(project.root, ".env")];
22
+
23
+ if (yargs.argv.env) {
24
+ paths.push(path.join(project.root, `.env.${yargs.argv.env}`));
25
+ }
26
+
27
+ // If the `WCP_PROJECT_ID` environment variable is not set already, we check if there's
28
+ // a WCP project ID set via the `webiny.project.ts` config file. If so, we assign it
29
+ // to the `WCP_PROJECT_ID` environment variable.
30
+ if (!process.env.WCP_PROJECT_ID) {
31
+ if (project.config.id) {
32
+ process.env.WCP_PROJECT_ID = project.config.id;
33
+ }
34
+ }
35
+
36
+ // Let's load environment variables
37
+ for (let i = 0; i < paths.length; i++) {
38
+ const path = paths[i];
39
+ const { error } = require("dotenv").config({ path });
40
+ if (boolean(yargs.argv.debug)) {
41
+ if (error) {
42
+ log.debug(`No environment file found on ${log.debug.hl(path)}.`);
43
+ } else {
44
+ log.success(`Successfully loaded environment variables from ${log.success.hl(path)}.`);
45
+ }
46
+ }
47
+ }
48
+
49
+ // Feature flags defined via the `featureFlags` property.
50
+ // We set twice, to be available for both backend and frontend application code.
51
+ // TODO: one day we might want to sync this up a bit.
52
+ if (project.config.featureFlags) {
53
+ process.env.WEBINY_FEATURE_FLAGS = JSON.stringify(project.config.featureFlags);
54
+ process.env.REACT_APP_WEBINY_FEATURE_FLAGS = JSON.stringify(project.config.featureFlags);
55
+ }
56
+
57
+ // With 5.38.0, we are hiding the `WEBINY_ELASTICSEARCH_INDEX_LOCALE` env variable and always setting it to `true`.
58
+ // This is because this variable is not something users should be concerned with, nor should they be able to change it.
59
+ // In order to ensure backwards compatibility, we first check if the variable is set, and if it is, we don't override it.
60
+ const esIndexLocaleEnvVarExists = "WEBINY_ELASTICSEARCH_INDEX_LOCALE" in process.env;
61
+ if (!esIndexLocaleEnvVarExists) {
62
+ process.env.WEBINY_ELASTICSEARCH_INDEX_LOCALE = "true";
63
+ }
@@ -1,15 +1,11 @@
1
1
  const { sendEvent } = require("@webiny/telemetry/cli");
2
2
  const getProject = require("./getProject");
3
3
 
4
- module.exports = ({ event, properties, extraPayload }) => {
4
+ module.exports = (event, properties) => {
5
5
  const project = getProject();
6
6
  if (project.config.cli && project.config.cli.telemetry === false) {
7
7
  return;
8
8
  }
9
9
 
10
- return sendEvent({
11
- event,
12
- properties,
13
- extraPayload
14
- });
10
+ return sendEvent({ event, properties });
15
11
  };
package/utils/sleep.js ADDED
@@ -0,0 +1,3 @@
1
+ const sleep = (ms = 1500) => new Promise(resolve => setTimeout(resolve, ms));
2
+
3
+ module.exports = sleep;
@@ -0,0 +1,8 @@
1
+ const sleepSync = (ms = 1500) => {
2
+ const start = Date.now();
3
+ while (Date.now() < start + ms) {
4
+ // Do nothing.
5
+ }
6
+ };
7
+
8
+ module.exports = sleepSync;
@@ -0,0 +1,7 @@
1
+ const originalConsoleError = console.error;
2
+ console.error = (message, ...args) => {
3
+ if (typeof message === "string" && message.includes("punycode")) {
4
+ return;
5
+ }
6
+ originalConsoleError.call(console, message, ...args);
7
+ };