From a64f2e3d01d82deb9aaaf2f569b36bd51b0a570e Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 29 Jun 2021 23:19:12 +0200 Subject: [PATCH] Fixed errors in Linter Signed-off-by: Avior --- SFTPPromise.ts | 10 +++++---- main.ts | 57 +++++++++++++++++++++++++------------------------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/SFTPPromise.ts b/SFTPPromise.ts index ef41e69..3ce3d0a 100644 --- a/SFTPPromise.ts +++ b/SFTPPromise.ts @@ -1,3 +1,4 @@ +/* eslint-disable max-statements */ import { ConnectConfig, Client, SFTPWrapper } from 'ssh2' import { Stats, InputAttributes } from 'ssh2-streams' import { promises as fs } from 'fs' @@ -26,7 +27,7 @@ export default class SFTPPromise { public constructor(public config: ConnectConfig) {} public connect(): Promise { - return new Promise((res, rej) => { + return new Promise((res) => { this.conn.on('ready', () => { this.conn.sftp((err, sftpLocal) => { this.sftp = sftpLocal @@ -154,7 +155,7 @@ export default class SFTPPromise { return res } - public async uploadDir(localPath: string, remotePath: string, exclude?: RegExp, root = true) { + public async uploadDir(localPath: string, remotePath: string, exclude?: RegExp, root = true): Promise { if (root) { this.filesToUpload = 0 this.filesUploaded = 0 @@ -165,7 +166,7 @@ export default class SFTPPromise { logger.log('Running !') this.filesToUpload += files.length this.queue.start() - for (const file of files) { + for await (const file of files) { // console.log('t1') if (exclude?.test(file)) { continue @@ -182,7 +183,7 @@ export default class SFTPPromise { this.lastTimeDiff.push(new Date().getTime() - now) this.lastTimeDiff.shift() const time = (this.filesToUpload - this.filesUploaded) * (this.lastTimeDiff.reduce((p, c) => p + c, 0) / this.lastTimeDiff.length) / 10000 - console.log(`Files uploaded ${(this.filesUploaded * 100 / this.filesToUpload).toFixed(0)}% ${time > 60 ? `${(time/60).toFixed(0)}m` : `${time.toFixed(0)}s`} ${this.filesUploaded}/${this.filesToUpload}`) + console.log(`Files uploaded ${(this.filesUploaded * 100 / this.filesToUpload).toFixed(0)}% ${time > 60 ? `${(time / 60).toFixed(0)}m` : `${time.toFixed(0)}s`} ${this.filesUploaded}/${this.filesToUpload}`) }) .catch((err) => logger.log(err, 'Error uploading', filePath, 'to', remoteFilePath)) ) @@ -200,6 +201,7 @@ export default class SFTPPromise { return this.sftp } + // eslint-disable-next-line id-length private l(...messages: Array) { if (this.debug) { logger.log(...messages) diff --git a/main.ts b/main.ts index f1315d4..7cbebf2 100644 --- a/main.ts +++ b/main.ts @@ -1,6 +1,7 @@ +/* eslint-disable max-statements */ import { SupportedLanguages } from 'db/interfaces' import { Endpoint } from 'interfaces' -import { promises as fs} from 'fs' +import { promises as fs } from 'fs' import { objectMap } from '@dzeio/object-util' import { urlize, fetchRemoteFile } from './utils/util' import { config } from 'dotenv' @@ -17,49 +18,49 @@ const VERSION = 'v2' console.log('Prefetching pictures') await fetchRemoteFile('https://assets.tcgdex.net/datas.json') - await fs.rm(`./dist/${VERSION}/${lang}`, {recursive: true, force: true}) + await fs.rm(`./dist/${VERSION}/${lang}`, { force: true, recursive: true }) console.log('Let\'s GO !') - for (const file of paths) { + for await (const file of paths) { const path = `./endpoints/${file}` console.log(file, 'Running Init') - const ep = (await import(path)).default - const endpoint = new ep(lang) as Endpoint + const Ep = (await import(path)).default + const endpoint = new Ep(lang) as Endpoint console.log(file, 'Running Common') - let common: any | undefined = undefined + let common: any | null = null if (endpoint.common) { common = await endpoint.common() } console.log(file, 'Running Index') const folder = `./dist/${VERSION}/${lang}/${urlize(path.replace('./endpoints/', '').replace('.ts', ''))}` - await fs.mkdir(folder, {recursive: true}) + await fs.mkdir(folder, { recursive: true }) await fs.writeFile(`${folder}/index.json`, JSON.stringify( await endpoint.index(common) )) console.log(file, 'Finished Index') console.log(file, 'Running Item') const item = await endpoint.item(common) - if (item) { - for (const key of Object.keys(item)) { - const val = item[key] - const subFolder = `${folder}/${urlize(key)}` - await fs.mkdir(subFolder, {recursive: true}) - await fs.writeFile(`${subFolder}/index.json`, JSON.stringify(val)) - if (endpoint.sub) { - console.log(file, 'Running subItem', key) - const subItems = await endpoint.sub(common, key) - if (subItems) { - await Promise.all(objectMap(subItems, async (subVal, sybKey) => { - const subSubFolder = `${subFolder}/${urlize(sybKey)}` - await fs.mkdir(subSubFolder, {recursive: true}) - await fs.writeFile(`${subSubFolder}/index.json`, JSON.stringify(subVal)) - })) - } - console.log(file, 'Finished subItem', key) - } - } - console.log(file, 'Finished Item') - } else { + if (!item) { console.log(file, 'skipped Item') + continue } + for await (const key of Object.keys(item)) { + const val = item[key] + const subFolder = `${folder}/${urlize(key)}` + await fs.mkdir(subFolder, { recursive: true }) + await fs.writeFile(`${subFolder}/index.json`, JSON.stringify(val)) + if (endpoint.sub) { + console.log(file, 'Running subItem', key) + const subItems = await endpoint.sub(common, key) + if (subItems) { + await Promise.all(objectMap(subItems, async (subVal, sybKey) => { + const subSubFolder = `${subFolder}/${urlize(sybKey)}` + await fs.mkdir(subSubFolder, { recursive: true }) + await fs.writeFile(`${subSubFolder}/index.json`, JSON.stringify(subVal)) + })) + } + console.log(file, 'Finished subItem', key) + } + } + console.log(file, 'Finished Item') } })()