From 8c5179fdb5856cf6474aa58c3effc51ccf4e136f Mon Sep 17 00:00:00 2001 From: shmyga Date: Tue, 3 Apr 2018 17:02:14 +0300 Subject: [PATCH] [haxe,flashplayer] fixes --- haxetool/flashplayer.js | 12 ++++------- haxetool/haxe.js | 44 ++++++++++++----------------------------- package.json | 11 ++++++++--- 3 files changed, 25 insertions(+), 42 deletions(-) diff --git a/haxetool/flashplayer.js b/haxetool/flashplayer.js index 940e823..5a52b78 100755 --- a/haxetool/flashplayer.js +++ b/haxetool/flashplayer.js @@ -3,12 +3,12 @@ const fs = require('fs'); const fse = require('fs-extra'); const os = require('os'); const through = require('through2'); -const gulp = require('gulp'); const Sdk = require('./sdk'); const exec = require('./exec'); const PluginError = require('plugin-error'); const colors = require('ansi-colors'); const log = require('fancy-log'); +const tar = require('tar'); class FlashPlayer extends Sdk { @@ -18,9 +18,7 @@ class FlashPlayer extends Sdk { } playerPath(debug) { - const v = this.version.split('.'); - const dir = `${v[0]}_${v[1]}_r${v[2]}_${v[3]}`; - return `${this.path}/${dir}${debug ? '_debug': ''}`; + return this.path; } prepare() { @@ -34,13 +32,11 @@ class FlashPlayer extends Sdk { const extract = (debug) => { const v = this.version.split('.'); const playerPath = this.playerPath(debug); - // ToDo: fix const archive = `${playerPath}/flashplayer${v[0]}_${v[1]}r${v[2]}_${v[3]}_linux_sa${debug ? '_debug' : ''}.${arch}.tar.gz`; - return gulp.src(archive) - .pipe(gunzip()).pipe(untar()) - .pipe(gulp.dest(playerPath)); + return fs.createReadStream(archive).pipe(tar.x({C: this.path})); }; + // ToDo: return new Promise((success, fail) => { extract().on('end', () => { extract(true).on('end', success).on('error', fail) diff --git a/haxetool/haxe.js b/haxetool/haxe.js index 36de769..61d05ca 100755 --- a/haxetool/haxe.js +++ b/haxetool/haxe.js @@ -5,7 +5,6 @@ const tmp = require('tmp-file'); const exec = require('./exec'); const through = require('through2'); const Sdk = require('./sdk'); -const dateformat = require('dateformat'); const Vinyl = require('vinyl'); const PluginError = require('plugin-error'); const colors = require('ansi-colors'); @@ -24,7 +23,7 @@ class Haxe extends Sdk { fs.chmodSync(binPath, 0o755); return binPath; } - return `` + throw `Unsupported OS: ${os.type()}`; } get binPath() { @@ -140,14 +139,15 @@ class Haxe extends Sdk { * command: 'build', * platform: 'flash', * version: '1.0.0', - * build: '1999.12.12 00:00', * values: {}, + * macro: [], * outputFile: 'out.swf', * } */ openfl(params) { params = Object.assign({ - build: dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss'), + version: null, + values: {}, macro: [], debug: false, }, params); @@ -164,7 +164,10 @@ class Haxe extends Sdk { const endStream = (callback) => { log(this.tag, colors.cyan(`openfl ${params.command} ${params.platform}`)); const args = ['-cwd', files[0].path, 'run', 'openfl', params.command, params.platform]; - if (params.values) for (let key of Object.keys(params.values)) { + for (const macro of params.macro) { + args.push(`--haxeflag="--macro ${macro}"`); + } + for (let key of Object.keys(params.values)) { const value = params.values[key]; if (value === true) { args.push(`-D${key}`); @@ -178,24 +181,13 @@ class Haxe extends Sdk { args.push(`--app-file=${params.outputFile}`); } if (params.version) args.push(`--meta-version=${params.version}`); - //if (params.build) args.push(`--haxedef=BUILD="${params.build}"`); - args.push(`--haxeflag="--macro CompilationOption.set('build','${params.build}')"`); - let debug = null; if (params.debug) { - debug = { - host: 'localhost', - port: 6000 + Math.floor(Math.random() * 1000), - }; - args.push(`--haxeflag="--macro CompilationOption.set('debug.address','${debug.host}')"`); - args.push(`--haxeflag="--macro CompilationOption.set('debug.port','${debug.port}')"`); args.push('-debug'); } - //console.log('haxelib', args.join(' ')); const target = `${buildDir}/${params.platform}/bin`; rmdir(target); this.haxelib(args).then(() => { vfs.src(`${target}/**/*`).pipe(through.obj((file, enc, cb) => { - file.debug = debug; stream.push(file); cb(); }, (cb) => { @@ -219,18 +211,19 @@ class Haxe extends Sdk { * { * platform: 'neko', * version: '1.0.0', - * build: '1999.12.12 00:00', * values: {}, + * macro: [], * lib: [], * src: [], * main: 'Main.hx', * outputFile: 'out.n', - * debug: true, + * debug: false, * } */ build(params) { params = Object.assign({ - build: dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss'), + version: null, + values: {}, macro: [], debug: false, }, params); @@ -257,7 +250,7 @@ class Haxe extends Sdk { for (const macro of params.macro) { args.push('--macro', `"${macro}"`); } - if (params.values) for (let key of Object.keys(params.values)) { + for (let key of Object.keys(params.values)) { const value = params.values[key]; if (value === true) { args.push(`-D ${key}`); @@ -266,18 +259,8 @@ class Haxe extends Sdk { } } const tmpFile = tmp.generateFile(); - const dir = path.dirname(tmpFile.path); - const name = path.basename(tmpFile.path); args.push(`-${params.platform}`, tmpFile.path); - args.push(`--macro "CompilationOption.set('build','${params.build}')"`); - let debug = null; if (params.debug) { - debug = { - host: 'localhost', - port: 6000 + Math.floor(Math.random() * 1000), - }; - args.push(`--macro "CompilationOption.set('debug.address','${debug.host}')"`); - args.push(`--macro "CompilationOption.set('debug.port','${debug.port}')"`); args.push('-debug'); } //console.log('haxe', args.join(' ')); @@ -287,7 +270,6 @@ class Haxe extends Sdk { //contents: fs.createReadStream(tmpFile.path), contents: fs.readFileSync(tmpFile.path), }); - out.debug = debug; stream.push(out); callback(); }).catch((error) => { diff --git a/package.json b/package.json index 56ddc06..e608744 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,26 @@ { "name": "gulp-haxetool", - "version": "0.0.1", + "version": "0.0.2", "description": "Haxe tool for gulp", "main": "index.js", "dependencies": { + "ansi-colors": "^1.1.0", "async": "^2.6.0", - "dateformat": "^3.0.3", + "fancy-log": "^1.3.2", "fs-extra": "^5.0.0", "got": "^8.3.0", "gulp": "github:gulpjs/gulp#4.0", + "mkdirp": "^0.5.1", "plugin-error": "^1.0.1", "progress": "^2.0.0", "promise-streams": "^2.1.1", "rmdir": "^1.2.0", "tar": "^4.4.1", + "through2": "^2.0.3", "tmp-file": "^2.0.1", - "unzip-stream": "^0.3.0" + "unzip-stream": "^0.3.0", + "vinyl": "^2.1.0", + "vinyl-fs": "^3.0.2" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1"