refactor(project): refactor project modules

This commit is contained in:
2026-10-13 22:56:25 +03:00
parent 78804036ab
commit ae094a9402
23 changed files with 608 additions and 524 deletions
+6
View File
@@ -0,0 +1,6 @@
export const streamToPromise = (stream: any) => {
return new Promise((resolve, reject) => {
stream.on("end", resolve);
stream.on("error", reject);
});
};
+1
View File
@@ -9,3 +9,4 @@ export * from "./impl/innosetup";
export * from "./impl/neko";
export * from "./impl/ruffle";
export * from "./project";
export * from "./project/impl";
-524
View File
@@ -1,524 +0,0 @@
import fs from "fs";
import fse from "fs-extra";
import gulp from "gulp";
import deb from "gulp-debian";
import gzip from "gulp-gzip";
import rename from "gulp-rename";
import tar from "gulp-tar";
import webserver from "gulp-webserver";
import zip from "gulp-zip";
import template from "lodash.template";
import os from "os";
import path from "path";
import vfs from "vinyl-fs";
import { DEBUG } from "./common/debug";
import exec from "./common/exec";
import { tail } from "./common/tail";
import { Config } from "./core/config";
import { BuildSystem, Platform } from "./core/type";
import { Android } from "./impl/android";
import { FlashPlayer } from "./impl/flashplayer";
import { Haxe } from "./impl/haxe";
import { InnoSetup } from "./impl/innosetup";
import { Neko } from "./impl/neko";
import { RufflePlayer } from "./impl/ruffle";
import run from "./run";
const streamToPromise = (stream: any) => {
return new Promise((resolve, reject) => {
stream.on("end", resolve);
stream.on("error", reject);
});
};
export class Target {
public config: Config;
public platform: string;
public target: string;
constructor(config: Config, platform: string) {
this.config = config;
this.platform = platform;
this.target = "target";
}
prepare(): Promise<any> {
return Promise.resolve();
}
call() {
throw "Not Implemented";
}
resolveTargetPath(platform = this.platform): string {
return path.resolve(this.target, this.config.name, platform);
}
get targetPath(): string {
return this.resolveTargetPath();
}
}
export class Builder extends Target {
static factory: Record<string, typeof Builder> = {};
public buildSystem: string;
public debug: boolean;
constructor(config: Config, platform: string, buildSystem: string, debug: boolean = false) {
super(config, platform);
this.buildSystem = buildSystem;
this.debug = debug;
}
static register(buildSystem: string, builder: typeof Builder) {
Builder.factory[buildSystem] = builder;
}
static new(config: Config, platform: string, buildSystem: string, debug: boolean = false): Builder {
return new Builder.factory[buildSystem](config, platform, buildSystem, debug);
}
}
export class HaxeBuilder extends Builder {
public haxe: Haxe;
public android: Android;
constructor(config: Config, platform: string, buildSystem: string, debug: boolean = false) {
super(config, platform, buildSystem, debug);
this.haxe = new Haxe();
this.android = new Android();
}
prepare() {
let result = this.haxe.prepare().then(() => this.haxe.install(this.config.libs));
if (this.buildSystem === BuildSystem.OPENFL) {
if (this.platform === Platform.ANDROID) {
result = result
.then(() => this.android.prepare())
.then(() => this.android.activate())
.then(() =>
this.android.sdkmanager([
// ToDo: android sdk dependencies config?
//'tools',
"platform-tools",
"build-tools;27.0.3",
"platforms;android-28", //ToDo: lime version 7.6.0 -> 28; 7.0.0 -> 26
//'ndk-bundle',
//'lldb;3.1',
"cmake;3.6.4111459",
]),
);
const AndroidSDK = this.android.android_home;
const AndroidNDK = this.android.ndk_home;
const answer = `echo "${[AndroidSDK, AndroidNDK].join("\n")}"`;
result = result.then(() => {
return exec(".", [answer, "|", this.haxe.haxelibBin, "run", "openfl", "setup", this.platform].join(" "));
});
}
}
return result;
}
call() {
const target = this.targetPath;
switch (this.buildSystem) {
case BuildSystem.OPENFL:
return this.haxe.openfl("build", this.platform, this.config, this.debug).then((result) => {
if (this.platform === Platform.ANDROID && this.config.key) {
result = result.pipe(this.android.sign(this.config.key.store, this.config.key.pass));
}
return streamToPromise(result.pipe(vfs.dest(target)));
});
case BuildSystem.HAXE:
return this.haxe
.build(this.platform, this.config, this.debug)
.then((result) => streamToPromise(result.pipe(vfs.dest(target))));
}
}
}
Builder.register(BuildSystem.HAXE, HaxeBuilder);
Builder.register(BuildSystem.OPENFL, HaxeBuilder);
export type PackerFactoty = new (config: Config) => Packer;
export class Packer extends Target {
static factory: Record<string, Record<string, PackerFactoty>> = {};
call() {
throw "Not Implemented";
}
static register(platform: string, name: string, packer: PackerFactoty) {
if (!Packer.factory[platform]) Packer.factory[platform] = {};
Packer.factory[platform][name] = packer;
}
static new(config: Config, platform: string, name: string): Packer {
return new Packer.factory[platform][name](config);
}
}
export class FlashHTMLPacker extends Packer {
static NAME = "html";
constructor(config: Config) {
super(config, Platform.FLASH);
}
call() {
const target = this.targetPath;
const indexTemplate = template(
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/flash/index.html")),
);
const index = indexTemplate(this.config);
fs.writeFileSync(path.resolve(target, "index.html"), index);
fs.copyFileSync(path.resolve(import.meta.dirname, "..", "template/flash/swf.js"), path.resolve(target, "swf.js"));
return Promise.resolve();
}
}
Packer.register(Platform.FLASH, FlashHTMLPacker.NAME, FlashHTMLPacker);
export class LinuxDEBPacker extends Packer {
static NAME = "deb";
constructor(config: Config) {
super(config, Platform.LINUX);
}
call() {
const target = this.targetPath;
const buildDir = path.join(os.tmpdir(), "build", this.config.name, "debian");
const iconfile = `${this.config.meta.filename}${path.extname(this.config.meta.icon!)}`;
const desktopTemplate = template(
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/linux/app.desktop")),
);
const desktop = desktopTemplate(Object.assign({ iconfile: iconfile }, this.config));
fse.ensureDirSync(`${buildDir}/usr/share/applications`);
fs.writeFileSync(`${buildDir}/usr/share/applications/${this.config.meta.filename}.desktop`, desktop);
fse.copySync(`${target}`, `${buildDir}/usr/share/${this.config.meta.filename}/`);
fse.copySync(this.config.meta.icon!, `${buildDir}/usr/share/${this.config.meta.filename}/${iconfile}`);
return gulp.src(`${buildDir}/*`).pipe(
deb({
package: this.config.meta.filename,
version: this.config.meta.version,
section: "base",
priority: "optional",
architecture: "all",
maintainer: this.config.meta.author,
description: this.config.meta.title,
changelog: [],
postinst: [
'if [ "$1" = "configure" ] && [ -x "`which update-menus 2>/dev/null`" ] ; then\n' +
" update-menus\n" +
"fi",
],
_target: "/",
_out: this.resolveTargetPath("debian"),
_clean: true,
_verbose: false,
}),
);
}
}
Packer.register(Platform.LINUX, LinuxDEBPacker.NAME, LinuxDEBPacker);
export class LinuxArchivePacker extends Packer {
static NAME = "archive";
constructor(config: Config) {
super(config, Platform.LINUX);
}
call() {
const target = this.targetPath;
const archiveName = `${this.config.meta.filename}_${this.config.meta.version}_linux.tar`;
return gulp
.src(`${target}/**/*`)
.pipe(tar(archiveName))
.pipe(gzip())
.pipe(gulp.dest(this.resolveTargetPath("archive")));
}
}
Packer.register(Platform.LINUX, LinuxArchivePacker.NAME, LinuxArchivePacker);
export class WindowsInstallerPacker extends Packer {
static NAME = "installer";
public innosetup: InnoSetup;
constructor(config: Config) {
super(config, Platform.WINDOWS);
this.innosetup = new InnoSetup();
}
prepare() {
return this.innosetup.prepare();
}
call() {
return this.innosetup.pack(this.config, this.targetPath, this.resolveTargetPath("installer"));
}
}
Packer.register(Platform.WINDOWS, WindowsInstallerPacker.NAME, WindowsInstallerPacker);
export class WindowsArchivePacker extends Packer {
static NAME = "archive";
constructor(config: Config) {
super(config, Platform.WINDOWS);
}
call() {
const target = this.targetPath;
const archiveName = `${this.config.meta.filename}_${this.config.meta.version}_win.zip`;
return gulp
.src(`${target}/**/*`)
.pipe(zip(archiveName))
.pipe(gulp.dest(this.resolveTargetPath("archive")));
}
}
Packer.register(Platform.WINDOWS, WindowsArchivePacker.NAME, WindowsArchivePacker);
export type RunnerFactory = new (config: Config, debug: boolean) => Runner;
export class Runner extends Target {
static factory: Record<string, RunnerFactory> = {};
public debug: boolean;
constructor(config: Config, platform: string, debug: boolean) {
super(config, platform);
this.debug = debug;
}
log(stream: any) {
return stream.pipe(tail(DEBUG.log)).pipe(rename("out.log")).pipe(gulp.dest(this.targetPath));
}
static register(platform: string, runner: RunnerFactory) {
Runner.factory[platform] = runner;
}
static new(config: Config, platform: string, debug: boolean): Runner {
return new Runner.factory[platform](config, debug);
}
}
export class FlashRunner extends Runner {
public player: FlashPlayer;
constructor(config: Config, debug: boolean, player: typeof FlashPlayer = FlashPlayer) {
super(config, Platform.FLASH, debug);
this.player = new player(debug);
}
prepare() {
return this.player.prepare();
}
call() {
const target = this.targetPath;
const filename = path.resolve(target, this.config.meta.filename + ".swf");
const result = this.player.run(filename, { cwd: target, verbosity: 0 });
return this.log(result);
}
}
class RuffleRunner extends FlashRunner {
constructor(config: Config, debug: boolean) {
super(config, debug, RufflePlayer);
}
}
Runner.register(Platform.FLASH, FlashRunner);
export class Html5Runner extends Runner {
constructor(config: Config, debug: boolean) {
super(config, Platform.HTML5, debug);
}
call() {
return gulp.src(this.targetPath).pipe(
webserver({
// ToDo: config?
host: "0.0.0.0",
port: 3000,
open: true,
fallback: "index.html",
}),
);
}
}
Runner.register(Platform.HTML5, Html5Runner);
export class LinuxRunner extends Runner {
constructor(config: Config, debug: boolean) {
super(config, Platform.LINUX, debug);
}
call() {
const target = this.targetPath;
const filename = path.resolve(target, this.config.meta.filename!);
const result = gulp.src(filename).pipe(run("./<%=file.basename%>", { cwd: target, verbosity: 0 }));
return this.log(result);
}
}
Runner.register(Platform.LINUX, LinuxRunner);
export class CPPRunner extends LinuxRunner {
constructor(config: Config, debug: boolean) {
super(config, debug);
this.platform = Platform.CPP;
}
}
Runner.register(Platform.CPP, CPPRunner);
export class WindowsRunner extends Runner {
constructor(config: Config, debug: boolean) {
super(config, Platform.WINDOWS, debug);
}
call() {
const target = this.targetPath;
const filename = path.resolve(target, this.config.meta.filename + ".exe");
const result = gulp.src(filename).pipe(run("<%=file.basename%>", { cwd: target, verbosity: 0 }));
return this.log(result);
}
}
Runner.register(Platform.WINDOWS, WindowsRunner);
export class NekoRunner extends Runner {
protected neko: Neko;
constructor(config: Config, debug: boolean) {
super(config, Platform.NEKO, debug);
this.neko = new Neko();
}
prepare() {
return this.neko.prepare();
}
call() {
const target = this.targetPath;
const filename = path.resolve(target, this.config.meta.filename + ".n");
const result = this.neko.run(filename, { cwd: target, verbosity: 0 });
return this.log(result);
}
}
Runner.register(Platform.NEKO, NekoRunner);
/**
*
*/
export class AndroidRunner extends Runner {
protected android: Android;
constructor(config: Config, debug: boolean) {
super(config, Platform.ANDROID, debug);
this.android = new Android();
}
prepare() {
return this.android.prepare();
}
call() {
const target = this.targetPath;
return this.log(
gulp
.src(`${target}/${this.config.meta.filename}_${this.config.meta.version}.apk`)
.pipe(this.android.apk())
.pipe(this.android.install())
.pipe(this.android.start())
.pipe(this.android.logcat()),
);
}
}
Runner.register(Platform.ANDROID, AndroidRunner);
export type Task = any; // TODO: gulp task type
export class Project {
// TODO: compatibility
static Config = Config;
static BuildSystem = BuildSystem;
static Platform = Platform;
static Builder = Builder;
public buildSystem: string;
public platforms: string[];
public config: Config;
public prepare: (() => Task) | null;
constructor(buildSystem: string, platforms: string[] | string, config: Config, prepare: (() => Task) | null = null) {
this.buildSystem = buildSystem;
this.platforms = Array.isArray(platforms) ? platforms : [platforms];
this.config = config;
this.prepare = prepare;
}
build(platform: string, debug: boolean = false): Task[] {
const builder = Builder.new(this.config, platform, this.buildSystem, debug);
const tasks: Task[] = [builder.prepare.bind(builder)];
if (this.prepare) tasks.push(this.prepare);
tasks.push(builder.call.bind(builder));
return tasks;
}
run(platform: string, debug: boolean = false): Task[] {
const runner = Runner.new(this.config, platform, debug);
return [runner.prepare.bind(runner), runner.call.bind(runner)];
}
test(platform: string, debug: boolean = true): Task[] {
return this.build(platform, debug).concat(this.run(platform, debug));
}
pack(platform: string, name: string) {
const packer = Packer.new(this.config, platform, name);
return [packer.prepare.bind(packer), packer.call.bind(packer)];
}
compile(external_gulp?: any): Record<string, Task> {
const result: Record<string, Task> = {};
const _gulp = external_gulp || gulp;
for (const platform of this.platforms) {
result[`${this.config.name}:${platform}:build`] = _gulp.series(this.build(platform));
if (Runner.factory[platform]) {
result[`${this.config.name}:${platform}:run`] = _gulp.series(this.run(platform));
result[`${this.config.name}:${platform}:test`] = _gulp.series(this.test(platform));
}
if (Packer.factory[platform]) {
for (const name of Object.keys(Packer.factory[platform])) {
result[`${this.config.name}:${platform}:${name}`] = _gulp.series(this.pack(platform, name));
}
}
}
return result;
}
register(external_gulp?: any) {
const _gulp = external_gulp || gulp;
for (const [k, v] of Object.entries(this.compile(_gulp))) {
_gulp.task(k, v);
}
}
static useRuffle() {
Runner.register(Platform.FLASH, RuffleRunner);
}
}
+23
View File
@@ -0,0 +1,23 @@
import type { Config } from "../../core/config";
import { Target } from "./target";
export class Builder extends Target {
static factory: Record<string, typeof Builder> = {};
public buildSystem: string;
public debug: boolean;
constructor(config: Config, platform: string, buildSystem: string, debug: boolean = false) {
super(config, platform);
this.buildSystem = buildSystem;
this.debug = debug;
}
static register(buildSystem: string, builder: typeof Builder) {
Builder.factory[buildSystem] = builder;
}
static new(config: Config, platform: string, buildSystem: string, debug: boolean = false): Builder {
return new Builder.factory[buildSystem](config, platform, buildSystem, debug);
}
}
+4
View File
@@ -0,0 +1,4 @@
export * from "./builder";
export * from "./packer";
export * from "./runner";
export * from "./target";
+21
View File
@@ -0,0 +1,21 @@
import type { Config } from "../../core/config";
import { Target } from "./target";
export type PackerFactory = new (config: Config) => Packer;
export class Packer extends Target {
static factory: Record<string, Record<string, PackerFactory>> = {};
call() {
throw "Not Implemented";
}
static register(platform: string, name: string, packer: PackerFactory) {
if (!Packer.factory[platform]) Packer.factory[platform] = {};
Packer.factory[platform][name] = packer;
}
static new(config: Config, platform: string, name: string): Packer {
return new Packer.factory[platform][name](config);
}
}
+31
View File
@@ -0,0 +1,31 @@
import gulp from "gulp";
import rename from "gulp-rename";
import { DEBUG } from "../../common/debug";
import { tail } from "../../common/tail";
import { Config } from "../../core/config";
import { Target } from "./target";
export type RunnerFactory = new (config: Config, debug: boolean) => Runner;
export class Runner extends Target {
static factory: Record<string, RunnerFactory> = {};
public debug: boolean;
constructor(config: Config, platform: string, debug: boolean) {
super(config, platform);
this.debug = debug;
}
log(stream: any) {
return stream.pipe(tail(DEBUG.log)).pipe(rename("out.log")).pipe(gulp.dest(this.targetPath));
}
static register(platform: string, runner: RunnerFactory) {
Runner.factory[platform] = runner;
}
static new(config: Config, platform: string, debug: boolean): Runner {
return new Runner.factory[platform](config, debug);
}
}
+30
View File
@@ -0,0 +1,30 @@
import path from "path";
import type { Config } from "../../core/config";
export class Target {
public config: Config;
public platform: string;
public target: string;
constructor(config: Config, platform: string) {
this.config = config;
this.platform = platform;
this.target = "target";
}
prepare(): Promise<any> {
return Promise.resolve();
}
call() {
throw "Not Implemented";
}
resolveTargetPath(platform = this.platform): string {
return path.resolve(this.target, this.config.name, platform);
}
get targetPath(): string {
return this.resolveTargetPath();
}
}
+69
View File
@@ -0,0 +1,69 @@
import vfs from "vinyl-fs";
import exec from "../../../common/exec";
import { streamToPromise } from "../../../common/util";
import { Config } from "../../../core/config";
import { BuildSystem, Platform } from "../../../core/type";
import { Android } from "../../../impl/android";
import { Haxe } from "../../../impl/haxe";
import { Builder } from "../../core/builder";
export class HaxeBuilder extends Builder {
public haxe: Haxe;
public android: Android;
constructor(config: Config, platform: string, buildSystem: string, debug: boolean = false) {
super(config, platform, buildSystem, debug);
this.haxe = new Haxe();
this.android = new Android();
}
prepare() {
let result = this.haxe.prepare().then(() => this.haxe.install(this.config.libs));
if (this.buildSystem === BuildSystem.OPENFL) {
if (this.platform === Platform.ANDROID) {
result = result
.then(() => this.android.prepare())
.then(() => this.android.activate())
.then(() =>
this.android.sdkmanager([
// ToDo: android sdk dependencies config?
//'tools',
"platform-tools",
"build-tools;27.0.3",
"platforms;android-28", //ToDo: lime version 7.6.0 -> 28; 7.0.0 -> 26
//'ndk-bundle',
//'lldb;3.1',
"cmake;3.6.4111459",
]),
);
const AndroidSDK = this.android.android_home;
const AndroidNDK = this.android.ndk_home;
const answer = `echo "${[AndroidSDK, AndroidNDK].join("\n")}"`;
result = result.then(() => {
return exec(".", [answer, "|", this.haxe.haxelibBin, "run", "openfl", "setup", this.platform].join(" "));
});
}
}
return result;
}
call() {
const target = this.targetPath;
switch (this.buildSystem) {
case BuildSystem.OPENFL:
return this.haxe.openfl("build", this.platform, this.config, this.debug).then((result) => {
if (this.platform === Platform.ANDROID && this.config.key) {
result = result.pipe(this.android.sign(this.config.key.store, this.config.key.pass));
}
return streamToPromise(result.pipe(vfs.dest(target)));
});
case BuildSystem.HAXE:
return this.haxe
.build(this.platform, this.config, this.debug)
.then((result) => streamToPromise(result.pipe(vfs.dest(target))));
}
}
}
Builder.register(BuildSystem.HAXE, HaxeBuilder);
Builder.register(BuildSystem.OPENFL, HaxeBuilder);
+13
View File
@@ -0,0 +1,13 @@
export * from "./builder/haxe";
export * from "./packer/flash";
export * from "./packer/linux/archive";
export * from "./packer/linux/deb";
export * from "./packer/windows/archive";
export * from "./packer/windows/installer";
export * from "./runner/android";
export * from "./runner/flash";
export * from "./runner/html5";
export * from "./runner/linux";
export * from "./runner/neko";
export * from "./runner/ruffle";
export * from "./runner/windows";
+27
View File
@@ -0,0 +1,27 @@
import fs from "fs";
import template from "lodash.template";
import path from "path";
import type { Config } from "../../../core/config";
import { Platform } from "../../../core/type";
import { Packer } from "../../core/packer";
export class FlashHTMLPacker extends Packer {
static NAME = "html";
constructor(config: Config) {
super(config, Platform.FLASH);
}
call() {
const target = this.targetPath;
const indexTemplate = template(
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/flash/index.html")),
);
const index = indexTemplate(this.config);
fs.writeFileSync(path.resolve(target, "index.html"), index);
fs.copyFileSync(path.resolve(import.meta.dirname, "..", "template/flash/swf.js"), path.resolve(target, "swf.js"));
return Promise.resolve();
}
}
Packer.register(Platform.FLASH, FlashHTMLPacker.NAME, FlashHTMLPacker);
+26
View File
@@ -0,0 +1,26 @@
import gulp from "gulp";
import gzip from "gulp-gzip";
import tar from "gulp-tar";
import type { Config } from "../../../../core/config";
import { Platform } from "../../../../core/type";
import { Packer } from "../../../core/packer";
export class LinuxArchivePacker extends Packer {
static NAME = "archive";
constructor(config: Config) {
super(config, Platform.LINUX);
}
call() {
const target = this.targetPath;
const archiveName = `${this.config.meta.filename}_${this.config.meta.version}_linux.tar`;
return gulp
.src(`${target}/**/*`)
.pipe(tar(archiveName))
.pipe(gzip())
.pipe(gulp.dest(this.resolveTargetPath("archive")));
}
}
Packer.register(Platform.LINUX, LinuxArchivePacker.NAME, LinuxArchivePacker);
+55
View File
@@ -0,0 +1,55 @@
import fs from "fs";
import fse from "fs-extra";
import gulp from "gulp";
import deb from "gulp-debian";
import template from "lodash.template";
import os from "os";
import path from "path";
import { Config } from "../../../../core/config";
import { Platform } from "../../../../core/type";
import { Packer } from "../../../core/packer";
export class LinuxDEBPacker extends Packer {
static NAME = "deb";
constructor(config: Config) {
super(config, Platform.LINUX);
}
call() {
const target = this.targetPath;
const buildDir = path.join(os.tmpdir(), "build", this.config.name, "debian");
const iconfile = `${this.config.meta.filename}${path.extname(this.config.meta.icon!)}`;
const desktopTemplate = template(
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/linux/app.desktop")),
);
const desktop = desktopTemplate(Object.assign({ iconfile: iconfile }, this.config));
fse.ensureDirSync(`${buildDir}/usr/share/applications`);
fs.writeFileSync(`${buildDir}/usr/share/applications/${this.config.meta.filename}.desktop`, desktop);
fse.copySync(`${target}`, `${buildDir}/usr/share/${this.config.meta.filename}/`);
fse.copySync(this.config.meta.icon!, `${buildDir}/usr/share/${this.config.meta.filename}/${iconfile}`);
return gulp.src(`${buildDir}/*`).pipe(
deb({
package: this.config.meta.filename,
version: this.config.meta.version,
section: "base",
priority: "optional",
architecture: "all",
maintainer: this.config.meta.author,
description: this.config.meta.title,
changelog: [],
postinst: [
'if [ "$1" = "configure" ] && [ -x "`which update-menus 2>/dev/null`" ] ; then\n' +
" update-menus\n" +
"fi",
],
_target: "/",
_out: this.resolveTargetPath("debian"),
_clean: true,
_verbose: false,
}),
);
}
}
Packer.register(Platform.LINUX, LinuxDEBPacker.NAME, LinuxDEBPacker);
@@ -0,0 +1,24 @@
import gulp from "gulp";
import zip from "gulp-zip";
import { Config } from "../../../../core/config";
import { Platform } from "../../../../core/type";
import { Packer } from "../../../core/packer";
export class WindowsArchivePacker extends Packer {
static NAME = "archive";
constructor(config: Config) {
super(config, Platform.WINDOWS);
}
call() {
const target = this.targetPath;
const archiveName = `${this.config.meta.filename}_${this.config.meta.version}_win.zip`;
return gulp
.src(`${target}/**/*`)
.pipe(zip(archiveName))
.pipe(gulp.dest(this.resolveTargetPath("archive")));
}
}
Packer.register(Platform.WINDOWS, WindowsArchivePacker.NAME, WindowsArchivePacker);
@@ -0,0 +1,25 @@
import { Config } from "../../../../core/config";
import { Platform } from "../../../../core/type";
import { InnoSetup } from "../../../../impl/innosetup";
import { Packer } from "../../../core/packer";
export class WindowsInstallerPacker extends Packer {
static NAME = "installer";
public innosetup: InnoSetup;
constructor(config: Config) {
super(config, Platform.WINDOWS);
this.innosetup = new InnoSetup();
}
prepare() {
return this.innosetup.prepare();
}
call() {
return this.innosetup.pack(this.config, this.targetPath, this.resolveTargetPath("installer"));
}
}
Packer.register(Platform.WINDOWS, WindowsInstallerPacker.NAME, WindowsInstallerPacker);
+32
View File
@@ -0,0 +1,32 @@
import gulp from "gulp";
import type { Config } from "../../../core/config";
import { Platform } from "../../../core/type";
import { Android } from "../../../impl/android";
import { Runner } from "../../core/runner";
export class AndroidRunner extends Runner {
protected android: Android;
constructor(config: Config, debug: boolean) {
super(config, Platform.ANDROID, debug);
this.android = new Android();
}
prepare() {
return this.android.prepare();
}
call() {
const target = this.targetPath;
return this.log(
gulp
.src(`${target}/${this.config.meta.filename}_${this.config.meta.version}.apk`)
.pipe(this.android.apk())
.pipe(this.android.install())
.pipe(this.android.start())
.pipe(this.android.logcat()),
);
}
}
Runner.register(Platform.ANDROID, AndroidRunner);
+27
View File
@@ -0,0 +1,27 @@
import path from "path";
import { Config } from "../../../core/config";
import { Platform } from "../../../core/type";
import { FlashPlayer } from "../../../impl/flashplayer";
import { Runner } from "../../core/runner";
export class FlashRunner extends Runner {
public player: FlashPlayer;
constructor(config: Config, debug: boolean, player: typeof FlashPlayer = FlashPlayer) {
super(config, Platform.FLASH, debug);
this.player = new player(debug);
}
prepare() {
return this.player.prepare();
}
call() {
const target = this.targetPath;
const filename = path.resolve(target, this.config.meta.filename + ".swf");
const result = this.player.run(filename, { cwd: target, verbosity: 0 });
return this.log(result);
}
}
Runner.register(Platform.FLASH, FlashRunner);
+25
View File
@@ -0,0 +1,25 @@
import gulp from "gulp";
import webserver from "gulp-webserver";
import { Config } from "../../../core/config";
import { Platform } from "../../../core/type";
import { Runner } from "../../core/runner";
export class Html5Runner extends Runner {
constructor(config: Config, debug: boolean) {
super(config, Platform.HTML5, debug);
}
call() {
return gulp.src(this.targetPath).pipe(
webserver({
// TODO: config?
host: "0.0.0.0",
port: 3000,
open: true,
fallback: "index.html",
}),
);
}
}
Runner.register(Platform.HTML5, Html5Runner);
+30
View File
@@ -0,0 +1,30 @@
import gulp from "gulp";
import path from "path";
import { Config } from "../../../core/config";
import { Platform } from "../../../core/type";
import run from "../../../run";
import { Runner } from "../../core/runner";
export class LinuxRunner extends Runner {
constructor(config: Config, debug: boolean) {
super(config, Platform.LINUX, debug);
}
call() {
const target = this.targetPath;
const filename = path.resolve(target, this.config.meta.filename!);
const result = gulp.src(filename).pipe(run("./<%=file.basename%>", { cwd: target, verbosity: 0 }));
return this.log(result);
}
}
Runner.register(Platform.LINUX, LinuxRunner);
export class CPPRunner extends LinuxRunner {
constructor(config: Config, debug: boolean) {
super(config, debug);
this.platform = Platform.CPP;
}
}
Runner.register(Platform.CPP, CPPRunner);
+27
View File
@@ -0,0 +1,27 @@
import path from "path";
import { Config } from "../../../core/config";
import { Platform } from "../../../core/type";
import { Neko } from "../../../impl/neko";
import { Runner } from "../../core/runner";
export class NekoRunner extends Runner {
public neko: Neko;
constructor(config: Config, debug: boolean) {
super(config, Platform.NEKO, debug);
this.neko = new Neko();
}
prepare() {
return this.neko.prepare();
}
call() {
const target = this.targetPath;
const filename = path.resolve(target, this.config.meta.filename + ".n");
const result = this.neko.run(filename, { cwd: target, verbosity: 0 });
return this.log(result);
}
}
Runner.register(Platform.NEKO, NekoRunner);
+9
View File
@@ -0,0 +1,9 @@
import type { Config } from "../../../core/config";
import { RufflePlayer } from "../../../impl/ruffle";
import { FlashRunner } from "./flash";
export class RuffleRunner extends FlashRunner {
constructor(config: Config, debug: boolean) {
super(config, debug, RufflePlayer);
}
}
+21
View File
@@ -0,0 +1,21 @@
import gulp from "gulp";
import path from "path";
import { Config } from "../../../core/config";
import { Platform } from "../../../core/type";
import run from "../../../run";
import { Runner } from "../../core/runner";
export class WindowsRunner extends Runner {
constructor(config: Config, debug: boolean) {
super(config, Platform.WINDOWS, debug);
}
call() {
const target = this.targetPath;
const filename = path.resolve(target, this.config.meta.filename + ".exe");
const result = gulp.src(filename).pipe(run("<%=file.basename%>", { cwd: target, verbosity: 0 }));
return this.log(result);
}
}
Runner.register(Platform.WINDOWS, WindowsRunner);
+82
View File
@@ -0,0 +1,82 @@
import gulp from "gulp";
import { Config } from "../core/config";
import { BuildSystem, Platform } from "../core/type";
import { Builder } from "./core/builder";
import { Packer } from "./core/packer";
import { Runner } from "./core/runner";
import { RuffleRunner } from "./impl/runner/ruffle";
export * from "./core";
export type Task = any; // TODO: gulp task type
export class Project {
// TODO: compatibility
static Config = Config;
static BuildSystem = BuildSystem;
static Platform = Platform;
static Builder = Builder;
public buildSystem: string;
public platforms: string[];
public config: Config;
public prepare: (() => Task) | null;
constructor(buildSystem: string, platforms: string[] | string, config: Config, prepare: (() => Task) | null = null) {
this.buildSystem = buildSystem;
this.platforms = Array.isArray(platforms) ? platforms : [platforms];
this.config = config;
this.prepare = prepare;
}
build(platform: string, debug: boolean = false): Task[] {
const builder = Builder.new(this.config, platform, this.buildSystem, debug);
const tasks: Task[] = [builder.prepare.bind(builder)];
if (this.prepare) tasks.push(this.prepare);
tasks.push(builder.call.bind(builder));
return tasks;
}
run(platform: string, debug: boolean = false): Task[] {
const runner = Runner.new(this.config, platform, debug);
return [runner.prepare.bind(runner), runner.call.bind(runner)];
}
test(platform: string, debug: boolean = true): Task[] {
return this.build(platform, debug).concat(this.run(platform, debug));
}
pack(platform: string, name: string) {
const packer = Packer.new(this.config, platform, name);
return [packer.prepare.bind(packer), packer.call.bind(packer)];
}
compile(external_gulp?: any): Record<string, Task> {
const result: Record<string, Task> = {};
const _gulp = external_gulp || gulp;
for (const platform of this.platforms) {
result[`${this.config.name}:${platform}:build`] = _gulp.series(this.build(platform));
if (Runner.factory[platform]) {
result[`${this.config.name}:${platform}:run`] = _gulp.series(this.run(platform));
result[`${this.config.name}:${platform}:test`] = _gulp.series(this.test(platform));
}
if (Packer.factory[platform]) {
for (const name of Object.keys(Packer.factory[platform])) {
result[`${this.config.name}:${platform}:${name}`] = _gulp.series(this.pack(platform, name));
}
}
}
return result;
}
register(external_gulp?: any) {
const _gulp = external_gulp || gulp;
for (const [k, v] of Object.entries(this.compile(_gulp))) {
_gulp.task(k, v);
}
}
// TODO:
static useRuffle() {
Runner.register(Platform.FLASH, RuffleRunner);
}
}