@@ -3,7 +3,7 @@ const JSONbig = require("json-bigint")({ storeAsString: false });
3
3
const { Command } = require("commander");
4
4
const { localConfig } = require("../config");
5
5
const { loaderInterval, clearLoaderInterval, } = require('../utils');
6
- const { formatterFunction } = require('../formatters ');
6
+ const { Updater, SPINNER_ARC, SPINNER_DOTS } = require('../updater ');
7
7
const { paginate } = require('../paginate');
8
8
const { questionsDeployBuckets, questionsDeployTeams, questionsDeployFunctions, questionsGetEntrypoint, questionsDeployCollections, questionsConfirmDeployCollections } = require("../questions");
9
9
const { actionRunner, success, log, error, commandDescriptions } = require("../parser");
@@ -271,19 +271,18 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
271
271
return func;
272
272
});
273
273
274
+ log('Pushing functions\n');
274
275
275
-
276
- log('Deploying functions\n');
277
-
276
+ Updater.start(false,)
278
277
let successfullyDeployed = 0;
279
278
280
279
await Promise.all(functions.map(async (func) => {
281
280
const ignore = func.ignore ? 'appwrite.json' : '.gitignore';
282
281
let functionExists = false;
283
282
284
- const bar = updatesBar.create(100, 0, { status: 'Deploying ', function : func.name, id: func['$id'], ignore })
285
- bar.update({ status: 'Getting' });
286
- const updatingInterval = loaderInterval(bar, 8, 1, 80 );
283
+ const updaterRow = new Updater( { status: '', resource : func.name, id: func['$id'], end: `Ignoring using: ${ ignore}` });
284
+
285
+ updaterRow.update({ status: 'Getting' }).startSpinner(SPINNER_DOTS );
287
286
288
287
try {
289
288
response = await functionsGet({
@@ -292,11 +291,11 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
292
291
});
293
292
functionExists = true;
294
293
if (response.runtime !== func.runtime) {
295
- bar.update({ status: 'Error', errorMessage: `Runtime missmatch! (local=${func.runtime},remote=${response.runtime}) Please delete remote function or update your appwrite.json` })
296
- clearLoaderInterval(bar, updatingInterval);
294
+ updaterRow.fail({ errorMessage: `Runtime mismatch! (local=${func.runtime},remote=${response.runtime}) Please delete remote function or update your appwrite.json` })
297
295
return;
298
296
}
299
- bar.update({ status: 'Updating' });
297
+
298
+ updaterRow.update({ status: 'Updating' }).replaceSpinner(SPINNER_ARC);
300
299
301
300
response = await functionsUpdate({
302
301
functionId: func['$id'],
@@ -317,17 +316,13 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
317
316
if (e.code == 404) {
318
317
functionExists = false;
319
318
} else {
320
- clearLoaderInterval(bar, updatingInterval)
321
- bar.update({ status: 'Error', errorMessage: e.message ?? 'General error occurs please try again' });
319
+ updaterRow.fail({ errorMessage: e.message ?? 'General error occurs please try again' });
322
320
return;
323
321
}
324
322
}
325
323
326
- clearLoaderInterval(bar, updatingInterval)
327
-
328
324
if (!functionExists) {
329
- bar.update({ status: 'Creating' })
330
- const creatingInterval = loaderInterval(bar, 8, 1, 80);
325
+ updaterRow.update({ status: 'Creating' }).replaceSpinner(SPINNER_DOTS);
331
326
332
327
try {
333
328
response = await functionsCreate({
@@ -350,13 +345,9 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
350
345
"$id": response['$id'],
351
346
});
352
347
func["$id"] = response['$id'];
353
- bar.update({ status: 'Created' });
354
-
355
- clearLoaderInterval(bar, creatingInterval);
348
+ updaterRow.update({ status: 'Created' });
356
349
} catch (e) {
357
- clearLoaderInterval(bar, creatingInterval);
358
-
359
- bar.update({ status: 'Error', errorMessage: e.message ?? 'General error occurs please try again' });
350
+ updaterRow.fail({ errorMessage: e.message ?? 'General error occurs please try again' });
360
351
return;
361
352
}
362
353
}
@@ -400,7 +391,7 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
400
391
401
392
let result = await awaitPools.wipeVariables(func['$id']);
402
393
if (!result) {
403
- bar.update({ status: 'Error', errorMessage: 'Variable deletion timed out' })
394
+ updaterRow.fail({ errorMessage: 'Variable deletion timed out' })
404
395
return;
405
396
}
406
397
@@ -422,10 +413,9 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
422
413
func.entrypoint = answers.entrypoint;
423
414
localConfig.updateFunction(func['$id'], func);
424
415
}
425
- bar.update({ status: 'Deploying' })
426
- const deployingInterval = loaderInterval(bar, 8, 1, 80);
427
416
428
417
try {
418
+ updaterRow.update({ status: 'Pushing' }).replaceSpinner(SPINNER_ARC);
429
419
response = await functionsCreateDeployment({
430
420
functionId: func['$id'],
431
421
entrypoint: func.entrypoint,
@@ -435,23 +425,23 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
435
425
parseOutput: false
436
426
})
437
427
438
- bar .update({ status: 'Deployed ' })
428
+ updaterRow .update({ status: 'Pushed ' })
439
429
successfullyDeployed++;
440
430
441
431
} catch (e) {
442
432
switch (e.code) {
443
433
case 'ENOENT':
444
- bar.update({ status: 'Error', errorMessage: 'Not found in the current directory. Skipping...' })
434
+ updaterRow.fail({ errorMessage: 'Not found in the current directory. Skipping...' })
445
435
break;
446
436
default:
447
- bar.update({ status: 'Error', errorMessage: e.message ?? 'General error occurs please try again' })
437
+ updaterRow.fail({ errorMessage: e.message ?? 'General error occurs please try again' })
448
438
}
449
439
}
450
- clearLoaderInterval(bar, deployingInterval );
440
+ updaterRow.stopSpinner( );
451
441
}))
442
+ Updater.stop();
452
443
453
- updatesBar.stop()
454
- success(`Deployed ${successfullyDeployed} functions`);
444
+ success(`Pushed ${successfullyDeployed} functions`);
455
445
}
456
446
457
447
const createAttribute = async (databaseId, collectionId, attribute) => {
0 commit comments