@webiny/cli 0.0.0-mt-2 → 0.0.0-unstable.1145e7667f
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 +1 -1
- package/bin.js +12 -10
- package/cli.js +3 -24
- package/commands/index.js +7 -0
- package/commands/run/index.js +9 -1
- package/commands/wcp/hooks.js +133 -0
- package/commands/wcp/index.js +8 -0
- package/commands/wcp/login.js +228 -0
- package/commands/wcp/logout.js +28 -0
- package/commands/wcp/project.js +202 -0
- package/commands/wcp/utils/getProjectEnvironment.js +120 -0
- package/commands/wcp/utils/getUser.js +100 -0
- package/commands/wcp/utils/getWcpPat.js +5 -0
- package/commands/wcp/utils/index.js +17 -0
- package/commands/wcp/utils/setProjectId.js +44 -0
- package/commands/wcp/utils/setWcpPat.js +5 -0
- package/commands/wcp/utils/sleep.js +1 -0
- package/commands/wcp/utils/updateUserLastActiveOn.js +28 -0
- package/commands/wcp/whoami.js +43 -0
- package/context.js +3 -3
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/package.json +19 -14
- package/types.d.ts +5 -41
- package/utils/createProjectApplicationWorkspace.js +16 -0
- package/utils/getApiProjectApplicationFolder.js +12 -0
- package/utils/getProjectApplication.js +31 -7
- package/utils/index.d.ts +1 -0
- package/utils/index.js +10 -1
- package/utils/loadEnvVariables.js +46 -0
- package/utils/log.js +15 -17
- package/CHANGELOG.md +0 -2896
package/types.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface PluginsContainer {
|
|
|
15
15
|
* A simplified plugin interface, used specifically within the Webiny CLI.
|
|
16
16
|
* Not in relation with "@webiny/plugins" package.
|
|
17
17
|
*/
|
|
18
|
-
export interface Plugin
|
|
18
|
+
export interface Plugin {
|
|
19
19
|
type: string;
|
|
20
20
|
name?: string;
|
|
21
21
|
[key: string]: any;
|
|
@@ -40,9 +40,9 @@ interface Project {
|
|
|
40
40
|
* A type that represents the logging method.
|
|
41
41
|
*/
|
|
42
42
|
interface Log {
|
|
43
|
-
(...args): string;
|
|
44
|
-
hl: (...args) => string;
|
|
45
|
-
highlight: (...args) => string;
|
|
43
|
+
(...args: any): string;
|
|
44
|
+
hl: (...args: any) => string;
|
|
45
|
+
highlight: (...args: any) => string;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -100,7 +100,7 @@ export interface CliContext {
|
|
|
100
100
|
/**
|
|
101
101
|
* Resolve given dir or dirs against project root path.
|
|
102
102
|
*/
|
|
103
|
-
resolve: (dir) => string;
|
|
103
|
+
resolve: (dir: string) => string;
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* Provides a way to store some meta data in the project's local ".webiny/cli.json" file.
|
|
@@ -111,39 +111,3 @@ export interface CliContext {
|
|
|
111
111
|
get: (key: string) => any;
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Args received from the CLI.
|
|
117
|
-
*/
|
|
118
|
-
interface CliUpgradePluginOptions {
|
|
119
|
-
/**
|
|
120
|
-
* Targeted version of the upgrade.
|
|
121
|
-
*/
|
|
122
|
-
targetVersion: string;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
*
|
|
126
|
-
*/
|
|
127
|
-
export interface CliUpgradePlugin extends Plugin {
|
|
128
|
-
/**
|
|
129
|
-
* Name of the plugin to differentiate from others.
|
|
130
|
-
* Something like: cli-upgrade-5.0.0
|
|
131
|
-
*/
|
|
132
|
-
name: string;
|
|
133
|
-
/**
|
|
134
|
-
* Type of the plugin.
|
|
135
|
-
*/
|
|
136
|
-
type: "cli-upgrade";
|
|
137
|
-
/**
|
|
138
|
-
* Version the plugin is for.
|
|
139
|
-
*/
|
|
140
|
-
version: string;
|
|
141
|
-
/**
|
|
142
|
-
* Is this plugin usable for the upgrade?
|
|
143
|
-
*/
|
|
144
|
-
canUpgrade?: (options: CliUpgradePluginOptions, context: CliContext) => Promise<boolean>;
|
|
145
|
-
/**
|
|
146
|
-
* Apply the upgrade.
|
|
147
|
-
*/
|
|
148
|
-
upgrade: (options: CliUpgradePluginOptions, context: CliContext) => Promise<void>;
|
|
149
|
-
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
// This function has been created in order to help preserve backwards compatibility
|
|
5
|
+
// (from 5.29.0, the `api` app has been moved into the `apps/api` directory).
|
|
6
|
+
module.exports = project => {
|
|
7
|
+
if (fs.existsSync(path.join(project.root, "api"))) {
|
|
8
|
+
return "api";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return "apps/api";
|
|
12
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { dirname, basename, join } = require("path");
|
|
1
|
+
const { dirname, basename, join, relative } = require("path");
|
|
2
2
|
const findUp = require("find-up");
|
|
3
3
|
const getProject = require("./getProject");
|
|
4
4
|
const { importModule } = require("./importModule");
|
|
@@ -15,31 +15,55 @@ module.exports = args => {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const rootFile = applicationRootFile.replace(/\\/g, "/");
|
|
18
|
-
const
|
|
18
|
+
const projectAppRootPath = dirname(rootFile);
|
|
19
19
|
|
|
20
20
|
let applicationConfig;
|
|
21
21
|
if (appConfigs.includes(basename(rootFile))) {
|
|
22
22
|
applicationConfig = importModule(rootFile);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
let name,
|
|
25
|
+
let id, name, description;
|
|
26
26
|
if (applicationConfig) {
|
|
27
27
|
id = applicationConfig.id;
|
|
28
28
|
name = applicationConfig.name;
|
|
29
|
+
description = applicationConfig.description;
|
|
29
30
|
} else {
|
|
30
|
-
name = basename(
|
|
31
|
+
name = basename(projectAppRootPath);
|
|
32
|
+
description = name;
|
|
31
33
|
id = name;
|
|
32
34
|
}
|
|
33
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
|
+
// 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
|
+
|
|
34
51
|
return {
|
|
35
52
|
id,
|
|
36
53
|
name,
|
|
37
|
-
|
|
54
|
+
description,
|
|
55
|
+
type,
|
|
56
|
+
root: projectAppRootPath,
|
|
57
|
+
paths: {
|
|
58
|
+
relative: projectAppRelativePath,
|
|
59
|
+
absolute: projectAppRootPath,
|
|
60
|
+
workspace: projectAppWorkspacePath
|
|
61
|
+
},
|
|
38
62
|
config: applicationConfig,
|
|
39
|
-
project
|
|
63
|
+
project,
|
|
40
64
|
get packages() {
|
|
41
65
|
const webinyConfigs = glob.sync(
|
|
42
|
-
join(
|
|
66
|
+
join(projectAppRootPath, "**/webiny.config*.{ts,js}").replace(/\\/g, "/")
|
|
43
67
|
);
|
|
44
68
|
|
|
45
69
|
return webinyConfigs.map(config => {
|
package/utils/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function getApiProjectApplicationFolder(project: Record<string, any>): boolean;
|
package/utils/index.js
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
const { importModule } = require("./importModule");
|
|
2
|
+
const createProjectApplicationWorkspace = require("./createProjectApplicationWorkspace");
|
|
2
3
|
const getProject = require("./getProject");
|
|
3
4
|
const getProjectApplication = require("./getProjectApplication");
|
|
5
|
+
const getApiProjectApplicationFolder = require("./getApiProjectApplicationFolder");
|
|
4
6
|
const localStorage = require("./localStorage");
|
|
5
7
|
const log = require("./log");
|
|
6
8
|
const sendEvent = require("./sendEvent");
|
|
7
9
|
const PluginsContainer = require("./PluginsContainer");
|
|
8
10
|
|
|
11
|
+
const noop = () => {
|
|
12
|
+
// Do nothing.
|
|
13
|
+
};
|
|
14
|
+
|
|
9
15
|
module.exports = {
|
|
10
|
-
|
|
16
|
+
createProjectApplicationWorkspace,
|
|
17
|
+
getApiProjectApplicationFolder,
|
|
11
18
|
getProject,
|
|
12
19
|
getProjectApplication,
|
|
20
|
+
importModule,
|
|
13
21
|
localStorage,
|
|
14
22
|
log,
|
|
23
|
+
noop,
|
|
15
24
|
sendEvent,
|
|
16
25
|
PluginsContainer
|
|
17
26
|
};
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
// Let's load environment variables
|
|
28
|
+
for (let i = 0; i < paths.length; i++) {
|
|
29
|
+
const path = paths[i];
|
|
30
|
+
const { error } = require("dotenv").config({ path });
|
|
31
|
+
if (boolean(yargs.argv.debug)) {
|
|
32
|
+
if (error) {
|
|
33
|
+
log.debug(`No environment file found on ${log.debug.hl(path)}.`);
|
|
34
|
+
} else {
|
|
35
|
+
log.success(`Successfully loaded environment variables from ${log.success.hl(path)}.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Feature flags defined via the `featureFlags` property.
|
|
41
|
+
// We set twice, to be available for both backend and frontend application code.
|
|
42
|
+
// TODO: one day we might want to sync this up a bit.
|
|
43
|
+
if (project.config.featureFlags) {
|
|
44
|
+
process.env.WEBINY_FEATURE_FLAGS = JSON.stringify(project.config.featureFlags);
|
|
45
|
+
process.env.REACT_APP_WEBINY_FEATURE_FLAGS = JSON.stringify(project.config.featureFlags);
|
|
46
|
+
}
|
package/utils/log.js
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
const chalk = require("chalk");
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return `${chalk.green(type)}`;
|
|
17
|
-
}
|
|
3
|
+
const logColors = {
|
|
4
|
+
log: v => v,
|
|
5
|
+
info: chalk.blueBright,
|
|
6
|
+
error: chalk.red,
|
|
7
|
+
warning: chalk.yellow,
|
|
8
|
+
debug: chalk.gray,
|
|
9
|
+
success: chalk.green
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const colorizePlaceholders = (type, string) => {
|
|
13
|
+
return string.replace(/\%[a-zA-Z]/g, match => {
|
|
14
|
+
return logColors[type](match);
|
|
15
|
+
});
|
|
18
16
|
};
|
|
19
17
|
|
|
20
18
|
const webinyLog = (type, ...args) => {
|
|
21
|
-
const prefix = `webiny ${
|
|
19
|
+
const prefix = `webiny ${logColors[type](type)}: `;
|
|
22
20
|
|
|
23
21
|
const [first, ...rest] = args;
|
|
24
22
|
if (typeof first === "string") {
|
|
25
|
-
return console.log(prefix + first, ...rest);
|
|
23
|
+
return console.log(prefix + colorizePlaceholders(type, first), ...rest);
|
|
26
24
|
}
|
|
27
25
|
return console.log(prefix, first, ...rest);
|
|
28
26
|
};
|