Skip to content

Commit 5ad093c

Browse files
committed
Beginning async function deployment
1 parent 36a37b8 commit 5ad093c

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const _progress = require('cli-progress');
12
const inquirer = require("inquirer");
23
const JSONbig = require("json-bigint")({ storeAsString: false });
34
const { Command } = require("commander");
@@ -269,8 +270,17 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
269270
return func;
270271
});
271272

273+
const updatesBar = new _progress.MultiBar({
274+
format: ` ${success('{status}')} | {function}({id})`,
275+
hideCursor: true,
276+
clearOnComplete: false,
277+
stopOnComplete: true,
278+
noTTYOutput: true
279+
});
280+
log('Deploying functions')
272281
for (let func of functions) {
273-
log(`Deploying function ${func.name} ( ${func['$id']} )`)
282+
const a = updatesBar.create(4, 0, { status: '', function: func.name, id: func['$id'] })
283+
{#log(`Deploying function ${func.name} ( ${func['$id']} )`)#}
274284

275285
try {
276286
response = await functionsGet({
@@ -281,7 +291,7 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
281291
if (response.runtime !== func.runtime) {
282292
throw new Error(`Runtime missmatch! (local=${func.runtime},remote=${response.runtime}) Please delete remote function or update your appwrite.json`);
283293
}
284-
294+
a.increment({status:'Updating'})
285295
response = await functionsUpdate({
286296
functionId: func['$id'],
287297
name: func.name,
@@ -298,6 +308,7 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
298308
});
299309
} catch (e) {
300310
if (e.code == 404) {
311+
a.increment({status:'Creating'})
301312
log(`Function ${func.name} ( ${func['$id']} ) does not exist in the project. Creating ... `);
302313
response = await functionsCreate({
303314
functionId: func.$id || 'unique()',
@@ -353,15 +364,15 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
353364
functionId: func['$id'],
354365
parseOutput: false
355366
}, 100, 'variables');
356-
367+
357368
await Promise.all(variables.map(async variable => {
358369
await functionsDeleteVariable({
359370
functionId: func['$id'],
360371
variableId: variable['$id'],
361372
parseOutput: false
362373
});
363374
}));
364-
375+
365376
let result = await awaitPools.wipeVariables(func['$id']);
366377
if (!result) {
367378
throw new Error("Variable deletion timed out.");
@@ -938,4 +949,4 @@ deploy
938949

939950
module.exports = {
940951
deploy
941-
}
952+
}

templates/cli/package.json.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"dependencies": {
2525
"undici": "^5.28.2",
2626
"chalk": "4.1.2",
27+
"cli-progress": "^3.12.0",
2728
"cli-table3": "^0.6.2",
2829
"commander": "^9.2.0",
2930
"form-data": "^4.0.0",

0 commit comments

Comments
 (0)