Compare commits
12
Commits
d9e8976e85
...
2.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57f7e88fab | ||
|
|
7f62df2364 | ||
|
|
6622d53167 | ||
|
|
561dd99cba | ||
|
|
bc77380aba | ||
|
|
a20e98d730 | ||
|
|
87fe852f99 | ||
|
|
dfad6d3aba | ||
|
|
bff3cc06ef | ||
|
|
6ff587cb65 | ||
|
|
bf6ff0deb9 | ||
|
|
2605c1bbc8 |
@@ -1,26 +1,12 @@
|
||||
# Gulp HaXe Tool
|
||||
# HaXeTool
|
||||
|
||||
[](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,25 +37,15 @@ 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"
|
||||
"hxcpp": "4.2.1"
|
||||
},
|
||||
"sources": ["src"],
|
||||
"main": "Main"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Commands
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
+1
-11
@@ -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"
|
||||
"hxcpp": "4.2.1"
|
||||
},
|
||||
"sources": ["src"],
|
||||
"main": "Main"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+3
-3
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "gulp-haxetool",
|
||||
"version": "1.2.0",
|
||||
"version": "2.0.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "gulp-haxetool",
|
||||
"version": "1.2.0",
|
||||
"version": "2.0.3",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ajv": "^8.20.0",
|
||||
@@ -35,7 +35,7 @@
|
||||
"vinyl-fs": "^4.0.2"
|
||||
},
|
||||
"bin": {
|
||||
"gulp-haxetool": "dist/bin/cli.mjs"
|
||||
"hxt": "dist/bin/cli.mjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/async": "^3.2.26",
|
||||
|
||||
+2
-3
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "gulp-haxetool",
|
||||
"type": "module",
|
||||
"version": "1.2.0",
|
||||
"description": "HaXe Tool for Gulp",
|
||||
"version": "2.0.3",
|
||||
"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": {
|
||||
|
||||
+5
-26
@@ -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 } 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);
|
||||
Preset.register(projects);
|
||||
|
||||
if (process.argv.length > 2) {
|
||||
await runTask(process.argv[2]);
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
@@ -7,7 +7,7 @@ const __dirname = path.dirname(__filename);
|
||||
|
||||
export default new Eta({
|
||||
autoFilter: true,
|
||||
filterFunction: (val: unknown): string => (val === null ? "" : String(val)),
|
||||
filterFunction: (val: unknown): string => (val === null || val === undefined ? "" : String(val)),
|
||||
useWith: true,
|
||||
views: path.join(__dirname, "..", "template"),
|
||||
views: path.join(__dirname, "template"),
|
||||
});
|
||||
|
||||
+80
-122
@@ -1,141 +1,99 @@
|
||||
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 interface LibDef {
|
||||
name: string;
|
||||
version: string;
|
||||
git?: string;
|
||||
branch?: string;
|
||||
}
|
||||
|
||||
export interface AndroidPreset {
|
||||
path: string;
|
||||
extensions: string[];
|
||||
}
|
||||
|
||||
export interface SignKey {
|
||||
store: string;
|
||||
pass: string;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
private _params: ConfigParams[];
|
||||
|
||||
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 = {
|
||||
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: [],
|
||||
haxe: null,
|
||||
};
|
||||
this.key = null;
|
||||
this.android = [];
|
||||
this.haxe = null;
|
||||
if (params) {
|
||||
this.update(params);
|
||||
this.afterUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
static absolutePath(file: string): 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;
|
||||
}
|
||||
};
|
||||
|
||||
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 })),
|
||||
export const compile = (source: ConfigSource): Config => {
|
||||
return branch(DEFAULT_CONFIG, source);
|
||||
};
|
||||
|
||||
export const branch = (config: Config, source: ConfigSource): Config => {
|
||||
const result = structuredClone(config);
|
||||
|
||||
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 (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 (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 (params.haxe !== undefined) this.haxe = params.haxe;
|
||||
if (this.meta.icon) this.icon = Config.absolutePath(this.meta.icon);
|
||||
}
|
||||
if (source.haxe !== undefined) {
|
||||
result.haxe = source.haxe;
|
||||
}
|
||||
if (result.meta.icon) {
|
||||
result.icon = absolutePath(result.meta.icon);
|
||||
}
|
||||
|
||||
afterUpdate() {
|
||||
if (this.meta.mobileWidth === null) {
|
||||
this.meta.mobileWidth = this.meta.width;
|
||||
if (!result.meta.mobileWidth) {
|
||||
result.meta.mobileWidth = result.meta.width;
|
||||
}
|
||||
if (this.meta.mobileHeight === null && this.meta.mobileWidth) {
|
||||
this.meta.mobileHeight = Math.round(this.meta.mobileWidth / 2.222222222);
|
||||
if (!result.meta.mobileHeight && result.meta.mobileWidth) {
|
||||
result.meta.mobileHeight = Math.round(result.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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -13,3 +13,82 @@ 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;
|
||||
icon?: 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 | null;
|
||||
meta: ConfigMeta;
|
||||
key: SignKey | null;
|
||||
android: AndroidPreset[];
|
||||
haxe: string | null;
|
||||
}
|
||||
|
||||
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>;
|
||||
|
||||
+3
-2
@@ -17,7 +17,8 @@ export class Android extends Sdk {
|
||||
static VERSION = Android.VERSION_7302050;
|
||||
|
||||
static NDK_VERSION_R15C = "r15c";
|
||||
static NDK_VERSION = Android.NDK_VERSION_R15C;
|
||||
static NDK_VERSION_R21E = "r21e";
|
||||
static NDK_VERSION = Android.NDK_VERSION_R21E;
|
||||
|
||||
private ndk_version: string;
|
||||
private repository: string;
|
||||
@@ -45,7 +46,7 @@ export class Android extends Sdk {
|
||||
}
|
||||
|
||||
get ndk_home(): string {
|
||||
return path.join(this.path, "ndk-bundle");
|
||||
return Sdk.path('android-ndk', this.ndk_version);
|
||||
}
|
||||
|
||||
get sdkmanager_bin(): string {
|
||||
|
||||
+3
-3
@@ -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,7 +28,7 @@ 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");
|
||||
@@ -81,7 +81,7 @@ export class Haxe extends Sdk {
|
||||
prepare() {
|
||||
return Promise.all([this.neko.prepare(), super.prepare()]).then(() => {
|
||||
fs.copyFileSync(
|
||||
path.resolve(import.meta.dirname, "..", "template/haxe/activate"),
|
||||
path.resolve(import.meta.dirname, "template/haxe/activate"),
|
||||
path.resolve(this.path, "activate"),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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";
|
||||
|
||||
+1
-1
@@ -73,7 +73,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(import.meta.dirname, "template/neko/activate"),
|
||||
path.resolve(this.path, "activate"),
|
||||
);
|
||||
});
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ export class RufflePlayer extends FlashPlayer {
|
||||
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";
|
||||
|
||||
|
||||
+1
-1
@@ -11,6 +11,6 @@ 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";
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { branch, compile } from "../core/config";
|
||||
import type { Config, PresetJson } from "../core/type";
|
||||
import { Project } from "../project";
|
||||
|
||||
export default (preset: PresetJson): Project[] => {
|
||||
const config: Config = compile(preset["default"] || {});
|
||||
const projects: Project[] = [];
|
||||
for (const [k, v] of Object.entries(preset)) {
|
||||
if (k == "default") {
|
||||
continue;
|
||||
}
|
||||
const projectConfig = branch(config, { ...v, name: k });
|
||||
projects.push(new Project(projectConfig));
|
||||
}
|
||||
return projects;
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import compiler from "./compiler";
|
||||
import loader from "./loader";
|
||||
import register from "./register";
|
||||
import validator from "./validator";
|
||||
|
||||
export const Preset = {
|
||||
compiler,
|
||||
loader,
|
||||
register,
|
||||
validator,
|
||||
};
|
||||
|
||||
export default Preset;
|
||||
@@ -0,0 +1,63 @@
|
||||
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 type { ConfigJson, ConfigSource, PackageJson, PresetJson } from "../core/type";
|
||||
import { Haxe } from "../impl/haxe";
|
||||
import { Project } 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) => {
|
||||
if (config.UseRuffle) {
|
||||
Project.useRuffle();
|
||||
}
|
||||
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;
|
||||
};
|
||||
@@ -0,0 +1,91 @@
|
||||
import gulp from "gulp";
|
||||
import gulpClean from "gulp-clean";
|
||||
import type { Task } from "undertaker";
|
||||
import { System } from "../common/system";
|
||||
import { Platform } from "../core/type";
|
||||
import { Haxe } from "../impl/haxe";
|
||||
import { Builder, type Project } from "../project";
|
||||
|
||||
export default (projects: Project[]): Task => {
|
||||
gulp.task("clean", () => {
|
||||
return gulp.src("target/*", { read: false }).pipe(gulpClean());
|
||||
});
|
||||
|
||||
const project = projects[0];
|
||||
|
||||
gulp.task("setup", () => {
|
||||
return Promise.all(
|
||||
project.config.platforms.map((platform) =>
|
||||
Builder.new(project.config, platform, project.config.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")!);
|
||||
}
|
||||
|
||||
for (const project of projects) {
|
||||
for (const platform of project.config.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;
|
||||
};
|
||||
@@ -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,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,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;
|
||||
|
||||
@@ -2,8 +2,7 @@ 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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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,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 {
|
||||
|
||||
@@ -5,8 +5,7 @@ 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";
|
||||
|
||||
export class LinuxDEBPacker extends Packer {
|
||||
@@ -19,12 +18,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.meta.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!,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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";
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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";
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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 {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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";
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Config } from "../../../core/config";
|
||||
import type { Config } from "../../../core/type";
|
||||
import { RufflePlayer } from "../../../impl/ruffle";
|
||||
import { FlashRunner } from "./flash";
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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";
|
||||
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
import gulp from "gulp";
|
||||
import type { Task, TaskFunction } from "undertaker";
|
||||
import { Config } from "../core/config";
|
||||
import { BuildSystem, Platform } from "../core/type";
|
||||
import { Platform, type Config } 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 * from "./impl";
|
||||
|
||||
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];
|
||||
constructor(config: Config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@@ -29,7 +25,7 @@ export class Project {
|
||||
}
|
||||
|
||||
build(platform: Platform, debug: boolean = false): Task[] {
|
||||
const builder = Builder.new(this.config, platform, this.buildSystem, debug);
|
||||
const builder = Builder.new(this.config, platform, this.config.buildSystem, debug);
|
||||
const tasks: Task[] = [builder.prepare.bind(builder)];
|
||||
tasks.push(builder.call.bind(builder));
|
||||
return tasks;
|
||||
@@ -52,7 +48,7 @@ export class Project {
|
||||
compile(external_gulp?: gulp.Gulp): Record<string, TaskFunction> {
|
||||
const result: Record<string, TaskFunction> = {};
|
||||
const _gulp = external_gulp || gulp;
|
||||
for (const platform of this.platforms) {
|
||||
for (const platform of this.config.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));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -8,4 +8,5 @@
|
||||
-D <%=item%><% }); %>
|
||||
|
||||
-main <%=main%>
|
||||
|
||||
-<%=out%> "<%=buildDir%>/<%=platform%>/bin/<%=meta.filename%><%=ext%>"
|
||||
|
||||
@@ -3,7 +3,7 @@ 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-"));
|
||||
|
||||
|
||||
+1
-1
@@ -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,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user