diff --git a/config.example.json b/config.example.json index 41316a7..658169f 100644 --- a/config.example.json +++ b/config.example.json @@ -1,8 +1,6 @@ { "SdkDir": "$HOME/sdk", "BuildDir": null, - "PublishDir": "$HOME/public/puzzlez", - "PublishUrl": "https://shmyga.ru/repo/puzzlez", "Develop": false, "Key": { "store": "keystore.jks", diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 5880426..0000000 --- a/gulpfile.js +++ /dev/null @@ -1,152 +0,0 @@ -const gulp = require("gulp"); -const gulpClean = require("gulp-clean"); -const Config = require("./config.json"); -const packageInfo = require("./package.json"); -const { System, Sdk, Haxe, Project } = require("gulp-haxetool"); -const dateformat = require("dateformat"); -const argv = require("yargs").argv; -const publish = require("./tasks/gulp-publish"); -const os = require("os"); - -const resolvePath = (path) => 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); -} - -exports.clean = function clean() { - return gulp.src("target/*", { read: false }).pipe(gulpClean()); -}; - -exports.setup = function setup() { - const builder = Project.Builder.new( - app.config, - Project.Platform.ANDROID, - app.buildSystem, - ); - return builder.prepare(); -}; - -exports.generate = function generate() { - return exports.setup().then(() => - new Haxe() - .haxelib(["run", "protohx", "generate", "protohx.json"]) - .then(({ stdout }) => { - if (stdout.indexOf("FAIL") > -1) { - throw stdout; - } - }), - ); -}; - -const config = new Project.Config({ - meta: { - title: "Puzzle'z", - filename: "puzzlez", - icon: "src/app/resources/icon.png", - pack: "ru.m.puzzlez", - author: "shmyga ", - 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, - ], - config.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"], - }), -).bind(module, gulp); - -const server = new Project( - Project.BuildSystem.HAXE, - [Project.Platform.NEKO, Project.Platform.CPP], - config.branch({ - name: "server", - sources: ["src-gen/haxe", "src/common/haxe", "src/server/haxe"], - main: "ru.m.puzzlez.PuzzlezServer", - }), -).bind(module, gulp); - -module.exports.publish = publish( - packageInfo.name, - packageInfo.version, - resolvePath(Config.PublishDir), - Config.PublishUrl, -); - -const defaultSeries = [ - exports.clean, - exports.generate, - 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"], - ); -} - -defaultSeries.push(exports.publish); - -module.exports.default = gulp.series(defaultSeries); diff --git a/gulpfile.ts b/gulpfile.ts new file mode 100644 index 0000000..ba08b0a --- /dev/null +++ b/gulpfile.ts @@ -0,0 +1,150 @@ +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 ", + 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); diff --git a/package.json b/package.json index 4f472ea..3097730 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "puzzlez", + "type": "module", "version": "0.6.2", "scripts": { "build": "gulp", diff --git a/tasks/gulp-publish.js b/tasks/gulp-publish.js deleted file mode 100755 index 0b1c729..0000000 --- a/tasks/gulp-publish.js +++ /dev/null @@ -1,134 +0,0 @@ -const gulp = require("gulp"); -const fs = require("fs"); -const fse = require("fs-extra"); -const path = require("path"); -const through = require("through2"); - -class Package { - constructor(platform, type, version, versionInt) { - this.platform = platform; - this.type = type; - this.version = version; - this.versionInt = versionInt; - } - - get key() { - return [this.platform, this.type].join(":"); - } - - static getPlatform(filename) { - for (const [platform, r] of [ - ["android", /^.*?\.apk$/], - ["linux", /^.*?\.deb$/], - ["linux", /^.*?linux\.tar\.gz$/], - ["windows", /^.*?win\.zip$/], - ["windows", /^.*?\.exe$/], - ]) { - if (r.test(filename)) { - return platform; - } - } - return null; - } - - static getType(filename) { - for (const [type, r] of [ - ["apk", /^.*?\.apk$/], - ["deb", /^.*?\.deb$/], - ["archive", /^.*?\.tar\.gz$/], - ["archive", /^.*?\.zip$/], - ["exe", /^.*?\.exe$/], - ]) { - if (r.test(filename)) { - return type; - } - } - return null; - } - - static getVersion(filename) { - const m = /(\d+)\.(\d+)\.(\d+)/.exec(filename); - if (m) { - return [ - m[0], - parseInt(m[1]) * 10000 + parseInt(m[2]) * 100 + parseInt(m[3]), - ]; - } - return null; - } - - static parseFilename(filename) { - const platform = this.getPlatform(filename); - const type = this.getType(filename); - const version = this.getVersion(filename); - if (platform && type && version) { - return new Package(platform, type, version[0], version[1]); - } - return null; - } -} - -module.exports = (name, version, publishDir, publishUrl) => - function publish(cb) { - const packages = {}; - fse.ensureDirSync(publishDir); - return gulp.series([ - function copy() { - return gulp - .src("target/app/@(android|archive|debian|installer)/*") - .pipe( - through.obj(function (file, enc, cb) { - const pack = Package.parseFilename(file.path); - if (pack) { - this.push(file); - } - cb(null); - }) - ) - .pipe(gulp.dest(publishDir)); - }, - function generate() { - return gulp - .src(`${publishDir}/*/*`) - .pipe( - through.obj(function (file, enc, cb) { - const basepath = file.path.replace(file.base + path.sep, ""); - const pack = Package.parseFilename(file.path); - if (pack) { - if ( - !packages[pack.key] || - packages[pack.key].versionInt < pack.versionInt - ) { - packages[pack.key] = { - platform: pack.platform, - type: pack.type, - version: pack.version, - versionInt: pack.versionInt, - path: basepath, - filename: basepath.split(path.sep).pop(), - url: `${publishUrl}/${basepath.replace(path.sep, "/")}`, - }; - } - } - cb(null); - }) - ) - .on("end", function () { - fs.writeFileSync( - path.join(publishDir, "packages.json"), - JSON.stringify( - { - name: name, - version: version, - packages: Object.values(packages), - }, - null, - 4 - ) - ); - }); - }, - ])(cb); - }; - -module.exports.Package = Package;