Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
@@ -3,14 +3,6 @@
|
|||||||
"buildSystem": "openfl",
|
"buildSystem": "openfl",
|
||||||
"platforms": ["flash", "html5", "linux", "windows", "android"],
|
"platforms": ["flash", "html5", "linux", "windows", "android"],
|
||||||
"config": {
|
"config": {
|
||||||
"meta": {
|
|
||||||
"title": "Example",
|
|
||||||
"filename": "example",
|
|
||||||
"icon": "./resources/icon.jpg",
|
|
||||||
"pack": "com.example",
|
|
||||||
"author": "Anonim <anonim@anonim.com>",
|
|
||||||
"company": "Any company"
|
|
||||||
},
|
|
||||||
"libs": {
|
"libs": {
|
||||||
"lime": "8.3.2",
|
"lime": "8.3.2",
|
||||||
"openfl": "9.5.2",
|
"openfl": "9.5.2",
|
||||||
|
|||||||
Generated
+1
-1
@@ -35,7 +35,7 @@
|
|||||||
"vinyl-fs": "^4.0.2"
|
"vinyl-fs": "^4.0.2"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"gulp-haxetool": "dist/bin/cli.mjs"
|
"hxt": "dist/bin/cli.mjs"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/async": "^3.2.26",
|
"@types/async": "^3.2.26",
|
||||||
|
|||||||
+1
-2
@@ -2,7 +2,7 @@
|
|||||||
"name": "gulp-haxetool",
|
"name": "gulp-haxetool",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"description": "HaXe Tool for Gulp",
|
"description": "HaXe Tool with Gulp",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./bin/cli": "./dist/bin/cli.mjs",
|
"./bin/cli": "./dist/bin/cli.mjs",
|
||||||
"./lib": "./dist/lib/index.mjs",
|
"./lib": "./dist/lib/index.mjs",
|
||||||
@@ -13,7 +13,6 @@
|
|||||||
},
|
},
|
||||||
"types": "./dist/lib/index.d.mts",
|
"types": "./dist/lib/index.d.mts",
|
||||||
"files": [
|
"files": [
|
||||||
"template",
|
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+8
-26
@@ -1,34 +1,14 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import Ajv from "ajv";
|
|
||||||
import fs from "fs";
|
|
||||||
import gulp from "gulp";
|
import gulp from "gulp";
|
||||||
import path from "path";
|
|
||||||
import { fileURLToPath } from "url";
|
|
||||||
import { Preset, type ProjectPreset } from ".";
|
|
||||||
import { name, version } from "../package.json" with { type: "json" };
|
import { name, version } from "../package.json" with { type: "json" };
|
||||||
|
import compiler from "./preset/compiler";
|
||||||
|
import loader from "./preset/loader";
|
||||||
|
import register from "./preset/register";
|
||||||
|
import validator from "./preset/validator";
|
||||||
|
|
||||||
console.log(`[${name} ${version}]`);
|
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 showTasks = () => {
|
||||||
const tree = gulp.tree({ deep: true });
|
const tree = gulp.tree({ deep: true });
|
||||||
console.log(tree.nodes.map((node) => node.label).join("\n"));
|
console.log(tree.nodes.map((node) => node.label).join("\n"));
|
||||||
@@ -47,8 +27,10 @@ const runTask = async (name: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const main = async () => {
|
export const main = async () => {
|
||||||
const preset = loadPreset();
|
const preset = loader();
|
||||||
preset.register(gulp);
|
validator(preset);
|
||||||
|
const projects = compiler(preset);
|
||||||
|
register(projects);
|
||||||
|
|
||||||
if (process.argv.length > 2) {
|
if (process.argv.length > 2) {
|
||||||
await runTask(process.argv[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({
|
export default new Eta({
|
||||||
autoFilter: true,
|
autoFilter: true,
|
||||||
filterFunction: (val: unknown): string => (val === null ? "" : String(val)),
|
filterFunction: (val: unknown): string => (val === null || val === undefined ? "" : String(val)),
|
||||||
useWith: true,
|
useWith: true,
|
||||||
views: path.join(__dirname, "..", "template"),
|
views: path.join(__dirname, "..", "template"),
|
||||||
});
|
});
|
||||||
|
|||||||
+2
-2
@@ -121,10 +121,10 @@ export class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
afterUpdate() {
|
afterUpdate() {
|
||||||
if (this.meta.mobileWidth === null) {
|
if (this.meta.mobileWidth === undefined) {
|
||||||
this.meta.mobileWidth = this.meta.width;
|
this.meta.mobileWidth = this.meta.width;
|
||||||
}
|
}
|
||||||
if (this.meta.mobileHeight === null && this.meta.mobileWidth) {
|
if (this.meta.mobileHeight === undefined && this.meta.mobileWidth) {
|
||||||
this.meta.mobileHeight = Math.round(this.meta.mobileWidth / 2.222222222);
|
this.meta.mobileHeight = Math.round(this.meta.mobileWidth / 2.222222222);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -11,6 +11,6 @@ export * from "./impl/haxe";
|
|||||||
export * from "./impl/innosetup";
|
export * from "./impl/innosetup";
|
||||||
export * from "./impl/neko";
|
export * from "./impl/neko";
|
||||||
export * from "./impl/ruffle";
|
export * from "./impl/ruffle";
|
||||||
|
export * from "./preset";
|
||||||
export * from "./project";
|
export * from "./project";
|
||||||
export * from "./project/impl";
|
export * from "./project/impl";
|
||||||
export * from "./project/preset";
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { Config } from "../core/config";
|
||||||
|
import { Project } from "../project";
|
||||||
|
import type { PresetBundle } from "./type";
|
||||||
|
|
||||||
|
export default (preset: PresetBundle): Project[] => {
|
||||||
|
const config = new Config(preset["default"]?.config || {});
|
||||||
|
const projects: Project[] = [];
|
||||||
|
for (const [k, v] of Object.entries(preset)) {
|
||||||
|
if (k == "default") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const projectConfig = config.branch({ ...v.config, name: k });
|
||||||
|
projects.push(new Project(v.buildSystem!, v.platforms!, projectConfig));
|
||||||
|
}
|
||||||
|
return projects;
|
||||||
|
};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from "./type";
|
||||||
@@ -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 { Haxe } from "../impl/haxe";
|
||||||
|
import { Project } from "../project";
|
||||||
|
import type { ConfigJson, PackageJson, Preset, PresetBundle } from "./type";
|
||||||
|
|
||||||
|
export const DEFAULT_CONFIG: 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 = "."): PresetBundle => {
|
||||||
|
const presetFile = path.join(basedir, "haxetool.json");
|
||||||
|
const configFile = path.join(basedir, "config.json");
|
||||||
|
const packageFile = path.join(basedir, "package.json");
|
||||||
|
const presetJson: PresetBundle = JSON.parse(fs.readFileSync(presetFile, "utf8"));
|
||||||
|
const configJson: ConfigJson = {
|
||||||
|
...DEFAULT_CONFIG,
|
||||||
|
...(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 defaultPreset: Preset = presetJson["default"] || { config: {} };
|
||||||
|
defaultPreset.config.meta = {
|
||||||
|
...{
|
||||||
|
title: packageJson.name,
|
||||||
|
filename: packageJson.name,
|
||||||
|
version: packageJson.version,
|
||||||
|
pack: `com.${packageJson.name}`,
|
||||||
|
author: packageJson.author as string,
|
||||||
|
},
|
||||||
|
...(defaultPreset.config.meta || {}),
|
||||||
|
};
|
||||||
|
presetJson["default"] = defaultPreset;
|
||||||
|
return presetJson;
|
||||||
|
};
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import defaultGulp 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[], gulp?: defaultGulp.Gulp): Task => {
|
||||||
|
if (!gulp) {
|
||||||
|
gulp = defaultGulp;
|
||||||
|
}
|
||||||
|
|
||||||
|
gulp.task("clean", () => {
|
||||||
|
return gulp.src("target/*", { read: false }).pipe(gulpClean());
|
||||||
|
});
|
||||||
|
|
||||||
|
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")!);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import type { ConfigParams, SignKey } from "../core/config";
|
||||||
|
import type { BuildSystem, Platform } from "../core/type";
|
||||||
|
|
||||||
|
export type PackageJson = Record<string, any>;
|
||||||
|
|
||||||
|
export interface ConfigJson {
|
||||||
|
SdkDir?: string;
|
||||||
|
BuildDir?: string;
|
||||||
|
Develop?: boolean;
|
||||||
|
UseRuffle?: boolean;
|
||||||
|
Key?: SignKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Preset {
|
||||||
|
buildSystem?: BuildSystem;
|
||||||
|
platforms?: Platform[];
|
||||||
|
config: ConfigParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PresetBundle = Record<string, Preset>;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import Ajv from "ajv";
|
||||||
|
import fs from "fs";
|
||||||
|
import asset from "../common/asset";
|
||||||
|
import type { PresetBundle } from "./type";
|
||||||
|
|
||||||
|
export default (preset: PresetBundle) => {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -4,6 +4,7 @@ import gulp from "gulp";
|
|||||||
import deb from "gulp-debian";
|
import deb from "gulp-debian";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import asset from "../../../../common/asset";
|
||||||
import template from "../../../../common/template";
|
import template from "../../../../common/template";
|
||||||
import { Config } from "../../../../core/config";
|
import { Config } from "../../../../core/config";
|
||||||
import { Platform } from "../../../../core/type";
|
import { Platform } from "../../../../core/type";
|
||||||
@@ -11,6 +12,7 @@ import { Packer } from "../../../core/packer";
|
|||||||
|
|
||||||
export class LinuxDEBPacker extends Packer {
|
export class LinuxDEBPacker extends Packer {
|
||||||
static NAME = "deb";
|
static NAME = "deb";
|
||||||
|
static DEFAULT_ICON = asset("icon.jpg");
|
||||||
|
|
||||||
constructor(config: Config) {
|
constructor(config: Config) {
|
||||||
super(config, Platform.LINUX);
|
super(config, Platform.LINUX);
|
||||||
@@ -19,12 +21,13 @@ export class LinuxDEBPacker extends Packer {
|
|||||||
call() {
|
call() {
|
||||||
const target = this.targetPath;
|
const target = this.targetPath;
|
||||||
const buildDir = path.join(os.tmpdir(), "build", this.config.name, "debian");
|
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 || LinuxDEBPacker.DEFAULT_ICON;
|
||||||
|
const iconfile = `${this.config.meta.filename}${path.extname(icon)}`;
|
||||||
const desktop = template.render("linux/app.desktop", { iconfile: iconfile, ...this.config });
|
const desktop = template.render("linux/app.desktop", { iconfile: iconfile, ...this.config });
|
||||||
fse.ensureDirSync(`${buildDir}/usr/share/applications`);
|
fse.ensureDirSync(`${buildDir}/usr/share/applications`);
|
||||||
fs.writeFileSync(`${buildDir}/usr/share/applications/${this.config.meta.filename}.desktop`, desktop);
|
fs.writeFileSync(`${buildDir}/usr/share/applications/${this.config.meta.filename}.desktop`, desktop);
|
||||||
fse.copySync(`${target}`, `${buildDir}/usr/share/${this.config.meta.filename}/`);
|
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(
|
return gulp.src(`${buildDir}/*`).pipe(
|
||||||
deb({
|
deb({
|
||||||
package: this.config.meta.filename!,
|
package: this.config.meta.filename!,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { Packer } from "./core/packer";
|
|||||||
import { Runner } from "./core/runner";
|
import { Runner } from "./core/runner";
|
||||||
import { RuffleRunner } from "./impl/runner/ruffle";
|
import { RuffleRunner } from "./impl/runner/ruffle";
|
||||||
export * from "./core";
|
export * from "./core";
|
||||||
|
export * from "./impl";
|
||||||
|
|
||||||
export class Project {
|
export class Project {
|
||||||
public buildSystem: BuildSystem;
|
public buildSystem: BuildSystem;
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,7 @@ import { existsSync, mkdtempSync } from "node:fs";
|
|||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import test from "node:test";
|
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 resolveTargetDir = () => mkdtempSync(join(tmpdir(), "test-"));
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ export default defineConfig({
|
|||||||
"bin/cli": "src/cli.ts",
|
"bin/cli": "src/cli.ts",
|
||||||
"lib/index": "src/index.ts",
|
"lib/index": "src/index.ts",
|
||||||
},
|
},
|
||||||
copy: ["haxetool.schema.json"],
|
copy: ["assets", "template"],
|
||||||
dts: {
|
dts: {
|
||||||
tsgo: true,
|
tsgo: true,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user