@@ -2,58 +2,77 @@ import { EventBridgeClient, PutEventsCommand } from "@webiny/aws-sdk/client-even
22import { CliContext } from "@webiny/cli/types" ;
33import { getStackOutput } from "@webiny/cli-plugin-deploy-pulumi/utils" ;
44
5+ export interface IRenderWebsiteParams {
6+ env : string ;
7+ inputs : IRenderWebsiteParamsInputs ;
8+ }
9+
10+ export interface IRenderWebsiteParamsInputs {
11+ preview ?: boolean ;
12+ build ?: boolean ;
13+ }
14+
15+ interface RenderWebsiteParams {
16+ prerender : ( params : IRenderWebsiteParams ) => boolean ;
17+ }
18+
519/**
620 * On every deployment of the Website project application, this plugin ensures all pages created
721 * with the Webiny Page Builder application are re-rendered.
822 */
9- export const renderWebsite = {
10- type : "hook-after-deploy" ,
11- name : "hook-after-deploy-website-render" ,
12- async hook ( params : Record < string , any > , context : CliContext ) {
13- if ( params . inputs . build === false ) {
14- context . info ( `"--no-build" argument detected - skipping Website re-rendering.` ) ;
15- return ;
16- }
23+ export const renderWebsite = ( renderWebsiteParams : RenderWebsiteParams ) => {
24+ return {
25+ type : "hook-after-deploy" ,
26+ name : "hook-after-deploy-website-render" ,
27+ async hook ( params : IRenderWebsiteParams , context : CliContext ) {
28+ if ( params . inputs . build === false ) {
29+ context . info ( `"--no-build" argument detected - skipping Website re-rendering.` ) ;
30+ return ;
31+ }
1732
18- // No need to re-render the website if we're doing a preview.
19- if ( params . inputs . preview ) {
20- return ;
21- }
33+ // No need to re-render the website if we're doing a preview.
34+ if ( params . inputs . preview ) {
35+ return ;
36+ }
2237
23- const coreOutput = getStackOutput ( { folder : "apps/core" , env : params . env } ) ;
24-
25- context . info ( "Issuing a complete website render job..." ) ;
26-
27- try {
28- const client = new EventBridgeClient ( { region : coreOutput [ "region" ] } ) ;
29-
30- const result = await client . send (
31- new PutEventsCommand ( {
32- Entries : [
33- {
34- Source : "webiny-cli" ,
35- EventBusName : coreOutput [ "eventBusArn" ] ,
36- DetailType : "RenderPages" ,
37- Detail : JSON . stringify ( { path : "*" , tenant : "*" } )
38- }
39- ]
40- } )
41- ) ;
42-
43- const entry = result . Entries ?. [ 0 ] ;
44- if ( entry ?. ErrorMessage ) {
45- throw new Error ( entry . ErrorMessage ) ;
38+ if ( ! renderWebsiteParams . prerender ( params ) ) {
39+ context . info ( "Skipping complete website rendering." ) ;
40+ return ;
4641 }
4742
48- context . success ( "Website re-render job successfully issued." ) ;
49- context . info (
50- "Please note that it can take a couple of minutes for the website to be fully updated."
51- ) ;
52- } catch ( e ) {
53- context . error (
54- `An error occurred while trying to update default Page Builder app's settings!`
55- ) ;
56- console . log ( e ) ;
43+ const coreOutput = getStackOutput ( { folder : "apps/core" , env : params . env } ) ;
44+
45+ context . info ( "Issuing a complete website rendering job..." ) ;
46+
47+ try {
48+ const client = new EventBridgeClient ( { region : coreOutput [ "region" ] } ) ;
49+
50+ const result = await client . send (
51+ new PutEventsCommand ( {
52+ Entries : [
53+ {
54+ Source : "webiny-cli" ,
55+ EventBusName : coreOutput [ "eventBusArn" ] ,
56+ DetailType : "RenderPages" ,
57+ Detail : JSON . stringify ( { path : "*" , tenant : "*" } )
58+ }
59+ ]
60+ } )
61+ ) ;
62+
63+ const entry = result . Entries ?. [ 0 ] ;
64+ if ( entry ?. ErrorMessage ) {
65+ throw new Error ( entry . ErrorMessage ) ;
66+ }
67+
68+ context . success ( "Website rendering job successfully issued." ) ;
69+ context . info (
70+ "Please note that it can take a couple of minutes for the website to be fully updated."
71+ ) ;
72+ } catch ( e ) {
73+ context . error ( `An error occurred while issuing a website rendering job!` ) ;
74+ console . log ( e ) ;
75+ }
5776 }
58- }
77+ } ;
5978} ;
0 commit comments