Fixed errors in Linter

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2021-06-29 23:19:12 +02:00
parent 0dc81b7657
commit a64f2e3d01
Signed by: Florian Bouillon
GPG Key ID: 50BD648F12C86AB6
2 changed files with 35 additions and 32 deletions

View File

@ -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<void> {
return new Promise<void>((res, rej) => {
return new Promise<void>((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<void> {
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<any>) {
if (this.debug) {
logger.log(...messages)

29
main.ts
View File

@ -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,32 +18,35 @@ 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)) {
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.mkdir(subFolder, { recursive: true })
await fs.writeFile(`${subFolder}/index.json`, JSON.stringify(val))
if (endpoint.sub) {
console.log(file, 'Running subItem', key)
@ -50,7 +54,7 @@ const VERSION = 'v2'
if (subItems) {
await Promise.all(objectMap(subItems, async (subVal, sybKey) => {
const subSubFolder = `${subFolder}/${urlize(sybKey)}`
await fs.mkdir(subSubFolder, {recursive: true})
await fs.mkdir(subSubFolder, { recursive: true })
await fs.writeFile(`${subSubFolder}/index.json`, JSON.stringify(subVal))
}))
}
@ -58,8 +62,5 @@ const VERSION = 'v2'
}
}
console.log(file, 'Finished Item')
} else {
console.log(file, 'skipped Item')
}
}
})()