@webiny/cli 6.0.0-beta.0 → 6.0.0-rc.1
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/README.md +10 -6
- package/bin.js +10 -33
- package/files/duplicates.json +1 -0
- package/files/references.json +1 -0
- package/index.js +2 -2
- package/package.json +16 -55
- package/utils/ensureSameWebinyPackageVersions.js +99 -0
- package/utils/suppressPunycodeWarnings.js +7 -0
- package/cli.js +0 -93
- package/commands/about/getDatabaseSetup.js +0 -45
- package/commands/about/getNpmVersion.js +0 -10
- package/commands/about/getNpxVersion.js +0 -10
- package/commands/about/getPulumiVersions.js +0 -43
- package/commands/about/getYarnVersion.js +0 -10
- package/commands/about/index.js +0 -97
- package/commands/index.js +0 -21
- package/commands/run/index.js +0 -38
- package/commands/telemetry/index.js +0 -31
- package/commands/upgrade/index.js +0 -108
- package/commands/wcp/hooks.js +0 -133
- package/commands/wcp/index.js +0 -8
- package/commands/wcp/login.js +0 -227
- package/commands/wcp/logout.js +0 -28
- package/commands/wcp/project.js +0 -202
- package/commands/wcp/utils/getProjectEnvironment.js +0 -120
- package/commands/wcp/utils/getUser.js +0 -100
- package/commands/wcp/utils/getWcpOrgProjectId.js +0 -9
- package/commands/wcp/utils/getWcpPat.js +0 -5
- package/commands/wcp/utils/getWcpProjectId.js +0 -3
- package/commands/wcp/utils/index.js +0 -21
- package/commands/wcp/utils/setProjectId.js +0 -44
- package/commands/wcp/utils/setWcpPat.js +0 -5
- package/commands/wcp/utils/sleep.js +0 -1
- package/commands/wcp/utils/updateUserLastActiveOn.js +0 -28
- package/commands/wcp/whoami.js +0 -43
- package/context.js +0 -137
- package/index.d.ts +0 -3
- package/types.d.ts +0 -172
- package/utils/PluginsContainer.js +0 -49
- package/utils/createProjectApplicationWorkspace.js +0 -16
- package/utils/getProject.js +0 -48
- package/utils/getProjectApplication.js +0 -83
- package/utils/importModule.js +0 -43
- package/utils/index.js +0 -24
- package/utils/loadEnvVariables.js +0 -63
- package/utils/localStorage.js +0 -44
- package/utils/log.js +0 -67
- package/utils/sendEvent.js +0 -11
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
package/types.d.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rename file to types.ts when switching the package to Typescript.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import glob from "fast-glob";
|
|
6
|
-
import { dirname, join } from "path";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A simplified plugins container interface, used specifically within the Webiny CLI.
|
|
10
|
-
* Not in relation with "@webiny/plugins" package.
|
|
11
|
-
*/
|
|
12
|
-
export interface PluginsContainer {
|
|
13
|
-
byType<T extends Plugin>(type: T["type"]): T[];
|
|
14
|
-
|
|
15
|
-
byName<T extends Plugin>(name: T["name"]): T;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* A simplified plugin interface, used specifically within the Webiny CLI.
|
|
20
|
-
* Not in relation with "@webiny/plugins" package.
|
|
21
|
-
*/
|
|
22
|
-
export interface Plugin {
|
|
23
|
-
type: string;
|
|
24
|
-
name?: string;
|
|
25
|
-
|
|
26
|
-
[key: string]: any;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface Project {
|
|
30
|
-
/**
|
|
31
|
-
* Name of the project.
|
|
32
|
-
*/
|
|
33
|
-
name: string;
|
|
34
|
-
/**
|
|
35
|
-
* Configurations.
|
|
36
|
-
*/
|
|
37
|
-
config: Record<string, any>;
|
|
38
|
-
/**
|
|
39
|
-
* Root path of the project.
|
|
40
|
-
*/
|
|
41
|
-
root: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface ProjectApplication {
|
|
45
|
-
/**
|
|
46
|
-
* Unique ID of the project application.
|
|
47
|
-
*/
|
|
48
|
-
id: string;
|
|
49
|
-
/**
|
|
50
|
-
* Name of the project application.
|
|
51
|
-
*/
|
|
52
|
-
name: string;
|
|
53
|
-
/**
|
|
54
|
-
* Description of the project application.
|
|
55
|
-
*/
|
|
56
|
-
description: string;
|
|
57
|
-
/**
|
|
58
|
-
* Type of the project application.
|
|
59
|
-
*/
|
|
60
|
-
type: string;
|
|
61
|
-
/**
|
|
62
|
-
* Root path of the project application.
|
|
63
|
-
*/
|
|
64
|
-
root: string;
|
|
65
|
-
/**
|
|
66
|
-
* Commonly used paths.
|
|
67
|
-
*/
|
|
68
|
-
paths: {
|
|
69
|
-
relative: string;
|
|
70
|
-
absolute: string;
|
|
71
|
-
workspace: string;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Project application config (exported via `webiny.application.ts` file).
|
|
75
|
-
*/
|
|
76
|
-
config: Record<string, any>;
|
|
77
|
-
/**
|
|
78
|
-
* Project application package.json.
|
|
79
|
-
*/
|
|
80
|
-
project: Project;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* A list of all the packages in the project application.
|
|
84
|
-
*/
|
|
85
|
-
get packages(): Array<{
|
|
86
|
-
name: string;
|
|
87
|
-
paths: {
|
|
88
|
-
root: string;
|
|
89
|
-
packageJson: string;
|
|
90
|
-
config: string;
|
|
91
|
-
};
|
|
92
|
-
packageJson: Record<string, any>;
|
|
93
|
-
get config(): any;
|
|
94
|
-
}>;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* A type that represents the logging method.
|
|
99
|
-
*/
|
|
100
|
-
interface Log {
|
|
101
|
-
(...args: any): string;
|
|
102
|
-
|
|
103
|
-
hl: (...args: any) => string;
|
|
104
|
-
highlight: (...args: any) => string;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Interface representing the CLI Context.
|
|
109
|
-
*/
|
|
110
|
-
export interface CliContext {
|
|
111
|
-
/**
|
|
112
|
-
* All registered plugins.
|
|
113
|
-
*/
|
|
114
|
-
plugins: PluginsContainer;
|
|
115
|
-
/**
|
|
116
|
-
* All the environment variables.
|
|
117
|
-
*/
|
|
118
|
-
loadedEnvFiles: Record<string, any>;
|
|
119
|
-
/**
|
|
120
|
-
* Version of the Webiny CLI.
|
|
121
|
-
*/
|
|
122
|
-
version: string;
|
|
123
|
-
/**
|
|
124
|
-
* Project information.
|
|
125
|
-
*/
|
|
126
|
-
project: Project;
|
|
127
|
-
/**
|
|
128
|
-
* Trigger given callback on SIGINT.
|
|
129
|
-
*/
|
|
130
|
-
onExit: (cb: () => any) => void;
|
|
131
|
-
/**
|
|
132
|
-
* Import a given module.
|
|
133
|
-
*/
|
|
134
|
-
import: (module: string) => Promise<void>;
|
|
135
|
-
/**
|
|
136
|
-
* Regular logging.
|
|
137
|
-
*/
|
|
138
|
-
log: Log;
|
|
139
|
-
/**
|
|
140
|
-
* Info logging.
|
|
141
|
-
*/
|
|
142
|
-
info: Log;
|
|
143
|
-
/**
|
|
144
|
-
* Success logging.
|
|
145
|
-
*/
|
|
146
|
-
success: Log;
|
|
147
|
-
/**
|
|
148
|
-
* Debug logging.
|
|
149
|
-
*/
|
|
150
|
-
debug: Log;
|
|
151
|
-
/**
|
|
152
|
-
* Warnings logging.
|
|
153
|
-
*/
|
|
154
|
-
warning: Log;
|
|
155
|
-
/**
|
|
156
|
-
* Errors logging.
|
|
157
|
-
*/
|
|
158
|
-
error: Log;
|
|
159
|
-
/**
|
|
160
|
-
* Resolve given dir or dirs against project root path.
|
|
161
|
-
*/
|
|
162
|
-
resolve: (dir: string) => string;
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Provides a way to store some meta data in the project's local ".webiny/cli.json" file.
|
|
166
|
-
* Only trivial data should be passed here, specific to the current project.
|
|
167
|
-
*/
|
|
168
|
-
localStorage: {
|
|
169
|
-
set: (key: string, value: string) => Record<string, any>;
|
|
170
|
-
get: (key: string) => any;
|
|
171
|
-
};
|
|
172
|
-
}
|
|
@@ -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
|
-
};
|
package/utils/getProject.js
DELETED
|
@@ -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
|
-
};
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
const { dirname, basename, join, relative } = require("path");
|
|
2
|
-
const findUp = require("find-up");
|
|
3
|
-
const getProject = require("./getProject");
|
|
4
|
-
const { importModule } = require("./importModule");
|
|
5
|
-
const glob = require("fast-glob");
|
|
6
|
-
|
|
7
|
-
const appConfigs = ["webiny.application.js", "webiny.application.ts"];
|
|
8
|
-
|
|
9
|
-
module.exports = args => {
|
|
10
|
-
// Using "Pulumi.yaml" for the backwards compatibility.
|
|
11
|
-
const applicationRootFile = findUp.sync(appConfigs.concat("Pulumi.yaml"), { cwd: args.cwd });
|
|
12
|
-
|
|
13
|
-
if (!applicationRootFile) {
|
|
14
|
-
throw new Error(`Could not detect project application in given directory (${args.cwd}).`);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const rootFile = applicationRootFile.replace(/\\/g, "/");
|
|
18
|
-
const projectAppRootPath = dirname(rootFile);
|
|
19
|
-
|
|
20
|
-
let applicationConfig;
|
|
21
|
-
if (appConfigs.includes(basename(rootFile))) {
|
|
22
|
-
applicationConfig = importModule(rootFile);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let id, name, description;
|
|
26
|
-
if (applicationConfig) {
|
|
27
|
-
id = applicationConfig.id;
|
|
28
|
-
name = applicationConfig.name;
|
|
29
|
-
description = applicationConfig.description;
|
|
30
|
-
} else {
|
|
31
|
-
name = basename(projectAppRootPath);
|
|
32
|
-
description = name;
|
|
33
|
-
id = name;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const project = getProject(args);
|
|
37
|
-
|
|
38
|
-
const projectAppRelativePath = relative(project.root, projectAppRootPath);
|
|
39
|
-
const projectAppWorkspacePath = join(
|
|
40
|
-
project.root,
|
|
41
|
-
".webiny",
|
|
42
|
-
"workspaces",
|
|
43
|
-
projectAppRelativePath
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
id,
|
|
48
|
-
name,
|
|
49
|
-
description,
|
|
50
|
-
root: projectAppRootPath,
|
|
51
|
-
paths: {
|
|
52
|
-
relative: projectAppRelativePath,
|
|
53
|
-
absolute: projectAppRootPath,
|
|
54
|
-
workspace: projectAppWorkspacePath
|
|
55
|
-
},
|
|
56
|
-
config: applicationConfig,
|
|
57
|
-
project,
|
|
58
|
-
get packages() {
|
|
59
|
-
const webinyConfigs = glob.sync(
|
|
60
|
-
join(projectAppRootPath, "**/webiny.config*.{ts,js}").replace(/\\/g, "/")
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
return webinyConfigs.map(config => {
|
|
64
|
-
const dirPath = dirname(config);
|
|
65
|
-
const packageJson = require(join(dirPath, "package.json"));
|
|
66
|
-
return {
|
|
67
|
-
name: packageJson.name,
|
|
68
|
-
paths: {
|
|
69
|
-
absolute: dirname(config),
|
|
70
|
-
relative: relative(project.root, dirPath),
|
|
71
|
-
root: dirname(config),
|
|
72
|
-
packageJson: join(dirPath, "package.json"),
|
|
73
|
-
config
|
|
74
|
-
},
|
|
75
|
-
packageJson,
|
|
76
|
-
get config() {
|
|
77
|
-
return require(config).default || require(config);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
};
|
package/utils/importModule.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const { addHook } = require("pirates");
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Add support for TS
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
addHook(
|
|
10
|
-
code => {
|
|
11
|
-
const ts = require("typescript");
|
|
12
|
-
const { outputText } = ts.transpileModule(code, {
|
|
13
|
-
compilerOptions: {
|
|
14
|
-
target: "es6",
|
|
15
|
-
allowJs: true,
|
|
16
|
-
allowSyntheticDefaultImports: true,
|
|
17
|
-
esModuleInterop: true,
|
|
18
|
-
outDir: "bin",
|
|
19
|
-
moduleResolution: "node",
|
|
20
|
-
module: "commonjs"
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
return outputText;
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
exts: [".ts"],
|
|
28
|
-
matcher: () => true
|
|
29
|
-
}
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
module.exports.importModule = configPath => {
|
|
33
|
-
if (!fs.existsSync(configPath)) {
|
|
34
|
-
throw Error(`"${configPath}" does not exist!`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const extension = path.extname(configPath);
|
|
38
|
-
if (extension === ".ts") {
|
|
39
|
-
return require(configPath).default;
|
|
40
|
-
} else {
|
|
41
|
-
return require(configPath);
|
|
42
|
-
}
|
|
43
|
-
};
|
package/utils/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const { importModule } = require("./importModule");
|
|
2
|
-
const createProjectApplicationWorkspace = require("./createProjectApplicationWorkspace");
|
|
3
|
-
const getProject = require("./getProject");
|
|
4
|
-
const getProjectApplication = require("./getProjectApplication");
|
|
5
|
-
const localStorage = require("./localStorage");
|
|
6
|
-
const log = require("./log");
|
|
7
|
-
const sendEvent = require("./sendEvent");
|
|
8
|
-
const PluginsContainer = require("./PluginsContainer");
|
|
9
|
-
|
|
10
|
-
const noop = () => {
|
|
11
|
-
// Do nothing.
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
module.exports = {
|
|
15
|
-
createProjectApplicationWorkspace,
|
|
16
|
-
getProject,
|
|
17
|
-
getProjectApplication,
|
|
18
|
-
importModule,
|
|
19
|
-
localStorage,
|
|
20
|
-
log,
|
|
21
|
-
noop,
|
|
22
|
-
sendEvent,
|
|
23
|
-
PluginsContainer
|
|
24
|
-
};
|
|
@@ -1,63 +0,0 @@
|
|
|
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
|
-
}
|
package/utils/localStorage.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// This is a small class that enables us to store some useful
|
|
2
|
-
// data into the .webiny folder, located in the project root.
|
|
3
|
-
// For example, we are saving the path entered while creating
|
|
4
|
-
// GraphQL services, so that the user doesn't have to type
|
|
5
|
-
// the same paths over and over.
|
|
6
|
-
const fs = require("fs");
|
|
7
|
-
const path = require("path");
|
|
8
|
-
const getProject = require("./getProject");
|
|
9
|
-
|
|
10
|
-
module.exports = function (filename = "cli.json") {
|
|
11
|
-
const project = getProject();
|
|
12
|
-
const DOT_WEBINY = path.join(project.root, ".webiny");
|
|
13
|
-
const dataFilePath = path.join(DOT_WEBINY, filename);
|
|
14
|
-
|
|
15
|
-
let data = {};
|
|
16
|
-
if (fs.existsSync(dataFilePath)) {
|
|
17
|
-
try {
|
|
18
|
-
data = JSON.parse(fs.readFileSync(dataFilePath));
|
|
19
|
-
} catch (e) {
|
|
20
|
-
throw new Error(
|
|
21
|
-
`Could not parse Webiny CLI's locale storage data file located at ${dataFilePath}.`
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
set(key, value) {
|
|
28
|
-
data[key] = value;
|
|
29
|
-
|
|
30
|
-
if (!fs.existsSync(DOT_WEBINY)) {
|
|
31
|
-
fs.mkdirSync(DOT_WEBINY);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
fs.writeFileSync(dataFilePath, JSON.stringify(data));
|
|
35
|
-
return data;
|
|
36
|
-
},
|
|
37
|
-
get(key) {
|
|
38
|
-
if (!key) {
|
|
39
|
-
return data;
|
|
40
|
-
}
|
|
41
|
-
return data[key];
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
};
|