big update
This commit is contained in:
104
haxetool/haxe.js
104
haxetool/haxe.js
@@ -56,7 +56,9 @@ class Haxe extends Sdk {
|
||||
process.env.HAXE_VERSION = this.version;
|
||||
process.env.HAXE_STD_PATH = `${this.binPath}/std`;
|
||||
process.env.HAXE_HOME = this.binPath;
|
||||
process.env.PATH = `${process.env.PATH}:${this.binPath}`;
|
||||
if (process.env.PATH.indexOf(this.binPath) === -1) {
|
||||
process.env.PATH = `${process.env.PATH}:${this.binPath}`;
|
||||
}
|
||||
}
|
||||
|
||||
prepare() {
|
||||
@@ -81,7 +83,7 @@ class Haxe extends Sdk {
|
||||
}
|
||||
|
||||
openfl(command, platform, config, debug=false) {
|
||||
log(this.tag, colors.cyan('openfl', platform));
|
||||
log(this.tag, colors.cyan(`openfl build ${platform}`));
|
||||
const buildDir = path.join(os.tmpdir(), 'build', config.name);
|
||||
mkdirp.sync(buildDir);
|
||||
|
||||
@@ -98,8 +100,33 @@ class Haxe extends Sdk {
|
||||
return this.haxelib(args).then(() => vfs.src(`${target}/**/*`));
|
||||
}
|
||||
|
||||
build(platform, config) {
|
||||
build(platform, config, debug=false) {
|
||||
log(this.tag, colors.cyan(`build ${platform}`));
|
||||
const buildDir = path.join(os.tmpdir(), 'build', config.name);
|
||||
mkdirp.sync(buildDir);
|
||||
|
||||
const projectTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/project.hxml')));
|
||||
|
||||
const ext = {
|
||||
flash: '.swf',
|
||||
neko: '.n',
|
||||
}[platform] || '';
|
||||
|
||||
const out = {
|
||||
flash: 'swf'
|
||||
}[platform] || platform;
|
||||
|
||||
const project = projectTemplate({...config, buildDir: buildDir, platform: platform, ext: ext, out: out});
|
||||
const projectHXML = path.resolve(buildDir, 'project.hxml');
|
||||
fs.writeFileSync(projectHXML, project);
|
||||
|
||||
const args = [projectHXML];
|
||||
if (debug) {
|
||||
args.push('-debug');
|
||||
}
|
||||
const target = path.resolve(buildDir, platform, 'bin');
|
||||
rmdir(target);
|
||||
return this.haxe(args).then(() => vfs.src(`${target}/**/*`));
|
||||
}
|
||||
|
||||
install(packages) {
|
||||
@@ -151,77 +178,6 @@ class Haxe extends Sdk {
|
||||
promise = promise.then(() => this.haxelib(['upgrade', '--always']));
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
||||
_build(params) {
|
||||
params = Object.assign({
|
||||
version: null,
|
||||
values: {},
|
||||
lib: [],
|
||||
macro: [],
|
||||
debug: false,
|
||||
}, params);
|
||||
|
||||
const files = [];
|
||||
let stream = null;
|
||||
|
||||
const bufferContents = (file, enc, callback) => {
|
||||
// ToDo: check file not stream
|
||||
files.push(file);
|
||||
callback();
|
||||
};
|
||||
|
||||
const endStream = (callback) => {
|
||||
log(this.tag, colors.cyan("haxe", params.platform), '=>', colors.magenta(params.outputFile));
|
||||
const args = [];
|
||||
// main
|
||||
args.push('-main', params.main);
|
||||
// lib
|
||||
let lib = params.lib;
|
||||
if (!Array.isArray(lib)) {
|
||||
lib = Object.entries(lib).map(([k, v]) => `${k}:${v.split('@')[0]}`);
|
||||
}
|
||||
for (const item of lib) {
|
||||
args.push('-lib', item);
|
||||
}
|
||||
// cp
|
||||
for (const cp of params.cp) {
|
||||
args.push('-cp', cp);
|
||||
}
|
||||
// macro
|
||||
for (const macro of params.macro) {
|
||||
args.push('--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 tmpFile = tmp.generateFile();
|
||||
args.push(`-${params.platform}`, tmpFile.path);
|
||||
if (params.debug) {
|
||||
args.push('-debug');
|
||||
}
|
||||
//console.log('haxe', args.join(' '));
|
||||
this.haxe(args).then(() => {
|
||||
const out = new Vinyl({
|
||||
path: params.outputFile,
|
||||
//contents: fs.createReadStream(tmpFile.path),
|
||||
contents: fs.readFileSync(tmpFile.path),
|
||||
});
|
||||
stream.push(out);
|
||||
callback();
|
||||
}).catch((error) => {
|
||||
stream.emit('error', new PluginError({plugin: this.name, message: error}));
|
||||
callback();
|
||||
});
|
||||
};
|
||||
|
||||
return stream = through.obj(bufferContents, endStream);
|
||||
}
|
||||
}
|
||||
|
||||
Haxe.ID = 'haxe';
|
||||
|
||||
Reference in New Issue
Block a user