Skip to content

Commit 901e045

Browse files
committed
feat(cli): Validation function possible path before deploying
1 parent 9318d48 commit 901e045

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

templates/cli/lib/commands/deploy.js.twig

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,45 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
270270
return func;
271271
});
272272

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');
273312
log('Pushing functions\n');
274313

275314
Updater.start(false,)
@@ -352,28 +391,10 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
352391
}
353392

354393
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' });
375396
} else {
376-
log(`Deploying variables for ${func.name} ( ${func['$id']} )`);
397+
updaterRow.update({ end: 'Pushing variables' });
377398

378399
const { variables } = await paginate(functionsListVariables, {
379400
functionId: func['$id'],
@@ -406,13 +427,6 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
406427
}
407428
}
408429

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-
416430
try {
417431
updaterRow.update({ status: 'Pushing' }).replaceSpinner(SPINNER_ARC);
418432
response = await functionsCreateDeployment({

templates/cli/lib/updater.js.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Updater {
5252
}
5353

5454
static #line(prefix, start, middle, end, separator = '•') {
55-
return `${prefix} ${start} ${separator} ${middle} ${separator} ${end}`;
55+
return `${prefix} ${start} ${separator} ${middle} ${!end ? '' : separator} ${end}`;
5656

5757
}
5858

0 commit comments

Comments
 (0)