@@ -0,0 +1,16 @@
|
||||
import { Config } from "../core/config";
|
||||
import { Project } from "../project";
|
||||
import type { PresetBundle } from "./type";
|
||||
|
||||
export default (preset: PresetBundle): Project[] => {
|
||||
const config = new Config(preset["default"]?.config || {});
|
||||
const projects: Project[] = [];
|
||||
for (const [k, v] of Object.entries(preset)) {
|
||||
if (k == "default") {
|
||||
continue;
|
||||
}
|
||||
const projectConfig = config.branch({ ...v.config, name: k });
|
||||
projects.push(new Project(v.buildSystem!, v.platforms!, projectConfig));
|
||||
}
|
||||
return projects;
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./type";
|
||||
@@ -0,0 +1,63 @@
|
||||
import dateformat from "dateformat";
|
||||
import fs from "fs";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import template from "../common/template";
|
||||
import { Sdk } from "../core/sdk";
|
||||
import { Haxe } from "../impl/haxe";
|
||||
import { Project } from "../project";
|
||||
import type { ConfigJson, PackageJson, Preset, PresetBundle } from "./type";
|
||||
|
||||
export const DEFAULT_CONFIG: ConfigJson = {
|
||||
SdkDir: "$HOME/sdk",
|
||||
};
|
||||
|
||||
export const resolvePath = (path: string) => path.replace("$HOME", os.homedir());
|
||||
|
||||
export const applyConfig = (config: ConfigJson) => {
|
||||
if (config.UseRuffle) {
|
||||
Project.useRuffle();
|
||||
}
|
||||
if (config.SdkDir) {
|
||||
Sdk.dir = resolvePath(config.SdkDir);
|
||||
}
|
||||
if (config.BuildDir) {
|
||||
Haxe.buildDir = resolvePath(config.BuildDir);
|
||||
}
|
||||
};
|
||||
|
||||
export default (basedir: string = "."): PresetBundle => {
|
||||
const presetFile = path.join(basedir, "haxetool.json");
|
||||
const configFile = path.join(basedir, "config.json");
|
||||
const packageFile = path.join(basedir, "package.json");
|
||||
const presetJson: PresetBundle = JSON.parse(fs.readFileSync(presetFile, "utf8"));
|
||||
const configJson: ConfigJson = {
|
||||
...DEFAULT_CONFIG,
|
||||
...(fs.existsSync(configFile) ? JSON.parse(fs.readFileSync(configFile, "utf8")) : {}),
|
||||
};
|
||||
applyConfig(configJson);
|
||||
const packageJson: PackageJson = fs.existsSync(packageFile) ? JSON.parse(fs.readFileSync(packageFile, "utf8")) : {};
|
||||
for (const [k, v] of Object.entries(presetJson)) {
|
||||
presetJson[k] = JSON.parse(
|
||||
template.renderString(JSON.stringify(v), {
|
||||
config: configJson,
|
||||
package: packageJson,
|
||||
env: process.env,
|
||||
dateformat: dateformat,
|
||||
}),
|
||||
);
|
||||
}
|
||||
const defaultPreset: Preset = presetJson["default"] || { config: {} };
|
||||
defaultPreset.config.meta = {
|
||||
...{
|
||||
title: packageJson.name,
|
||||
filename: packageJson.name,
|
||||
version: packageJson.version,
|
||||
pack: `com.${packageJson.name}`,
|
||||
author: packageJson.author as string,
|
||||
},
|
||||
...(defaultPreset.config.meta || {}),
|
||||
};
|
||||
presetJson["default"] = defaultPreset;
|
||||
return presetJson;
|
||||
};
|
||||
@@ -0,0 +1,93 @@
|
||||
import defaultGulp from "gulp";
|
||||
import gulpClean from "gulp-clean";
|
||||
import type { Task } from "undertaker";
|
||||
import { System } from "../common/system";
|
||||
import { Platform } from "../core/type";
|
||||
import { Haxe } from "../impl/haxe";
|
||||
import { Builder, type Project } from "../project";
|
||||
|
||||
export default (projects: Project[], gulp?: defaultGulp.Gulp): Task => {
|
||||
if (!gulp) {
|
||||
gulp = defaultGulp;
|
||||
}
|
||||
|
||||
gulp.task("clean", () => {
|
||||
return gulp.src("target/*", { read: false }).pipe(gulpClean());
|
||||
});
|
||||
|
||||
const project = projects[0];
|
||||
|
||||
gulp.task("setup", () => {
|
||||
return Promise.all(
|
||||
project.platforms.map((platform) => Builder.new(project.config, platform, project.buildSystem).prepare()),
|
||||
);
|
||||
});
|
||||
|
||||
const protohx = project.hasLib("protohx");
|
||||
if (protohx) {
|
||||
gulp.task("protohx:generate", () =>
|
||||
new Haxe().haxelib(["run", "protohx", "generate", "protohx.json"]).then((result: any) => {
|
||||
if (result.stdout.indexOf("FAIL") > -1) {
|
||||
throw result.stdout;
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
for (const project of projects) {
|
||||
project.register(gulp);
|
||||
}
|
||||
|
||||
const defaultSeries: Task[] = [gulp.task("clean")!, gulp.task("setup")!];
|
||||
|
||||
if (protohx) {
|
||||
defaultSeries.push(gulp.task("protohx:generate")!);
|
||||
}
|
||||
|
||||
for (const project of projects) {
|
||||
for (const platform of project.platforms) {
|
||||
switch (platform) {
|
||||
case Platform.FLASH:
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:html`)!);
|
||||
break;
|
||||
case Platform.HTML5:
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
break;
|
||||
case Platform.LINUX:
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:archive`)!);
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:deb`)!);
|
||||
}
|
||||
break;
|
||||
case Platform.CPP:
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
}
|
||||
break;
|
||||
case Platform.NEKO:
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
}
|
||||
break;
|
||||
case Platform.ANDROID:
|
||||
if (System.isLinux) {
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
}
|
||||
break;
|
||||
case Platform.WINDOWS:
|
||||
if (System.isWindows) {
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:build`)!);
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:archive`)!);
|
||||
defaultSeries.push(gulp.task(`${project.config.name}:${platform}:installer`)!);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const defaultTask = gulp.series(defaultSeries);
|
||||
gulp.task("default", defaultTask);
|
||||
return defaultTask;
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
import type { ConfigParams, SignKey } from "../core/config";
|
||||
import type { BuildSystem, Platform } from "../core/type";
|
||||
|
||||
export type PackageJson = Record<string, any>;
|
||||
|
||||
export interface ConfigJson {
|
||||
SdkDir?: string;
|
||||
BuildDir?: string;
|
||||
Develop?: boolean;
|
||||
UseRuffle?: boolean;
|
||||
Key?: SignKey;
|
||||
}
|
||||
|
||||
export interface Preset {
|
||||
buildSystem?: BuildSystem;
|
||||
platforms?: Platform[];
|
||||
config: ConfigParams;
|
||||
}
|
||||
|
||||
export type PresetBundle = Record<string, Preset>;
|
||||
@@ -0,0 +1,13 @@
|
||||
import Ajv from "ajv";
|
||||
import fs from "fs";
|
||||
import asset from "../common/asset";
|
||||
import type { PresetBundle } from "./type";
|
||||
|
||||
export default (preset: PresetBundle) => {
|
||||
const ajv = new Ajv();
|
||||
const presetSchema = ajv.compile(JSON.parse(fs.readFileSync(asset("haxetool.schema.json"), "utf-8")));
|
||||
const valid = presetSchema(preset);
|
||||
if (!valid) {
|
||||
throw presetSchema.errors;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user