Compare commits

...
11 Commits
Author SHA1 Message Date
shmyga 05be4ab622 feat: add "hxt" cli command
test / test (push) Failing after 5m52s
2026-10-28 20:46:12 +03:00
shmyga ce51ab817c fix(npm): downgrade gulp-debian dependecy
test / test (push) Failing after 5m36s
2026-10-28 00:53:52 +03:00
shmyga 0672f2a1e0 refactor: rework BuildSystem and Platorm with enum
test / test (push) Failing after 5m53s
2026-10-28 00:41:52 +03:00
shmyga 428f9d100e refactor(types): improve vinyl types
test / test (push) Failing after 6m5s
2026-10-27 19:24:54 +03:00
shmyga fc7f97b520 refactor(env): refactor env module
test / test (push) Failing after 31m39s
2026-10-27 01:18:23 +03:00
shmyga cf3a707a47 refactor(download): refactor download module
test / test (push) Failing after 5m35s
2026-10-27 01:04:16 +03:00
shmyga 188fcc8e4c refactor(log): refactor log and output
test / test (push) Failing after 5m51s
2026-10-26 22:22:16 +03:00
shmyga c8720102f9 fix: fix command options 2026-10-26 22:21:53 +03:00
shmyga e58d63f260 build(npm): update dependencies
test / test (push) Failing after 5m18s
2026-10-26 20:36:18 +03:00
shmyga f45effe571 refactor: replace lodash.template with eta
test / test (push) Failing after 3m8s
2026-10-25 14:58:31 +03:00
shmyga bf9ac8a8bf docs(example): update example
test / test (push) Successful in 52s
2026-10-25 14:11:32 +03:00
40 changed files with 9116 additions and 1206 deletions
+1
View File
@@ -1,3 +1,4 @@
node_modules/ node_modules/
target/ target/
dist/ dist/
build/
-71
View File
@@ -1,71 +0,0 @@
const gulp = require('gulp');
const gulpClean = require('gulp-clean');
const packageInfo = require('./package.json');
const {System, Sdk, Haxe, Project} = require('gulp-haxetool');
//Sdk.dir = '/opt/sdk';
exports.clean = function clean() {
return gulp.src('target/*', {read: false}).pipe(gulpClean());
};
exports.install = function install() {
const haxe = new Haxe();
return haxe.prepare().then(() => haxe.install(packageInfo.haxeDependencies));
};
const config = new Project.Config({
meta: {
title: 'Application',
filename: 'app',
icon: './resources/icon.jpg',
pack: 'com.example',
author: 'Anonim <anonim@anonim.com>',
company: 'Any company',
version: packageInfo.version,
},
name: 'app',
libs: packageInfo.haxeDependencies,
sources: ['src'],
assets: ['resources'],
main: 'Main',
});
const project = new Project(
Project.BuildSystem.OPENFL,
[
Project.Platform.FLASH,
Project.Platform.HTML5,
Project.Platform.LINUX,
Project.Platform.WINDOWS,
],
config
).bind(module);
const defaultSeries = [
exports.clean,
module.exports['app:flash:build'],
module.exports['app:flash:html'],
module.exports['app:html5:build'],
];
if (System.isLinux) {
defaultSeries.push(
module.exports['app:linux:build'],
module.exports['app:linux:archive'],
module.exports['app:linux:deb'],
module.exports['app:android:build'],
);
}
if (System.isWindows) {
defaultSeries.push(
module.exports['app:windows:build'],
module.exports['app:windows:archive'],
module.exports['app:windows:installer'],
);
}
module.exports.default = gulp.series(defaultSeries);
+25
View File
@@ -0,0 +1,25 @@
{
"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",
"version": "<%=package.version%>"
},
"haxe": "4.2.5",
"libs": {
"lime": "8.0.0",
"openfl": "9.2.0",
"hxcpp": "4.2.1"
},
"sources": ["src"],
"main": "Main"
}
}
}
+7601
View File
File diff suppressed because it is too large Load Diff
+8 -9
View File
@@ -1,14 +1,13 @@
{ {
"name": "app", "name": "example",
"type": "module",
"version": "0.0.1", "version": "0.0.1",
"devDependencies": { "scripts": {
"gulp": "^4.0.0", "tasks": "hxt",
"gulp-clean": "^0.4.0", "build": "hxt default",
"gulp-haxetool": "^0.1.0" "dev": "hxt app:flash:test"
}, },
"haxeDependencies": { "devDependencies": {
"lime": "7.6.0", "gulp-haxetool": "file:.."
"openfl": "8.9.2",
"hxcpp": "4.0.19"
} }
} }
+70
View File
@@ -0,0 +1,70 @@
{
"$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
}
}
}
+889 -806
View File
File diff suppressed because it is too large Load Diff
+12 -13
View File
@@ -4,9 +4,14 @@
"version": "1.2.0", "version": "1.2.0",
"description": "HaXe Tool for Gulp", "description": "HaXe Tool for Gulp",
"exports": { "exports": {
".": "./dist/index.mjs", "./bin/cli": "./dist/bin/cli.mjs",
"./lib": "./dist/lib/index.mjs",
"./package.json": "./package.json" "./package.json": "./package.json"
}, },
"bin": {
"hxt": "./dist/bin/cli.mjs"
},
"types": "./dist/lib/index.d.mts",
"files": [ "files": [
"template", "template",
"dist" "dist"
@@ -29,12 +34,13 @@
"license": "MIT", "license": "MIT",
"homepage": "https://git.shmyga.ru/InfernalGames/gulp-haxetool#readme", "homepage": "https://git.shmyga.ru/InfernalGames/gulp-haxetool#readme",
"dependencies": { "dependencies": {
"ansi-colors": "^1.1.0", "ajv": "^8.20.0",
"async": "^2.6.0", "ansi-colors": "^4.1.3",
"async": "^3.2.6",
"cli-progress": "^3.12.0", "cli-progress": "^3.12.0",
"dateformat": "^5.0.4", "dateformat": "^5.0.5",
"fancy-log": "^1.3.2", "eta": "^4.6.0",
"fs-extra": "^5.0.0", "fs-extra": "^11.4.1",
"got": "^16.1.0", "got": "^16.1.0",
"gulp": "^5.0.1", "gulp": "^5.0.1",
"gulp-clean": "^0.4.0", "gulp-clean": "^0.4.0",
@@ -44,9 +50,6 @@
"gulp-rename": "^2.1.0", "gulp-rename": "^2.1.0",
"gulp-tar": "^5.0.0", "gulp-tar": "^5.0.0",
"gulp-zip": "^6.1.0", "gulp-zip": "^6.1.0",
"lodash.defaults": "^4.2.0",
"lodash.template": "^4.4.0",
"plugin-error": "^1.0.1",
"promise-streams": "^2.1.1", "promise-streams": "^2.1.1",
"tail": "^2.2.6", "tail": "^2.2.6",
"tar": "^7.5.22", "tar": "^7.5.22",
@@ -67,7 +70,6 @@
"@types/gulp-rename": "^2.0.7", "@types/gulp-rename": "^2.0.7",
"@types/gulp-tar": "^4.0.1", "@types/gulp-tar": "^4.0.1",
"@types/gulp-zip": "^4.0.4", "@types/gulp-zip": "^4.0.4",
"@types/lodash.template": "^4.5.3",
"@types/node": "^26.6.5", "@types/node": "^26.6.5",
"@types/tail": "^2.2.3", "@types/tail": "^2.2.3",
"@types/tar": "^7.0.87", "@types/tar": "^7.0.87",
@@ -77,8 +79,5 @@
"prettier": "^3.9.10", "prettier": "^3.9.10",
"tsdown": "0.22.14", "tsdown": "0.22.14",
"typescript": "^7.0.2" "typescript": "^7.0.2"
},
"inlinedDependencies": {
"lodash": "4.18.1"
} }
} }
+39 -7
View File
@@ -1,14 +1,46 @@
declare module "vinyl" { declare module "vinyl" {
export class File { import { type Stats } from "fs";
path: string; import type Stream from "stream";
export type Contents = Stream | Buffer | null;
export interface Options<C extends Contents = Contents> {
contents?: C;
cwd?: string;
base?: string;
path?: string;
stat?: Stats;
history?: string[];
}
export class File<C extends Contents = Contents> {
contents: C;
cwd: string; cwd: string;
base: string; base: string;
contents: any; relative: string;
stat: any; dirname: string;
history: any[]; basename: string;
constructor(params: any); stem: string;
clone(options?: any); extname: string;
path: string;
symlink: string;
stat: Stats;
history: string[];
constructor(options?: Options<C>);
isBuffer(): boolean;
isStream(): boolean;
isNull(): boolean;
isDirectory(): boolean;
isSymbolic(): boolean;
clone(options?: Options<C>);
static isCustomProp(key: string): boolean;
static isVinyl(file: File | any): boolean;
} }
export type StreamFile = File<Stream>;
export type BufferFile = File<Buffer>;
export default File; export default File;
} }
+62
View File
@@ -0,0 +1,62 @@
#!/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" };
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"));
};
const runTask = async (name: string) => {
const task = gulp.task(name);
if (!task) {
throw `task '${name}' not found`;
}
return await task((error) => {
if (error) {
console.error(error);
}
});
};
export const main = async () => {
const preset = loadPreset();
preset.register(gulp);
if (process.argv.length > 2) {
await runTask(process.argv[2]);
} else {
showTasks();
}
};
export default main;
await main();
-42
View File
@@ -1,42 +0,0 @@
import colors from "ansi-colors";
const _colors = {
"[DEBUG]": colors.white,
"[INFO]": colors.cyan,
"[ERROR]": colors.red,
"Called from ": colors.red,
"[WARNING]": colors.yellow,
};
export type Color = (v: string) => string;
export const getColor = (line: string): Color | null => {
for (const [tag, color] of Object.entries(_colors)) {
if (line.indexOf(tag) > -1) {
return color;
}
}
return null; // colors.reset;
};
export class Debug {
public color: Color;
constructor() {
this.color = colors.white;
this.log = this.log.bind(this);
}
log(line: string) {
const newColor = getColor(line);
if (newColor) this.color = newColor;
if (line[0] === "\t" || line.startsWith("Called from ")) {
console.log(this.color(line));
} else {
const result = line.split(" ");
console.log(colors.gray(result.slice(0, 4).join(" ")) + " " + this.color(result.slice(4).join(" ")));
}
}
}
export const DEBUG = new Debug();
+74 -52
View File
@@ -1,59 +1,26 @@
import progress from "cli-progress"; import progress from "cli-progress";
import fs from "fs"; import fs from "fs";
import fse from "fs-extra"; import fse from "fs-extra";
import got from "got"; import got, { type Progress, type Request } from "got";
import path from "path"; import path from "path";
import ps from "promise-streams"; import ps from "promise-streams";
import type { Stream, Writable } from "stream"; import type { Stream, Writable } from "stream";
import * as tar from "tar"; import { x as tarX } from "tar";
import unzip from "unzip-stream"; import unzip from "unzip-stream";
export class Downloader { export interface DownloadOptions {
static bar: progress.MultiBar | null; progress?: boolean;
strip?: number;
executable?: boolean;
}
static createProgressBar() { const DEFAULT_OPTIONS: DownloadOptions = { progress: true, strip: 1, executable: false };
if (Downloader.bar == null) {
Downloader.bar = new progress.MultiBar(
{
clearOnComplete: true,
},
progress.Presets.shades_grey,
);
}
return Downloader.bar.create(0, 0);
}
static releaseProgressBar(bar: progress.SingleBar) { type Extractor = (stream: Request, dest: string, options: DownloadOptions) => Stream;
bar.stop();
if (Downloader.bar != null) {
Downloader.bar.remove(bar);
if (!Downloader.bar.isActive) {
Downloader.bar.stop();
Downloader.bar = null;
}
}
}
static download(url: string, dest: string, strip = 1, executable = false) { const ZIP_EXTRACTOR: Extractor = (stream: Request, dest: string, options: DownloadOptions): Stream => {
fse.ensureDirSync(dest); return stream.pipe(unzip.Parse()).on("entry", (entry: any) => {
const bar = Downloader.createProgressBar(); const filePath = entry.path.split("/").slice(options.strip).join(path.sep);
let stream: Stream = got.stream(url);
stream = stream
.on("request", (r: any) => {
if (bar) bar.start(1, 0);
})
.on("downloadProgress", (p: any) => {
if (bar) {
bar.setTotal(p.total);
bar.update(p.transferred);
if (p.total === p.transferred) {
Downloader.releaseProgressBar(bar);
}
}
});
if (url.endsWith(".zip")) {
stream = stream.pipe(unzip.Parse()).on("entry", (entry: any) => {
const filePath = entry.path.split("/").slice(strip).join(path.sep);
if (filePath.length > 0) { if (filePath.length > 0) {
if (entry.type === "Directory") { if (entry.type === "Directory") {
fse.ensureDirSync(path.join(dest, path.normalize(filePath))); fse.ensureDirSync(path.join(dest, path.normalize(filePath)));
@@ -65,8 +32,8 @@ export class Downloader {
} }
entry.pipe( entry.pipe(
fs.createWriteStream(path.join(dest, path.normalize(filePath)), { fs.createWriteStream(path.join(dest, path.normalize(filePath)), {
// ToDo: zip entry file mode? // TODO: zip entry file mode?
mode: executable ? 0o755 : undefined, mode: options.executable ? 0o755 : undefined,
}), }),
); );
} }
@@ -74,11 +41,66 @@ export class Downloader {
entry.autodrain(); entry.autodrain();
} }
}); });
} else if (url.endsWith("tar.gz")) { };
stream = stream.pipe(tar.x({ C: dest, strip }) as unknown as Writable);
} else { const QZ_EXTRACTOR: Extractor = (stream: Request, dest: string, options: DownloadOptions): Stream => {
stream = stream.pipe(fs.createWriteStream(path.join(dest, url.split("/").pop()!))); // TODO: cast tar.Unpack to Writable
return stream.pipe(tarX({ C: dest, strip: options.strip }) as unknown as Writable);
};
const DEFAULT_EXTRACTOR: Extractor = (stream: Request, dest: string, options: DownloadOptions): Stream => {
const filename = String(stream.requestUrl as URL)
.split("/")
.pop()!;
return stream.pipe(fs.createWriteStream(path.join(dest, filename)));
};
const EXTRACTOR_MAP: Record<string, Extractor> = {
".zip": ZIP_EXTRACTOR,
".gz": QZ_EXTRACTOR,
"": DEFAULT_EXTRACTOR,
};
class ProgressBar {
private multiBar: progress.MultiBar = new progress.MultiBar(
{
stopOnComplete: true,
},
progress.Presets.shades_classic,
);
handle(request: Request): Request {
const bar = this.multiBar.create(0, 0);
return request
.on("request", (request: Request) => {
bar.start(1, 0);
})
.on("downloadProgress", (progress: Progress) => {
if (progress.total) {
bar.setTotal(progress.total);
} }
return ps.wait(stream); bar.update(progress.transferred);
if (progress.total === progress.transferred) {
bar.render();
bar.stop();
this.multiBar.remove(bar);
}
});
} }
} }
const progressBar = new ProgressBar();
export const download = async (url: string, dest: string, options?: DownloadOptions): Promise<void> => {
options = Object.assign({}, DEFAULT_OPTIONS, options);
fse.ensureDirSync(dest);
let stream: Request = got.stream(url);
if (options.progress) {
stream = progressBar.handle(stream);
}
const ext = path.extname(url);
const extractor = EXTRACTOR_MAP[ext] || EXTRACTOR_MAP[""];
return ps.wait(extractor(stream, dest, options));
};
export default download;
+15 -9
View File
@@ -1,19 +1,25 @@
import path from "path"; import path from "path";
export class Env { export class Env {
static set(key: string, value: string) { constructor(private target: Record<string, string | undefined>) {}
process.env[key] = value;
set(key: string, value: string) {
this.target[key] = value;
} }
static get(key: string) { get(key: string) {
return process.env[key]; return this.target[key];
} }
static addPath(value: string, key = "PATH") { addPath(value: string, key: string = "PATH") {
if (!process.env[key]) { if (!this.target[key]) {
process.env[key] = value; this.target[key] = value;
} else if (process.env[key].split(path.delimiter).indexOf(value) === -1) { } else if (this.target[key].split(path.delimiter).indexOf(value) === -1) {
process.env[key] = [process.env[key], value].join(path.delimiter); this.target[key] = [this.target[key], value].join(path.delimiter);
} }
} }
} }
export const env = new Env(process.env);
export default env;
+17 -5
View File
@@ -1,10 +1,22 @@
import async from "async"; import async, { type ErrorCallback } from "async";
import child_process from "child_process"; import child_process from "child_process";
import { Log } from "./log"; import { Logger } from "./log";
const log = new Log("exec"); const log = new Logger("exec");
const queue = async.queue((task: any, done: any) => { export interface Result {
stdout: string;
stderr: string;
}
interface Task {
dir: string;
command: string;
success: (result: Result) => void;
failure: (error: string) => void;
}
const queue = async.queue((task: Task, done: ErrorCallback) => {
log.d("*%s*", task.command); log.d("*%s*", task.command);
//process.chdir(task.dir); //process.chdir(task.dir);
child_process.exec(task.command, { cwd: task.dir, maxBuffer: 1024 * 10000 }, (err, stdout, stderr) => { child_process.exec(task.command, { cwd: task.dir, maxBuffer: 1024 * 10000 }, (err, stdout, stderr) => {
@@ -19,7 +31,7 @@ const queue = async.queue((task: any, done: any) => {
}); });
}); });
export default (dir: string, command: string) => { export default (dir: string, command: string): Promise<Result> => {
return new Promise((success, failure) => { return new Promise((success, failure) => {
queue.push({ queue.push({
dir: dir, dir: dir,
+54 -31
View File
@@ -1,63 +1,86 @@
import colors from "ansi-colors"; import colors from "ansi-colors";
const Level = { export enum Level {
VERBOSE: -1, VERBOSE = -1,
DEBUG: 0, DEBUG = 0,
INFO: 1, INFO = 1,
WARN: 2, WARNING = 2,
ERROR: 3, ERROR = 3,
}; }
const level = process.argv.indexOf("--verbose") > -1 ? Level.VERBOSE : Level.INFO; export const DEFAULT_LEVEL: Level = process.argv.indexOf("--verbose") > -1 ? Level.VERBOSE : Level.INFO;
const formatTime = (date: Date): string => date.toTimeString().split(" ")[0]; export type FormatPattern = [string, colors.StyleFunction];
export class Log { export const DEFAULT_PATTERNS: FormatPattern[] = [
static level = level;
static colorPatterns: [string, (m: string) => string][] = [
["_", colors.cyan], ["_", colors.cyan],
["\\*", colors.magenta], ["\\*", colors.magenta],
["!", colors.red], ["!", colors.red],
]; ];
static colorize(pattern: string) { export class Formatter {
for (const item of this.colorPatterns) { constructor(
private patterns: FormatPattern[] = DEFAULT_PATTERNS,
private time: boolean = true,
) {}
colorize(text: string): string {
for (const item of this.patterns) {
const r = new RegExp(item[0] + "(.*?)" + item[0], "g"); const r = new RegExp(item[0] + "(.*?)" + item[0], "g");
pattern = pattern.replace(r, item[1]("$1")); text = text.replace(r, item[1]("$1"));
} }
return pattern; return text;
} }
static write(level: number, tag: string, pattern: string, args: any[]) { buildTime(): string {
return new Date().toTimeString().split(" ")[0];
}
format(message: string, tag: string, level: Level): string {
const values = [];
if (this.time) {
values.push(`[${colors.gray(this.buildTime())}]`);
}
if (tag) {
values.push(colors.green(tag));
}
values.push(this.colorize(message));
return values.join(" ");
}
}
export const DEFAULT_FORMATTER = new Formatter();
export class Logger {
constructor(
private tag: string,
private level: Level = DEFAULT_LEVEL,
private formatter: Formatter = DEFAULT_FORMATTER,
) {}
write(level: Level, message: string, args: any[]) {
if (level >= this.level) { if (level >= this.level) {
const message = `[${colors.gray(formatTime(new Date()))}] ${colors.green(tag)} ${this.colorize(pattern)}`; console.log(this.formatter.format(message, this.tag, level), ...args);
console.log(message, ...args);
} }
} }
public tag: string;
constructor(tag: string) {
this.tag = tag;
}
v(message: string, ...args: any) { v(message: string, ...args: any) {
Log.write(-1, this.tag, message, args); this.write(Level.VERBOSE, message, args);
} }
d(message: string, ...args: any) { d(message: string, ...args: any) {
Log.write(0, this.tag, message, args); this.write(Level.DEBUG, message, args);
} }
i(message: string, ...args: any) { i(message: string, ...args: any) {
Log.write(1, this.tag, message, args); this.write(Level.INFO, message, args);
} }
w(message: string, ...args: any) { w(message: string, ...args: any) {
Log.write(2, this.tag, message, args); this.write(Level.WARNING, message, args);
} }
e(message: string, ...args: any) { e(message: string, ...args: any) {
Log.write(3, this.tag, message, args); this.write(Level.ERROR, message, args);
} }
} }
+57
View File
@@ -0,0 +1,57 @@
import colors from "ansi-colors";
import { Formatter, Level, Logger } from "./log";
export class OutputFormatter extends Formatter {
private colorMap: Record<Level, colors.StyleFunction> = {
[Level.VERBOSE]: colors.white,
[Level.DEBUG]: colors.white,
[Level.INFO]: colors.cyan,
[Level.ERROR]: colors.red,
[Level.WARNING]: colors.yellow,
};
format(message: string, tag: string, level: Level): string {
const color = this.colorMap[level];
if (message[0] === "\t" || message.startsWith("Called from ")) {
return color(message);
} else {
const result = message.split(" ");
return colors.gray(result.slice(0, 4).join(" ")) + " " + color(result.slice(4).join(" "));
}
}
}
export const DEFAULT_OUTPUT_FORMATTER = new OutputFormatter();
export class OutputLogger extends Logger {
private levelMap: Record<string, Level> = {
"[DEBUG]": Level.DEBUG,
"[INFO]": Level.INFO,
"[ERROR]": Level.ERROR,
"Called from ": Level.ERROR,
"[WARNING]": Level.WARNING,
};
constructor() {
super("", Level.VERBOSE, DEFAULT_OUTPUT_FORMATTER);
}
detectLevel(line: string): number {
for (const [tag, color] of Object.entries(this.levelMap)) {
if (line.indexOf(tag) > -1) {
return color;
}
}
return Level.DEBUG;
}
log(line: string) {
this.write(this.detectLevel(line), line, []);
}
}
export const OUTPUT_LOGGER = new OutputLogger();
export const output = (line: string) => OUTPUT_LOGGER.log(line);
export default output;
+13
View File
@@ -0,0 +1,13 @@
import { Eta } from "eta";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default new Eta({
autoFilter: true,
filterFunction: (val: unknown): string => (val === null ? "" : String(val)),
useWith: true,
views: path.join(__dirname, "..", "template"),
});
+2 -1
View File
@@ -15,7 +15,8 @@ class BufferingTransform extends Transform {
callback(); callback();
} }
} }
export class TailVinyl extends Vinyl {
export class TailVinyl extends Vinyl<BufferingTransform> {
private tail?: Tail; private tail?: Tail;
constructor(params: WatchParams) { constructor(params: WatchParams) {
+4
View File
@@ -13,6 +13,7 @@ export interface ConfigParams {
meta?: ConfigMeta; meta?: ConfigMeta;
key?: SignKey; key?: SignKey;
android?: AndroidPreset[]; android?: AndroidPreset[];
haxe?: string;
} }
export interface ConfigMeta { export interface ConfigMeta {
@@ -60,6 +61,7 @@ export class Config {
public meta: ConfigMeta; public meta: ConfigMeta;
public key: SignKey | null; public key: SignKey | null;
public android: AndroidPreset[]; public android: AndroidPreset[];
public haxe: string | null;
private _params: ConfigParams[]; private _params: ConfigParams[];
@@ -81,6 +83,7 @@ export class Config {
}; };
this.key = null; this.key = null;
this.android = []; this.android = [];
this.haxe = null;
if (params) { if (params) {
this.update(params); this.update(params);
this.afterUpdate(); this.afterUpdate();
@@ -113,6 +116,7 @@ export class Config {
this.android = this.android.concat( this.android = this.android.concat(
params.android.map((item) => ({ path: Config.absolutePath(item.path), extensions: item.extensions })), 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 (this.meta.icon) this.icon = Config.absolutePath(this.meta.icon);
} }
+5 -5
View File
@@ -1,7 +1,7 @@
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import { Downloader } from "../common/download"; import download from "../common/download";
import { Log } from "../common/log"; import { Logger } from "../common/log";
export class Sdk { export class Sdk {
static _dir: string; static _dir: string;
@@ -20,12 +20,12 @@ export class Sdk {
public name: string; public name: string;
public version: string; public version: string;
public log: Log; public log: Logger;
public path: string; public path: string;
constructor(name: string, version: string) { constructor(name: string, version: string) {
this.name = name; this.name = name;
this.log = new Log(name); this.log = new Logger(name);
this.version = version; this.version = version;
this.path = Sdk.path(name, version); this.path = Sdk.path(name, version);
} }
@@ -55,7 +55,7 @@ export class Sdk {
return Promise.resolve(); return Promise.resolve();
} else { } else {
this.log.i("download: *%s*", this.link); this.log.i("download: *%s*", this.link);
return Downloader.download(this.link, this.path, strip); return download(this.link, this.path, { strip });
} }
} }
} }
+14 -14
View File
@@ -1,15 +1,15 @@
export const BuildSystem = { export enum BuildSystem {
HAXE: "haxe", HAXE = "haxe",
OPENFL: "openfl", OPENFL = "openfl",
ADOBE_AIR: "adobe_air", ADOBE_AIR = "adobe_air",
}; }
export const Platform = { export enum Platform {
FLASH: "flash", FLASH = "flash",
HTML5: "html5", HTML5 = "html5",
LINUX: "linux", LINUX = "linux",
WINDOWS: "windows", WINDOWS = "windows",
ANDROID: "android", ANDROID = "android",
NEKO: "neko", NEKO = "neko",
CPP: "cpp", CPP = "cpp",
}; }
+7 -7
View File
@@ -2,8 +2,8 @@ import fs from "fs";
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import through from "through2"; import through from "through2";
import { Downloader } from "../common/download"; import download from "../common/download";
import { Env } from "../common/env"; import env from "../common/env";
import exec from "../common/exec"; import exec from "../common/exec";
import { System } from "../common/system"; import { System } from "../common/system";
import { HandlerWriter } from "../common/tail"; import { HandlerWriter } from "../common/tail";
@@ -62,10 +62,10 @@ export class Android extends Sdk {
} }
prepare_ndk(): Promise<any> { prepare_ndk(): Promise<any> {
// ToDo: support windows // TODO: support windows
const url = `${this.repository}/android-ndk-${this.ndk_version}-${System.os}-x86_64.zip`; const url = `${this.repository}/android-ndk-${this.ndk_version}-${System.os}-x86_64.zip`;
this.log.d("download: *%s*", url); this.log.d("download: *%s*", url);
return Downloader.download(url, this.ndk_home, 1, true); return download(url, this.ndk_home, { executable: true });
} }
sdkmanager(packages: string[]) { sdkmanager(packages: string[]) {
@@ -101,9 +101,9 @@ export class Android extends Sdk {
} }
activate() { activate() {
Env.set("ANDROID_HOME", this.android_home); env.set("ANDROID_HOME", this.android_home);
Env.set("ANDROID_NDK_HOME", this.ndk_home); env.set("ANDROID_NDK_HOME", this.ndk_home);
Env.set("NDK_HOME", this.ndk_home); env.set("NDK_HOME", this.ndk_home);
} }
get adbBin(): string { get adbBin(): string {
+2 -2
View File
@@ -2,7 +2,7 @@ import fs from "fs";
import fse from "fs-extra"; import fse from "fs-extra";
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import { Env } from "../common/env"; import env from "../common/env";
import { System } from "../common/system"; import { System } from "../common/system";
import { watch } from "../common/watch"; import { watch } from "../common/watch";
import { Sdk } from "../core/sdk"; import { Sdk } from "../core/sdk";
@@ -31,7 +31,7 @@ export class FlashPlayer extends Sdk {
constructor(debug: boolean = false, version?: string, playerId = FlashPlayer.ID) { constructor(debug: boolean = false, version?: string, playerId = FlashPlayer.ID) {
super(playerId, version || FlashPlayer.VERSION); super(playerId, version || FlashPlayer.VERSION);
this.debug = debug; this.debug = debug;
this.baseUrl = Env.get("FLASHPLAYER_URL") || this.BASE_URL; this.baseUrl = env.get("FLASHPLAYER_URL") || this.BASE_URL;
} }
prepare() { prepare() {
+37 -29
View File
@@ -1,15 +1,16 @@
import fs from "fs"; import fs from "fs";
import fse from "fs-extra"; import fse from "fs-extra";
import rename from "gulp-rename"; import rename from "gulp-rename";
import template from "lodash.template";
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import vfs from "vinyl-fs"; import vfs from "vinyl-fs";
import { Env } from "../common/env"; import env from "../common/env";
import exec from "../common/exec"; import exec from "../common/exec";
import { System } from "../common/system"; import { System } from "../common/system";
import template from "../common/template";
import type { Config, LibDef } from "../core/config"; import type { Config, LibDef } from "../core/config";
import { Sdk } from "../core/sdk"; import { Sdk } from "../core/sdk";
import { Platform } from "../core/type";
import { Neko } from "./neko"; import { Neko } from "./neko";
export class Haxe extends Sdk { export class Haxe extends Sdk {
@@ -68,11 +69,11 @@ export class Haxe extends Sdk {
activate() { activate() {
this.neko.activate(); this.neko.activate();
Env.set("HAXE_VERSION", this.version); env.set("HAXE_VERSION", this.version);
Env.set("HAXE_STD_PATH", path.join(this.path, "std")); env.set("HAXE_STD_PATH", path.join(this.path, "std"));
Env.set("HAXE_HOME", this.path); env.set("HAXE_HOME", this.path);
Env.addPath(this.path); env.addPath(this.path);
Env.addPath(this.path, "LD_LIBRARY_PATH"); env.addPath(this.path, "LD_LIBRARY_PATH");
} }
prepare() { prepare() {
@@ -109,16 +110,13 @@ export class Haxe extends Sdk {
return path.join(Haxe.buildDir, config.name); return path.join(Haxe.buildDir, config.name);
} }
openfl(command: string, platform: string, config: Config, debug = false) { openfl(command: string, platform: Platform, config: Config, debug = false) {
this.log.i("_openfl_ _build_ *%s*", platform); this.log.i("_openfl_ _build_ *%s*", platform);
this.activate(); this.activate();
const buildDir = this.resolveBuildDir(config); const buildDir = this.resolveBuildDir(config);
fse.ensureDirSync(buildDir); fse.ensureDirSync(buildDir);
const projectTemplate = template( const project = template.render("project.xml", { ...config, buildDir: buildDir });
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/project.xml"), "utf8"),
);
const project = projectTemplate({ ...config, buildDir: buildDir });
fs.writeFileSync(path.resolve(buildDir, "project.xml"), project); fs.writeFileSync(path.resolve(buildDir, "project.xml"), project);
const args = ["-cwd", buildDir, "run", "openfl", command, platform]; const args = ["-cwd", buildDir, "run", "openfl", command, platform];
@@ -128,41 +126,49 @@ export class Haxe extends Sdk {
const target = path.resolve(buildDir, platform, "bin"); const target = path.resolve(buildDir, platform, "bin");
fse.emptyDirSync(target); fse.emptyDirSync(target);
const result = const result =
(
{ {
android: `app/build/outputs/**/${config.meta.filename}-debug.apk`, [Platform.ANDROID]: `app/build/outputs/**/${config.meta.filename}-debug.apk`,
flash: "*.swf", [Platform.FLASH]: "*.swf",
}[platform] || "**/*"; } as Record<Platform, string>
)[platform] || "**/*";
return this.haxelib(args).then(() => { return this.haxelib(args).then(() => {
let r = vfs.src(`${target}/${result}`, { encoding: false }); let r = vfs.src(`${target}/${result}`, { encoding: false });
if (platform === "android") { if (platform === Platform.ANDROID) {
r = r.pipe(rename(`${config.meta.filename}_${config.meta.version}.apk`)); r = r.pipe(rename(`${config.meta.filename}_${config.meta.version}.apk`));
} }
return r; return r;
}); });
} }
build(platform: string, config: Config, debug = false) { build(platform: Platform, config: Config, debug = false) {
this.log.i("_build_ *%s*", platform); this.log.i("_build_ *%s*", platform);
this.activate(); this.activate();
const buildDir = this.resolveBuildDir(config); const buildDir = this.resolveBuildDir(config);
fse.ensureDirSync(buildDir); fse.ensureDirSync(buildDir);
const projectTemplate = template(
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/project.hxml"), "utf8"),
);
const ext = const ext =
(
{ {
flash: ".swf", [Platform.FLASH]: ".swf",
neko: ".n", [Platform.NEKO]: ".n",
}[platform] || ""; } as Record<Platform, string>
)[platform] || "";
const out = const out =
(
{ {
flash: "swf", [Platform.FLASH]: "swf",
}[platform] || platform; } as Record<Platform, string>
)[platform] || platform;
const project = projectTemplate({ ...config, buildDir: buildDir, platform: platform, ext: ext, out: out }); const project = template.render("project.hxml", {
...config,
buildDir: buildDir,
platform: platform,
ext: ext,
out: out,
});
const projectHXML = path.resolve(buildDir, "project.hxml"); const projectHXML = path.resolve(buildDir, "project.hxml");
fs.writeFileSync(projectHXML, project); fs.writeFileSync(projectHXML, project);
@@ -178,9 +184,11 @@ export class Haxe extends Sdk {
fse.copySync(asset, path.join(target, asset.split("/").pop()!)); fse.copySync(asset, path.join(target, asset.split("/").pop()!));
} }
const result = const result =
(
{ {
cpp: `${config.meta.filename}/${config.main.split(".").pop()}${debug ? "-debug" : ""}`, [Platform.CPP]: `${config.meta.filename}/${config.main.split(".").pop()}${debug ? "-debug" : ""}`,
}[platform] || "**/*"; } as Record<Platform, string>
)[platform] || "**/*";
return this.haxe(args).then(() => { return this.haxe(args).then(() => {
let r = vfs.src(`${target}/${result}`, { encoding: false }); let r = vfs.src(`${target}/${result}`, { encoding: false });
if (platform === "cpp") { if (platform === "cpp") {
+2 -5
View File
@@ -1,9 +1,9 @@
import fs from "fs"; import fs from "fs";
import fse from "fs-extra"; import fse from "fs-extra";
import template from "lodash.template";
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import exec from "../common/exec"; import exec from "../common/exec";
import template from "../common/template";
import type { Config } from "../core/config"; import type { Config } from "../core/config";
import { Sdk } from "../core/sdk"; import { Sdk } from "../core/sdk";
@@ -43,10 +43,7 @@ export class InnoSetup extends Sdk {
pack(config: Config, source: string, output: string) { pack(config: Config, source: string, output: string) {
const buildDir = path.join(os.tmpdir(), "build", config.name, "innosetup"); const buildDir = path.join(os.tmpdir(), "build", config.name, "innosetup");
const appTemplate = template( const app = template.render("windows/app.iss", { ...config, buildDir: buildDir, output: output });
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/windows/app.iss"), "utf8"),
);
const app = appTemplate({ ...config, buildDir: buildDir, output: output });
fse.ensureDirSync(buildDir); fse.ensureDirSync(buildDir);
fse.copySync(`${source}`, `${buildDir}`); fse.copySync(`${source}`, `${buildDir}`);
+4 -4
View File
@@ -1,7 +1,7 @@
import fs from "fs"; import fs from "fs";
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import { Env } from "../common/env"; import env from "../common/env";
import { Sdk } from "../core/sdk"; import { Sdk } from "../core/sdk";
import run from "../run/index"; import run from "../run/index";
@@ -63,9 +63,9 @@ export class Neko extends Sdk {
} }
activate() { activate() {
Env.set("NEKO_INSTPATH", this.path); env.set("NEKO_INSTPATH", this.path);
Env.addPath(this.path); env.addPath(this.path);
Env.addPath(this.path, "LD_LIBRARY_PATH"); env.addPath(this.path, "LD_LIBRARY_PATH");
} }
prepare() { prepare() {
+2 -2
View File
@@ -1,6 +1,6 @@
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import { Env } from "../common/env"; import env from "../common/env";
import { System } from "../common/system"; import { System } from "../common/system";
import { watch } from "../common/watch"; import { watch } from "../common/watch";
import run from "../run"; import run from "../run";
@@ -20,7 +20,7 @@ export class RufflePlayer extends FlashPlayer {
constructor(debug: boolean, version: string) { constructor(debug: boolean, version: string) {
super(debug, version || RufflePlayer.VERSION, RufflePlayer.ID); super(debug, version || RufflePlayer.VERSION, RufflePlayer.ID);
this.baseUrl = Env.get("RUFFLE_URL") || this.BASE_URL; this.baseUrl = env.get("RUFFLE_URL") || this.BASE_URL;
} }
get link(): string { get link(): string {
+3 -1
View File
@@ -1,6 +1,8 @@
export * from "./common/download";
export * from "./common/log";
export * from "./common/output";
export * from "./common/system"; export * from "./common/system";
export * from "./core/config"; export * from "./core/config";
export * from "./common/download";
export * from "./core/sdk"; export * from "./core/sdk";
export * from "./core/type"; export * from "./core/type";
export * from "./impl/android"; export * from "./impl/android";
+3 -2
View File
@@ -1,4 +1,5 @@
import type { Config } from "../../core/config"; import type { Config } from "../../core/config";
import type { BuildSystem, Platform } from "../../core/type";
import { Target } from "./target"; import { Target } from "./target";
export class Builder extends Target { export class Builder extends Target {
@@ -7,7 +8,7 @@ export class Builder extends Target {
public buildSystem: string; public buildSystem: string;
public debug: boolean; public debug: boolean;
constructor(config: Config, platform: string, buildSystem: string, debug: boolean = false) { constructor(config: Config, platform: Platform, buildSystem: BuildSystem, debug: boolean = false) {
super(config, platform); super(config, platform);
this.buildSystem = buildSystem; this.buildSystem = buildSystem;
this.debug = debug; this.debug = debug;
@@ -17,7 +18,7 @@ export class Builder extends Target {
Builder.factory[buildSystem] = builder; Builder.factory[buildSystem] = builder;
} }
static new(config: Config, platform: string, buildSystem: string, debug: boolean = false): Builder { static new(config: Config, platform: Platform, buildSystem: BuildSystem, debug: boolean = false): Builder {
return new Builder.factory[buildSystem](config, platform, buildSystem, debug); return new Builder.factory[buildSystem](config, platform, buildSystem, debug);
} }
} }
+5 -4
View File
@@ -1,21 +1,22 @@
import type { Config } from "../../core/config"; import type { Config } from "../../core/config";
import type { Platform } from "../../core/type";
import { Target } from "./target"; import { Target } from "./target";
export type PackerFactory = new (config: Config) => Packer; export type PackerFactory = new (config: Config) => Packer;
export class Packer extends Target { export class Packer extends Target {
static factory: Record<string, Record<string, PackerFactory>> = {}; static factory: Partial<Record<Platform, Record<string, PackerFactory>>> = {};
call() { call() {
throw "Not Implemented"; throw "Not Implemented";
} }
static register(platform: string, name: string, packer: PackerFactory) { static register(platform: Platform, name: string, packer: PackerFactory) {
if (!Packer.factory[platform]) Packer.factory[platform] = {}; if (!Packer.factory[platform]) Packer.factory[platform] = {};
Packer.factory[platform][name] = packer; Packer.factory[platform][name] = packer;
} }
static new(config: Config, platform: string, name: string): Packer { static new(config: Config, platform: Platform, name: string): Packer {
return new Packer.factory[platform][name](config); return new Packer.factory[platform]![name](config);
} }
} }
+4 -3
View File
@@ -1,8 +1,9 @@
import gulp from "gulp"; import gulp from "gulp";
import rename from "gulp-rename"; import rename from "gulp-rename";
import { DEBUG } from "../../common/debug"; import output from "../../common/output";
import { tail } from "../../common/tail"; import { tail } from "../../common/tail";
import { Config } from "../../core/config"; import { Config } from "../../core/config";
import type { Platform } from "../../core/type";
import { Target } from "./target"; import { Target } from "./target";
export type RunnerFactory = new (config: Config, debug: boolean) => Runner; export type RunnerFactory = new (config: Config, debug: boolean) => Runner;
@@ -12,13 +13,13 @@ export class Runner extends Target {
public debug: boolean; public debug: boolean;
constructor(config: Config, platform: string, debug: boolean) { constructor(config: Config, platform: Platform, debug: boolean) {
super(config, platform); super(config, platform);
this.debug = debug; this.debug = debug;
} }
log(stream: any) { log(stream: any) {
return stream.pipe(tail(DEBUG.log)).pipe(rename("out.log")).pipe(gulp.dest(this.targetPath)); return stream.pipe(tail(output)).pipe(rename("out.log")).pipe(gulp.dest(this.targetPath));
} }
static register(platform: string, runner: RunnerFactory) { static register(platform: string, runner: RunnerFactory) {
+4 -3
View File
@@ -1,12 +1,13 @@
import path from "path"; import path from "path";
import type { Config } from "../../core/config"; import type { Config } from "../../core/config";
import type { Platform } from "../../core/type";
export class Target { export class Target {
public config: Config; public config: Config;
public platform: string; public platform: Platform;
public target: string; public target: string;
constructor(config: Config, platform: string) { constructor(config: Config, platform: Platform) {
this.config = config; this.config = config;
this.platform = platform; this.platform = platform;
this.target = "target"; this.target = "target";
@@ -20,7 +21,7 @@ export class Target {
throw "Not Implemented"; throw "Not Implemented";
} }
resolveTargetPath(platform = this.platform): string { resolveTargetPath(platform: Platform | string = this.platform): string {
return path.resolve(this.target, this.config.name, platform); return path.resolve(this.target, this.config.name, platform);
} }
+3 -3
View File
@@ -11,14 +11,14 @@ export class HaxeBuilder extends Builder {
public haxe: Haxe; public haxe: Haxe;
public android: Android; public android: Android;
constructor(config: Config, platform: string, buildSystem: string, debug: boolean = false) { constructor(config: Config, platform: Platform, buildSystem: BuildSystem, debug: boolean = false) {
super(config, platform, buildSystem, debug); super(config, platform, buildSystem, debug);
this.haxe = new Haxe(); this.haxe = new Haxe(config.haxe ? config.haxe : undefined);
this.android = new Android(); this.android = new Android();
} }
prepare() { prepare() {
let result = this.haxe.prepare().then(() => this.haxe.install(this.config.libs)); let result: Promise<any> = this.haxe.prepare().then(() => this.haxe.install(this.config.libs));
if (this.buildSystem === BuildSystem.OPENFL) { if (this.buildSystem === BuildSystem.OPENFL) {
if (this.platform === Platform.ANDROID) { if (this.platform === Platform.ANDROID) {
result = result result = result
+2 -5
View File
@@ -1,6 +1,6 @@
import fs from "fs"; import fs from "fs";
import template from "lodash.template";
import path from "path"; import path from "path";
import template from "../../../common/template";
import type { Config } from "../../../core/config"; import type { Config } from "../../../core/config";
import { Platform } from "../../../core/type"; import { Platform } from "../../../core/type";
import { Packer } from "../../core/packer"; import { Packer } from "../../core/packer";
@@ -14,10 +14,7 @@ export class FlashHTMLPacker extends Packer {
call() { call() {
const target = this.targetPath; const target = this.targetPath;
const indexTemplate = template( const index = template.render("flash/index.html", this.config);
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/flash/index.html"), "utf8"),
);
const index = indexTemplate(this.config);
fs.writeFileSync(path.resolve(target, "index.html"), index); 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(); return Promise.resolve();
+2 -5
View File
@@ -2,9 +2,9 @@ import fs from "fs";
import fse from "fs-extra"; import fse from "fs-extra";
import gulp from "gulp"; import gulp from "gulp";
import deb from "gulp-debian"; import deb from "gulp-debian";
import { template } from "lodash";
import os from "os"; import os from "os";
import path from "path"; import path from "path";
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";
import { Packer } from "../../../core/packer"; import { Packer } from "../../../core/packer";
@@ -20,10 +20,7 @@ export class LinuxDEBPacker extends Packer {
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 iconfile = `${this.config.meta.filename}${path.extname(this.config.meta.icon!)}`;
const desktopTemplate = template( const desktop = template.render("linux/app.desktop", Object.assign({ iconfile: iconfile }, this.config));
fs.readFileSync(path.resolve(import.meta.dirname, "..", "template/linux/app.desktop"), "utf8"),
);
const desktop = desktopTemplate(Object.assign({ 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}/`);
+7 -13
View File
@@ -9,17 +9,11 @@ import { RuffleRunner } from "./impl/runner/ruffle";
export * from "./core"; export * from "./core";
export class Project { export class Project {
// TODO: compatibility public buildSystem: BuildSystem;
static Config = Config; public platforms: Platform[];
static BuildSystem = BuildSystem;
static Platform = Platform;
static Builder = Builder;
public buildSystem: string;
public platforms: string[];
public config: Config; public config: Config;
constructor(buildSystem: string, platforms: string[] | string, config: Config) { constructor(buildSystem: BuildSystem, platforms: Platform[] | Platform, config: Config) {
this.buildSystem = buildSystem; this.buildSystem = buildSystem;
this.platforms = Array.isArray(platforms) ? platforms : [platforms]; this.platforms = Array.isArray(platforms) ? platforms : [platforms];
this.config = config; this.config = config;
@@ -34,23 +28,23 @@ export class Project {
return false; return false;
} }
build(platform: string, debug: boolean = false): Task[] { 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.buildSystem, debug);
const tasks: Task[] = [builder.prepare.bind(builder)]; const tasks: Task[] = [builder.prepare.bind(builder)];
tasks.push(builder.call.bind(builder)); tasks.push(builder.call.bind(builder));
return tasks; return tasks;
} }
run(platform: string, debug: boolean = false): Task[] { run(platform: Platform, debug: boolean = false): Task[] {
const runner = Runner.new(this.config, platform, debug); const runner = Runner.new(this.config, platform, debug);
return [runner.prepare.bind(runner), runner.call.bind(runner)]; return [runner.prepare.bind(runner), runner.call.bind(runner)];
} }
test(platform: string, debug: boolean = true): Task[] { test(platform: Platform, debug: boolean = true): Task[] {
return this.build(platform, debug).concat(this.run(platform, debug)); return this.build(platform, debug).concat(this.run(platform, debug));
} }
pack(platform: string, name: string) { pack(platform: Platform, name: string) {
const packer = Packer.new(this.config, platform, name); const packer = Packer.new(this.config, platform, name);
return [packer.prepare.bind(packer), packer.call.bind(packer)]; return [packer.prepare.bind(packer), packer.call.bind(packer)];
} }
+15 -13
View File
@@ -1,14 +1,14 @@
import dateformat from "dateformat"; import dateformat from "dateformat";
import gulp from "gulp"; import gulp from "gulp";
import gulpClean from "gulp-clean"; import gulpClean from "gulp-clean";
import template from "lodash.template";
import os from "os"; import os from "os";
import type { Task } from "undertaker"; import type { Task } from "undertaker";
import { Builder, Project } from "."; import { Builder, Project } from ".";
import { System } from "../common/system"; import { System } from "../common/system";
import { Config, type ConfigParams } from "../core/config"; import template from "../common/template";
import { Config, type ConfigParams, type SignKey } from "../core/config";
import { Sdk } from "../core/sdk"; import { Sdk } from "../core/sdk";
import { Platform } from "../core/type"; import { BuildSystem, Platform } from "../core/type";
import { Haxe } from "../impl/haxe"; import { Haxe } from "../impl/haxe";
export interface PresetConfig { export interface PresetConfig {
@@ -16,7 +16,7 @@ export interface PresetConfig {
BuildDir?: string; BuildDir?: string;
Develop?: boolean; Develop?: boolean;
UseRuffle?: boolean; UseRuffle?: boolean;
Key?: any; Key?: SignKey;
} }
export const DEFAULT_CONFIG: PresetConfig = { export const DEFAULT_CONFIG: PresetConfig = {
@@ -24,8 +24,8 @@ export const DEFAULT_CONFIG: PresetConfig = {
}; };
export interface ProjectPreset { export interface ProjectPreset {
buildSystem?: string; buildSystem?: BuildSystem;
platforms?: string[]; platforms?: Platform[];
config: ConfigParams; config: ConfigParams;
} }
@@ -44,9 +44,13 @@ export class Preset {
} }
private fillPreset(preset: ProjectPreset): ProjectPreset { private fillPreset(preset: ProjectPreset): ProjectPreset {
const configTemplate = template(JSON.stringify(preset));
return JSON.parse( return JSON.parse(
configTemplate({ config: this.config, package: this.packageInfo, env: process.env, dateformat: dateformat }), template.renderString(JSON.stringify(preset), {
config: this.config,
package: this.packageInfo,
env: process.env,
dateformat: dateformat,
}),
); );
} }
@@ -75,10 +79,6 @@ export class Preset {
Project.useRuffle(); Project.useRuffle();
} }
if (this.packageInfo.haxe) {
Haxe.VERSION = this.packageInfo.haxe;
}
if (this.config.SdkDir) { if (this.config.SdkDir) {
Sdk.dir = resolvePath(this.config.SdkDir); Sdk.dir = resolvePath(this.config.SdkDir);
} }
@@ -170,6 +170,8 @@ export class Preset {
} }
} }
return _gulp.series(defaultSeries); const defaultTask = _gulp.series(defaultSeries);
_gulp.task("default", defaultTask);
return defaultTask;
} }
} }
+8 -5
View File
@@ -1,10 +1,10 @@
import colors from "ansi-colors"; import colors from "ansi-colors";
import cp from "child_process"; import cp from "child_process";
import { defaults, template } from "lodash";
import path from "path"; import path from "path";
import stream from "stream"; import stream from "stream";
import util from "util"; import util from "util";
import Vinyl from "vinyl"; import Vinyl from "vinyl";
import template from "../common/template";
export class Command { export class Command {
private command: string; private command: string;
@@ -14,12 +14,15 @@ export class Command {
constructor(command: string, options?: any) { constructor(command: string, options?: any) {
this.command = command; this.command = command;
this.isWindows = process.platform.lastIndexOf("win") === 0; this.isWindows = process.platform.lastIndexOf("win") === 0;
this.options = defaults(options || {}, { this.options = Object.assign(
{
cwd: process.cwd(), cwd: process.cwd(),
env: process.env, env: process.env,
verbosity: options && options.silent ? 1 : 2, verbosity: options && options.silent ? 1 : 2,
usePowerShell: false, usePowerShell: false,
}); },
options || {},
);
let previousPath; let previousPath;
previousPath = this.options.env.PATH; previousPath = this.options.env.PATH;
@@ -28,7 +31,7 @@ export class Command {
this.options.env.PATH += previousPath; this.options.env.PATH += previousPath;
} }
exec(stdin?: any, callback?: any) { exec(stdin?: any, callback?: any): Vinyl<stream.Stream> {
let fileName; let fileName;
let directory; let directory;
let subShell; let subShell;
@@ -69,7 +72,7 @@ export class Command {
// execute the command. // execute the command.
// we spawn the command in a subshell, so things like i/o redirection // we spawn the command in a subshell, so things like i/o redirection
// just work. e.g. `echo hello world >> ./hello.txt` works as expected. // just work. e.g. `echo hello world >> ./hello.txt` works as expected.
const command = template(this.command)({ const command = template.renderString(this.command, {
file: stdin, file: stdin,
}); });
+2 -2
View File
@@ -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 { Downloader } from "../dist/index.mjs"; import { download } from "../dist/index.mjs";
const resolveTargetDir = () => mkdtempSync(join(tmpdir(), "test-")); const resolveTargetDir = () => mkdtempSync(join(tmpdir(), "test-"));
@@ -16,7 +16,7 @@ const TEST_DATA = {
for (const [url, file] of Object.entries(TEST_DATA)) { for (const [url, file] of Object.entries(TEST_DATA)) {
test(`Test download: ${url}`, async () => { test(`Test download: ${url}`, async () => {
const target = resolveTargetDir(); const target = resolveTargetDir();
await Downloader.download(url, target); await download(url, target);
assert(existsSync(join(target, file))); assert(existsSync(join(target, file)));
}); });
} }
+10 -1
View File
@@ -1,9 +1,18 @@
import { defineConfig } from "tsdown"; import { defineConfig } from "tsdown";
export default defineConfig({ export default defineConfig({
entry: {
"bin/cli": "src/cli.ts",
"lib/index": "src/index.ts",
},
copy: ["haxetool.schema.json"],
dts: { dts: {
tsgo: true, tsgo: true,
}, },
exports: true, exports: {
bin: {
hxt: "src/cli.ts",
},
},
sourcemap: true, sourcemap: true,
}); });