@@ -14,39 +14,39 @@ module.exports = () => [
14
14
type : "hook-before-deploy" ,
15
15
name : "hook-before-deploy-environment-get-environment" ,
16
16
async hook ( args , context ) {
17
- // If the project isn't activated, do nothing.
18
- if ( ! context . project . config . id ) {
19
- return ;
20
- }
17
+ const apiKey = process . env . WCP_PROJECT_ENVIRONMENT_API_KEY ;
18
+ if ( apiKey ) {
19
+ projectEnvironment = await getProjectEnvironment ( { apiKey } ) ;
20
+ } else {
21
+ // If the project isn't activated, do nothing.
22
+ const wcpProjectId = context . project . config . id || process . env . WCP_PROJECT_ID ;
23
+ if ( ! wcpProjectId ) {
24
+ return ;
25
+ }
21
26
22
- if ( process . env . WCP_PROJECT_ENVIRONMENT ) {
23
- // If we have WCP_PROJECT_ENVIRONMENT env var, we set the WCP_PROJECT_ENVIRONMENT_API_KEY too.
24
- if ( ! process . env . WCP_PROJECT_ENVIRONMENT_API_KEY ) {
27
+ // For development purposes, we allow setting the WCP_PROJECT_ENVIRONMENT env var directly.
28
+ // TODO: discuss this, do we really want to have this feature? Maybe we can remove it?
29
+ if ( process . env . WCP_PROJECT_ENVIRONMENT ) {
30
+ // If we have WCP_PROJECT_ENVIRONMENT env var, we set the WCP_PROJECT_ENVIRONMENT_API_KEY too.
25
31
const decryptedProjectEnvironment = decrypt (
26
32
process . env . WCP_PROJECT_ENVIRONMENT
27
33
) ;
28
34
process . env . WCP_PROJECT_ENVIRONMENT_API_KEY =
29
35
decryptedProjectEnvironment . apiKey ;
30
- }
31
36
32
- return ;
33
- }
37
+ return ;
38
+ }
34
39
35
- // The `id` has the orgId/projectId structure, for example `my-org-x/my-project-y`.
36
- const orgProject = context . project . config . id ;
37
- const [ orgId , projectId ] = orgProject . split ( "/" ) ;
40
+ // The `id` has the orgId/projectId structure, for example `my-org-x/my-project-y`.
41
+ const [ orgId , projectId ] = wcpProjectId . split ( "/" ) ;
38
42
39
- const isValidId = orgId && projectId ;
40
- if ( ! isValidId ) {
41
- throw new Error (
42
- `It seems the project ID, specified in "webiny.project.ts" file, is invalid.`
43
- ) ;
44
- }
43
+ const isValidId = orgId && projectId ;
44
+ if ( ! isValidId ) {
45
+ throw new Error (
46
+ `It seems the project ID, specified in "webiny.project.ts" file, is invalid.`
47
+ ) ;
48
+ }
45
49
46
- const apiKey = process . env . WCP_PROJECT_ENVIRONMENT_API_KEY ;
47
- if ( apiKey ) {
48
- projectEnvironment = await getProjectEnvironment ( { apiKey } ) ;
49
- } else {
50
50
// If there is no API key, that means we need to retrieve the currently logged-in user.
51
51
const user = await getUser ( ) ;
52
52
const project = user . projects . find ( item => item . id === projectId ) ;
0 commit comments