11/*
2- Copyright 2020 Adobe. All rights reserved.
2+ Copyright 2024 Adobe. All rights reserved.
33This file is licensed to you under the Apache License, Version 2.0 (the "License");
44you may not use this file except in compliance with the License. You may obtain a copy
55of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -10,60 +10,52 @@ OF ANY KIND, either express or implied. See the License for the specific languag
1010governing permissions and limitations under the License.
1111*/
1212
13- const { runInProcess, createWebExportFilter } = require ( './app-helper' )
13+ const { runInProcess } = require ( './app-helper' )
1414const { deployActions } = require ( '@adobe/aio-lib-runtime' )
15+ const logActions = require ( './log-actions' )
1516
1617/**
1718 * Deploys actions.
1819 *
19- * @param {object } config see src/lib/config-loader.js
20- * @param {boolean } isLocalDev default false, set to true if it's a local deploy
21- * @param {Function } [log] a log function
22- * @param {boolean } filter true if a filter by built actions is desired.
20+ * @private
21+ * @param {object } options
22+ * @param {object } options.config see src/lib/config-loader.js
23+ * @param {object } [options.deployConfig] see https://github.com/adobe/aio-lib-runtime/blob/master/README.md#typedefs
24+ * @param {Function } [options.log] a log function
25+ * @param {Function } [options.inprocHook] a hook function
2326 */
24- /** @private */
25- module . exports = async ( config , isLocalDev = false , log = ( ) => { } , filter = false , inprocHook ) => {
27+ module . exports = async ( {
28+ config,
29+ deployConfig = { } ,
30+ log = ( ) => { } ,
31+ inprocHook
32+ } ) => {
2633 await runInProcess ( config . hooks [ 'pre-app-deploy' ] , config )
27- const script = await runInProcess ( config . hooks [ 'deploy-actions' ] , { config, options : { isLocalDev, filter } } )
34+
35+ const hookFilterEntities = Array . isArray ( deployConfig . filterEntities ?. actions ) ? deployConfig . filterEntities . actions : [ ]
36+ const hookData = {
37+ appConfig : config ,
38+ filterEntities : hookFilterEntities ,
39+ isLocalDev : deployConfig . isLocalDev
40+ }
41+
42+ let entities
43+ const script = await runInProcess ( config . hooks [ 'deploy-actions' ] , hookData )
2844 if ( ! script ) {
29- const deployConfig = {
30- isLocalDev,
31- filterEntities : {
32- byBuiltActions : filter
33- }
34- }
3545 if ( inprocHook ) {
36- const hookFilterEntities = Array . isArray ( filter ) ? filter : [ ]
37- const hookResults = await inprocHook ( 'deploy-actions' , {
38- appConfig : config ,
39- filterEntities : hookFilterEntities ,
40- isLocalDev
41- } )
46+ const hookResults = await inprocHook ( 'deploy-actions' , hookData )
4247 if ( hookResults ?. failures ?. length > 0 ) {
4348 // output should be "Error : <plugin-name> : <error-message>\n" for each failure
4449 log ( 'Error: ' + hookResults . failures . map ( f => `${ f . plugin . name } : ${ f . error . message } ` ) . join ( '\nError: ' ) )
4550 throw new Error ( `Hook 'deploy-actions' failed with ${ hookResults . failures [ 0 ] . error } ` )
4651 }
4752 }
48- const entities = await deployActions ( config , deployConfig , log )
49- if ( entities . actions ) {
50- const web = entities . actions . filter ( createWebExportFilter ( true ) )
51- const nonWeb = entities . actions . filter ( createWebExportFilter ( false ) )
5253
53- if ( web . length > 0 ) {
54- log ( 'web actions:' )
55- web . forEach ( a => {
56- log ( ` -> ${ a . url || a . name } ` )
57- } )
58- }
59-
60- if ( nonWeb . length > 0 ) {
61- log ( 'non-web actions:' )
62- nonWeb . forEach ( a => {
63- log ( ` -> ${ a . url || a . name } ` )
64- } )
65- }
66- }
54+ entities = await deployActions ( config , deployConfig , log )
55+ await logActions ( { entities, log } )
6756 }
57+
6858 await runInProcess ( config . hooks [ 'post-app-deploy' ] , config )
59+
60+ return { script, entities }
6961}
0 commit comments