diff --git a/haxetool/haxe.js b/haxetool/haxe.js index d07c076..b189e57 100755 --- a/haxetool/haxe.js +++ b/haxetool/haxe.js @@ -11,6 +11,8 @@ const colors = require('ansi-colors'); const log = require('fancy-log'); const vfs = require('vinyl-fs'); const rmdir = require('rmdir'); +const template = require('lodash.template'); +const mkdirp = require('mkdirp'); class Haxe extends Sdk { @@ -143,17 +145,23 @@ class Haxe extends Sdk { * values: {}, * macro: [], * outputFile: 'out.swf', + * debug: false * } */ openfl(params) { params = Object.assign({ + title: null, + pack: null, + company: null, version: null, lib: [], cp: [], + asset: [], main: null, values: {}, macro: [], - debug: false, + outputFile: null, + debug: false }, params); const files = []; @@ -167,45 +175,30 @@ 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]; - // lib - let lib = params.lib; - if (!Array.isArray(lib)) { - lib = Object.entries(lib).map(([k, v]) => `${k}:${v.split('@')[0]}`); + + if (!Array.isArray(params.lib)) { + params.lib = Object.entries(params.lib).map(([k, v]) => ({name: k, version: v.split('@')[0]})); } - for (const item of lib) { - args.push(`--haxelib="${item}"`); - } - // cp - for (const item of params.cp) { - args.push(`--source="${item}"`); - } - if (params.main) { - args.push(`--app-main="${params.main}"`); - } - // macro - 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}`); - } else if (value) { - args.push(`-D${key}="${value}"`); - } - } - const buildDir = path.join(os.tmpdir(), 'build'); - args.push(`--app-path="${buildDir}"`); - if (params.outputFile) { - args.push(`--app-file="${params.outputFile}"`); - } - if (params.version) args.push(`--meta-version=${params.version}`); + + params.cp = params.cp.map(item => path.resolve(files[0].path, item)); + params.asset = params.asset.map(item => path.resolve(files[0].path, item)); + + const buildDir = path.join(os.tmpdir(), 'build', params.outputFile); + params.buildDir = buildDir; + mkdirp.sync(params.buildDir); + + const projectTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/project.xml'))); + const project = projectTemplate(params); + fs.writeFileSync(path.resolve(buildDir, 'project.xml'), project); + + const args = ['-cwd', params.buildDir, 'run', 'openfl', params.command, params.platform]; + if (params.debug) { args.push('-debug'); } const target = `${buildDir}/${params.platform}/bin`; rmdir(target); + this.haxelib(args).then(() => { vfs.src(`${target}/**/*`).pipe(through.obj((file, enc, cb) => { stream.push(file); diff --git a/package.json b/package.json index 266934c..9590471 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-haxetool", - "version": "0.0.3", + "version": "0.0.4", "description": "Haxe tool for gulp", "main": "index.js", "dependencies": { @@ -10,6 +10,7 @@ "fs-extra": "^5.0.0", "got": "^8.3.0", "gulp": "github:gulpjs/gulp#4.0", + "lodash.template": "^4.4.0", "mkdirp": "^0.5.1", "plugin-error": "^1.0.1", "progress": "^2.0.0", diff --git a/template/project.xml b/template/project.xml new file mode 100644 index 0000000..b81073a --- /dev/null +++ b/template/project.xml @@ -0,0 +1,18 @@ + + + + + <% cp.forEach(function(item) { %> + <% }); %> + <% asset.forEach(function(item) { %> + <% }); %> + <% lib.forEach(function(item) { %> + <% }); %> + + + + + + + + \ No newline at end of file