UNPKG

gmll

Version:

A generic launcher core for building custom launchers

63 lines (62 loc) 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.processFile = exports.expand = exports.toDownloadable = exports.check = void 0; const gfsl_1 = require("gfsl"); function check(json) { const f = new gfsl_1.File(...json.path, json.name); let i = 2; if (json.dynamic && f.exists()) return 2; if (json.executable || json.unzip) i = 1; if (!json.chk || !json.path || !json.name) return 0; return f.chkSelf(json.chk) ? i : 0; } exports.check = check; function toDownloadable(file, url, key, chk, opt) { file.mkdir(); const d = { key: key || [...file.path, file.name].join("/"), name: file.name, path: file.path, url: url, chk: {}, }; if (chk) { d.chk = chk; } if (opt) { d.executable = opt.executable; if (opt.unzip) { opt.unzip.file.mkdir(); d.unzip = { file: opt.unzip.file.path, exclude: opt.unzip.exclude }; } } return d; } exports.toDownloadable = toDownloadable; async function expand(file, json, zipDir) { if (json.unzip) { await file.unzip(new gfsl_1.Dir(...json.unzip.file), { exclude: json.unzip.exclude, zipDir, }); } if (json.executable) { if (typeof json.executable == "boolean") file.chmod(); else new gfsl_1.File(json.executable).chmod(); } } exports.expand = expand; async function processFile(json, zipDir) { const f = new gfsl_1.File(...json.path, json.name); if (json.dynamic && f.exists()) { return; } await f.download(json.url, json.chk, { noRetry: json.noRetry }); await expand(f, json, zipDir); } exports.processFile = processFile;