diff --git a/.gitignore b/.gitignore index c08ef50..d6e6f8f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.idea -/node_modules +node_modules/ +target/ package-lock.json \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..108492e --- /dev/null +++ b/README.md @@ -0,0 +1,170 @@ +# Gulp HaXe Tool + +## Introducing + +### Dignity + +* Automatically download HaXe SDK, FlashPlayer, Adobe AIR SDK. +* Universal project config for simple HaXe build and OpenFL build. +* Branch project config for many build presets (many OpenFL apps in one project). +* Packaging linux output in DEB. +* Create html wrapper for flash output. + +### Flaws + +* Hardcode build output in {projectDir}/target (need param in Project.Config). +* HTML5 run output not caught. +* Adobe AIR Build System in progress. +* Packaging Windows application in progress (with [Inno Setup](http://www.jrsoftware.org/isinfo.php)) + +### Dependencies + +* [Neko VM](https://nekovm.org/download/) + + +## API + +### Project.Config + +#### constructor + +* **meta**: meta information + * **title**: application title + * **filename**: application filename + * **icon**: path to icon file + * **pack**: package name for OpenFL + * **author**: author name for DEB packaging + * **company**: company name for OpenFL + * **version**: application version +* **name**: name for output directory +* **libs**: list of haxe dependencies +* **sources**: list of HaXe sources +* **assets**: list of resources +* **main**: main class name +* **macros**: list of macros + +### Project + +#### constructor + +* **buildSystem**: Project.BuildSystem +* **platforms**: Project.Platform (list supported) +* **config**: Project.Config + +#### bind + +* **module** + +create gulp tasks in module: + +``` +::build +::run +::pack (optionaly if supported) +``` + +eg: ```gulp app:flash:build``` + +## Example + +[package.json](example/package.json) +```json +{ + "name": "app", + "version": "0.0.1", + "devDependencies": { + "gulp": "^4.0.0", + "gulp-clean": "^0.4.0", + "gulp-haxetool": "file:../../gulp-haxetool" + }, + "haxeDependencies": { + "lime": "6.0.1", + "openfl": "7.0.0", + "hxcpp": "3.4.188" + } +} +``` + +[src/Main.hx](example/src/Main.hx) +```haxe +import flash.display.Shape; +import flash.Lib; + +class Main { + + public static function main() { + trace("Hello world!"); + var shape = new Shape(); + shape.graphics.beginFill(0x00ff00); + shape.graphics.drawCircle(50, 50, 20); + shape.graphics.endFill(); + Lib.current.addChild(shape); + } +} +``` + +[gulpfile.js](example/gulpfile.js) +```javascript +const gulp = require('gulp'); +const gulpClean = require('gulp-clean'); +const packageInfo = require('./package.json'); +const {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 ', + 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, + ], + config +).bind(module, gulp); + +module.exports.default = gulp.series( + exports.clean, + exports.install, + module.exports['app:flash:build'], + module.exports['app:html5:build'], + module.exports['app:linux:build'], + module.exports['app:flash:pack'], + module.exports['app:linux:pack'], +); +``` + +Build for all platforms: `gulp default` + +Build app for specific platform: `gulp app:flash:build` + +Run flash app in flashplayer: `gulp app:flash:run` + +Run html5 app in brpwser: `gulp app:html5:tun` + +Run linux app native: `gulp app:linux:run` diff --git a/example/gulpfile.js b/example/gulpfile.js new file mode 100644 index 0000000..91fb93c --- /dev/null +++ b/example/gulpfile.js @@ -0,0 +1,52 @@ +const gulp = require('gulp'); +const gulpClean = require('gulp-clean'); +const packageInfo = require('./package.json'); +const {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 ', + 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, + ], + config +).bind(module, gulp); + +module.exports.default = gulp.series( + exports.clean, + exports.install, + module.exports['app:flash:build'], + module.exports['app:html5:build'], + module.exports['app:linux:build'], + module.exports['app:flash:pack'], + module.exports['app:linux:pack'], +); \ No newline at end of file diff --git a/example/package.json b/example/package.json new file mode 100644 index 0000000..967c901 --- /dev/null +++ b/example/package.json @@ -0,0 +1,14 @@ +{ + "name": "app", + "version": "0.0.1", + "devDependencies": { + "gulp": "^4.0.0", + "gulp-clean": "^0.4.0", + "gulp-haxetool": "file:../../gulp-haxetool" + }, + "haxeDependencies": { + "lime": "6.0.1", + "openfl": "7.0.0", + "hxcpp": "3.4.188" + } +} diff --git a/example/resources/icon.jpg b/example/resources/icon.jpg new file mode 100644 index 0000000..7dbb6ef Binary files /dev/null and b/example/resources/icon.jpg differ diff --git a/example/src/Main.hx b/example/src/Main.hx new file mode 100644 index 0000000..5fc3433 --- /dev/null +++ b/example/src/Main.hx @@ -0,0 +1,14 @@ +import flash.display.Shape; +import flash.Lib; + +class Main { + + public static function main() { + trace("Hello world!"); + var shape = new Shape(); + shape.graphics.beginFill(0x00ff00); + shape.graphics.drawCircle(50, 50, 20); + shape.graphics.endFill(); + Lib.current.addChild(shape); + } +} \ No newline at end of file diff --git a/haxetool/core.js b/haxetool/core.js index c722d12..fc02ac1 100644 --- a/haxetool/core.js +++ b/haxetool/core.js @@ -28,6 +28,7 @@ class Config { this.assets = []; this.libs = []; this.macros = []; + this.icon = null; this.meta = { title: null, filename: null, @@ -45,13 +46,14 @@ class Config { update(params) { this._params.push(params); if (params.name !== undefined) this.name = params.name; - if (params.name !== undefined) this.main = params.main; + if (params.main !== undefined) this.main = params.main; const cwd = process.cwd(); if (params.sources !== undefined) this.sources = this.sources.concat(params.sources.map(item => path.resolve(cwd, item))); if (params.assets !== undefined) this.assets = this.assets.concat(params.assets.map(item => path.resolve(cwd, item))); if (params.libs !== undefined) this.libs = this.libs.concat(Array.isArray(params.libs) ? params.libs : Object.entries(params.libs).map(([k, v]) => ({name: k, version: v}))); if (params.macros !== undefined) this.macros = this.macros.concat(params.macros); if (params.meta !== undefined) this.meta = {...this.meta, ...params.meta}; + if (this.meta.icon) this.icon = path.resolve(cwd, this.meta.icon) } branch(params) { diff --git a/haxetool/haxe.js b/haxetool/haxe.js index 1bc1d71..4974ead 100755 --- a/haxetool/haxe.js +++ b/haxetool/haxe.js @@ -22,7 +22,9 @@ class Haxe extends Sdk { return `${this.binPath}/${name}.exe`; } else if (Sdk.System.isLinux) { const binPath = `${this.binPath}/${name}`; - fs.chmodSync(binPath, 0o755); + if (fs.existsSync(binPath)) { + fs.chmodSync(binPath, 0o755); + } return binPath; } throw `Unsupported OS: ${os.type()}`; diff --git a/package.json b/package.json index ead7cc3..663f663 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gulp-haxetool", - "version": "0.0.7", - "description": "Haxe tool for gulp", + "version": "0.0.8", + "description": "HaXe Tool for Gulp", "main": "index.js", "dependencies": { "ansi-colors": "^1.1.0", diff --git a/template/project.xml b/template/project.xml index 3f960e5..0a7e1bb 100644 --- a/template/project.xml +++ b/template/project.xml @@ -2,6 +2,7 @@ + <% sources.forEach(function(item) { %> <% }); %> <% assets.forEach(function(item) { %>