test: add tests

This commit is contained in:
2026-10-16 00:43:09 +03:00
parent c3c0b07d32
commit 0edfb12473
10 changed files with 2112 additions and 2952 deletions
-9
View File
@@ -75,17 +75,8 @@ export class Config {
this.flags = [];
this.icon = null;
this.meta = {
title: null,
filename: null,
icon: null,
version: null,
pack: null,
author: null,
company: null,
width: 800,
height: 600,
mobileWidth: null,
mobileHeight: null,
fps: 60,
};
this.key = null;
+84
View File
@@ -0,0 +1,84 @@
import progress from "cli-progress";
import fs from "fs";
import fse from "fs-extra";
import got from "got";
import path from "path";
import ps from "promise-streams";
import type Stream from "stream";
import * as tar from "tar";
import unzip from "unzip-stream";
export class Downloader {
static bar: progress.MultiBar | null;
static createProgressBar() {
if (Downloader.bar == null) {
Downloader.bar = new progress.MultiBar(
{
clearOnComplete: true,
},
progress.Presets.shades_grey,
);
}
return Downloader.bar.create(0, 0);
}
static releaseProgressBar(bar: progress.SingleBar) {
bar.stop();
if (Downloader.bar != null) {
Downloader.bar.remove(bar);
if (!Downloader.bar.isActive) {
Downloader.bar.stop();
Downloader.bar = null;
}
}
}
static download(url: string, dest: string, strip = 1, executable = false) {
fse.ensureDirSync(dest);
const bar = Downloader.createProgressBar();
let stream: Stream = got.stream(url);
stream = stream
.on("request", (r: any) => {
if (bar) bar.start(1, 0);
})
.on("downloadProgress", (p: any) => {
if (bar) {
bar.setTotal(p.total);
bar.update(p.transferred);
if (p.total === p.transferred) {
Downloader.releaseProgressBar(bar);
}
}
});
if (url.endsWith(".zip")) {
stream = stream.pipe(unzip.Parse()).on("entry", (entry: any) => {
const filePath = entry.path.split("/").slice(strip).join(path.sep);
if (filePath.length > 0) {
if (entry.type === "Directory") {
fse.ensureDirSync(path.join(dest, path.normalize(filePath)));
} else if (entry.type === "File") {
const fullFilePath = path.join(dest, path.normalize(filePath));
const dirPath = path.dirname(fullFilePath);
if (!fs.existsSync(dirPath)) {
fse.ensureDirSync(dirPath);
}
entry.pipe(
fs.createWriteStream(path.join(dest, path.normalize(filePath)), {
// ToDo: zip entry file mode?
mode: executable ? 0o755 : undefined,
}),
);
}
} else {
entry.autodrain();
}
});
} else if (url.endsWith("tar.gz")) {
stream = stream.pipe(tar.x({ C: dest, strip }));
} else {
stream = stream.pipe(fs.createWriteStream(path.join(dest, url.split("/").pop()!)));
}
return ps.wait(stream);
}
}
+1 -82
View File
@@ -1,88 +1,7 @@
import progress from "cli-progress";
import fs from "fs";
import fse from "fs-extra";
import got from "got";
import os from "os";
import path from "path";
import ps from "promise-streams";
import tar from "tar";
import unzip from "unzip-stream";
import { Log } from "../common/log";
export class Downloader {
static bar: progress.MultiBar;
static createProgressBar() {
if (Downloader.bar == null) {
Downloader.bar = new progress.MultiBar(
{
clearOnComplete: true,
},
progress.Presets.shades_grey,
);
}
return Downloader.bar.create();
}
static releaseProgressBar(bar: progress.MultiBar) {
bar.stop();
if (Downloader.bar != null) {
Downloader.bar.remove(bar);
if (Downloader.bar.bars.length === 0) {
Downloader.bar.stop();
Downloader.bar = null;
}
}
}
static download(url: string, dest: string, strip = 1, executable = false) {
fse.ensureDirSync(dest);
const bar = Downloader.createProgressBar();
let stream = got.stream(url);
stream = stream
.on("request", (r: any) => {
if (bar) bar.start(1, 0);
})
.on("downloadProgress", (p: any) => {
if (bar) {
bar.setTotal(p.total);
bar.update(p.transferred);
if (p.total === p.transferred) {
Downloader.releaseProgressBar(bar);
}
}
});
if (url.endsWith(".zip")) {
stream = stream.pipe(unzip.Parse()).on("entry", (entry: any) => {
const filePath = entry.path.split("/").slice(strip).join(path.sep);
if (filePath.length > 0) {
if (entry.type === "Directory") {
fse.ensureDirSync(path.join(dest, path.normalize(filePath)));
} else if (entry.type === "File") {
const fullFilePath = path.join(dest, path.normalize(filePath));
const dirPath = path.dirname(fullFilePath);
if (!fs.existsSync(dirPath)) {
fse.ensureDirSync(dirPath);
}
entry.pipe(
fs.createWriteStream(path.join(dest, path.normalize(filePath)), {
// ToDo: zip entry file mode?
mode: executable ? 0o755 : undefined,
}),
);
}
} else {
entry.autodrain();
}
});
} else if (url.endsWith("tar.gz")) {
stream = stream.pipe(tar.x({ C: dest, strip: strip }));
} else {
stream = stream.pipe(fs.createWriteStream(path.join(dest, url.split("/").pop()!)));
}
return ps.wait(stream);
}
}
import { Downloader } from "./download";
export class Sdk {
static _dir: string;