Compare commits

...
21 Commits
Author SHA1 Message Date
shmyga f59ef2893e ci(version): 2.1.0
release / release (push) Successful in 57s
test / test (push) Successful in 1m33s
2026-11-11 22:05:54 +03:00
shmyga 6a887d10ff docs: remove CHANGELOG.md
test / test (push) Successful in 58s
2026-11-11 21:54:07 +03:00
shmyga 6940c65b88 feat: add task module
test / test (push) Successful in 2m13s
2026-11-11 21:34:11 +03:00
shmyga 0a355ee680 feat: add link module 2026-11-10 15:34:18 +03:00
shmyga bb6d82d538 feat: add link module
test / test (push) Failing after 5m44s
2026-11-02 02:41:43 +03:00
shmyga 7615dbfc48 ci(version): 2.0.4
release / release (push) Failing after 5m38s
test / test (push) Failing after 5m44s
2026-11-01 21:22:45 +03:00
shmyga d079cbaac5 fix(haxe): replace old broken haxelib when haxe preparing
test / test (push) Failing after 5m43s
2026-11-01 18:28:46 +03:00
shmyga b3d1aee9ed fix: replace unzip-stream with unzipper
test / test (push) Failing after 5m35s
2026-11-01 17:26:56 +03:00
shmyga 769127d6f0 fix(template): fix project.hxml template
test / test (push) Failing after 5m38s
2026-11-01 16:19:02 +03:00
shmyga 57f7e88fab ci(version): 2.0.3
release / release (push) Failing after 5m30s
test / test (push) Failing after 5m39s
2026-11-01 14:17:06 +03:00
shmyga 7f62df2364 fix: fix template dir 2026-11-01 14:16:58 +03:00
shmyga 6622d53167 ci(version): 2.0.2
release / release (push) Failing after 5m40s
test / test (push) Failing after 5m39s
2026-11-01 13:59:34 +03:00
shmyga 561dd99cba fix: fix template basepath 2026-11-01 13:59:24 +03:00
shmyga bc77380aba ci(version): 2.0.1
release / release (push) Failing after 5m29s
test / test (push) Failing after 5m51s
2026-10-31 22:31:25 +03:00
shmyga a20e98d730 fix(asset): fix asset basepath 2026-10-31 22:31:13 +03:00
shmyga 87fe852f99 ci(version): 2.0.0
release / release (push) Successful in 36s
test / test (push) Successful in 35s
2026-10-31 15:54:13 +03:00
shmyga dfad6d3aba docs: update README
test / test (push) Successful in 35s
2026-10-31 15:50:42 +03:00
shmyga bff3cc06ef refactor(preset): rework preset exports
test / test (push) Successful in 1m11s
2026-10-31 15:18:39 +03:00
shmyga 6ff587cb65 fix: up android-ndk version
test / test (push) Successful in 1m4s
2026-10-30 14:52:48 +03:00
shmyga bf6ff0deb9 fix: fix default icon
test / test (push) Successful in 6m6s
2026-10-30 00:03:46 +03:00
shmyga 2605c1bbc8 refactor(preset): rework preset
test / test (push) Failing after 5m32s
2026-10-29 20:35:53 +03:00
61 changed files with 951 additions and 2128 deletions
-29
View File
@@ -1,29 +0,0 @@
## v0.2.0 (2026-05-15)
### Feat
- **ruffle**: add alternative ruffle flash target runner
## 0.1.9 (2021-05-24)
### Feat
- **android**: up android sdk version
## 0.1.8 (2020-03-30)
## 0.1.7 (2020-03-25)
## 0.1.6 (2020-02-19)
## 0.1.5 (2020-02-18)
## 0.1.0 (2019-09-03)
## 0.0.18 (2019-05-20)
## 0.0.17 (2019-03-28)
## 0.0.16 (2019-03-14)
## 0.0.15 (2019-03-14)
+23 -37
View File
@@ -1,26 +1,12 @@
# Gulp HaXe Tool
# HaXeTool
[![test](https://git.shmyga.ru/InfernalGames/gulp-haxetool/actions/workflows/test.yaml/badge.svg?branch=master)](https://git.shmyga.ru/InfernalGames/gulp-haxetool/actions?workflow=test.yaml)
## Introducing
### Dignity
Tool for simple building and pack HaXe and OpenFl project
- Automatically download HaXe SDK, Neko, FlashPlayer (or RufflePlayer), Android SDK.
- Universal project config for simple HaXe build and OpenFL build.
- Branch project config for many build presets (many OpenFL apps in one project).
- Packaging linux output in DEB.
- Packaging windows output in exe install with InnoSetup.
- Create html wrapper for flash output.
### Flaws
- Hardcode build output in {projectDir}/target (need param in Project.Config).
- HTML5 run output not caught.
- Adobe AIR Build System in progress.
- Windows target depends Visual Studio 2017 build tools
## Example
## OpenFL Example
[Example project](./example)
@@ -37,7 +23,7 @@
"dev": "hxt app:flash:test"
},
"devDependencies": {
"gulp-haxetool": "^1.2.0"
"gulp-haxetool": "^2.0.0"
}
}
```
@@ -51,23 +37,13 @@ JSON schema: https://shmyga.ru/public/haxetool.schema.json
"app": {
"buildSystem": "openfl",
"platforms": ["flash", "html5", "linux", "windows", "android"],
"config": {
"meta": {
"title": "Example",
"filename": "example",
"icon": "./resources/icon.jpg",
"pack": "com.example",
"author": "Anonim <anonim@anonim.com>",
"company": "Any company"
},
"libs": {
"lime": "8.3.2",
"openfl": "9.5.2",
"hxcpp": "4.3.2"
},
"sources": ["src"],
"main": "Main"
}
"libs": {
"lime": "8.3.2",
"openfl": "9.5.2",
"hxcpp": "4.2.1"
},
"sources": ["src"],
"main": "Main"
}
}
```
@@ -80,7 +56,7 @@ JSON schema: https://shmyga.ru/public/haxetool.schema.json
npx hxt
```
### Build and pack all presets platform variants
### Build and pack all platform variants
Results places in `target` directory
@@ -101,9 +77,19 @@ npx hxt app:android:test
npx hxt app:windows:test
```
## Dependencies requiring manual installation
### Windows
* Visual Studio 2017 build tools
### Android
* Java JDK 17
## VS Code settings
JSON schema for `haxetool.json`
### JSON schema for `haxetool.json`
```json
{
+64
View File
@@ -0,0 +1,64 @@
{
"$id": "https://shmyga.ru/public/haxetool.schema.json",
"title": "Haxe tool",
"description": "Haxe tool presets",
"type": "object",
"patternProperties": {
".*": {
"type": "object",
"properties": {
"buildSystem": { "enum": ["haxe", "openfl"] },
"platforms": {
"type": "array",
"items": { "enum": ["flash", "html5", "linux", "windows", "android", "neko", "cpp"] }
},
"name": { "type": "string" },
"main": { "type": "string" },
"preloader": { "type": "string" },
"sources": { "type": "array", "items": { "type": "string" } },
"assets": { "type": "array", "items": { "type": "string" } },
"libs": { "type": "object", "patternProperties": { ".*": { "type": "string" } } },
"macros": { "type": "array", "items": { "type": "string" } },
"flags": { "type": "array", "items": { "type": "string" } },
"meta": {
"type": "object",
"properties": {
"title": { "type": "string" },
"filename": { "type": "string" },
"icon": { "type": "string" },
"version": { "type": "string" },
"pack": { "type": "string" },
"author": { "type": "string" },
"company": { "type": "string" },
"width": { "type": "number" },
"height": { "type": "number" },
"mobileWidth": { "type": "number" },
"mobileHeight": { "type": "number" },
"fps": { "type": "number" }
},
"additionalProperties": false
},
"key": {
"type": "object",
"properties": {
"store": { "type": "string" },
"pass": { "type": "string" }
},
"required": ["store", "pass"]
},
"android": {
"type": "array",
"items": {
"type": "object",
"properties": {
"path": { "type": "string" },
"extensions": { "type": "array", "items": { "type": "string" } }
}
}
},
"haxe": { "type": "string" }
},
"additionalProperties": false
}
}
}
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

+7 -17
View File
@@ -2,22 +2,12 @@
"app": {
"buildSystem": "openfl",
"platforms": ["flash", "html5", "linux", "windows", "android"],
"config": {
"meta": {
"title": "Example",
"filename": "example",
"icon": "./resources/icon.jpg",
"pack": "com.example",
"author": "Anonim <anonim@anonim.com>",
"company": "Any company"
},
"libs": {
"lime": "8.3.2",
"openfl": "9.5.2",
"hxcpp": "4.3.2"
},
"sources": ["src"],
"main": "Main"
}
"libs": {
"lime": "8.3.2",
"openfl": "9.5.2",
"hxcpp": "4.2.1"
},
"sources": ["src"],
"main": "Main"
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"indentation": {
"character": " "
},
"wrapping": {
"maxLineLength": 120
}
}
+9 -10
View File
@@ -2,13 +2,12 @@ import flash.display.Shape;
import flash.Lib;
class Main {
public static function main() {
trace("Hello world!");
var shape = new Shape();
shape.graphics.beginFill(0x00ff00);
shape.graphics.drawCircle(50, 50, 20);
shape.graphics.endFill();
Lib.current.addChild(shape);
}
}
public static function main() {
trace("Hello world!");
var shape = new Shape();
shape.graphics.beginFill(0x00ff00);
shape.graphics.drawCircle(50, 50, 20);
shape.graphics.endFill();
Lib.current.addChild(shape);
}
}
-70
View File
@@ -1,70 +0,0 @@
{
"$id": "https://shmyga.ru/public/haxetool.schema.json",
"title": "Haxe tool",
"description": "Haxe tool presets",
"type": "object",
"patternProperties": {
".*": {
"type": "object",
"properties": {
"buildSystem": { "enum": ["haxe", "openfl"] },
"platforms": {
"type": "array",
"items": { "enum": ["flash", "html5", "linux", "windows", "android", "neko", "cpp"] }
},
"config": {
"type": "object",
"properties": {
"name": { "type": "string" },
"main": { "type": "string" },
"preloader": { "type": "string" },
"sources": { "type": "array", "items": { "type": "string" } },
"assets": { "type": "array", "items": { "type": "string" } },
"libs": { "type": "object", "patternProperties": { ".*": { "type": "string" } } },
"macros": { "type": "array", "items": { "type": "string" } },
"flags": { "type": "array", "items": { "type": "string" } },
"meta": {
"type": "object",
"properties": {
"title": { "type": "string" },
"filename": { "type": "string" },
"icon": { "type": "string" },
"version": { "type": "string" },
"pack": { "type": "string" },
"author": { "type": "string" },
"company": { "type": "string" },
"width": { "type": "number" },
"height": { "type": "number" },
"mobileWidth": { "type": "number" },
"mobileHeight": { "type": "number" },
"fps": { "type": "number" }
},
"additionalProperties": false
},
"key": {
"type": "object",
"properties": {
"store": { "type": "string" },
"pass": { "type": "string" }
},
"required": ["store", "pass"]
},
"android": {
"type": "array",
"items": {
"type": "object",
"properties": {
"path": { "type": "string" },
"extensions": { "type": "array", "items": { "type": "string" } }
}
}
},
"haxe": { "type": "string" }
},
"additionalProperties": false
}
},
"additionalProperties": false
}
}
}
+89 -1328
View File
File diff suppressed because it is too large Load Diff
+4 -5
View File
@@ -1,8 +1,8 @@
{
"name": "gulp-haxetool",
"type": "module",
"version": "1.2.0",
"description": "HaXe Tool for Gulp",
"version": "2.1.0",
"description": "HaXe Tool with Gulp",
"exports": {
"./bin/cli": "./dist/bin/cli.mjs",
"./lib": "./dist/lib/index.mjs",
@@ -13,7 +13,6 @@
},
"types": "./dist/lib/index.d.mts",
"files": [
"template",
"dist"
],
"scripts": {
@@ -55,7 +54,7 @@
"tar": "^7.5.22",
"through2": "^5.0.12",
"tmp-file": "^2.0.1",
"unzip-stream": "^0.3.4",
"unzipper": "^0.12.5",
"vinyl": "^3.0.1",
"vinyl-fs": "^4.0.2"
},
@@ -74,7 +73,7 @@
"@types/tail": "^2.2.3",
"@types/tar": "^7.0.87",
"@types/through2": "^5.0.0",
"@types/unzip-stream": "^0.3.4",
"@types/unzipper": "^0.10.11",
"eslint": "^10.13.0",
"prettier": "^3.9.10",
"tsdown": "0.22.14",
+5 -26
View File
@@ -1,34 +1,11 @@
#!/usr/bin/env node
import Ajv from "ajv";
import fs from "fs";
import gulp from "gulp";
import path from "path";
import { fileURLToPath } from "url";
import { Preset, type ProjectPreset } from ".";
import { Preset, Task } from ".";
import { name, version } from "../package.json" with { type: "json" };
console.log(`[${name} ${version}]`);
const loadPreset = (): Preset => {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const presetData: Record<string, ProjectPreset> = JSON.parse(fs.readFileSync("haxetool.json", "utf8"));
const ajv = new Ajv();
const presetSchema = ajv.compile(
JSON.parse(fs.readFileSync(path.join(__dirname, "..", "haxetool.schema.json"), "utf-8")),
);
const valid = presetSchema(presetData);
if (!valid) {
throw presetSchema.errors;
}
const packageInfo = JSON.parse(fs.readFileSync("package.json", "utf8"));
const configData = fs.existsSync("config.json") ? JSON.parse(fs.readFileSync("config.json", "utf8")) : null;
return new Preset(presetData, configData, packageInfo);
};
const showTasks = () => {
const tree = gulp.tree({ deep: true });
console.log(tree.nodes.map((node) => node.label).join("\n"));
@@ -47,8 +24,10 @@ const runTask = async (name: string) => {
};
export const main = async () => {
const preset = loadPreset();
preset.register(gulp);
const preset = Preset.loader();
Preset.validator(preset);
const projects = Preset.compiler(preset);
Task.register(Task.compiler(projects));
if (process.argv.length > 2) {
await runTask(process.argv[2]);
+9
View File
@@ -0,0 +1,9 @@
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default (name: string): string => {
return path.join(__dirname, "assets", name);
};
+4 -4
View File
@@ -4,9 +4,9 @@ import fse from "fs-extra";
import got, { type Progress, type Request } from "got";
import path from "path";
import ps from "promise-streams";
import type { Stream, Writable } from "stream";
import { type Stream, type Writable } from "stream";
import { x as tarX } from "tar";
import unzip from "unzip-stream";
import unzipper from "unzipper";
export interface DownloadOptions {
progress?: boolean;
@@ -19,7 +19,7 @@ const DEFAULT_OPTIONS: DownloadOptions = { progress: true, strip: 1, executable:
type Extractor = (stream: Request, dest: string, options: DownloadOptions) => Stream;
const ZIP_EXTRACTOR: Extractor = (stream: Request, dest: string, options: DownloadOptions): Stream => {
return stream.pipe(unzip.Parse()).on("entry", (entry: any) => {
return stream.pipe(unzipper.Parse()).on("entry", (entry: unzipper.Entry) => {
const filePath = entry.path.split("/").slice(options.strip).join(path.sep);
if (filePath.length > 0) {
if (entry.type === "Directory") {
@@ -94,7 +94,7 @@ const progressBar = new ProgressBar();
export const download = async (url: string, dest: string, options?: DownloadOptions): Promise<void> => {
options = { ...DEFAULT_OPTIONS, ...options };
fse.ensureDirSync(dest);
let stream: Request = got.stream(url);
let stream: Request = got.stream(url, { decompress: false });
if (options.progress) {
stream = progressBar.handle(stream);
}
+6 -3
View File
@@ -5,9 +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,
filterFunction: (val: unknown): string => (val === null ? "" : String(val)),
escapeFunction: (val: unknown): string => String(val),
filterFunction: (val: unknown): string => (val === null || val === undefined ? "" : String(val)),
useWith: true,
views: path.join(__dirname, "..", "template"),
views: path.join(__dirname, "template"),
});
export default template;
+95 -129
View File
@@ -1,141 +1,107 @@
import os from "os";
import path from "path";
import asset from "../common/asset";
import { BuildSystem, type Config, type ConfigSource } from "./type";
export interface ConfigParams {
name?: string;
main?: string;
preloader?: string;
sources?: string[];
assets?: string[];
libs?: LibDef[] | Record<string, string>;
macros?: string[];
flags?: string[];
meta?: ConfigMeta;
key?: SignKey;
android?: AndroidPreset[];
haxe?: string;
}
export const DEFAULT_ICON = asset("icon.jpg");
export interface ConfigMeta {
title?: string;
filename?: string;
icon?: string;
version?: string;
pack?: string;
author?: string;
company?: string;
width?: number;
height?: number;
mobileWidth?: number;
mobileHeight?: number;
fps?: number;
}
export const DEFAULT_CONFIG: Config = {
buildSystem: BuildSystem.HAXE,
platforms: [],
name: "",
main: "",
preloader: null,
sources: [],
assets: [],
libs: [],
macros: [],
flags: [],
icon: DEFAULT_ICON,
meta: {
width: 800,
height: 600,
fps: 60,
},
key: null,
android: [],
};
export interface LibDef {
name: string;
version: string;
git?: string;
branch?: string;
}
export const absolutePath = (file: string): string => {
const result = path.resolve(process.cwd(), path.normalize(file));
return os.type() === "Windows_NT" ? result.split("\\").join("/") : result;
};
export interface AndroidPreset {
path: string;
extensions: string[];
}
export const compile = (source: ConfigSource): Config => {
return branch(DEFAULT_CONFIG, source);
};
export interface SignKey {
store: string;
pass: string;
}
export const branch = (config: Config, source: ConfigSource | Config): Config => {
const result = structuredClone(config);
export class Config {
public name: string;
public main: string;
public preloader: string | null;
public sources: string[];
public assets: string[];
public libs: LibDef[];
public macros: string[];
public flags: string[];
public icon: string | null;
public meta: ConfigMeta;
public key: SignKey | null;
public android: AndroidPreset[];
public haxe: string | null;
if (source.buildSystem !== undefined) {
result.buildSystem = source.buildSystem;
}
if (source.platforms !== undefined) {
result.platforms = result.platforms.concat(source.platforms);
}
if (source.name !== undefined) {
result.name = source.name;
}
if (source.main !== undefined) {
result.main = source.main;
}
if (source.preloader !== undefined) {
result.preloader = source.preloader;
}
if (source.sources !== undefined) {
result.sources = result.sources.concat(source.sources.map(absolutePath));
}
if (source.assets !== undefined) {
result.assets = result.assets.concat(source.assets.map(absolutePath));
}
if (source.libs !== undefined) {
result.libs = result.libs.concat(
Array.isArray(source.libs) ? source.libs : Object.entries(source.libs).map(([k, v]) => ({ name: k, version: v })),
);
}
if (source.macros !== undefined) {
result.macros = result.macros.concat(source.macros);
}
if (source.flags !== undefined) {
result.flags = result.flags.concat(source.flags);
}
if (source.meta !== undefined) {
result.meta = { ...result.meta, ...source.meta };
}
if (source.key !== undefined) {
result.key = source.key;
}
if (source.android !== undefined) {
result.android = result.android.concat(
source.android.map((item) => ({ path: absolutePath(item.path), extensions: item.extensions })),
);
}
if (source.haxe !== undefined) {
result.haxe = source.haxe;
}
if (result.icon) {
result.icon = absolutePath(result.icon);
}
private _params: ConfigParams[];
if (!result.meta.mobileWidth) {
result.meta.mobileWidth = result.meta.width;
}
if (!result.meta.mobileHeight && result.meta.mobileWidth) {
result.meta.mobileHeight = Math.round(result.meta.mobileWidth / 2.222222222);
}
return result;
};
constructor(params?: ConfigParams) {
this._params = [];
this.name = "";
this.main = "";
this.preloader = null;
this.sources = [];
this.assets = [];
this.libs = [];
this.macros = [];
this.flags = [];
this.icon = null;
this.meta = {
width: 800,
height: 600,
fps: 60,
};
this.key = null;
this.android = [];
this.haxe = null;
if (params) {
this.update(params);
this.afterUpdate();
export const hasLib = (config: Config, name: string): boolean => {
for (const lib of config.libs) {
if (lib.name === name) {
return true;
}
}
static absolutePath(file: string): string {
const result = path.resolve(process.cwd(), path.normalize(file));
return os.type() === "Windows_NT" ? result.split("\\").join("/") : result;
}
update(params: ConfigParams) {
this._params.push(params);
if (params.name !== undefined) this.name = params.name;
if (params.main !== undefined) this.main = params.main;
if (params.preloader !== undefined) this.preloader = params.preloader;
if (params.sources !== undefined) this.sources = this.sources.concat(params.sources.map(Config.absolutePath));
if (params.assets !== undefined) this.assets = this.assets.concat(params.assets.map(Config.absolutePath));
if (params.libs !== undefined)
this.libs = this.libs.concat(
Array.isArray(params.libs)
? params.libs
: Object.entries(params.libs).map(([k, v]) => ({ name: k, version: v })),
);
if (params.macros !== undefined) this.macros = this.macros.concat(params.macros);
if (params.flags !== undefined) this.flags = this.flags.concat(params.flags);
if (params.meta !== undefined) this.meta = { ...this.meta, ...params.meta };
if (params.key !== undefined) this.key = params.key;
if (params.android !== undefined)
this.android = this.android.concat(
params.android.map((item) => ({ path: Config.absolutePath(item.path), extensions: item.extensions })),
);
if (params.haxe !== undefined) this.haxe = params.haxe;
if (this.meta.icon) this.icon = Config.absolutePath(this.meta.icon);
}
afterUpdate() {
if (this.meta.mobileWidth === null) {
this.meta.mobileWidth = this.meta.width;
}
if (this.meta.mobileHeight === null && this.meta.mobileWidth) {
this.meta.mobileHeight = Math.round(this.meta.mobileWidth / 2.222222222);
}
}
branch(params: ConfigParams) {
const result = new Config();
for (const params of this._params) {
result.update(params);
}
result.update(params);
result.afterUpdate();
return result;
}
}
return false;
};
+40
View File
@@ -0,0 +1,40 @@
import os from "os";
import template from "../common/template";
export type Params = Record<string, any>;
export interface Link {
version?: string;
url: string;
}
export const DefaultParams: string[][] = [
["debug", "<%= false %>"],
["os_name", "<%= {Linux:'linux',Windows_NT:'win'}[os.type()] %>"],
["os_name_long", "<%= {linux:'linux',win:'windows'}[os_name] %>"],
["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));
}
};
+11 -4
View File
@@ -2,10 +2,13 @@ import os from "os";
import path from "path";
import download from "../common/download";
import { Logger } from "../common/log";
import { resolveLink, type Link } from "./link";
export class Sdk {
static _dir: string;
url!: string;
static set dir(value) {
Sdk._dir = value;
}
@@ -45,8 +48,11 @@ export class Sdk {
throw "Not implemented";
}
get link(): string {
throw "Not implemented";
get link(): string | Link {
return {
version: this.version,
url: this.url,
};
}
prepare(strip = 1): Promise<any> {
@@ -54,8 +60,9 @@ export class Sdk {
if (this.prepared) {
return Promise.resolve();
} else {
this.log.i("download: *%s*", this.link);
return download(this.link, this.path, { strip });
const url = resolveLink(this.link, { name: this.name, version: this.version });
this.log.i("download: *%s*", url);
return download(url, this.path, { strip });
}
}
}
+78
View File
@@ -13,3 +13,81 @@ export enum Platform {
NEKO = "neko",
CPP = "cpp",
}
export interface LibDef {
name: string;
version: string;
git?: string;
branch?: string;
}
export interface ConfigMeta {
title?: string;
filename?: string;
version?: string;
pack?: string;
author?: string;
company?: string;
width?: number;
height?: number;
mobileWidth?: number;
mobileHeight?: number;
fps?: number;
}
export interface AndroidPreset {
path: string;
extensions: string[];
}
export interface SignKey {
store: string;
pass: string;
}
export interface ConfigSource {
buildSystem?: BuildSystem;
platforms?: Platform[];
name?: string;
main?: string;
preloader?: string;
sources?: string[];
assets?: string[];
libs?: LibDef[] | Record<string, string>;
macros?: string[];
flags?: string[];
meta?: ConfigMeta;
key?: SignKey;
android?: AndroidPreset[];
haxe?: string;
}
export interface Config {
buildSystem: BuildSystem;
platforms: Platform[];
name: string;
main: string;
preloader: string | null;
sources: string[];
assets: string[];
libs: LibDef[];
macros: string[];
flags: string[];
icon: string;
meta: ConfigMeta;
key: SignKey | null;
android: AndroidPreset[];
haxe?: string;
}
export type PackageJson = Record<string, any>;
export interface ConfigJson {
SdkDir?: string;
BuildDir?: string;
Develop?: boolean;
UseRuffle?: boolean;
Key?: SignKey;
}
export type PresetJson = Record<string, ConfigSource>;
+27 -23
View File
@@ -2,30 +2,47 @@ import fs from "fs";
import os from "os";
import path from "path";
import through from "through2";
import download from "../common/download";
import env from "../common/env";
import exec from "../common/exec";
import { System } from "../common/system";
import { HandlerWriter } from "../common/tail";
import { Sdk } from "../core/sdk";
import { Command } from "../run/command";
export class AndroidNdk extends Sdk {
static ID = "android-ndk";
static VERSION_R15C = "r15c";
static VERSION_R21E = "r21e";
static VERSION = AndroidNdk.VERSION_R21E;
url = "https://dl.google.com/android/repository/android-ndk-<%= version %>-<%= os_name_long %>-x86_64.zip";
constructor(version?: string) {
super(AndroidNdk.ID, version || AndroidNdk.VERSION);
}
get prepared(): boolean {
try {
return fs.existsSync(`${this.path}/build/ndk-build`);
} catch (e) {
return false;
}
}
}
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: AndroidNdk;
private ndk_version: string;
private repository: string;
url = "https://dl.google.com/android/repository/commandlinetools-<%= os_name %>-<%= version %>_latest.zip";
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";
this.ndk = new AndroidNdk(ndkVersion);
}
get prepared(): boolean {
@@ -36,16 +53,12 @@ export class Android extends Sdk {
}
}
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");
return this.ndk.path;
}
get sdkmanager_bin(): string {
@@ -55,19 +68,10 @@ export class Android extends Sdk {
prepare(): Promise<any> {
const result = [];
result.push(super.prepare(0));
if (!fs.existsSync(path.join(this.ndk_home))) {
result.push(this.prepare_ndk());
}
result.push(this.ndk.prepare());
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 download(url, this.ndk_home, { executable: true });
}
sdkmanager(packages: string[]) {
this.log.i("sdkmanager: *%s*", packages.join(", "));
const installedFile = path.join(this.path, ".installed");
+5 -14
View File
@@ -2,7 +2,6 @@ import fs from "fs";
import fse from "fs-extra";
import os from "os";
import path from "path";
import env from "../common/env";
import { System } from "../common/system";
import { watch } from "../common/watch";
import { Sdk } from "../core/sdk";
@@ -26,12 +25,15 @@ export class FlashPlayer extends Sdk {
BASE_URL = "https://fpdownload.macromedia.com/pub/flashplayer/updaters";
private debug: boolean;
protected baseUrl: string;
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] %>";
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() {
@@ -46,17 +48,6 @@ export class FlashPlayer extends Sdk {
}
}
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 playerName = `flashplayer_${this.version}_sa${this.debug ? "_debug" : ""}.exe`;
+28 -26
View File
@@ -8,8 +8,8 @@ import env from "../common/env";
import exec from "../common/exec";
import { System } from "../common/system";
import template from "../common/template";
import type { Config, LibDef } from "../core/config";
import { Sdk } from "../core/sdk";
import type { Config, LibDef } from "../core/type";
import { Platform } from "../core/type";
import { Neko } from "./neko";
@@ -28,11 +28,16 @@ export class Haxe extends Sdk {
static VERSION_4_0_5 = "4.0.5";
static VERSION_4_2_5 = "4.2.5";
static VERSION_4_3_7 = "4.3.7";
static VERSION_4 = Haxe.VERSION_4_3_7;
static VERSION_4 = Haxe.VERSION_4_2_5;
static VERSION = Haxe.VERSION_4;
static buildDir = path.join(process.cwd(), "build");
url =
"https://github.com/HaxeFoundation/haxe/releases/download/" +
"<%= version %>/" +
"haxe-<%= version %>-<%= os_name %><%= os_arch %>.<%= os_archive_ext %>";
getBin(name: string) {
if (System.isWindows) {
return path.join(this.path, name + ".exe");
@@ -78,33 +83,30 @@ export class Haxe extends Sdk {
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"),
);
});
async replaceHaxelib(version: string): Promise<any> {
const haxe = new Haxe(version);
await haxe.prepare();
fs.copyFileSync(haxe.haxelibBin, this.haxelibBin);
}
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}`;
async prepare(): Promise<any> {
await Promise.all([this.neko.prepare(), super.prepare()]);
fs.copyFileSync(path.resolve(import.meta.dirname, "template/haxe/activate"), path.resolve(this.path, "activate"));
// TODO: old haxelib fail with EOF
if (this.intVersion < 430) {
await this.replaceHaxelib(Haxe.VERSION_4_3_7);
}
}
haxe(args: any) {
this.activate();
this.log.d("_haxe_ *%s*", args.join(" "));
return exec(".", [this.haxeBin].concat(args).join(" "));
}
haxelib(args: any) {
this.activate();
this.log.d("_haxelib_ *%s*", args.join(" "));
return exec(".", [this.haxelibBin].concat(args).join(" "));
}
@@ -179,7 +181,7 @@ export class Haxe extends Sdk {
args.push("-debug");
}
const target = path.resolve(buildDir, platform, "bin");
if (platform !== "cpp") {
if (platform !== Platform.CPP) {
fse.emptyDirSync(target);
}
for (const asset of config.assets) {
@@ -193,7 +195,7 @@ export class Haxe extends Sdk {
)[platform] || "**/*";
return this.haxe(args).then(() => {
let r = vfs.src(`${target}/${result}`, { encoding: false });
if (platform === "cpp") {
if (platform === Platform.CPP) {
r = r.pipe(rename(config.meta.filename!));
}
return r;
@@ -201,17 +203,17 @@ export class Haxe extends Sdk {
}
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 }));
}
this.log.i("_install_ *%s*", packages.map((item) => `${item.name}:${item.version}`).join(" "));
this.activate();
let promise = this.haxelib(["setup", path.join(this.path, "lib")]);
const next = (args: any) => () => {
return this.haxelib(args);
};
for (let pack of packages) {
const args = [];
let version = null;
+1 -1
View File
@@ -4,8 +4,8 @@ import os from "os";
import path from "path";
import exec from "../common/exec";
import template from "../common/template";
import type { Config } from "../core/config";
import { Sdk } from "../core/sdk";
import type { Config } from "../core/type";
export class InnoSetup extends Sdk {
static ID = "innosetup";
+6 -43
View File
@@ -5,41 +5,6 @@ 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";
@@ -48,14 +13,15 @@ export class Neko extends Sdk {
static VERSION_2_4_1 = "2.4.1";
static VERSION = Neko.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 %>";
constructor(version?: string) {
super(Neko.ID, version || Neko.VERSION);
}
get link() {
return NekoLink.get(this.version);
}
get prepared() {
try {
return fs.existsSync(this.nekoBin);
@@ -72,10 +38,7 @@ export class Neko extends Sdk {
prepare() {
return Promise.all([super.prepare()]).then(() => {
fs.copyFileSync(
path.resolve(import.meta.dirname, "..", "template/neko/activate"),
path.resolve(this.path, "activate"),
);
fs.copyFileSync(path.resolve(import.meta.dirname, "template/neko/activate"), path.resolve(this.path, "activate"));
});
}
+5 -18
View File
@@ -1,6 +1,5 @@
import os from "os";
import path from "path";
import env from "../common/env";
import { System } from "../common/system";
import { watch } from "../common/watch";
import run from "../run";
@@ -9,30 +8,18 @@ import { FlashPlayer } from "./flashplayer";
export class RufflePlayer extends FlashPlayer {
static ID = "ruffle";
static VERSION_2026_05_15 = "nightly-2026_05_15";
static VERSION_2026_10_13 = "nightly-2026_10_13";
static VERSION_0_5_0 = "0.5.0";
static VERSION_0_6_0 = "0.6.0";
static VERSION_0_7_1 = "0.7.1";
static VERSION = RufflePlayer.VERSION_2026_10_13;
static VERSION = RufflePlayer.VERSION_0_7_1;
BASE_URL = "https://github.com/ruffle-rs/ruffle/releases/download";
url =
"https://github.com/ruffle-rs/ruffle/releases/download/" +
"v<%= version %>/" +
"ruffle-<%= version %>-<%= os_name_long %>-x86_64.<%= os_archive_ext %>";
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 nightly = this.version.includes("nightly");
const baseUrl = `${this.baseUrl}/${nightly ? "" : "v"}${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 {
+4 -1
View File
@@ -2,7 +2,9 @@ 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/link";
export * from "./core/sdk";
export * from "./core/type";
export * from "./impl/android";
@@ -11,6 +13,7 @@ export * from "./impl/haxe";
export * from "./impl/innosetup";
export * from "./impl/neko";
export * from "./impl/ruffle";
export * from "./preset";
export * from "./project";
export * from "./project/impl";
export * from "./project/preset";
export * from "./task";
+14
View File
@@ -0,0 +1,14 @@
import { branch, compile } from "../core/config";
import type { Config, PresetJson } from "../core/type";
export default (preset: PresetJson): Config[] => {
const config: Config = compile(preset["default"] || {});
const result: Config[] = [];
for (const [k, v] of Object.entries(preset)) {
if (k == "default") {
continue;
}
result.push(branch(config, { ...v, name: k }));
}
return result;
};
+11
View File
@@ -0,0 +1,11 @@
import compiler from "./compiler";
import loader from "./loader";
import validator from "./validator";
export const Preset = {
compiler,
loader,
validator,
};
export default Preset;
+64
View File
@@ -0,0 +1,64 @@
import dateformat from "dateformat";
import fs from "fs";
import os from "os";
import path from "path";
import template from "../common/template";
import { Sdk } from "../core/sdk";
import { Platform, type ConfigJson, type ConfigSource, type PackageJson, type PresetJson } from "../core/type";
import { Haxe } from "../impl/haxe";
import { RuffleRunner, Runner } from "../project";
export const DEFAULT_CONFIG_JSON: ConfigJson = {
SdkDir: "$HOME/sdk",
};
export const resolvePath = (path: string) => path.replace("$HOME", os.homedir());
export const applyConfig = (config: ConfigJson) => {
// TODO: ruffle kludge
if (config.UseRuffle) {
Runner.register(Platform.FLASH, RuffleRunner);
}
if (config.SdkDir) {
Sdk.dir = resolvePath(config.SdkDir);
}
if (config.BuildDir) {
Haxe.buildDir = resolvePath(config.BuildDir);
}
};
export default (basedir: string = "."): PresetJson => {
const presetFile = path.join(basedir, "haxetool.json");
const configFile = path.join(basedir, "config.json");
const packageFile = path.join(basedir, "package.json");
const presetJson: PresetJson = JSON.parse(fs.readFileSync(presetFile, "utf8"));
const configJson: ConfigJson = {
...DEFAULT_CONFIG_JSON,
...(fs.existsSync(configFile) ? JSON.parse(fs.readFileSync(configFile, "utf8")) : {}),
};
applyConfig(configJson);
const packageJson: PackageJson = fs.existsSync(packageFile) ? JSON.parse(fs.readFileSync(packageFile, "utf8")) : {};
for (const [k, v] of Object.entries(presetJson)) {
presetJson[k] = JSON.parse(
template.renderString(JSON.stringify(v), {
config: configJson,
package: packageJson,
env: process.env,
dateformat: dateformat,
}),
);
}
const defaultConfig: ConfigSource = presetJson["default"] || {};
defaultConfig.meta = {
...{
title: packageJson.name,
filename: packageJson.name,
version: packageJson.version,
pack: `com.${packageJson.name}`,
author: packageJson.author as string,
},
...(defaultConfig.meta || {}),
};
presetJson["default"] = defaultConfig;
return presetJson;
};
+13
View File
@@ -0,0 +1,13 @@
import Ajv from "ajv";
import fs from "fs";
import asset from "../common/asset";
import type { PresetJson } from "../core/type";
export default (preset: PresetJson) => {
const ajv = new Ajv();
const presetSchema = ajv.compile(JSON.parse(fs.readFileSync(asset("haxetool.schema.json"), "utf-8")));
const valid = presetSchema(preset);
if (!valid) {
throw presetSchema.errors;
}
};
+1 -2
View File
@@ -1,5 +1,4 @@
import type { Config } from "../../core/config";
import type { BuildSystem, Platform } from "../../core/type";
import { BuildSystem, type Config, Platform } from "../../core/type";
import { Target } from "./target";
export class Builder extends Target {
+1 -2
View File
@@ -1,5 +1,4 @@
import type { Config } from "../../core/config";
import type { Platform } from "../../core/type";
import { type Config, Platform } from "../../core/type";
import { Target } from "./target";
export type PackerFactory = new (config: Config) => Packer;
+5 -6
View File
@@ -2,20 +2,19 @@ import gulp from "gulp";
import rename from "gulp-rename";
import output from "../../common/output";
import { tail } from "../../common/tail";
import { Config } from "../../core/config";
import type { Platform } from "../../core/type";
import { type Config, Platform } from "../../core/type";
import { Target } from "./target";
export type RunnerFactory = new (config: Config, debug: boolean) => Runner;
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: Platform, debug: boolean) {
constructor(config: Config, platform: Platform, debug?: boolean) {
super(config, platform);
this.debug = debug;
this.debug = debug || false;
}
log(stream: any) {
@@ -26,7 +25,7 @@ export class Runner extends Target {
Runner.factory[platform] = runner;
}
static new(config: Config, platform: string, debug: boolean): Runner {
static new(config: Config, platform: string, debug?: boolean): Runner {
return new Runner.factory[platform](config, debug);
}
}
+2 -3
View File
@@ -1,6 +1,5 @@
import path from "path";
import type { Config } from "../../core/config";
import type { Platform } from "../../core/type";
import { type Config, Platform } from "../../core/type";
export class Target {
public config: Config;
@@ -13,7 +12,7 @@ export class Target {
this.target = "target";
}
prepare(): Promise<any> {
setup(): Promise<any> {
return Promise.resolve();
}
+4 -8
View File
@@ -1,8 +1,7 @@
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 { BuildSystem, type Config, Platform } from "../../../core/type";
import { Android } from "../../../impl/android";
import { Haxe } from "../../../impl/haxe";
import { Builder } from "../../core/builder";
@@ -17,7 +16,7 @@ export class HaxeBuilder extends Builder {
this.android = new Android();
}
prepare() {
setup() {
let result: Promise<any> = this.haxe.prepare().then(() => this.haxe.install(this.config.libs));
if (this.buildSystem === BuildSystem.OPENFL) {
if (this.platform === Platform.ANDROID) {
@@ -26,13 +25,10 @@ export class HaxeBuilder extends Builder {
.then(() => this.android.activate())
.then(() =>
this.android.sdkmanager([
// ToDo: android sdk dependencies config?
//'tools',
// TODO: android sdk dependencies config?
"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',
"platforms;android-28",
"cmake;3.6.4111459",
]),
);
+2 -3
View File
@@ -1,8 +1,7 @@
import fs from "fs";
import path from "path";
import template from "../../../common/template";
import type { Config } from "../../../core/config";
import { Platform } from "../../../core/type";
import { type Config, Platform } from "../../../core/type";
import { Packer } from "../../core/packer";
export class FlashHTMLPacker extends Packer {
@@ -16,7 +15,7 @@ export class FlashHTMLPacker extends Packer {
const target = this.targetPath;
const index = template.render("flash/index.html", 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"));
fs.copyFileSync(path.resolve(import.meta.dirname, "template/flash/swf.js"), path.resolve(target, "swf.js"));
return Promise.resolve();
}
}
+1 -2
View File
@@ -1,8 +1,7 @@
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 { type Config, Platform } from "../../../../core/type";
import { Packer } from "../../../core/packer";
export class LinuxArchivePacker extends Packer {
+11 -9
View File
@@ -5,10 +5,15 @@ import deb from "gulp-debian";
import os from "os";
import path from "path";
import template from "../../../../common/template";
import { Config } from "../../../../core/config";
import { Platform } from "../../../../core/type";
import { type Config, Platform } from "../../../../core/type";
import { Packer } from "../../../core/packer";
const UPDATE_MENUS = `
if [ "$1" = "configure" ] && [ -x "\`which update-menus 2>/dev/null\`" ] ; then
update-menus
fi
`;
export class LinuxDEBPacker extends Packer {
static NAME = "deb";
@@ -19,12 +24,13 @@ export class LinuxDEBPacker extends Packer {
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 icon = this.config.icon;
const iconfile = `${this.config.meta.filename}${path.extname(icon)}`;
const desktop = template.render("linux/app.desktop", { 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}`);
fse.copySync(icon, `${buildDir}/usr/share/${this.config.meta.filename}/${iconfile}`);
return gulp.src(`${buildDir}/*`).pipe(
deb({
package: this.config.meta.filename!,
@@ -35,11 +41,7 @@ export class LinuxDEBPacker extends Packer {
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",
],
postinst: [UPDATE_MENUS],
_target: "/",
_out: this.resolveTargetPath("debian"),
_clean: true,
+1 -2
View File
@@ -1,7 +1,6 @@
import gulp from "gulp";
import zip from "gulp-zip";
import { Config } from "../../../../core/config";
import { Platform } from "../../../../core/type";
import { type Config, Platform } from "../../../../core/type";
import { Packer } from "../../../core/packer";
export class WindowsArchivePacker extends Packer {
+2 -3
View File
@@ -1,5 +1,4 @@
import { Config } from "../../../../core/config";
import { Platform } from "../../../../core/type";
import { type Config, Platform } from "../../../../core/type";
import { InnoSetup } from "../../../../impl/innosetup";
import { Packer } from "../../../core/packer";
@@ -13,7 +12,7 @@ export class WindowsInstallerPacker extends Packer {
this.innosetup = new InnoSetup();
}
prepare() {
setup() {
return this.innosetup.prepare();
}
+3 -4
View File
@@ -1,18 +1,17 @@
import gulp from "gulp";
import type { Config } from "../../../core/config";
import { Platform } from "../../../core/type";
import { type Config, 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) {
constructor(config: Config, debug?: boolean) {
super(config, Platform.ANDROID, debug);
this.android = new Android();
}
prepare() {
setup() {
return this.android.prepare();
}
+3 -4
View File
@@ -1,18 +1,17 @@
import path from "path";
import { Config } from "../../../core/config";
import { Platform } from "../../../core/type";
import { type Config, 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) {
constructor(config: Config, debug?: boolean, player: typeof FlashPlayer = FlashPlayer) {
super(config, Platform.FLASH, debug);
this.player = new player(debug);
}
prepare() {
setup() {
return this.player.prepare();
}
+2 -3
View File
@@ -1,10 +1,9 @@
import connect from "gulp-connect";
import { Config } from "../../../core/config";
import { Platform } from "../../../core/type";
import { type Config, Platform } from "../../../core/type";
import { Runner } from "../../core/runner";
export class Html5Runner extends Runner {
constructor(config: Config, debug: boolean) {
constructor(config: Config, debug?: boolean) {
super(config, Platform.HTML5, debug);
}
+3 -4
View File
@@ -1,12 +1,11 @@
import gulp from "gulp";
import path from "path";
import { Config } from "../../../core/config";
import { Platform } from "../../../core/type";
import { type Config, Platform } from "../../../core/type";
import run from "../../../run";
import { Runner } from "../../core/runner";
export class LinuxRunner extends Runner {
constructor(config: Config, debug: boolean) {
constructor(config: Config, debug?: boolean) {
super(config, Platform.LINUX, debug);
}
@@ -21,7 +20,7 @@ export class LinuxRunner extends Runner {
Runner.register(Platform.LINUX, LinuxRunner);
export class CPPRunner extends LinuxRunner {
constructor(config: Config, debug: boolean) {
constructor(config: Config, debug?: boolean) {
super(config, debug);
this.platform = Platform.CPP;
}
+3 -4
View File
@@ -1,18 +1,17 @@
import path from "path";
import { Config } from "../../../core/config";
import { Platform } from "../../../core/type";
import { type Config, 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) {
constructor(config: Config, debug?: boolean) {
super(config, Platform.NEKO, debug);
this.neko = new Neko();
}
prepare() {
setup() {
return this.neko.prepare();
}
+2 -2
View File
@@ -1,9 +1,9 @@
import type { Config } from "../../../core/config";
import type { Config } from "../../../core/type";
import { RufflePlayer } from "../../../impl/ruffle";
import { FlashRunner } from "./flash";
export class RuffleRunner extends FlashRunner {
constructor(config: Config, debug: boolean) {
constructor(config: Config, debug?: boolean) {
super(config, debug, RufflePlayer);
}
}
+2 -3
View File
@@ -1,12 +1,11 @@
import gulp from "gulp";
import path from "path";
import { Config } from "../../../core/config";
import { Platform } from "../../../core/type";
import { type Config, Platform } from "../../../core/type";
import run from "../../../run";
import { Runner } from "../../core/runner";
export class WindowsRunner extends Runner {
constructor(config: Config, debug: boolean) {
constructor(config: Config, debug?: boolean) {
super(config, Platform.WINDOWS, debug);
}
+1 -80
View File
@@ -1,81 +1,2 @@
import gulp from "gulp";
import type { Task, TaskFunction } from "undertaker";
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 class Project {
public buildSystem: BuildSystem;
public platforms: Platform[];
public config: Config;
constructor(buildSystem: BuildSystem, platforms: Platform[] | Platform, config: Config) {
this.buildSystem = buildSystem;
this.platforms = Array.isArray(platforms) ? platforms : [platforms];
this.config = config;
}
hasLib(name: string): boolean {
for (const lib of this.config.libs) {
if (lib.name === name) {
return true;
}
}
return false;
}
build(platform: Platform, debug: boolean = false): Task[] {
const builder = Builder.new(this.config, platform, this.buildSystem, debug);
const tasks: Task[] = [builder.prepare.bind(builder)];
tasks.push(builder.call.bind(builder));
return tasks;
}
run(platform: Platform, debug: boolean = false): Task[] {
const runner = Runner.new(this.config, platform, debug);
return [runner.prepare.bind(runner), runner.call.bind(runner)];
}
test(platform: Platform, debug: boolean = true): Task[] {
return this.build(platform, debug).concat(this.run(platform, debug));
}
pack(platform: Platform, name: string) {
const packer = Packer.new(this.config, platform, name);
return [packer.prepare.bind(packer), packer.call.bind(packer)];
}
compile(external_gulp?: gulp.Gulp): Record<string, TaskFunction> {
const result: Record<string, TaskFunction> = {};
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?: gulp.Gulp) {
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);
}
}
export * from "./impl";
-177
View File
@@ -1,177 +0,0 @@
import dateformat from "dateformat";
import gulp from "gulp";
import gulpClean from "gulp-clean";
import os from "os";
import type { Task } from "undertaker";
import { Builder, Project } from ".";
import { System } from "../common/system";
import template from "../common/template";
import { Config, type ConfigParams, type SignKey } from "../core/config";
import { Sdk } from "../core/sdk";
import { BuildSystem, Platform } from "../core/type";
import { Haxe } from "../impl/haxe";
export interface PresetConfig {
SdkDir?: string;
BuildDir?: string;
Develop?: boolean;
UseRuffle?: boolean;
Key?: SignKey;
}
export const DEFAULT_CONFIG: PresetConfig = {
SdkDir: "$HOME/sdk",
};
export interface ProjectPreset {
buildSystem?: BuildSystem;
platforms?: Platform[];
config: ConfigParams;
}
export class Preset {
public options: Record<string, ProjectPreset>;
public config: PresetConfig;
public packageInfo: Record<string, any>;
constructor(options: Record<string, ProjectPreset>, config?: PresetConfig, packageInfo?: Record<string, any>) {
this.config = { ...DEFAULT_CONFIG, ...(config || {}) };
this.packageInfo = packageInfo || {};
for (const [k, v] of Object.entries(options)) {
options[k] = this.fillPreset(v);
}
this.options = options;
}
private fillPreset(preset: ProjectPreset): ProjectPreset {
return JSON.parse(
template.renderString(JSON.stringify(preset), {
config: this.config,
package: this.packageInfo,
env: process.env,
dateformat: dateformat,
}),
);
}
compile(): Project[] {
const config = new Config({
meta: { version: this.packageInfo.version },
...(this.options["default"]?.config || {}),
});
const projects: Project[] = [];
for (const [k, v] of Object.entries(this.options)) {
if (k == "default") {
continue;
}
const projectConfig = config.branch({ ...v.config, name: k });
projects.push(new Project(v.buildSystem!, v.platforms!, projectConfig));
}
return projects;
}
register(external_gulp?: gulp.Gulp, additional_tasks?: string[]) {
const _gulp = external_gulp || gulp;
const resolvePath = (path: string) => path.replace("$HOME", os.homedir());
if (this.config.UseRuffle) {
Project.useRuffle();
}
if (this.config.SdkDir) {
Sdk.dir = resolvePath(this.config.SdkDir);
}
if (this.config.BuildDir) {
Haxe.buildDir = resolvePath(this.config.BuildDir);
}
_gulp.task("clean", () => {
return _gulp.src("target/*", { read: false }).pipe(gulpClean());
});
const projects = this.compile();
const project = projects[0];
_gulp.task("setup", () => {
return Promise.all(
project.platforms.map((platform) => Builder.new(project.config, platform, project.buildSystem).prepare()),
);
});
const protohx = project.hasLib("protohx");
if (protohx) {
_gulp.task("protohx:generate", () =>
new Haxe().haxelib(["run", "protohx", "generate", "protohx.json"]).then((result: any) => {
if (result.stdout.indexOf("FAIL") > -1) {
throw result.stdout;
}
}),
);
}
for (const project of projects) {
project.register(_gulp);
}
const defaultSeries: Task[] = [_gulp.task("clean")!, _gulp.task("setup")!];
if (protohx) {
defaultSeries.push(_gulp.task("protohx:generate")!);
}
if (additional_tasks) {
for (const task of additional_tasks) {
defaultSeries.push(_gulp.task(task)!);
}
}
for (const project of projects) {
for (const platform of project.platforms) {
switch (platform) {
case Platform.FLASH:
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:html`)!);
break;
case Platform.HTML5:
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
break;
case Platform.LINUX:
if (System.isLinux) {
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:archive`)!);
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:deb`)!);
}
break;
case Platform.CPP:
if (System.isLinux) {
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
}
break;
case Platform.NEKO:
if (System.isLinux) {
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
}
break;
case Platform.ANDROID:
if (System.isLinux) {
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
}
break;
case Platform.WINDOWS:
if (System.isWindows) {
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:build`)!);
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:archive`)!);
defaultSeries.push(_gulp.task(`${project.config.name}:${platform}:installer`)!);
}
break;
}
}
}
const defaultTask = _gulp.series(defaultSeries);
_gulp.task("default", defaultTask);
return defaultTask;
}
}
+23
View File
@@ -0,0 +1,23 @@
import { branch, compile } from "../core/config";
import type { Config } from "../core/type";
import type { TaskCompilerType, TaskDef } from "./core";
import { CleanTaskCompiler } from "./impl/clean";
import { FormatTaskCompiler } from "./impl/format";
import { ProjectTaskCompiler } from "./impl/project";
import { ProtoTaskCompiler } from "./impl/proto";
import { SetupTaskCompiler } from "./impl/setup";
const COMPILERS: TaskCompilerType[] = [FormatTaskCompiler, CleanTaskCompiler, SetupTaskCompiler, ProtoTaskCompiler];
const PROJECT_COMPILERS: TaskCompilerType[] = [ProjectTaskCompiler];
export default function* (projects: Config[]): Iterable<TaskDef> {
const config = projects.reduce((config, project) => branch(config, project), compile({}));
for (const compiler of COMPILERS) {
yield* new compiler(config).compile();
}
for (const compiler of PROJECT_COMPILERS) {
for (const project of projects) {
yield* new compiler(project).compile();
}
}
}
+22
View File
@@ -0,0 +1,22 @@
import type { TaskFunction } from "gulp";
import type { Config } from "../core/type";
export interface TaskCompiler {
config: Config;
debug?: boolean;
compile(): Iterable<TaskDef>;
}
export type TaskDef = readonly [string, TaskFunction] | readonly [string, TaskFunction, boolean];
export abstract class TaskCompilerImpl implements TaskCompiler {
constructor(
public config: Config,
public debug?: boolean,
) {}
abstract compile(): Iterable<TaskDef>;
}
export type TaskCompilerType = new (config: Config, debug?: boolean) => TaskCompiler;
+9
View File
@@ -0,0 +1,9 @@
import gulp from "gulp";
import gulpClean from "gulp-clean";
import { TaskCompilerImpl, type TaskDef } from "../core";
export class CleanTaskCompiler extends TaskCompilerImpl {
*compile(): Iterable<TaskDef> {
yield ["clean", () => gulp.src("target/*", { read: false }).pipe(gulpClean()), true];
}
}
+36
View File
@@ -0,0 +1,36 @@
import fs from "fs";
import path from "path";
import { Haxe } from "../../impl/haxe";
import { TaskCompilerImpl, type TaskDef } from "../core";
export class FormatTaskCompiler extends TaskCompilerImpl {
*compile(): Iterable<TaskDef> {
const hxformatFile = path.join(".", "hxformat.json");
if (fs.existsSync(hxformatFile)) {
yield [
"check",
async () => {
const haxe = new Haxe(this.config.haxe);
await haxe.install({ formatter: "" });
await haxe.haxelib(
["run", "formatter", "--check"].concat(
this.config.sources.reduce<string[]>((sources, source) => sources.concat(["-s", source]), []),
),
);
},
];
yield [
"format",
async () => {
const haxe = new Haxe(this.config.haxe);
await haxe.install({ formatter: "" });
await haxe.haxelib(
["run", "formatter"].concat(
this.config.sources.reduce<string[]>((sources, source) => sources.concat(["-s", source]), []),
),
);
},
];
}
}
}
+42
View File
@@ -0,0 +1,42 @@
import gulp from "gulp";
import os from "os";
import { Platform } from "../../core/type";
import { Builder, Packer, Runner } from "../../project";
import { TaskCompilerImpl, type TaskDef } from "../core";
const isPlatformSupported = (platform: Platform): boolean => {
switch (platform) {
case Platform.LINUX:
return os.type() === "Linux";
case Platform.WINDOWS:
return os.type() === "Windows_NT";
default:
return true;
}
};
export class ProjectTaskCompiler extends TaskCompilerImpl {
*compile(): Iterable<TaskDef> {
for (const platform of this.config.platforms.filter(isPlatformSupported)) {
const builder = Builder.new(this.config, platform, this.config.buildSystem, this.debug);
const setupKey = `${this.config.name}:${platform}:setup`;
const buildKey = `${this.config.name}:${platform}:build`;
yield [setupKey, builder.setup.bind(builder)];
yield [buildKey, gulp.series(builder.setup.bind(builder), builder.call.bind(builder)), true];
if (Runner.factory[platform]) {
const testKey = `${this.config.name}:${platform}:test`;
const runner = Runner.new(this.config, platform, this.debug);
yield [testKey, gulp.series(builder.setup.bind(builder), runner.setup.bind(runner), runner.call.bind(runner))];
}
if (Packer.factory[platform]) {
for (const name of Object.keys(Packer.factory[platform])) {
const packKey = `${this.config.name}:${platform}:${name}`;
const packer = Packer.new(this.config, platform, name);
yield [packKey, gulp.series(packer.setup.bind(packer), packer.call.bind(packer)), true];
}
}
}
}
}
+23
View File
@@ -0,0 +1,23 @@
import fs from "fs";
import path from "path";
import { Haxe } from "../../impl/haxe";
import { TaskCompilerImpl, type TaskDef } from "../core";
export class ProtoTaskCompiler extends TaskCompilerImpl {
*compile(): Iterable<TaskDef> {
const protohxFile = path.join(".", "protohx.json");
if (fs.existsSync(protohxFile)) {
yield [
"protohx:generate",
async () => {
const haxe = new Haxe(this.config.haxe);
const result = await haxe.haxelib(["run", "protohx", "generate", "protohx.json"]);
if (result.stdout.indexOf("FAIL") > -1) {
throw result.stdout;
}
},
true,
];
}
}
}
+14
View File
@@ -0,0 +1,14 @@
import { Builder } from "../../project";
import { TaskCompilerImpl, type TaskDef } from "../core";
export class SetupTaskCompiler extends TaskCompilerImpl {
*compile(): Iterable<TaskDef> {
yield [
"setup",
() =>
Promise.all(
this.config.platforms.map((platform) => Builder.new(this.config, platform, this.config.buildSystem).setup()),
),
];
}
}
+12
View File
@@ -0,0 +1,12 @@
import compiler from "./compiler";
import register from "./register";
export * from "./core";
export * from "./impl/format";
export * from "./impl/project";
export const Task = {
compiler,
register,
};
export default Task;
+15
View File
@@ -0,0 +1,15 @@
import gulp from "gulp";
import type { TaskDef } from "./core";
export default (tasks: Iterable<TaskDef>) => {
const defaultTasks = [];
for (const item of tasks) {
gulp.task(item[0], item[1]);
if (item[2]) {
defaultTasks.push(item[0]);
}
}
if (defaultTasks.length > 0) {
gulp.task("default", gulp.series(defaultTasks));
}
};
+10 -4
View File
@@ -1,11 +1,17 @@
<% sources.forEach(function(item) { %>
-cp "<%=item%>"<% }); %>
-cp "<%=item%>"
<% }); %>
<% libs.forEach(function(item) { %>
-lib <%=item.name%>:<%=item.version.split('@').shift()%><% }); %>
-lib <%=item.name%>:<%=item.version.split('@').shift()%>
<% }); %>
<% macros.forEach(function(item) { %>
--macro "<%=item%>"<% }); %>
--macro "<%=item%>"
<% }); %>
<% flags.forEach(function(item) { %>
-D <%=item%><% }); %>
-D <%=item%>
<% }); %>
-main <%=main%>
-<%=out%> "<%=buildDir%>/<%=platform%>/bin/<%=meta.filename%><%=ext%>"
+10 -14
View File
@@ -3,20 +3,16 @@ import { existsSync, mkdtempSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import { download } from "../dist/index.mjs";
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",
const testUrl = async (url, file) => {
const target = mkdtempSync(join(tmpdir(), "test-"));
await download(url, target);
assert(existsSync(join(target, file)));
};
for (const [url, file] of Object.entries(TEST_DATA)) {
test(`Test download: ${url}`, async () => {
const target = resolveTargetDir();
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"));
+55
View File
@@ -0,0 +1,55 @@
import assert from "node:assert/strict";
import test from "node:test";
import { Android, AndroidNdk, FlashPlayer, Haxe, Neko, resolveLink, RufflePlayer } 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(new Neko().link, [
[{ 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(new Haxe().link, [
[{ os_name: "linux" }, "https://github.com/HaxeFoundation/haxe/releases/download/4.2.5/haxe-4.2.5-linux64.tar.gz"],
[{ os_name: "win" }, "https://github.com/HaxeFoundation/haxe/releases/download/4.2.5/haxe-4.2.5-win64.zip"],
]));
test("flashplayer", () =>
testLink(new FlashPlayer().link, [
[
{ 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("ruffle", () =>
testLink(new RufflePlayer().link, [
[
{ os_name: "linux" },
"https://github.com/ruffle-rs/ruffle/releases/download/v0.7.1/ruffle-0.7.1-linux-x86_64.tar.gz",
],
[
{ os_name: "win" },
"https://github.com/ruffle-rs/ruffle/releases/download/v0.7.1/ruffle-0.7.1-windows-x86_64.zip",
],
]));
test("android", () =>
testLink(new Android().link, [
[{ 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"],
]));
test("android-ndk", () =>
testLink(new AndroidNdk().link, [
[{ os_name: "linux" }, "https://dl.google.com/android/repository/android-ndk-r21e-linux-x86_64.zip"],
[{ os_name: "win" }, "https://dl.google.com/android/repository/android-ndk-r21e-windows-x86_64.zip"],
]));
+1 -1
View File
@@ -5,7 +5,7 @@ export default defineConfig({
"bin/cli": "src/cli.ts",
"lib/index": "src/index.ts",
},
copy: ["haxetool.schema.json"],
copy: ["assets", "template"],
dts: {
tsgo: true,
},