refactor: rewrite on typescript
This commit is contained in:
Executable
+262
@@ -0,0 +1,262 @@
|
||||
import fs from "fs";
|
||||
import gulp from "gulp";
|
||||
import through from "through2";
|
||||
import tmp from "tmp-file";
|
||||
import exec from "../common/exec";
|
||||
import { Sdk } from "../core/sdk";
|
||||
|
||||
// TODO: refactor or remove
|
||||
export class AdobeAir extends Sdk {
|
||||
static ID = "adobe-air";
|
||||
|
||||
static VERSION_26 = "26.0";
|
||||
static VERSION_25 = "25.0";
|
||||
static VERSION_24 = "24.0";
|
||||
static VERSION = AdobeAir.VERSION_26;
|
||||
|
||||
get adtBin(): string {
|
||||
return `${this.path}/bin/adt.bat`;
|
||||
}
|
||||
|
||||
get adlBin(): string {
|
||||
return `${this.path}/bin/adl.exe`;
|
||||
}
|
||||
|
||||
static buildAdtArgs(
|
||||
params: any,
|
||||
descriptor: { path: string },
|
||||
keystore: { path: string; storepass: string },
|
||||
files: { path: string; base: string }[],
|
||||
output: string,
|
||||
) {
|
||||
//const quote = (value) => `"${value}"`;
|
||||
const quote = (value: string): string => value; // TODO:
|
||||
const command = ["-package"];
|
||||
const target = params.target || "native";
|
||||
if (target !== "native") command.push("-target", target); //TODO: adobe bleat' (target param position in native and apk-captive-runtime targets)
|
||||
if (params.useLegacyAOT) {
|
||||
command.push("-useLegacyAOT", "yes");
|
||||
}
|
||||
if (params.profile) {
|
||||
command.push("-provisioning-profile", quote(params.profile));
|
||||
}
|
||||
if (keystore) {
|
||||
command.push("-storetype", "PKCS12");
|
||||
command.push("-keystore", keystore.path);
|
||||
command.push("-storepass", keystore.storepass);
|
||||
}
|
||||
if (params.target === "native") {
|
||||
command.push("-tsa", "http://sha256timestamp.ws.symantec.com/sha256/timestamp");
|
||||
command.push("-target", target);
|
||||
}
|
||||
command.push(quote(output), quote(descriptor.path));
|
||||
if (params.extdir) {
|
||||
command.push("-extdir", quote(params.extdir));
|
||||
}
|
||||
if (params.content) {
|
||||
for (let k in params.content)
|
||||
if (params.content.hasOwnProperty(k)) {
|
||||
command.push("-C", quote(k), quote(params.content[k]));
|
||||
}
|
||||
}
|
||||
for (let file of files) {
|
||||
command.push("-C", quote(file.base), quote(file.path.split(file.base)[1]));
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
constructor(version?: string) {
|
||||
super(AdobeAir.ID, version || AdobeAir.VERSION);
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
return fs.existsSync(`${this.path}/air-sdk-description.xml`);
|
||||
}
|
||||
|
||||
get link() {
|
||||
return `http://airdownload.adobe.com/air/win/download/${this.version}/AIRSDK_Compiler.zip`;
|
||||
}
|
||||
|
||||
adt(path: string, args: any) {
|
||||
return exec(path, [this.adtBin].concat(args).join(" "));
|
||||
}
|
||||
|
||||
adl(path: string, args: any) {
|
||||
return exec(path, [this.adlBin].concat(args).join(" "));
|
||||
}
|
||||
|
||||
pack(params: any) {
|
||||
const files = [];
|
||||
let descriptor = null;
|
||||
let keystore = null;
|
||||
let stream = null;
|
||||
|
||||
const bufferContents = (file, enc, callback) => {
|
||||
// ToDo: check file not stream
|
||||
switch (file.mark) {
|
||||
case "descriptor":
|
||||
descriptor = file;
|
||||
break;
|
||||
case "keystore":
|
||||
keystore = file;
|
||||
break;
|
||||
default:
|
||||
files.push(file);
|
||||
}
|
||||
callback();
|
||||
};
|
||||
|
||||
const endStream = (callback: any) => {
|
||||
gutil.log(this.tag, col.cyan("adt", "build", params.target), "=>", col.magenta(params.outputFile));
|
||||
if (!descriptor) {
|
||||
stream.emit("error", new gutil.PluginError({ plugin: this.name, message: "descriptor is not defined" }));
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
const tmpFile = tmp.generateFile();
|
||||
const command = AdobeAir.buildAdtArgs(params, descriptor, keystore, files, tmpFile.path);
|
||||
this.adt(".", command)
|
||||
.then(() => {
|
||||
stream.push(
|
||||
new gutil.File({
|
||||
path: params.outputFile,
|
||||
contents: fs.createReadStream(tmpFile.path),
|
||||
}),
|
||||
);
|
||||
callback();
|
||||
})
|
||||
.catch((error) => {
|
||||
stream.emit("error", new gutil.PluginError({ plugin: this.name, message: error }));
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
return (stream = through.obj(bufferContents, endStream));
|
||||
}
|
||||
|
||||
install() {
|
||||
let stream = null;
|
||||
const bufferContents = (file, enc, callback) => {
|
||||
gutil.log(this.tag, col.cyan("adt", "install"), col.magenta(file.name));
|
||||
const command = ["-installApp", "-platform", "android", "-package", file.path];
|
||||
this.adt(".", command)
|
||||
.then(() => {
|
||||
stream.push(file);
|
||||
callback();
|
||||
})
|
||||
.catch((error) => {
|
||||
stream.emit("error", new gutil.PluginError({ plugin: this.name, message: error }));
|
||||
callback();
|
||||
});
|
||||
};
|
||||
return (stream = through.obj(bufferContents));
|
||||
}
|
||||
|
||||
launch(appid) {
|
||||
let stream = null;
|
||||
const bufferContents = (file, enc, callback) => {
|
||||
gutil.log(this.tag, col.cyan("adt", "launch"), col.magenta(appid));
|
||||
const command = ["-launchApp", "-platform", "android", "-appid", appid];
|
||||
this.adt(".", command)
|
||||
.then(() => {
|
||||
stream.push(file);
|
||||
callback();
|
||||
})
|
||||
.catch((error) => {
|
||||
stream.emit("error", new gutil.PluginError({ plugin: this.name, message: error }));
|
||||
callback();
|
||||
});
|
||||
};
|
||||
return (stream = through.obj(bufferContents));
|
||||
}
|
||||
|
||||
test(params) {
|
||||
let root = null;
|
||||
let descriptor = null;
|
||||
let stream = null;
|
||||
|
||||
const bufferContents = (file, enc, callback) => {
|
||||
// ToDo: check file not stream
|
||||
switch (file.mark) {
|
||||
case "descriptor":
|
||||
descriptor = file;
|
||||
break;
|
||||
default:
|
||||
root = file;
|
||||
}
|
||||
callback();
|
||||
};
|
||||
|
||||
const endStream = (callback) => {
|
||||
gutil.log(this.tag, col.cyan("adl"));
|
||||
//const command = AdobeAir.buildAdtArgs(params, files, tmpFile.path);
|
||||
const command = [];
|
||||
if (params.profile) command.push("-profile", params.profile);
|
||||
if (params.extdir) command.push("-extdir", params.extdir);
|
||||
if (!descriptor) {
|
||||
stream.emit("error", new gutil.PluginError({ plugin: this.name, message: "descriptor is not defined" }));
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
command.push(descriptor.path);
|
||||
command.push(root.path);
|
||||
if (params.args) {
|
||||
command.push("--");
|
||||
for (let key of Object.keys(params.args)) {
|
||||
const value = params.args[key];
|
||||
if (value === true) {
|
||||
command.push(`-${key}`);
|
||||
} else if (value) {
|
||||
command.push(`-${key}`, `${value}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.adl(".", command)
|
||||
.then(() => {
|
||||
stream.emit("end");
|
||||
callback();
|
||||
})
|
||||
.catch((error) => {
|
||||
stream.emit("error", new gutil.PluginError({ plugin: this.name, message: error }));
|
||||
callback();
|
||||
});
|
||||
|
||||
//callback();
|
||||
stream.push(root);
|
||||
};
|
||||
|
||||
return (stream = through.obj(bufferContents, endStream));
|
||||
}
|
||||
|
||||
static descriptor(template, values) {
|
||||
const tmpFile = tmp.generateFile();
|
||||
const patterns = [];
|
||||
for (let k in values)
|
||||
if (values.hasOwnProperty(k)) {
|
||||
patterns.push({ match: k, replacement: values[k] });
|
||||
}
|
||||
return gulp
|
||||
.src(template)
|
||||
.pipe(replace({ patterns: patterns }))
|
||||
.pipe(mark.set("descriptor"))
|
||||
.pipe(gulp.dest(tmpFile.path));
|
||||
}
|
||||
|
||||
static keystore(keystore, storepass) {
|
||||
return gulp.src(keystore).pipe(
|
||||
through.obj((file, enc, callback) => {
|
||||
file.mark = "keystore";
|
||||
file.storepass = storepass;
|
||||
callback(null, file);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
static pack(params) {
|
||||
return new AdobeAir().pack(params);
|
||||
}
|
||||
|
||||
static test(params) {
|
||||
return new AdobeAir().test(params);
|
||||
}
|
||||
}
|
||||
Executable
+257
@@ -0,0 +1,257 @@
|
||||
import fs from "fs";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import through from "through2";
|
||||
import { Env } from "../common/env";
|
||||
import exec from "../common/exec";
|
||||
import { System } from "../common/system";
|
||||
import { StringWritable } from "../common/tail";
|
||||
import { Downloader, Sdk } from "../core/sdk";
|
||||
import { Command } from "../run/command";
|
||||
|
||||
export class Android extends Sdk {
|
||||
static ID = "android";
|
||||
|
||||
static VERSION_7302050 = "7302050";
|
||||
static VERSION = Android.VERSION_7302050;
|
||||
|
||||
static NDK_VERSION_R15C = "r15c";
|
||||
static NDK_VERSION = Android.NDK_VERSION_R15C;
|
||||
|
||||
private ndk_version: string;
|
||||
private repository: string;
|
||||
|
||||
constructor(version?: string, ndkVersion?: string) {
|
||||
super(Android.ID, version || Android.VERSION);
|
||||
this.ndk_version = ndkVersion || Android.NDK_VERSION;
|
||||
this.repository = "https://dl.google.com/android/repository";
|
||||
}
|
||||
|
||||
get prepared(): boolean {
|
||||
try {
|
||||
return fs.existsSync(this.sdkmanager_bin);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
get link(): string {
|
||||
return `${this.repository}/commandlinetools-${System.os}-${this.version}_latest.zip`;
|
||||
}
|
||||
|
||||
get android_home(): string {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
get ndk_home(): string {
|
||||
return path.join(this.path, "ndk-bundle");
|
||||
}
|
||||
|
||||
get sdkmanager_bin(): string {
|
||||
return path.join(this.path, "cmdline-tools/bin/sdkmanager");
|
||||
}
|
||||
|
||||
prepare(): Promise<any> {
|
||||
const result = [];
|
||||
result.push(super.prepare(0));
|
||||
if (!fs.existsSync(path.join(this.ndk_home))) {
|
||||
result.push(this.prepare_ndk());
|
||||
}
|
||||
return Promise.all(result);
|
||||
}
|
||||
|
||||
prepare_ndk(): Promise<any> {
|
||||
// ToDo: support windows
|
||||
const url = `${this.repository}/android-ndk-${this.ndk_version}-${System.os}-x86_64.zip`;
|
||||
this.log.d("download: *%s*", url);
|
||||
return Downloader.download(url, this.ndk_home, 1, true);
|
||||
}
|
||||
|
||||
sdkmanager(packages: string[]) {
|
||||
this.log.i("sdkmanager: *%s*", packages.join(", "));
|
||||
const installedFile = path.join(this.path, ".installed");
|
||||
const installed = new Set(
|
||||
fs.existsSync(installedFile) ? fs.readFileSync(installedFile, { encoding: "utf8" }).split("\n") : [],
|
||||
);
|
||||
const install = new Set(packages);
|
||||
for (const key of installed) {
|
||||
if (install.has(key)) {
|
||||
install.delete(key);
|
||||
}
|
||||
}
|
||||
if (install.size === 0) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
const sdkmanagerBin = this.sdkmanager_bin;
|
||||
if (fs.existsSync(sdkmanagerBin)) {
|
||||
fs.chmodSync(sdkmanagerBin, 0o755);
|
||||
}
|
||||
const yes = '(while sleep 3; do echo "y"; done)';
|
||||
const command = [yes, "|", sdkmanagerBin]
|
||||
.concat(Array.from(install).map((name) => `"${name}"`))
|
||||
.concat([`--sdk_root="${this.path}"`])
|
||||
.join(" ");
|
||||
return exec(".", command).then(() => {
|
||||
for (const key of install) {
|
||||
installed.add(key);
|
||||
}
|
||||
fs.writeFileSync(installedFile, Array.from(installed).join("\n"), { encoding: "utf8" });
|
||||
});
|
||||
}
|
||||
|
||||
activate() {
|
||||
Env.set("ANDROID_HOME", this.android_home);
|
||||
Env.set("ANDROID_NDK_HOME", this.ndk_home);
|
||||
Env.set("NDK_HOME", this.ndk_home);
|
||||
}
|
||||
|
||||
get adbBin(): string {
|
||||
return path.join(this.path, "platform-tools/adb");
|
||||
}
|
||||
|
||||
adb(args: any) {
|
||||
return exec(".", [this.adbBin].concat(args).join(" ")).then((data: any) => {
|
||||
for (let line of data.stderr.split("\n")) {
|
||||
if (line.indexOf("Error") > -1) {
|
||||
throw line;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
buildTool(name: string) {
|
||||
let buildToolsVersion = ""; // TODO: default build-tools version value
|
||||
fs.readdirSync(path.join(this.path, "build-tools")).forEach((file) => {
|
||||
buildToolsVersion = file;
|
||||
});
|
||||
return path.join(this.path, "build-tools", buildToolsVersion, name);
|
||||
}
|
||||
|
||||
aapt(args: any) {
|
||||
const aaptBin = this.buildTool("aapt");
|
||||
return exec(".", [aaptBin].concat(args).join(" "));
|
||||
}
|
||||
|
||||
apk() {
|
||||
const self = this;
|
||||
return through.obj(function (file: any, enc: string, callback: any) {
|
||||
self.aapt(["l", "-a", file.path]).then((data: any) => {
|
||||
let activity = false;
|
||||
for (let line of data.stdout.split("\n")) {
|
||||
if (line.indexOf("package") > -1) {
|
||||
const value = /"(.*?)"/.exec(line);
|
||||
if (value) file.package = value[1];
|
||||
}
|
||||
if (line.indexOf("activity") > -1) {
|
||||
activity = true;
|
||||
}
|
||||
if (activity && line.indexOf("name") > -1) {
|
||||
const value = /"(.*?)"/.exec(line);
|
||||
if (value) {
|
||||
file.activity = value[1];
|
||||
activity = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.push(file);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_installApk(filename: string, pack: string) {
|
||||
this.log.i("install *%s*", filename);
|
||||
return this.adb(["install", "-r", "-d", filename])
|
||||
.then(() => {
|
||||
return false;
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error.includes("INSTALL_FAILED_UPDATE_INCOMPATIBLE")) {
|
||||
this.log.w("!INSTALL FAILED UPDATE INCOMPATIBLE!");
|
||||
return true;
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
})
|
||||
.then((reinstall) => {
|
||||
if (reinstall) {
|
||||
this.log.i("uninstall *%s*", pack);
|
||||
return this.adb(["uninstall", pack]).then(() => {
|
||||
this.log.i("install *%s*", filename);
|
||||
return this.adb(["install", "-r", "-d", filename]);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
install() {
|
||||
const self = this;
|
||||
return through.obj(function (file: any, enc: string, callback: any) {
|
||||
self._installApk(file.path, file.package).then(() => {
|
||||
// ToDo: kludge: delay before start
|
||||
setTimeout(() => {
|
||||
this.push(file);
|
||||
callback();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
start() {
|
||||
const self = this;
|
||||
return through.obj(function (file: any, enc: string, callback: any) {
|
||||
const name = `${file.package}/${file.activity}`;
|
||||
self.log.i("start *%s*", name);
|
||||
self.adb(["shell", "am", "start", "-n", name]).then(() => {
|
||||
setTimeout(() => {
|
||||
self.adb(["shell", `"ps | grep ${file.package}"`]).then((result) => {
|
||||
file.pid = result.stdout.split(/\s+/)[1];
|
||||
this.push(file);
|
||||
callback();
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
logcat() {
|
||||
const self = this;
|
||||
return through.obj(function (file: any, enc: string, callback: any) {
|
||||
const cmd = `${self.adbBin} logcat --pid ${file.pid}`;
|
||||
const command = new Command(cmd).exec();
|
||||
this.push(command);
|
||||
command.contents.pipe(
|
||||
new StringWritable((line) => {
|
||||
if (line.includes("SDL") && (line.includes("onDestroy()") || line.includes("onStop()"))) {
|
||||
callback();
|
||||
throw "Exit"; // ToDo:
|
||||
}
|
||||
}),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
sign(keystore: string, keypass: string) {
|
||||
const self = this;
|
||||
return through.obj(function (file: any, enc: string, callback: any) {
|
||||
self.log.i("sign *%s*", file.path);
|
||||
const filename = path.join(os.tmpdir(), "tmp.apk");
|
||||
fs.writeFileSync(filename, file.contents);
|
||||
const cmd = [
|
||||
self.buildTool("apksigner"),
|
||||
"sign",
|
||||
"--ks",
|
||||
keystore,
|
||||
"--ks-pass",
|
||||
`pass:${keypass}`,
|
||||
filename,
|
||||
].join(" ");
|
||||
exec(".", cmd).then(() => {
|
||||
file.contents = fs.readFileSync(filename);
|
||||
this.push(file);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Executable
+136
@@ -0,0 +1,136 @@
|
||||
import fs from "fs";
|
||||
import fse from "fs-extra";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import through from "through2";
|
||||
import { Env } from "../common/env";
|
||||
import { System } from "../common/system";
|
||||
import { TailVinyl } from "../common/tail";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import run from "../run";
|
||||
|
||||
export class FlashPlayer extends Sdk {
|
||||
static ID = "flashplayer";
|
||||
|
||||
static VERSION_24 = "24";
|
||||
static VERSION_25 = "25";
|
||||
static VERSION_26 = "26";
|
||||
static VERSION_27 = "27";
|
||||
static VERSION_28 = "28";
|
||||
static VERSION_29 = "29";
|
||||
static VERSION_30 = "30";
|
||||
static VERSION_31 = "31";
|
||||
static VERSION_32 = "32";
|
||||
|
||||
static VERSION = FlashPlayer.VERSION_32;
|
||||
|
||||
BASE_URL = "https://fpdownload.macromedia.com/pub/flashplayer/updaters";
|
||||
|
||||
private debug: boolean;
|
||||
protected baseUrl: string;
|
||||
|
||||
constructor(debug: boolean = false, version?: string, playerId = FlashPlayer.ID) {
|
||||
super(playerId, version || FlashPlayer.VERSION);
|
||||
this.debug = debug;
|
||||
this.baseUrl = Env.get("FLASHPLAYER_URL") || this.BASE_URL;
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return super.prepare(0);
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
try {
|
||||
return fs.existsSync(this.flashPlayerBin);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
get link(): string {
|
||||
const baseUrl = `${this.baseUrl}/${this.version}`;
|
||||
if (System.isWindows) {
|
||||
return baseUrl + `/flashplayer_${this.version}_sa${this.debug ? "_debug" : ""}.exe`;
|
||||
} else if (System.isLinux) {
|
||||
return baseUrl + `/flash_player_sa_linux${this.debug ? "_debug" : ""}.x86_64.tar.gz`;
|
||||
} else {
|
||||
throw `Unsupported os '${os.type()}'`;
|
||||
}
|
||||
}
|
||||
|
||||
get flashPlayerBin(): string {
|
||||
if (System.isWindows) {
|
||||
const v = this.version.split(".");
|
||||
const playerName = `flashplayer_${this.version}_sa${this.debug ? "_debug" : ""}.exe`;
|
||||
return path.join(this.path, playerName);
|
||||
} else if (System.isLinux) {
|
||||
const binPath = path.join(this.path, `flashplayer${this.debug ? "debugger" : ""}`);
|
||||
fs.chmodSync(binPath, 0o755);
|
||||
return binPath;
|
||||
} else {
|
||||
throw `Unsupported os '${os.type()}'`;
|
||||
}
|
||||
}
|
||||
|
||||
static get flashPlayerDir(): string {
|
||||
if (os.type() === "Windows_NT") {
|
||||
return path.join(process.env.APPDATA, "Macromedia", "Flash Player");
|
||||
} else if (os.type() === "Linux") {
|
||||
return path.join(os.homedir(), ".macromedia", "Flash_Player");
|
||||
} else {
|
||||
throw `Unuspported os: ${os.type()}`;
|
||||
}
|
||||
}
|
||||
|
||||
static get log() {
|
||||
return path.join(this.flashPlayerDir, "Logs", "flashlog.txt");
|
||||
}
|
||||
|
||||
static enableLog() {
|
||||
const filename = path.join(os.homedir(), "mm.cfg");
|
||||
const value = "TraceOutputFileEnable=1";
|
||||
if (fs.existsSync(filename)) {
|
||||
const data = fs.readFileSync(filename);
|
||||
if (data.indexOf(value) === -1) {
|
||||
fs.appendFileSync(filename, `${value}\n`);
|
||||
}
|
||||
} else {
|
||||
fs.writeFileSync(filename, `${value}\n`);
|
||||
}
|
||||
fse.ensureDirSync(path.join(this.flashPlayerDir, "Logs"));
|
||||
fs.writeFileSync(FlashPlayer.log, "");
|
||||
}
|
||||
|
||||
static trust(value: string) {
|
||||
const filename = path.join(this.flashPlayerDir, "#Security", "FlashPlayerTrust", "gulp.cfg");
|
||||
if (fs.existsSync(filename)) {
|
||||
const data = fs.readFileSync(filename);
|
||||
if (data.indexOf(value) === -1) {
|
||||
fs.appendFileSync(filename, `${value}\n`);
|
||||
}
|
||||
} else {
|
||||
if (!fs.existsSync(path.dirname(filename))) {
|
||||
fse.ensureDirSync(path.dirname(filename));
|
||||
}
|
||||
fs.writeFileSync(filename, `${value}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
run(filename: string, params: any) {
|
||||
this.log.i("_run_ *%s*", filename);
|
||||
FlashPlayer.trust(filename);
|
||||
FlashPlayer.enableLog();
|
||||
return run(`${this.flashPlayerBin} ${filename}`, params)
|
||||
.exec()
|
||||
.pipe(
|
||||
through.obj(function (file: any, enc: string, callback: any) {
|
||||
const log = new TailVinyl({
|
||||
path: FlashPlayer.log,
|
||||
});
|
||||
this.on("end", () => log.dispose());
|
||||
this.push(log);
|
||||
callback();
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Executable
+236
@@ -0,0 +1,236 @@
|
||||
import fs from "fs";
|
||||
import fse from "fs-extra";
|
||||
import rename from "gulp-rename";
|
||||
import template from "lodash.template";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import vfs from "vinyl-fs";
|
||||
import { Env } from "../common/env";
|
||||
import exec from "../common/exec";
|
||||
import { System } from "../common/system";
|
||||
import type { Config, LibDef } from "../core/config";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import { Neko } from "./neko";
|
||||
|
||||
export class Haxe extends Sdk {
|
||||
static ID = "haxe";
|
||||
|
||||
static VERSION_3_4_0 = "3.4.0";
|
||||
static VERSION_3_4_2 = "3.4.2";
|
||||
static VERSION_3_4_3 = "3.4.3";
|
||||
static VERSION_3_4_7 = "3.4.7";
|
||||
static VERSION_3 = Haxe.VERSION_3_4_7;
|
||||
static VERSION_4_0_0 = "4.0.0";
|
||||
static VERSION_4_0_1 = "4.0.1";
|
||||
static VERSION_4_0_2 = "4.0.2";
|
||||
static VERSION_4_0_3 = "4.0.3";
|
||||
static VERSION_4_0_5 = "4.0.5";
|
||||
static VERSION_4 = Haxe.VERSION_4_0_5;
|
||||
static VERSION = Haxe.VERSION_4;
|
||||
|
||||
static buildDir = path.join(process.cwd(), "build");
|
||||
|
||||
getBin(name: string) {
|
||||
if (System.isWindows) {
|
||||
return path.join(this.path, name + ".exe");
|
||||
} else if (System.isLinux) {
|
||||
const binPath = path.join(this.path, name);
|
||||
if (fs.existsSync(binPath)) {
|
||||
fs.chmodSync(binPath, 0o755);
|
||||
}
|
||||
return binPath;
|
||||
}
|
||||
throw `Unsupported OS: ${os.type()}`;
|
||||
}
|
||||
|
||||
get haxeBin() {
|
||||
return this.getBin("haxe");
|
||||
}
|
||||
|
||||
get haxelibBin() {
|
||||
return this.getBin("haxelib");
|
||||
}
|
||||
|
||||
private neko: Neko;
|
||||
|
||||
constructor(version?: string) {
|
||||
super(Haxe.ID, version || Haxe.VERSION);
|
||||
this.neko = new Neko();
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
try {
|
||||
return fs.existsSync(this.haxeBin);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
activate() {
|
||||
this.neko.activate();
|
||||
Env.set("HAXE_VERSION", this.version);
|
||||
Env.set("HAXE_STD_PATH", path.join(this.path, "std"));
|
||||
Env.set("HAXE_HOME", this.path);
|
||||
Env.addPath(this.path);
|
||||
Env.addPath(this.path, "LD_LIBRARY_PATH");
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return Promise.all([this.neko.prepare(), super.prepare()]).then(() => {
|
||||
fs.copyFileSync(path.resolve(import.meta.dirname, "..", "template/haxe/activate"), path.resolve(this.path, "activate"));
|
||||
});
|
||||
}
|
||||
|
||||
get link(): string {
|
||||
if (System.isWindows) {
|
||||
return `https://github.com/HaxeFoundation/haxe/releases/download/${this.version}/haxe-${this.version}-win.zip`;
|
||||
} else if (System.isLinux) {
|
||||
let arch = System.archInt;
|
||||
return `https://github.com/HaxeFoundation/haxe/releases/download/${this.version}/haxe-${this.version}-linux${arch}.tar.gz`;
|
||||
} else {
|
||||
throw `Unsupported os: ${System.os}`;
|
||||
}
|
||||
}
|
||||
|
||||
haxe(args: any) {
|
||||
this.activate();
|
||||
return exec(".", [this.haxeBin].concat(args).join(" "));
|
||||
}
|
||||
|
||||
haxelib(args: any) {
|
||||
this.activate();
|
||||
return exec(".", [this.haxelibBin].concat(args).join(" "));
|
||||
}
|
||||
|
||||
resolveBuildDir(config: Config) {
|
||||
return path.join(Haxe.buildDir, config.name);
|
||||
}
|
||||
|
||||
openfl(command: string, platform: string, config: Config, debug = false) {
|
||||
this.log.i("_openfl_ _build_ *%s*", platform);
|
||||
this.activate();
|
||||
const buildDir = this.resolveBuildDir(config);
|
||||
fse.ensureDirSync(buildDir);
|
||||
|
||||
const projectTemplate = template(fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/project.xml")));
|
||||
const project = projectTemplate({ ...config, buildDir: buildDir });
|
||||
fs.writeFileSync(path.resolve(buildDir, "project.xml"), project);
|
||||
|
||||
const args = ["-cwd", buildDir, "run", "openfl", command, platform];
|
||||
if (debug) {
|
||||
args.push("-debug");
|
||||
}
|
||||
const target = path.resolve(buildDir, platform, "bin");
|
||||
fse.emptyDirSync(target);
|
||||
const result =
|
||||
{
|
||||
android: `app/build/outputs/**/${config.meta.filename}-debug.apk`,
|
||||
flash: "*.swf",
|
||||
}[platform] || "**/*";
|
||||
return this.haxelib(args).then(() => {
|
||||
let r = vfs.src(`${target}/${result}`);
|
||||
if (platform === "android") {
|
||||
r = r.pipe(rename(`${config.meta.filename}_${config.meta.version}.apk`));
|
||||
}
|
||||
return r;
|
||||
});
|
||||
}
|
||||
|
||||
build(platform: string, config: Config, debug = false) {
|
||||
this.log.i("_build_ *%s*", platform);
|
||||
this.activate();
|
||||
const buildDir = this.resolveBuildDir(config);
|
||||
fse.ensureDirSync(buildDir);
|
||||
|
||||
const projectTemplate = template(fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/project.hxml")));
|
||||
|
||||
const ext =
|
||||
{
|
||||
flash: ".swf",
|
||||
neko: ".n",
|
||||
}[platform] || "";
|
||||
|
||||
const out =
|
||||
{
|
||||
flash: "swf",
|
||||
}[platform] || platform;
|
||||
|
||||
const project = projectTemplate({ ...config, buildDir: buildDir, platform: platform, ext: ext, out: out });
|
||||
const projectHXML = path.resolve(buildDir, "project.hxml");
|
||||
fs.writeFileSync(projectHXML, project);
|
||||
|
||||
const args = [projectHXML];
|
||||
if (debug) {
|
||||
args.push("-debug");
|
||||
}
|
||||
const target = path.resolve(buildDir, platform, "bin");
|
||||
if (platform !== "cpp") {
|
||||
fse.emptyDirSync(target);
|
||||
}
|
||||
for (const asset of config.assets) {
|
||||
fse.copySync(asset, path.join(target, asset.split("/").pop()!));
|
||||
}
|
||||
const result =
|
||||
{
|
||||
cpp: `${config.meta.filename}/${config.main.split(".").pop()}${debug ? "-debug" : ""}`,
|
||||
}[platform] || "**/*";
|
||||
return this.haxe(args).then(() => {
|
||||
let r = vfs.src(`${target}/${result}`);
|
||||
if (platform === "cpp") {
|
||||
r = r.pipe(rename(config.meta.filename));
|
||||
}
|
||||
return r;
|
||||
});
|
||||
}
|
||||
|
||||
install(packages: Record<string, string> | LibDef[]) {
|
||||
this.activate();
|
||||
let promise = this.haxelib(["setup", path.join(this.path, "lib")]);
|
||||
const next = (args: any) => () => {
|
||||
this.log.i("_haxelib_ _install_ *%s:%s*", args[1], args[2]);
|
||||
return this.haxelib(args);
|
||||
};
|
||||
|
||||
if (!Array.isArray(packages)) {
|
||||
packages = Object.entries(packages).map(([k, v]) => ({ name: k, version: v }));
|
||||
}
|
||||
|
||||
for (let pack of packages) {
|
||||
const args = [];
|
||||
let version = null;
|
||||
if (typeof pack === "string") {
|
||||
args.push("install", pack);
|
||||
} else if (typeof pack === "object") {
|
||||
version = pack.version;
|
||||
if (version.substr(0, 3) === "git") {
|
||||
pack.git = version;
|
||||
version = null;
|
||||
}
|
||||
if (pack.git) {
|
||||
args.push("git", pack.name, pack.git);
|
||||
if (pack.branch) args.push(pack.branch);
|
||||
} else {
|
||||
args.push("install", pack.name);
|
||||
if (version) args.push(version);
|
||||
}
|
||||
args.push("--always");
|
||||
}
|
||||
let path = `${this.path}/lib/${args[1]}`;
|
||||
if (version) {
|
||||
path += `/${version.replace(/\./g, ",")}`;
|
||||
} else if (pack.git) {
|
||||
path += "/git";
|
||||
}
|
||||
if (!fs.existsSync(path)) {
|
||||
promise = promise.then(next(args));
|
||||
}
|
||||
}
|
||||
return promise;
|
||||
}
|
||||
|
||||
upgrade() {
|
||||
let promise = this.haxelib(["setup", path.join(this.path, "lib")]);
|
||||
promise = promise.then(() => this.haxelib(["upgrade", "--always"]));
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
import fs from "fs";
|
||||
import fse from "fs-extra";
|
||||
import template from "lodash.template";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import exec from "../common/exec";
|
||||
import type { Config } from "../core/config";
|
||||
import { Sdk } from "../core/sdk";
|
||||
|
||||
export class InnoSetup extends Sdk {
|
||||
static ID = "innosetup";
|
||||
static VERSION = "6";
|
||||
|
||||
constructor(version?: string) {
|
||||
super(InnoSetup.ID, version || InnoSetup.VERSION);
|
||||
}
|
||||
|
||||
get link() {
|
||||
return "http://www.jrsoftware.org/download.php/is.exe";
|
||||
}
|
||||
|
||||
prepare(strip = 1) {
|
||||
let result = super.prepare(strip);
|
||||
if (!this.prepared) {
|
||||
result = result.then(() => {
|
||||
return exec(this.path, `is.exe /VERYSILENT /SUPPRESSMSGBOXES /DIR=${this.path}`);
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
get isccBin() {
|
||||
return path.join(this.path, "ISCC.exe");
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
try {
|
||||
return fs.existsSync(this.isccBin);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
pack(config: Config, source: string, output: string) {
|
||||
const buildDir = path.join(os.tmpdir(), "build", config.name, "innosetup");
|
||||
const appTemplate = template(fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/windows/app.iss"), "utf8"));
|
||||
const app = appTemplate({ ...config, buildDir: buildDir, output: output });
|
||||
|
||||
fse.ensureDirSync(buildDir);
|
||||
fse.copySync(`${source}`, `${buildDir}`);
|
||||
|
||||
fs.writeFileSync(path.resolve(buildDir, "app.iss"), app);
|
||||
return exec(buildDir, [`"${this.isccBin}"`, "app.iss"].join(" "));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import fs from "fs";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import { Env } from "../common/env";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import run from "../run/index";
|
||||
|
||||
export class NekoLink {
|
||||
static get type() {
|
||||
switch (os.type()) {
|
||||
case "Linux":
|
||||
return "linux";
|
||||
case "Windows_NT":
|
||||
return "win";
|
||||
}
|
||||
}
|
||||
|
||||
static get arch() {
|
||||
switch (os.arch()) {
|
||||
case "ia32":
|
||||
return "";
|
||||
case "x64":
|
||||
return "64";
|
||||
}
|
||||
}
|
||||
|
||||
static get ext() {
|
||||
switch (os.type()) {
|
||||
case "Linux":
|
||||
return "tar.gz";
|
||||
case "Windows_NT":
|
||||
return "zip";
|
||||
}
|
||||
}
|
||||
|
||||
static get(version: string) {
|
||||
const vv = version.split("\.").join("-");
|
||||
const filename = `neko-${version}-${NekoLink.type}${NekoLink.arch}.${NekoLink.ext}`;
|
||||
return `https://github.com/HaxeFoundation/neko/releases/download/v${vv}/${filename}`;
|
||||
}
|
||||
}
|
||||
|
||||
export class Neko extends Sdk {
|
||||
static ID = "neko";
|
||||
|
||||
static VERSION_2_2_0 = "2.2.0";
|
||||
static VERSION = Neko.VERSION_2_2_0;
|
||||
|
||||
constructor(version?: string) {
|
||||
super(Neko.ID, version || Neko.VERSION);
|
||||
}
|
||||
|
||||
get link() {
|
||||
return NekoLink.get(this.version);
|
||||
}
|
||||
|
||||
get prepared() {
|
||||
try {
|
||||
return fs.existsSync(this.nekoBin);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
activate() {
|
||||
Env.set("NEKO_INSTPATH", this.path);
|
||||
Env.addPath(this.path);
|
||||
Env.addPath(this.path, "LD_LIBRARY_PATH");
|
||||
}
|
||||
|
||||
prepare() {
|
||||
return Promise.all([super.prepare()]).then(() => {
|
||||
fs.copyFileSync(
|
||||
path.resolve(import.meta.dirname, "..", "template/neko/activate"),
|
||||
path.resolve(this.path, "activate"),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
get nekoBin() {
|
||||
let binname = "neko";
|
||||
if (os.type() === "Windows_NT") binname += ".exe";
|
||||
return path.join(this.path, binname);
|
||||
}
|
||||
|
||||
run(filename: string, params: any) {
|
||||
this.log.i("_run_ *%s*", filename);
|
||||
this.activate();
|
||||
return run(`${this.nekoBin} ${filename}`, params).exec();
|
||||
}
|
||||
}
|
||||
Executable
+68
@@ -0,0 +1,68 @@
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import through from "through2";
|
||||
import { Env } from "../common/env";
|
||||
import { System } from "../common/system";
|
||||
import { TailVinyl } from "../common/tail";
|
||||
import run from "../run";
|
||||
import { FlashPlayer } from "./flashplayer";
|
||||
|
||||
export class RufflePlayer extends FlashPlayer {
|
||||
static ID = "ruffle";
|
||||
|
||||
static VERSION_2026_05_15 = "nightly-2026_05_15";
|
||||
static VERSION = RufflePlayer.VERSION_2026_05_15;
|
||||
|
||||
BASE_URL = "https://github.com/ruffle-rs/ruffle/releases/download";
|
||||
|
||||
constructor(debug: boolean, version: string) {
|
||||
super(debug, version || RufflePlayer.VERSION, RufflePlayer.ID);
|
||||
this.baseUrl = Env.get("RUFFLE_URL") || this.BASE_URL;
|
||||
}
|
||||
|
||||
get link(): string {
|
||||
const baseUrl = `${this.baseUrl}/${this.version.replaceAll("_", "-")}`;
|
||||
if (System.isWindows) {
|
||||
return baseUrl + `/ruffle-${this.version}-windows-x86_64.zip`;
|
||||
} else if (System.isLinux) {
|
||||
return baseUrl + `/ruffle-${this.version}-linux-x86_64.tar.gz`;
|
||||
} else {
|
||||
throw `Unsupported os '${os.type()}'`;
|
||||
}
|
||||
}
|
||||
|
||||
get flashPlayerBin(): string {
|
||||
if (System.isWindows) {
|
||||
return path.join(this.path, "ruffle.exe");
|
||||
} else if (System.isLinux) {
|
||||
return path.join(this.path, "ruffle");
|
||||
} else {
|
||||
throw `Unsupported os '${os.type()}'`;
|
||||
}
|
||||
}
|
||||
|
||||
static get log(): string {
|
||||
return path.join(os.homedir(), ".cache/ruffle/log/ruffle.log");
|
||||
}
|
||||
|
||||
run(filename: string, params: any) {
|
||||
this.log.i("_run_ *%s*", filename);
|
||||
return run(`${this.flashPlayerBin} ${filename}`, params)
|
||||
.exec()
|
||||
.pipe(
|
||||
through.obj(function (file: any, enc: string, callback: any) {
|
||||
const log = new TailVinyl({
|
||||
path: RufflePlayer.log,
|
||||
handler: (line: string) => {
|
||||
if (line.includes("avm_trace")) {
|
||||
return line.split("avm_trace: ").pop();
|
||||
}
|
||||
},
|
||||
});
|
||||
this.on("end", () => log.dispose());
|
||||
this.push(log);
|
||||
callback();
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user