[haxe] generate project.xml for openfl build
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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",
|
||||
|
||||
18
template/project.xml
Normal file
18
template/project.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<meta title="<%-title%>" package="<%-pack%>" company="<%-company%>"/>
|
||||
<app main="<%-main%>" path="<%-buildDir%>" file="<%-outputFile%>"/>
|
||||
<% cp.forEach(function(item) { %>
|
||||
<source path="<%-item%>"/><% }); %>
|
||||
<% asset.forEach(function(item) { %>
|
||||
<assets path="<%-item%>" rename="<%-item.split('/').pop()%>" include="*"/><% }); %>
|
||||
<% lib.forEach(function(item) { %>
|
||||
<haxelib name="<%-item.name%>" version="<%-item.version%>"/><% }); %>
|
||||
|
||||
<window fps="30"/>
|
||||
<window width="1024" height="768" unless="html5"/>
|
||||
|
||||
<haxeflag name="-D" value="swf-gpu"/>
|
||||
<haxeflag name="-D" value="native-trace"/>
|
||||
<haxeflag name="-dce" value="no"/>
|
||||
</project>
|
||||
Reference in New Issue
Block a user