@webiny/cli 5.31.0-beta.1 → 5.32.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.
- package/CHANGELOG.md +27 -0
- package/commands/wcp/hooks.js +100 -87
- package/context.js +2 -2
- package/package.json +4 -4
- package/utils/index.js +5 -0
- package/utils/log.js +15 -17
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,33 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [5.32.0](https://github.com/webiny/webiny-js/compare/v5.32.0-beta.0...v5.32.0) (2022-09-07)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @webiny/cli
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [5.32.0-beta.0](https://github.com/webiny/webiny-js/compare/v5.31.0...v5.32.0-beta.0) (2022-09-06)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* run WCP-related hooks in watch command ([370a381](https://github.com/webiny/webiny-js/commit/370a381b5dad78184803db63ed529ff725cba9f7))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# [5.31.0](https://github.com/webiny/webiny-js/compare/v5.31.0-beta.1...v5.31.0) (2022-08-18)
|
|
26
|
+
|
|
27
|
+
**Note:** Version bump only for package @webiny/cli
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
6
33
|
# [5.31.0-beta.1](https://github.com/webiny/webiny-js/compare/v5.31.0-beta.0...v5.31.0-beta.1) (2022-08-17)
|
|
7
34
|
|
|
8
35
|
**Note:** Version bump only for package @webiny/cli
|
package/commands/wcp/hooks.js
CHANGED
|
@@ -21,100 +21,113 @@ const { getUser, getProjectEnvironment, updateUserLastActiveOn } = require("./ut
|
|
|
21
21
|
|
|
22
22
|
let projectEnvironment;
|
|
23
23
|
|
|
24
|
+
const getEnvironmentHookHandler = async (args, context) => {
|
|
25
|
+
// For development purposes, we allow setting the WCP_PROJECT_ENVIRONMENT env var directly.
|
|
26
|
+
if (process.env.WCP_PROJECT_ENVIRONMENT) {
|
|
27
|
+
// If we have WCP_PROJECT_ENVIRONMENT env var, we set the WCP_PROJECT_ENVIRONMENT_API_KEY too.
|
|
28
|
+
const decryptedProjectEnvironment = decrypt(process.env.WCP_PROJECT_ENVIRONMENT);
|
|
29
|
+
process.env.WCP_PROJECT_ENVIRONMENT_API_KEY = decryptedProjectEnvironment.apiKey;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// If the project isn't activated, do nothing.
|
|
34
|
+
const wcpProjectId = context.project.config.id || process.env.WCP_PROJECT_ID;
|
|
35
|
+
if (!wcpProjectId) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// The `id` has the orgId/projectId structure, for example `my-org-x/my-project-y`.
|
|
40
|
+
const [orgId, projectId] = wcpProjectId.split("/");
|
|
41
|
+
|
|
42
|
+
const apiKey = process.env.WCP_PROJECT_ENVIRONMENT_API_KEY;
|
|
43
|
+
|
|
44
|
+
let projectEnvironment;
|
|
45
|
+
if (apiKey) {
|
|
46
|
+
projectEnvironment = await getProjectEnvironment({ apiKey });
|
|
47
|
+
} else {
|
|
48
|
+
const isValidId = orgId && projectId;
|
|
49
|
+
if (!isValidId) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`It seems the project ID, specified in "webiny.project.ts" file, is invalid.`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// If there is no API key, that means we need to retrieve the currently logged-in user.
|
|
56
|
+
const user = await getUser();
|
|
57
|
+
const project = user.projects.find(item => item.id === projectId);
|
|
58
|
+
if (!project) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`It seems you don't belong to the current project or the current project has been deleted.`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
projectEnvironment = await getProjectEnvironment({
|
|
65
|
+
orgId,
|
|
66
|
+
projectId,
|
|
67
|
+
userId: user.id,
|
|
68
|
+
environmentId: args.env
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (projectEnvironment.org.id !== orgId) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`Cannot proceed with the deployment because the "${projectEnvironment.name}" project environment doesn't belong to the "${orgId}" organization. Please check your WCP project ID (currently set to "${wcpProjectId}").`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (projectEnvironment.project.id !== projectId) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Cannot proceed with the deployment because the "${projectEnvironment.name}" project environment doesn't belong to the "${wcpProjectId}" project. Please check your WCP project ID (currently set to "${wcpProjectId}").`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (projectEnvironment && projectEnvironment.status !== "enabled") {
|
|
85
|
+
throw new Error(
|
|
86
|
+
`Cannot proceed with the deployment because the "${projectEnvironment.name}" project environment has been disabled.`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Assign `WCP_PROJECT_ENVIRONMENT` and `WCP_PROJECT_ENVIRONMENT_API_KEY`
|
|
91
|
+
const wcpProjectEnvironment = {
|
|
92
|
+
id: projectEnvironment.id,
|
|
93
|
+
apiKey: projectEnvironment.apiKey,
|
|
94
|
+
org: { id: projectEnvironment.org.id },
|
|
95
|
+
project: { id: projectEnvironment.project.id }
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
process.env.WCP_PROJECT_ENVIRONMENT = encrypt(wcpProjectEnvironment);
|
|
99
|
+
process.env.WCP_PROJECT_ENVIRONMENT_API_KEY = projectEnvironment.apiKey;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const updateLastActiveOnHookHandler = async () => {
|
|
103
|
+
if (!projectEnvironment) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Is this a user environment? If so, let's update his "last active" field.
|
|
108
|
+
if (projectEnvironment.user) {
|
|
109
|
+
await updateUserLastActiveOn();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// Export hooks plugins for deploy and watch commands.
|
|
24
114
|
module.exports = () => [
|
|
115
|
+
// Deploy hook handlers.
|
|
25
116
|
{
|
|
26
117
|
type: "hook-before-deploy",
|
|
27
118
|
name: "hook-before-deploy-environment-get-environment",
|
|
28
|
-
|
|
29
|
-
// For development purposes, we allow setting the WCP_PROJECT_ENVIRONMENT env var directly.
|
|
30
|
-
if (process.env.WCP_PROJECT_ENVIRONMENT) {
|
|
31
|
-
// If we have WCP_PROJECT_ENVIRONMENT env var, we set the WCP_PROJECT_ENVIRONMENT_API_KEY too.
|
|
32
|
-
const decryptedProjectEnvironment = decrypt(process.env.WCP_PROJECT_ENVIRONMENT);
|
|
33
|
-
process.env.WCP_PROJECT_ENVIRONMENT_API_KEY = decryptedProjectEnvironment.apiKey;
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// If the project isn't activated, do nothing.
|
|
38
|
-
const wcpProjectId = context.project.config.id || process.env.WCP_PROJECT_ID;
|
|
39
|
-
if (!wcpProjectId) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// The `id` has the orgId/projectId structure, for example `my-org-x/my-project-y`.
|
|
44
|
-
const [orgId, projectId] = wcpProjectId.split("/");
|
|
45
|
-
|
|
46
|
-
const apiKey = process.env.WCP_PROJECT_ENVIRONMENT_API_KEY;
|
|
47
|
-
|
|
48
|
-
let projectEnvironment;
|
|
49
|
-
if (apiKey) {
|
|
50
|
-
projectEnvironment = await getProjectEnvironment({ apiKey });
|
|
51
|
-
} else {
|
|
52
|
-
const isValidId = orgId && projectId;
|
|
53
|
-
if (!isValidId) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
`It seems the project ID, specified in "webiny.project.ts" file, is invalid.`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// If there is no API key, that means we need to retrieve the currently logged-in user.
|
|
60
|
-
const user = await getUser();
|
|
61
|
-
const project = user.projects.find(item => item.id === projectId);
|
|
62
|
-
if (!project) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
`It seems you don't belong to the current project or the current project has been deleted.`
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
projectEnvironment = await getProjectEnvironment({
|
|
69
|
-
orgId,
|
|
70
|
-
projectId,
|
|
71
|
-
userId: user.id,
|
|
72
|
-
environmentId: args.env
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (projectEnvironment.org.id !== orgId) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
`Cannot proceed with the deployment because the "${projectEnvironment.name}" project environment doesn't belong to the "${orgId}" organization. Please check your WCP project ID (currently set to "${wcpProjectId}").`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (projectEnvironment.project.id !== projectId) {
|
|
83
|
-
throw new Error(
|
|
84
|
-
`Cannot proceed with the deployment because the "${projectEnvironment.name}" project environment doesn't belong to the "${wcpProjectId}" project. Please check your WCP project ID (currently set to "${wcpProjectId}").`
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (projectEnvironment && projectEnvironment.status !== "enabled") {
|
|
89
|
-
throw new Error(
|
|
90
|
-
`Cannot proceed with the deployment because the "${projectEnvironment.name}" project environment has been disabled.`
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Assign `WCP_PROJECT_ENVIRONMENT` and `WCP_PROJECT_ENVIRONMENT_API_KEY`
|
|
95
|
-
const wcpProjectEnvironment = {
|
|
96
|
-
id: projectEnvironment.id,
|
|
97
|
-
apiKey: projectEnvironment.apiKey,
|
|
98
|
-
org: { id: projectEnvironment.org.id },
|
|
99
|
-
project: { id: projectEnvironment.project.id }
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
process.env.WCP_PROJECT_ENVIRONMENT = encrypt(wcpProjectEnvironment);
|
|
103
|
-
process.env.WCP_PROJECT_ENVIRONMENT_API_KEY = projectEnvironment.apiKey;
|
|
104
|
-
}
|
|
119
|
+
hook: getEnvironmentHookHandler
|
|
105
120
|
},
|
|
106
121
|
{
|
|
107
122
|
type: "hook-before-deploy",
|
|
108
123
|
name: "hook-before-deploy-update-last-active-on",
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
}
|
|
124
|
+
hook: updateLastActiveOnHookHandler
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
// Watch hook handlers.
|
|
128
|
+
{
|
|
129
|
+
type: "hook-before-watch",
|
|
130
|
+
name: "hook-before-watch-environment-get-environment",
|
|
131
|
+
hook: getEnvironmentHookHandler
|
|
119
132
|
}
|
|
120
133
|
];
|
package/context.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
|
-
const { importModule, getProject, PluginsContainer, log, localStorage } = require("./utils");
|
|
3
|
+
const { importModule, getProject, PluginsContainer, log, localStorage, noop } = require("./utils");
|
|
4
4
|
|
|
5
5
|
const project = getProject();
|
|
6
6
|
|
|
@@ -92,7 +92,7 @@ class Context {
|
|
|
92
92
|
log = log.log;
|
|
93
93
|
info = log.info;
|
|
94
94
|
success = log.success;
|
|
95
|
-
debug = log.debug;
|
|
95
|
+
debug = process.argv.includes("--debug") ? log.debug : noop;
|
|
96
96
|
warning = log.warning;
|
|
97
97
|
error = log.error;
|
|
98
98
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/cli",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.32.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"webiny": "./bin.js"
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"author": "Pavel Denisjuk <pavel@webiny.com>",
|
|
14
14
|
"description": "A tool to bootstrap a Webiny project.",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@webiny/telemetry": "5.
|
|
17
|
-
"@webiny/wcp": "5.
|
|
16
|
+
"@webiny/telemetry": "5.32.0",
|
|
17
|
+
"@webiny/wcp": "5.32.0",
|
|
18
18
|
"boolean": "3.1.4",
|
|
19
19
|
"camelcase": "5.3.1",
|
|
20
20
|
"chalk": "4.1.2",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
]
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "1227aa53c68afa4ccd518c8a4344195a2b8e354b"
|
|
68
68
|
}
|
package/utils/index.js
CHANGED
|
@@ -8,6 +8,10 @@ const log = require("./log");
|
|
|
8
8
|
const sendEvent = require("./sendEvent");
|
|
9
9
|
const PluginsContainer = require("./PluginsContainer");
|
|
10
10
|
|
|
11
|
+
const noop = () => {
|
|
12
|
+
// Do nothing.
|
|
13
|
+
};
|
|
14
|
+
|
|
11
15
|
module.exports = {
|
|
12
16
|
createProjectApplicationWorkspace,
|
|
13
17
|
getApiProjectApplicationFolder,
|
|
@@ -16,6 +20,7 @@ module.exports = {
|
|
|
16
20
|
importModule,
|
|
17
21
|
localStorage,
|
|
18
22
|
log,
|
|
23
|
+
noop,
|
|
19
24
|
sendEvent,
|
|
20
25
|
PluginsContainer
|
|
21
26
|
};
|
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
|
};
|