Skip to content

Commit 329acc3

Browse files
committed
feat: Deploy all resources or single resource at once.
1 parent af7e4b5 commit 329acc3

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

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

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const JSONbig = require("json-bigint")({ storeAsString: false });
33
const { Command } = require("commander");
44
const { localConfig } = require("../config");
55
const { paginate } = require('../paginate');
6-
const { questionsDeployBuckets, questionsDeployTeams, questionsDeployFunctions, questionsGetEntrypoint, questionsDeployCollections, questionsConfirmDeployCollections } = require("../questions");
6+
const { questionsDeployResources, questionsDeployBuckets, questionsDeployTeams, questionsDeployFunctions, questionsGetEntrypoint, questionsDeployCollections, questionsConfirmDeployCollections } = require("../questions");
77
const { actionRunner, success, log, error, commandDescriptions } = require("../parser");
88
const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsUpdateDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions');
99
const {
@@ -227,14 +227,27 @@ const awaitPools = {
227227
},
228228
}
229229

230-
const deploy = new Command("deploy")
231-
.description(commandDescriptions['deploy'])
232-
.configureHelp({
233-
helpWidth: process.stdout.columns || 80
234-
})
235-
.action(actionRunner(async (_options, command) => {
236-
command.help()
237-
}));
230+
const deployResources = async ({ all, yes } = {}) => {
231+
const actions = {
232+
functions: deployFunction,
233+
collections: deployCollection,
234+
buckets: deployBucket,
235+
teams: deployTeam,
236+
messages: new Function()
237+
}
238+
239+
if (all) {
240+
Object.values(actions).forEach(action => action({ all: true, yes }));
241+
} else {
242+
const answers = await inquirer.prompt(questionsDeployResources[0]);
243+
answers.resources.forEach((resource) => {
244+
const action = actions[resource];
245+
if (action !== undefined) {
246+
action({ all: true, yes });
247+
}
248+
})
249+
}
250+
};
238251

239252
const deployFunction = async ({ functionId, all, yes } = {}) => {
240253
let response = {};
@@ -353,15 +366,15 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
353366
functionId: func['$id'],
354367
parseOutput: false
355368
}, 100, 'variables');
356-
369+
357370
await Promise.all(variables.map(async variable => {
358371
await functionsDeleteVariable({
359372
functionId: func['$id'],
360373
variableId: variable['$id'],
361374
parseOutput: false
362375
});
363376
}));
364-
377+
365378
let result = await awaitPools.wipeVariables(func['$id']);
366379
if (!result) {
367380
throw new Error("Variable deletion timed out.");
@@ -906,6 +919,11 @@ const deployTeam = async ({ all, yes } = {}) => {
906919
}
907920
}
908921
}
922+
const deploy = new Command("deploy")
923+
.description(commandDescriptions['deploy'])
924+
.option(`--all`, `Flag to deploy all resources`)
925+
.option(`--yes`, `Flag to confirm all warnings`)
926+
.action(actionRunner(deployResources));
909927

910928
deploy
911929
.command("function")
@@ -938,4 +956,4 @@ deploy
938956

939957
module.exports = {
940958
deploy
941-
}
959+
}

templates/cli/lib/questions.js.twig

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,12 @@ const questionsInitFunction = [
209209
parseOutput: false
210210
})
211211
let runtimes = response["runtimes"]
212-
let choices = runtimes.map((runtime, idx) => {
212+
let choices = runtimes.map((runtime, idx) => {
213213
return {
214214
name: `${runtime.name} (${runtime['$id']})`,
215-
value: {
216-
id: runtime['$id'],
217-
entrypoint: getEntrypoint(runtime['$id']),
215+
value: {
216+
id: runtime['$id'],
217+
entrypoint: getEntrypoint(runtime['$id']),
218218
ignore: getIgnores(runtime['$id']),
219219
commands : getInstallCommand(runtime['$id'])
220220
},
@@ -276,6 +276,21 @@ const questionsLogin = [
276276
},
277277
];
278278

279+
const questionsDeployResources = [
280+
{
281+
type: "checkbox",
282+
name: "resources",
283+
message: "Which resources would you like to deploy?",
284+
choices: [
285+
{ name: 'Functions', value: 'functions' },
286+
{ name: 'Collections', value: 'collections' },
287+
{ name: 'Buckets', value: 'buckets' },
288+
{ name: 'Teams', value: 'teams' },
289+
{ name: 'Messages', value: 'messages' }
290+
]
291+
}
292+
]
293+
279294
const questionsDeployFunctions = [
280295
{
281296
type: "checkbox",
@@ -403,7 +418,7 @@ const questionsListFactors = [
403418
sdk: client,
404419
parseOutput: false
405420
});
406-
421+
407422
const choices = [
408423
{
409424
name: `TOTP (Time-based One-time Password)`,
@@ -447,6 +462,7 @@ module.exports = {
447462
questionsLogin,
448463
questionsInitFunction,
449464
questionsInitCollection,
465+
questionsDeployResources,
450466
questionsDeployFunctions,
451467
questionsDeployCollections,
452468
questionsDeployBuckets,

0 commit comments

Comments
 (0)