Files
puzzlez/gulpfile.ts
T

151 lines
3.5 KiB
TypeScript

import dateformat from "dateformat";
import gulp from "gulp";
import gulpClean from "gulp-clean";
import { Builder, Config, Haxe, Project, Sdk, System } from "gulp-haxetool";
import os from "os";
import yargs from "yargs";
import config from "./config.json" with { type: "json" };
import packageInfo from "./package.json" with { type: "json" };
const argv = yargs.argv;
const resolvePath = (path: string) => path.replace("$HOME", os.homedir());
Project.useRuffle();
if (packageInfo.haxe) {
Haxe.VERSION = packageInfo.haxe;
}
if (config.SdkDir) {
Sdk.dir = resolvePath(config.SdkDir);
}
if (config.BuildDir) {
Haxe.buildDir = resolvePath(config.BuildDir);
}
gulp.task("clean", () => {
return gulp.src("target/*", { read: false }).pipe(gulpClean());
});
gulp.task("setup", () => {
const builder = Builder.new(
app.config,
Project.Platform.ANDROID,
app.buildSystem,
);
return builder.prepare();
});
gulp.task(
"generate",
gulp.series([
gulp.task("setup"),
() =>
new Haxe()
.haxelib(["run", "protohx", "generate", "protohx.json"])
.then((result: any) => {
if (result.stdout.indexOf("FAIL") > -1) {
throw result.stdout;
}
}),
]),
);
const projectConfig = new Config({
meta: {
title: "Puzzle'z",
filename: "puzzlez",
icon: "src/app/resources/icon.png",
pack: "ru.m.puzzlez",
author: "shmyga <shmyga.z@gmail.com>",
company: "MegaLoMania",
version: packageInfo.version + (config.Develop ? "-SNAPSHOT" : ""),
},
key: config.Key,
libs: packageInfo.haxeDependencies,
macros: [
`CompilationOption.set('build','${dateformat(new Date(), "yyyy-mm-dd HH:MM:ss")}')`,
`CompilationOption.set('UNSPLASH_KEY','${config.UnsplashKey}')`,
`CompilationOption.set('PIXABAY_KEY','${config.PixabayKey}')`,
],
flags: ["proto_debug"],
});
const host = argv.host || "localhost";
const port = argv.port || 5000;
const app = new Project(
Project.BuildSystem.OPENFL,
[
Project.Platform.FLASH,
Project.Platform.HTML5,
Project.Platform.LINUX,
Project.Platform.WINDOWS,
Project.Platform.ANDROID,
],
projectConfig.branch({
name: "app",
sources: ["src-gen/haxe", "src/common/haxe", "src/app/haxe"],
android: [
{
path: "dependencies/android",
extensions: ["ru.m.android.FileUtil"],
},
],
assets: ["src/app/resources"],
main: "ru.m.puzzlez.PuzzlezApp",
meta: {
width: 1280,
height: 768,
},
macros: [
`CompilationOption.set('host','${host}')`,
`CompilationOption.set('port',${port})`,
],
flags: ["app"],
}),
);
app.register(gulp);
const server = new Project(
Project.BuildSystem.HAXE,
[Project.Platform.NEKO, Project.Platform.CPP],
projectConfig.branch({
name: "server",
sources: ["src-gen/haxe", "src/common/haxe", "src/server/haxe"],
main: "ru.m.puzzlez.PuzzlezServer",
}),
);
server.register(gulp);
const defaultSeries = [
gulp.task("clean"),
gulp.task("generate"),
gulp.task("app:flash:build"),
gulp.task("app:flash:html"),
gulp.task("app:html5:build"),
];
if (System.isLinux) {
defaultSeries.push(
gulp.task("app:linux:build"),
gulp.task("app:linux:archive"),
gulp.task("app:linux:deb"),
gulp.task("app:android:build"),
);
}
if (System.isWindows) {
defaultSeries.push(
gulp.task("app:windows:build"),
gulp.task("app:windows:archive"),
gulp.task("app:windows:installer"),
);
}
export default gulp.series(defaultSeries);