Skip to content

Commit 836e79c

Browse files
committed
refactor(cli): Updater -> Spinner, and refactoring
1 parent 3e9d58c commit 836e79c

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/SDK/Language/CLI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ public function getFiles(): array
134134
],
135135
[
136136
'scope' => 'default',
137-
'destination' => 'lib/updater.js',
138-
'template' => 'cli/lib/updater.js.twig',
137+
'destination' => 'lib/spinner.js',
138+
'template' => 'cli/lib/spinner.js.twig',
139139
],
140140
[
141141
'scope' => 'default',

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const inquirer = require("inquirer");
22
const JSONbig = require("json-bigint")({ storeAsString: false });
33
const { Command } = require("commander");
44
const { localConfig } = require("../config");
5-
const { Updater, SPINNER_ARC, SPINNER_DOTS } = require('../updater');
5+
const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner');
66
const { paginate } = require('../paginate');
77
const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionsConfirmPushCollections } = require("../questions");
88
const { actionRunner, success, log, error, commandDescriptions } = require("../parser");
@@ -272,8 +272,7 @@ const pushFunction = async ({ functionId, all, yes } = {}) => {
272272

273273
log('Validating functions');
274274
// Validation is done BEFORE pushing 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];
275+
for (let func of functions) {
277276

278277
if (!func.entrypoint) {
279278
log(`Function ${func.name} does not have an endpoint`);
@@ -311,14 +310,14 @@ const pushFunction = async ({ functionId, all, yes } = {}) => {
311310
log('All functions are validated');
312311
log('Pushing functions\n');
313312

314-
Updater.start(false,)
313+
Spinner.start(false);
315314
let successfullyPushed = 0;
316315

317316
await Promise.all(functions.map(async (func) => {
318317
const ignore = func.ignore ? 'appwrite.json' : '.gitignore';
319318
let functionExists = false;
320319

321-
const updaterRow = new Updater({ status: '', resource: func.name, id: func['$id'], end: `Ignoring using: ${ignore}` });
320+
const updaterRow = new Spinner({ status: '', resource: func.name, id: func['$id'], end: `Ignoring using: ${ignore}` });
322321

323322
updaterRow.update({ status: 'Getting' }).startSpinner(SPINNER_DOTS);
324323

@@ -453,7 +452,7 @@ const pushFunction = async ({ functionId, all, yes } = {}) => {
453452
updaterRow.stopSpinner();
454453
}));
455454

456-
Updater.stop();
455+
Spinner.stop();
457456

458457
success(`Pushed ${successfullyPushed} functions`);
459458
}

templates/cli/lib/updater.js.twig renamed to templates/cli/lib/spinner.js.twig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const spinners = {
1515
}
1616
}
1717

18-
class Updater {
18+
class Spinner {
1919
static start(clearOnComplete = true, hideCursor = true) {
20-
Updater.updatesBar = new progress.MultiBar({
20+
Spinner.updatesBar = new progress.MultiBar({
2121
format: this.#formatter,
2222
hideCursor,
2323
clearOnComplete,
@@ -27,7 +27,7 @@ class Updater {
2727
}
2828

2929
static stop() {
30-
Updater.updatesBar.stop();
30+
Spinner.updatesBar.stop();
3131
}
3232

3333
static #formatter(options, params, payload) {
@@ -48,7 +48,7 @@ class Updater {
4848
end = chalk.red(payload.errorMessage);
4949
}
5050

51-
return Updater.#line(prefix, start, middle, end);
51+
return Spinner.#line(prefix, start, middle, end);
5252
}
5353

5454
static #line(prefix, start, middle, end, separator = '•') {
@@ -57,7 +57,7 @@ class Updater {
5757
}
5858

5959
constructor(payload, total = 100, startValue = 0) {
60-
this.bar = Updater.updatesBar.create(total, startValue, payload)
60+
this.bar = Spinner.updatesBar.create(total, startValue, payload)
6161
}
6262

6363
update(payload) {
@@ -92,7 +92,7 @@ class Updater {
9292

9393

9494
module.exports = {
95-
Updater,
95+
Spinner,
9696
SPINNER_ARC,
9797
SPINNER_DOTS
9898
}

0 commit comments

Comments
 (0)