[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 log = require('fancy-log');
|
||||||
const vfs = require('vinyl-fs');
|
const vfs = require('vinyl-fs');
|
||||||
const rmdir = require('rmdir');
|
const rmdir = require('rmdir');
|
||||||
|
const template = require('lodash.template');
|
||||||
|
const mkdirp = require('mkdirp');
|
||||||
|
|
||||||
|
|
||||||
class Haxe extends Sdk {
|
class Haxe extends Sdk {
|
||||||
@@ -143,17 +145,23 @@ class Haxe extends Sdk {
|
|||||||
* values: {},
|
* values: {},
|
||||||
* macro: [],
|
* macro: [],
|
||||||
* outputFile: 'out.swf',
|
* outputFile: 'out.swf',
|
||||||
|
* debug: false
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
openfl(params) {
|
openfl(params) {
|
||||||
params = Object.assign({
|
params = Object.assign({
|
||||||
|
title: null,
|
||||||
|
pack: null,
|
||||||
|
company: null,
|
||||||
version: null,
|
version: null,
|
||||||
lib: [],
|
lib: [],
|
||||||
cp: [],
|
cp: [],
|
||||||
|
asset: [],
|
||||||
main: null,
|
main: null,
|
||||||
values: {},
|
values: {},
|
||||||
macro: [],
|
macro: [],
|
||||||
debug: false,
|
outputFile: null,
|
||||||
|
debug: false
|
||||||
}, params);
|
}, params);
|
||||||
|
|
||||||
const files = [];
|
const files = [];
|
||||||
@@ -167,45 +175,30 @@ class Haxe extends Sdk {
|
|||||||
|
|
||||||
const endStream = (callback) => {
|
const endStream = (callback) => {
|
||||||
log(this.tag, colors.cyan(`openfl ${params.command} ${params.platform}`));
|
log(this.tag, colors.cyan(`openfl ${params.command} ${params.platform}`));
|
||||||
const args = ['-cwd', files[0].path, 'run', 'openfl', params.command, params.platform];
|
|
||||||
// lib
|
if (!Array.isArray(params.lib)) {
|
||||||
let lib = params.lib;
|
params.lib = Object.entries(params.lib).map(([k, v]) => ({name: k, version: v.split('@')[0]}));
|
||||||
if (!Array.isArray(lib)) {
|
|
||||||
lib = Object.entries(lib).map(([k, v]) => `${k}:${v.split('@')[0]}`);
|
|
||||||
}
|
}
|
||||||
for (const item of lib) {
|
|
||||||
args.push(`--haxelib="${item}"`);
|
params.cp = params.cp.map(item => path.resolve(files[0].path, item));
|
||||||
}
|
params.asset = params.asset.map(item => path.resolve(files[0].path, item));
|
||||||
// cp
|
|
||||||
for (const item of params.cp) {
|
const buildDir = path.join(os.tmpdir(), 'build', params.outputFile);
|
||||||
args.push(`--source="${item}"`);
|
params.buildDir = buildDir;
|
||||||
}
|
mkdirp.sync(params.buildDir);
|
||||||
if (params.main) {
|
|
||||||
args.push(`--app-main="${params.main}"`);
|
const projectTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/project.xml')));
|
||||||
}
|
const project = projectTemplate(params);
|
||||||
// macro
|
fs.writeFileSync(path.resolve(buildDir, 'project.xml'), project);
|
||||||
for (const macro of params.macro) {
|
|
||||||
args.push(`--haxeflag="--macro ${macro}"`);
|
const args = ['-cwd', params.buildDir, 'run', 'openfl', params.command, params.platform];
|
||||||
}
|
|
||||||
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}`);
|
|
||||||
if (params.debug) {
|
if (params.debug) {
|
||||||
args.push('-debug');
|
args.push('-debug');
|
||||||
}
|
}
|
||||||
const target = `${buildDir}/${params.platform}/bin`;
|
const target = `${buildDir}/${params.platform}/bin`;
|
||||||
rmdir(target);
|
rmdir(target);
|
||||||
|
|
||||||
this.haxelib(args).then(() => {
|
this.haxelib(args).then(() => {
|
||||||
vfs.src(`${target}/**/*`).pipe(through.obj((file, enc, cb) => {
|
vfs.src(`${target}/**/*`).pipe(through.obj((file, enc, cb) => {
|
||||||
stream.push(file);
|
stream.push(file);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gulp-haxetool",
|
"name": "gulp-haxetool",
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"description": "Haxe tool for gulp",
|
"description": "Haxe tool for gulp",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
"fs-extra": "^5.0.0",
|
"fs-extra": "^5.0.0",
|
||||||
"got": "^8.3.0",
|
"got": "^8.3.0",
|
||||||
"gulp": "github:gulpjs/gulp#4.0",
|
"gulp": "github:gulpjs/gulp#4.0",
|
||||||
|
"lodash.template": "^4.4.0",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
"plugin-error": "^1.0.1",
|
"plugin-error": "^1.0.1",
|
||||||
"progress": "^2.0.0",
|
"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