+62
@@ -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();
|
||||
@@ -13,6 +13,7 @@ export interface ConfigParams {
|
||||
meta?: ConfigMeta;
|
||||
key?: SignKey;
|
||||
android?: AndroidPreset[];
|
||||
haxe?: string;
|
||||
}
|
||||
|
||||
export interface ConfigMeta {
|
||||
@@ -60,6 +61,7 @@ export class Config {
|
||||
public meta: ConfigMeta;
|
||||
public key: SignKey | null;
|
||||
public android: AndroidPreset[];
|
||||
public haxe: string | null;
|
||||
|
||||
private _params: ConfigParams[];
|
||||
|
||||
@@ -81,6 +83,7 @@ export class Config {
|
||||
};
|
||||
this.key = null;
|
||||
this.android = [];
|
||||
this.haxe = null;
|
||||
if (params) {
|
||||
this.update(params);
|
||||
this.afterUpdate();
|
||||
@@ -113,6 +116,7 @@ export class Config {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ export class HaxeBuilder extends Builder {
|
||||
|
||||
constructor(config: Config, platform: Platform, buildSystem: BuildSystem, debug: boolean = false) {
|
||||
super(config, platform, buildSystem, debug);
|
||||
this.haxe = new Haxe();
|
||||
this.haxe = new Haxe(config.haxe ? config.haxe : undefined);
|
||||
this.android = new Android();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,12 +9,6 @@ import { RuffleRunner } from "./impl/runner/ruffle";
|
||||
export * from "./core";
|
||||
|
||||
export class Project {
|
||||
// TODO: compatibility
|
||||
static Config = Config;
|
||||
static BuildSystem = BuildSystem;
|
||||
static Platform = Platform;
|
||||
static Builder = Builder;
|
||||
|
||||
public buildSystem: BuildSystem;
|
||||
public platforms: Platform[];
|
||||
public config: Config;
|
||||
|
||||
@@ -79,10 +79,6 @@ export class Preset {
|
||||
Project.useRuffle();
|
||||
}
|
||||
|
||||
if (this.packageInfo.haxe) {
|
||||
Haxe.VERSION = this.packageInfo.haxe;
|
||||
}
|
||||
|
||||
if (this.config.SdkDir) {
|
||||
Sdk.dir = resolvePath(this.config.SdkDir);
|
||||
}
|
||||
@@ -174,6 +170,8 @@ export class Preset {
|
||||
}
|
||||
}
|
||||
|
||||
return _gulp.series(defaultSeries);
|
||||
const defaultTask = _gulp.series(defaultSeries);
|
||||
_gulp.task("default", defaultTask);
|
||||
return defaultTask;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user