Use eslint&prettier for code linting&formatting

This commit is contained in:
Francesco Stasi
2021-06-16 15:08:48 +02:00
committed by Francesco Stasi
parent 2a3873a923
commit 0592199858
173 changed files with 8963 additions and 3841 deletions

View File

@@ -1,5 +1,11 @@
import { ProgressMessage, ResponseService } from '../common/protocol/response-service';
import { DownloadProgress, TaskProgress } from './cli-protocol/cc/arduino/cli/commands/v1/common_pb';
import {
ProgressMessage,
ResponseService,
} from '../common/protocol/response-service';
import {
DownloadProgress,
TaskProgress,
} from './cli-protocol/cc/arduino/cli/commands/v1/common_pb';
export interface InstallResponse {
getProgress?(): DownloadProgress | undefined;
@@ -7,7 +13,6 @@ export interface InstallResponse {
}
export namespace InstallWithProgress {
export interface Options {
/**
* _unknown_ progress if falsy.
@@ -16,23 +21,36 @@ export namespace InstallWithProgress {
readonly responseService: ResponseService;
}
export function createDataCallback({ responseService, progressId }: InstallWithProgress.Options): (response: InstallResponse) => void {
export function createDataCallback({
responseService,
progressId,
}: InstallWithProgress.Options): (response: InstallResponse) => void {
let localFile = '';
let localTotalSize = Number.NaN;
return (response: InstallResponse) => {
const download = response.getProgress ? response.getProgress() : undefined;
const download = response.getProgress
? response.getProgress()
: undefined;
const task = response.getTaskProgress();
if (!download && !task) {
throw new Error("Implementation error. Neither 'download' nor 'task' is available.");
throw new Error(
"Implementation error. Neither 'download' nor 'task' is available."
);
}
if (task && download) {
throw new Error("Implementation error. Both 'download' and 'task' are available.");
throw new Error(
"Implementation error. Both 'download' and 'task' are available."
);
}
if (task) {
const message = task.getName() || task.getMessage();
if (message) {
if (progressId) {
responseService.reportProgress({ progressId, message, work: { done: Number.NaN, total: Number.NaN } });
responseService.reportProgress({
progressId,
message,
work: { done: Number.NaN, total: Number.NaN },
});
}
responseService.appendToOutput({ chunk: `${message}\n` });
}
@@ -40,7 +58,10 @@ export namespace InstallWithProgress {
if (download.getFile() && !localFile) {
localFile = download.getFile();
}
if (download.getTotalSize() > 0 && Number.isNaN(localTotalSize)) {
if (
download.getTotalSize() > 0 &&
Number.isNaN(localTotalSize)
) {
localTotalSize = download.getTotalSize();
}
@@ -51,15 +72,29 @@ export namespace InstallWithProgress {
if (progressId && localFile) {
let work: ProgressMessage.Work | undefined = undefined;
if (download.getDownloaded() > 0 && !Number.isNaN(localTotalSize)) {
work = { total: localTotalSize, done: download.getDownloaded() };
if (
download.getDownloaded() > 0 &&
!Number.isNaN(localTotalSize)
) {
work = {
total: localTotalSize,
done: download.getDownloaded(),
};
}
responseService.reportProgress({ progressId, message: `Downloading ${localFile}`, work });
responseService.reportProgress({
progressId,
message: `Downloading ${localFile}`,
work,
});
}
if (download.getCompleted()) {
// Discard local state.
if (progressId && !Number.isNaN(localTotalSize)) {
responseService.reportProgress({ progressId, message: '', work: { done: Number.NaN, total: Number.NaN } });
responseService.reportProgress({
progressId,
message: '',
work: { done: Number.NaN, total: Number.NaN },
});
}
localFile = '';
localTotalSize = Number.NaN;
@@ -67,6 +102,4 @@ export namespace InstallWithProgress {
}
};
}
}