@@ -8,7 +8,7 @@ const { deployAmazon } = require('./deployer/amazon/index')
88const { publishAmazon } = require ( './publisher/amazon/index' )
99const { spinnies, log, logdev } = require ( './printers/index' )
1010const { zip } = require ( './zipper/index' )
11- const { deployGoogle } = require ( './deployer/google/index' )
11+ const { deployGoogle, publishGoogle } = require ( './deployer/google/index' )
1212const { transpile } = require ( './transpiler/index' )
1313const schema = require ( './schemas/index' ) . hyperformJsonSchema
1414
@@ -73,9 +73,10 @@ async function bundleTranspileZipGoogle(fpath) {
7373 * @param {string } name
7474 * @param {string } region
7575 * @param {string } zipPath
76- * @returns {string } URL of the endpoint of the Lambda
76+ * @param {boolean } isPublic whether to publish
77+ * @returns {string? } If isPublic was true, URL of the endpoint of the Lambda
7778 */
78- async function deployPublishAmazon ( name , region , zipPath ) {
79+ async function deployPublishAmazon ( name , region , zipPath , isPublic ) {
7980 const amazonSpinnieName = `amazon-main-${ name } `
8081 try {
8182 spinnies . add ( amazonSpinnieName , { text : `Deploying ${ name } ` } )
@@ -86,11 +87,14 @@ async function deployPublishAmazon(name, region, zipPath) {
8687 region : region ,
8788 }
8889 const amazonArn = await deployAmazon ( zipPath , amazonDeployOptions )
89- // Publish it
90- const amazonUrl = await publishAmazon ( amazonArn , region )
90+ let amazonUrl
91+ // Publish it if isPpublic
92+ if ( isPublic === true ) {
93+ amazonUrl = await publishAmazon ( amazonArn , region )
94+ }
9195 spinnies . succ ( amazonSpinnieName , { text : `🟢 ${ name } ${ chalk . rgb ( 255 , 255 , 255 ) . bgWhite ( amazonUrl ) } ` } )
9296
93- // return url
97+ // ( return url)
9498 return amazonUrl
9599 } catch ( e ) {
96100 spinnies . f ( amazonSpinnieName , {
@@ -107,9 +111,10 @@ async function deployPublishAmazon(name, region, zipPath) {
107111 * @param {string } region
108112 * @param {string } project
109113 * @param {string } zipPath
110- * @returns {string } URL of the Google Cloud Function
114+ * @param {boolean } isPublic whether to publish
115+ * @returns {string? } If isPublic was true, URL of the Google Cloud Function
111116 */
112- async function deployPublishGoogle ( name , region , project , zipPath ) {
117+ async function deployPublishGoogle ( name , region , project , zipPath , isPublic ) {
113118 const googleSpinnieName = `google-main-${ name } `
114119 try {
115120 spinnies . add ( googleSpinnieName , { text : `Deploying ${ name } ` } )
@@ -120,6 +125,11 @@ async function deployPublishGoogle(name, region, project, zipPath) {
120125 runtime : 'nodejs12' ,
121126 }
122127 const googleUrl = await deployGoogle ( zipPath , googleOptions )
128+
129+ if ( isPublic === true ) {
130+ // enables anyone with the URL to call the function
131+ await publishGoogle ( name , project , region )
132+ }
123133 spinnies . succ ( googleSpinnieName , { text : `🟢 ${ name } ${ chalk . rgb ( 255 , 255 , 255 ) . bgWhite ( googleUrl ) } ` } )
124134 console . log ( 'Google takes another 1 - 2m for changes to take effect' )
125135
@@ -138,9 +148,10 @@ async function deployPublishGoogle(name, region, project, zipPath) {
138148 * @param {string } dir
139149 * @param {Regex } fnregex
140150 * @param {* } parsedHyperformJson
151+ * @param {boolean } isPublic Controls whether (Amazon) to create URL endpoint and (Google) whether to remove IAM protection on the URL
141152 * @returns {{ urls: string[] } } urls: Mixed, nested Array of endpoint URLs.
142153 */
143- async function main ( dir , fnregex , parsedHyperformJson ) {
154+ async function main ( dir , fnregex , parsedHyperformJson , isPublic ) {
144155 const infos = await getInfos ( dir , fnregex )
145156 /*
146157 [
@@ -203,6 +214,7 @@ async function main(dir, fnregex, parsedHyperformJson) {
203214 exp ,
204215 parsedHyperformJson . amazon . aws_default_region ,
205216 amazonZipPath ,
217+ isPublic ,
206218 )
207219 }
208220
@@ -216,6 +228,7 @@ async function main(dir, fnregex, parsedHyperformJson) {
216228 'us-central1' ,
217229 'firstnodefunc' ,
218230 googleZipPath ,
231+ isPublic ,
219232 )
220233 }
221234
0 commit comments