From 8b142980f51f5bef26a9464f6f301e0857ceb193 Mon Sep 17 00:00:00 2001 From: shmyga Date: Thu, 29 Oct 2026 18:31:53 +0300 Subject: [PATCH] refactor(preset): rework preset --- assets/haxetool.schema.json | 64 ++++++ assets/icon.jpg | Bin 0 -> 16228 bytes example/haxetool.json | 24 +-- haxetool.schema.json | 70 ------ package-lock.json | 2 +- package.json | 3 +- src/cli.ts | 34 +-- src/common/asset.ts | 9 + src/common/template.ts | 2 +- src/core/config.ts | 215 ++++++++----------- src/core/type.ts | 79 +++++++ src/impl/haxe.ts | 2 +- src/impl/innosetup.ts | 2 +- src/index.ts | 2 +- src/preset/compiler.ts | 16 ++ src/preset/index.ts | 4 + src/preset/loader.ts | 63 ++++++ src/preset/register.ts | 91 ++++++++ src/preset/validator.ts | 13 ++ src/project/core/builder.ts | 3 +- src/project/core/packer.ts | 3 +- src/project/core/runner.ts | 3 +- src/project/core/target.ts | 3 +- src/project/impl/builder/haxe.ts | 3 +- src/project/impl/packer/flash.ts | 3 +- src/project/impl/packer/linux/archive.ts | 3 +- src/project/impl/packer/linux/deb.ts | 10 +- src/project/impl/packer/windows/archive.ts | 3 +- src/project/impl/packer/windows/installer.ts | 3 +- src/project/impl/runner/android.ts | 3 +- src/project/impl/runner/flash.ts | 3 +- src/project/impl/runner/html5.ts | 3 +- src/project/impl/runner/linux.ts | 3 +- src/project/impl/runner/neko.ts | 3 +- src/project/impl/runner/ruffle.ts | 2 +- src/project/impl/runner/windows.ts | 3 +- src/project/index.ts | 14 +- src/project/preset.ts | 177 --------------- test/download.test.js | 2 +- tsdown.config.ts | 2 +- 40 files changed, 474 insertions(+), 473 deletions(-) create mode 100644 assets/haxetool.schema.json create mode 100644 assets/icon.jpg delete mode 100644 haxetool.schema.json create mode 100644 src/common/asset.ts create mode 100644 src/preset/compiler.ts create mode 100644 src/preset/index.ts create mode 100644 src/preset/loader.ts create mode 100644 src/preset/register.ts create mode 100644 src/preset/validator.ts delete mode 100644 src/project/preset.ts diff --git a/assets/haxetool.schema.json b/assets/haxetool.schema.json new file mode 100644 index 0000000..4bc56ed --- /dev/null +++ b/assets/haxetool.schema.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 + } + } +} diff --git a/assets/icon.jpg b/assets/icon.jpg new file mode 100644 index 0000000000000000000000000000000000000000..7dbb6efb1571c97053b428de4f1ba0504d792c8a GIT binary patch literal 16228 zcmeHucUTn5wr>wP=OiFQ5>NyrXGTS`ihv3tIcFqGno&eiP=}yo7!@Q3l_Y|UqJZR_ z5s;kIkY*TWUZeZ$z0bL4-*@(X-}~o%ulS}|Rkf;n)mp2oYt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h?BU~8`q zE;C}m1@25FdMt_fGssPxNHbRt%t7T{M{hoK?u2fD&+U_RxX;fW=zE7AsGY1mv~Jl# zP(wy^oiOO3;4WyoBq+|j5Pm)z+jIr9v-jMwr`%;b;7!Hb=-K1;nZaN0&pf9R?$kG_ zJhitj0>3&Mth(jZx&=S(=Dw_YoMQgGWx&+cl*CyF6UA(~z|xo`p90mC+0x0be}1>CIk zk@~&(G`~=Z+TA+GUb%gZGLMam@qECoya3}!)~>12Nd7rZ&b!8h7lpF-dQTC83{4@gp!}%F(o=>g45L*Y8wZQgTqboSf z17>Hluh%z<$Um!R(bG7o!uq4~)MuD7dVUu(!m+u2Sp9T!cNp|MPa8m-;4krw;DWHxJnr$BPAlUN!Pxy-JD@k@fpd z(*(FVWI!AQ!CXhoRh9M{?CB*TYo>1!9nX1M{T7)wBhC8Lo~WdHqQrKu?!tV+keQ64i;Fl&PL1&!_qnt+xG*&uf$|?@l6%5ZFWMU z^`>OZr(MKh)}b8YCR!I9k1j$H1cw%BmI-N+;v71#HJpRd!{}vBF2SZ@J<`g~j|k`;g8L#XvlYBlQqA;<`=zqv^qr_14U#bE m", - "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.3.2" + }, + "sources": ["src"], + "main": "Main" } } diff --git a/haxetool.schema.json b/haxetool.schema.json deleted file mode 100644 index 315bcd9..0000000 --- a/haxetool.schema.json +++ /dev/null @@ -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 - } - } -} diff --git a/package-lock.json b/package-lock.json index e777c1a..063da23 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 5ac0f11..ed8a9ed 100755 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "gulp-haxetool", "type": "module", "version": "1.2.0", - "description": "HaXe Tool for Gulp", + "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": { diff --git a/src/cli.ts b/src/cli.ts index 3a59bf1..61afb85 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,34 +1,14 @@ #!/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 { 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}]`); -const loadPreset = (): Preset => { - const __filename = fileURLToPath(import.meta.url); - const __dirname = path.dirname(__filename); - - const presetData: Record = 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 +27,10 @@ const runTask = async (name: string) => { }; export const main = async () => { - const preset = loadPreset(); - preset.register(gulp); + const preset = loader(); + validator(preset); + const projects = compiler(preset); + register(projects); if (process.argv.length > 2) { await runTask(process.argv[2]); diff --git a/src/common/asset.ts b/src/common/asset.ts new file mode 100644 index 0000000..db230ff --- /dev/null +++ b/src/common/asset.ts @@ -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); +}; diff --git a/src/common/template.ts b/src/common/template.ts index 6af18f1..86eea29 100644 --- a/src/common/template.ts +++ b/src/common/template.ts @@ -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"), }); diff --git a/src/core/config.ts b/src/core/config.ts index a724c33..7701e9d 100644 --- a/src/core/config.ts +++ b/src/core/config.ts @@ -1,141 +1,96 @@ import os from "os"; import path from "path"; +import { BuildSystem, type Config, type ConfigSource } from "./type"; -export interface ConfigParams { - name?: string; - main?: string; - preloader?: string; - sources?: string[]; - assets?: string[]; - libs?: LibDef[] | Record; - macros?: string[]; - flags?: string[]; - meta?: ConfigMeta; - key?: SignKey; - android?: AndroidPreset[]; - haxe?: string; -} +export const DEFAULT_CONFIG: Config = { + buildSystem: BuildSystem.HAXE, + platforms: [], + name: "", + main: "", + preloader: null, + sources: [], + assets: [], + libs: [], + macros: [], + flags: [], + icon: null, + meta: { + width: 800, + height: 600, + fps: 60, + }, + key: null, + android: [], + haxe: null, +}; -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 absolutePath = (file: string): string => { + const result = path.resolve(process.cwd(), path.normalize(file)); + return os.type() === "Windows_NT" ? result.split("\\").join("/") : result; +}; -export interface LibDef { - name: string; - version: string; - git?: string; - branch?: string; -} +export const compile = (source: ConfigSource): Config => { + return branch(DEFAULT_CONFIG, source); +}; -export interface AndroidPreset { - path: string; - extensions: string[]; -} +export const branch = (config: Config, source: ConfigSource): Config => { + const result = structuredClone(config); -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 = { - width: 800, - height: 600, - fps: 60, - }; - this.key = null; - this.android = []; - this.haxe = null; - if (params) { - this.update(params); - this.afterUpdate(); - } + 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.meta.icon) { + result.icon = absolutePath(result.meta.icon); } - static absolutePath(file: string): string { - const result = path.resolve(process.cwd(), path.normalize(file)); - return os.type() === "Windows_NT" ? result.split("\\").join("/") : result; + if (!result.meta.mobileWidth) { + result.meta.mobileWidth = result.meta.width; } - - 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); + if (!result.meta.mobileHeight && result.meta.mobileWidth) { + result.meta.mobileHeight = Math.round(result.meta.mobileWidth / 2.222222222); } - - 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 result; +}; diff --git a/src/core/type.ts b/src/core/type.ts index dabbdf2..f40bc73 100644 --- a/src/core/type.ts +++ b/src/core/type.ts @@ -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; + 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; + +export interface ConfigJson { + SdkDir?: string; + BuildDir?: string; + Develop?: boolean; + UseRuffle?: boolean; + Key?: SignKey; +} + +export type PresetJson = Record; diff --git a/src/impl/haxe.ts b/src/impl/haxe.ts index ad8b961..e371e90 100755 --- a/src/impl/haxe.ts +++ b/src/impl/haxe.ts @@ -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"; diff --git a/src/impl/innosetup.ts b/src/impl/innosetup.ts index d07b174..23a5fbc 100755 --- a/src/impl/innosetup.ts +++ b/src/impl/innosetup.ts @@ -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"; diff --git a/src/index.ts b/src/index.ts index a2daaf5..fdb5cbb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"; diff --git a/src/preset/compiler.ts b/src/preset/compiler.ts new file mode 100644 index 0000000..d2bb150 --- /dev/null +++ b/src/preset/compiler.ts @@ -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; +}; diff --git a/src/preset/index.ts b/src/preset/index.ts new file mode 100644 index 0000000..ea85f91 --- /dev/null +++ b/src/preset/index.ts @@ -0,0 +1,4 @@ +export * from "./compiler"; +export * from "./loader"; +export * from "./register"; +export * from "./validator"; diff --git a/src/preset/loader.ts b/src/preset/loader.ts new file mode 100644 index 0000000..4e4c602 --- /dev/null +++ b/src/preset/loader.ts @@ -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; +}; diff --git a/src/preset/register.ts b/src/preset/register.ts new file mode 100644 index 0000000..5653fbf --- /dev/null +++ b/src/preset/register.ts @@ -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; +}; diff --git a/src/preset/validator.ts b/src/preset/validator.ts new file mode 100644 index 0000000..52697af --- /dev/null +++ b/src/preset/validator.ts @@ -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; + } +}; diff --git a/src/project/core/builder.ts b/src/project/core/builder.ts index 4912d34..ec127bd 100644 --- a/src/project/core/builder.ts +++ b/src/project/core/builder.ts @@ -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 { diff --git a/src/project/core/packer.ts b/src/project/core/packer.ts index 7289423..618dc8e 100644 --- a/src/project/core/packer.ts +++ b/src/project/core/packer.ts @@ -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; diff --git a/src/project/core/runner.ts b/src/project/core/runner.ts index 1e8ca27..47ca90b 100644 --- a/src/project/core/runner.ts +++ b/src/project/core/runner.ts @@ -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; diff --git a/src/project/core/target.ts b/src/project/core/target.ts index 7c2ae23..156f477 100644 --- a/src/project/core/target.ts +++ b/src/project/core/target.ts @@ -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; diff --git a/src/project/impl/builder/haxe.ts b/src/project/impl/builder/haxe.ts index 4f482fc..df37ee3 100644 --- a/src/project/impl/builder/haxe.ts +++ b/src/project/impl/builder/haxe.ts @@ -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"; diff --git a/src/project/impl/packer/flash.ts b/src/project/impl/packer/flash.ts index fcd9cc2..823df78 100644 --- a/src/project/impl/packer/flash.ts +++ b/src/project/impl/packer/flash.ts @@ -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 { diff --git a/src/project/impl/packer/linux/archive.ts b/src/project/impl/packer/linux/archive.ts index 0b1693d..9760714 100644 --- a/src/project/impl/packer/linux/archive.ts +++ b/src/project/impl/packer/linux/archive.ts @@ -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 { diff --git a/src/project/impl/packer/linux/deb.ts b/src/project/impl/packer/linux/deb.ts index 34eff1f..3b5ad44 100644 --- a/src/project/impl/packer/linux/deb.ts +++ b/src/project/impl/packer/linux/deb.ts @@ -4,13 +4,14 @@ import gulp from "gulp"; import deb from "gulp-debian"; import os from "os"; import path from "path"; +import asset from "../../../../common/asset"; 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 { static NAME = "deb"; + static DEFAULT_ICON = asset("icon.jpg"); constructor(config: Config) { super(config, Platform.LINUX); @@ -19,12 +20,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 || LinuxDEBPacker.DEFAULT_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!, diff --git a/src/project/impl/packer/windows/archive.ts b/src/project/impl/packer/windows/archive.ts index 44cd9d4..53f0088 100644 --- a/src/project/impl/packer/windows/archive.ts +++ b/src/project/impl/packer/windows/archive.ts @@ -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 { diff --git a/src/project/impl/packer/windows/installer.ts b/src/project/impl/packer/windows/installer.ts index 85841fa..81a4941 100644 --- a/src/project/impl/packer/windows/installer.ts +++ b/src/project/impl/packer/windows/installer.ts @@ -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"; diff --git a/src/project/impl/runner/android.ts b/src/project/impl/runner/android.ts index 08b5cbc..d007d62 100644 --- a/src/project/impl/runner/android.ts +++ b/src/project/impl/runner/android.ts @@ -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"; diff --git a/src/project/impl/runner/flash.ts b/src/project/impl/runner/flash.ts index bd1311d..8075e8b 100644 --- a/src/project/impl/runner/flash.ts +++ b/src/project/impl/runner/flash.ts @@ -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"; diff --git a/src/project/impl/runner/html5.ts b/src/project/impl/runner/html5.ts index c4670a9..09dd4ac 100644 --- a/src/project/impl/runner/html5.ts +++ b/src/project/impl/runner/html5.ts @@ -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 { diff --git a/src/project/impl/runner/linux.ts b/src/project/impl/runner/linux.ts index a90c1a7..9b06a48 100644 --- a/src/project/impl/runner/linux.ts +++ b/src/project/impl/runner/linux.ts @@ -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"; diff --git a/src/project/impl/runner/neko.ts b/src/project/impl/runner/neko.ts index dc337b9..4f7ec04 100644 --- a/src/project/impl/runner/neko.ts +++ b/src/project/impl/runner/neko.ts @@ -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"; diff --git a/src/project/impl/runner/ruffle.ts b/src/project/impl/runner/ruffle.ts index dab441a..8bc818a 100644 --- a/src/project/impl/runner/ruffle.ts +++ b/src/project/impl/runner/ruffle.ts @@ -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"; diff --git a/src/project/impl/runner/windows.ts b/src/project/impl/runner/windows.ts index 191a9d5..46287b7 100644 --- a/src/project/impl/runner/windows.ts +++ b/src/project/impl/runner/windows.ts @@ -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"; diff --git a/src/project/index.ts b/src/project/index.ts index 7a1ce3f..20233c0 100644 --- a/src/project/index.ts +++ b/src/project/index.ts @@ -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 { const result: Record = {}; 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)); diff --git a/src/project/preset.ts b/src/project/preset.ts deleted file mode 100644 index 2ad9828..0000000 --- a/src/project/preset.ts +++ /dev/null @@ -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; - public config: PresetConfig; - public packageInfo: Record; - - constructor(options: Record, config?: PresetConfig, packageInfo?: Record) { - 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; - } -} diff --git a/test/download.test.js b/test/download.test.js index 9fdaf3d..f39c490 100644 --- a/test/download.test.js +++ b/test/download.test.js @@ -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-")); diff --git a/tsdown.config.ts b/tsdown.config.ts index 8844093..e3caf21 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -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, },