@@ -270,6 +270,45 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
270
270
return func;
271
271
});
272
272
273
+ log('Validating functions');
274
+ // Validation is done BEFORE deploying so the deployment process can be run in async with progress update
275
+ for (let i = 0; i < functions.length; i++) {
276
+ const func = functions[i];
277
+
278
+ if (!func.entrypoint) {
279
+ log(`Function ${func.name} does not have an endpoint`);
280
+ const answers = await inquirer.prompt(questionsGetEntrypoint)
281
+ func.entrypoint = answers.entrypoint;
282
+ localConfig.updateFunction(func['$id'], func);
283
+ }
284
+
285
+ if (func.variables) {
286
+ func.deployVariables = yes;
287
+
288
+ try {
289
+ const { total } = await functionsListVariables({
290
+ functionId: func['$id'],
291
+ queries: [JSON.stringify({ method: 'limit', values: [1] })],
292
+ parseOutput: false
293
+ });
294
+
295
+ if (total === 0) {
296
+ func.deployVariables = true;
297
+ } else if (total > 0 && !func.deployVariables) {
298
+ log(`The function ${func.name} has remote variables setup`);
299
+ const variableAnswers = await inquirer.prompt(questionsDeployFunctions[1])
300
+ func.deployVariables = variableAnswers.override.toLowerCase() === "yes";
301
+ }
302
+ } catch (e) {
303
+ if (e.code != 404) {
304
+ throw e.message;
305
+ }
306
+ }
307
+ }
308
+ }
309
+
310
+
311
+ log('All functions are validated');
273
312
log('Pushing functions\n');
274
313
275
314
Updater.start(false,)
@@ -352,28 +391,10 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
352
391
}
353
392
354
393
if (func.variables) {
355
- // TODO:
356
- // Delete existing variables
357
-
358
- const { total } = await functionsListVariables({
359
- functionId: func['$id'],
360
- queries: [JSON.stringify({ method: 'limit', values: [1] })],
361
- parseOutput: false
362
- });
363
-
364
- let deployVariables = yes;
365
-
366
- if (total === 0) {
367
- deployVariables = true;
368
- } else if (total > 0 && !yes) {
369
- const variableAnswers = await inquirer.prompt(questionsDeployFunctions[1])
370
- deployVariables = variableAnswers.override.toLowerCase() === "yes";
371
- }
372
-
373
- if (!deployVariables) {
374
- log(`Skipping variables for ${func.name} ( ${func['$id']} )`);
394
+ if (!func.deployVariables) {
395
+ updaterRow.update({ end: 'Skipping variables' });
375
396
} else {
376
- log(`Deploying variables for ${func.name} ( ${func['$id']} )` );
397
+ updaterRow.update({ end: 'Pushing variables' } );
377
398
378
399
const { variables } = await paginate(functionsListVariables, {
379
400
functionId: func['$id'],
@@ -406,13 +427,6 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
406
427
}
407
428
}
408
429
409
- // Create tag
410
- if (!func.entrypoint) {
411
- const answers = await inquirer.prompt(questionsGetEntrypoint)
412
- func.entrypoint = answers.entrypoint;
413
- localConfig.updateFunction(func['$id'], func);
414
- }
415
-
416
430
try {
417
431
updaterRow.update({ status: 'Pushing' }).replaceSpinner(SPINNER_ARC);
418
432
response = await functionsCreateDeployment({
0 commit comments