@@ -5,10 +5,12 @@ import { fileURLToPath } from "url";
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
export default new Eta({
|
||||
export const template = new Eta({
|
||||
autoFilter: true,
|
||||
escapeFunction: (val: unknown): string => String(val),
|
||||
filterFunction: (val: unknown): string => (val === null || val === undefined ? "" : String(val)),
|
||||
useWith: true,
|
||||
views: path.join(__dirname, "template"),
|
||||
});
|
||||
|
||||
export default template;
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import env from "../common/env";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import run from "../run/index";
|
||||
|
||||
export class NekoLink {
|
||||
class NekoLink {
|
||||
static get type() {
|
||||
switch (os.type()) {
|
||||
case "Linux":
|
||||
|
||||
@@ -2,6 +2,7 @@ export * from "./common/download";
|
||||
export * from "./common/log";
|
||||
export * from "./common/output";
|
||||
export * from "./common/system";
|
||||
export * from "./common/template";
|
||||
export * from "./core/config";
|
||||
export * from "./core/sdk";
|
||||
export * from "./core/type";
|
||||
@@ -14,3 +15,4 @@ export * from "./impl/ruffle";
|
||||
export * from "./preset";
|
||||
export * from "./project";
|
||||
export * from "./project/impl";
|
||||
export * from "./v2/link";
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import os from "os";
|
||||
import template from "../common/template";
|
||||
|
||||
export type Params = Record<string, any>;
|
||||
|
||||
export interface Link {
|
||||
version: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export const NekoLink: Link = {
|
||||
version: "2.4.1",
|
||||
url: "https://github.com/HaxeFoundation/neko/releases/download/v<%= version.split('.').join('-') %>/neko-<%= version %>-<%= os_name %><%= os_arch %>.<%= os_archive_ext %>",
|
||||
};
|
||||
|
||||
export const HaxeLink: Link = {
|
||||
version: "3.4.2",
|
||||
url: "https://github.com/HaxeFoundation/haxe/releases/download/<%= version %>/haxe-<%= version %>-<%= os_name %><%= os_arch %>.<%= os_archive_ext %>",
|
||||
};
|
||||
|
||||
export const FlashplayerLink: Link = {
|
||||
version: "32",
|
||||
url: "https://fpdownload.macromedia.com/pub/flashplayer/updaters/<%= version %>/<%= {linux:'flash_player_sa_linux' + (debug ? '_debug' : '') +'.x86_64.tar.gz','win':'flashplayer_'+version+'_sa'+(debug ? '_debug' : '')+'.exe'}[os_name] %>",
|
||||
};
|
||||
|
||||
export const AndroidLink: Link = {
|
||||
version: "7302050",
|
||||
url: "https://dl.google.com/android/repository/commandlinetools-<%= os_name %>-<%= version %>_latest.zip",
|
||||
};
|
||||
|
||||
export const DefaultParams: string[][] = [
|
||||
["debug", "<%= false %>"],
|
||||
["os_name", "<%= {Linux:'linux',Windows_NT:'win'}[os.type()] %>"],
|
||||
["os_arch", "<%= {x64:'64',ia32:''}[os.arch()] %>"],
|
||||
["os_archive_ext", "<%= {linux:'tar.gz',win:'zip'}[os_name] %>"],
|
||||
];
|
||||
|
||||
export const resolveParams = (source: Params, custom?: Params): Params => {
|
||||
const params: Params = { ...source, os, debug: false };
|
||||
if (custom) {
|
||||
for (const [k, v] of Object.entries(custom)) {
|
||||
params[k] = template.renderString(v, params);
|
||||
}
|
||||
}
|
||||
for (const [k, v] of DefaultParams) {
|
||||
if (!Object.hasOwn(params, k)) {
|
||||
params[k] = template.renderString(v, params);
|
||||
}
|
||||
}
|
||||
return params;
|
||||
};
|
||||
|
||||
export const resolveLink = (link: Link | string, params?: Params): string => {
|
||||
if (typeof link === "string") {
|
||||
return template.renderString(link, resolveParams({}, params));
|
||||
} else {
|
||||
return template.renderString(link.url, resolveParams(link, params));
|
||||
}
|
||||
};
|
||||
+9
-13
@@ -5,18 +5,14 @@ import { join } from "node:path";
|
||||
import test from "node:test";
|
||||
import { download } from "../dist/lib/index.mjs";
|
||||
|
||||
const resolveTargetDir = () => mkdtempSync(join(tmpdir(), "test-"));
|
||||
|
||||
const TEST_DATA = {
|
||||
"https://home.shmyga.ru/public/sdk/haxe/haxe-4.2.5-win.zip": "haxe.exe",
|
||||
"https://home.shmyga.ru/public/sdk/haxe/haxe-4.2.5-linux64.tar.gz": "haxe",
|
||||
"https://home.shmyga.ru/public/test.txt": "test.txt",
|
||||
};
|
||||
|
||||
for (const [url, file] of Object.entries(TEST_DATA)) {
|
||||
test(`Test download: ${url}`, async () => {
|
||||
const target = resolveTargetDir();
|
||||
const testUrl = async (url, file) => {
|
||||
const target = mkdtempSync(join(tmpdir(), "test-"));
|
||||
await download(url, target);
|
||||
assert(existsSync(join(target, file)));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
test("zip", async () => await testUrl("https://home.shmyga.ru/public/sdk/haxe/haxe-4.2.5-win.zip", "haxe.exe"));
|
||||
|
||||
test("tar.gz", async () => await testUrl("https://home.shmyga.ru/public/sdk/haxe/haxe-4.2.5-linux64.tar.gz", "haxe"));
|
||||
|
||||
test("plain", async () => await testUrl("https://home.shmyga.ru/public/test.txt", "test.txt"));
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { AndroidLink, FlashplayerLink, HaxeLink, NekoLink, resolveLink } from "../dist/lib/index.mjs";
|
||||
|
||||
const testLink = (link, args) => {
|
||||
for (const [params, targetUrl] of args) {
|
||||
const url = resolveLink(link, params);
|
||||
assert.equal(url, targetUrl);
|
||||
}
|
||||
};
|
||||
|
||||
test("neko", () =>
|
||||
testLink(NekoLink, [
|
||||
[{ os_name: "linux" }, "https://github.com/HaxeFoundation/neko/releases/download/v2-4-1/neko-2.4.1-linux64.tar.gz"],
|
||||
[{ os_name: "win" }, "https://github.com/HaxeFoundation/neko/releases/download/v2-4-1/neko-2.4.1-win64.zip"],
|
||||
]));
|
||||
|
||||
test("haxe", () =>
|
||||
testLink(HaxeLink, [
|
||||
[{ os_name: "linux" }, "https://github.com/HaxeFoundation/haxe/releases/download/3.4.2/haxe-3.4.2-linux64.tar.gz"],
|
||||
[{ os_name: "win" }, "https://github.com/HaxeFoundation/haxe/releases/download/3.4.2/haxe-3.4.2-win64.zip"],
|
||||
]));
|
||||
|
||||
test("flashplayer", () =>
|
||||
testLink(FlashplayerLink, [
|
||||
[
|
||||
{ os_name: "linux" },
|
||||
"https://fpdownload.macromedia.com/pub/flashplayer/updaters/32/flash_player_sa_linux.x86_64.tar.gz",
|
||||
],
|
||||
[{ os_name: "win" }, "https://fpdownload.macromedia.com/pub/flashplayer/updaters/32/flashplayer_32_sa.exe"],
|
||||
]));
|
||||
|
||||
test("android", () =>
|
||||
testLink(AndroidLink, [
|
||||
[{ os_name: "linux" }, "https://dl.google.com/android/repository/commandlinetools-linux-7302050_latest.zip"],
|
||||
[{ os_name: "win" }, "https://dl.google.com/android/repository/commandlinetools-win-7302050_latest.zip"],
|
||||
]));
|
||||
Reference in New Issue
Block a user