[haxe] fixes for windows compatibility

This commit is contained in:
2018-04-27 15:36:15 +03:00
parent 251d2fea1e
commit 22a371292f
5 changed files with 33 additions and 19 deletions

View File

@@ -1,3 +1,4 @@
const os = require('os');
const path = require('path');
@@ -43,17 +44,21 @@ class Config {
}
}
static absolutePath(file) {
const result = path.resolve(process.cwd(), path.normalize(file));
return os.type() === 'Windows_NT' ? result.split('\\').join('/') : result;
}
update(params) {
this._params.push(params);
if (params.name !== undefined) this.name = params.name;
if (params.main !== undefined) this.main = params.main;
const cwd = process.cwd();
if (params.sources !== undefined) this.sources = this.sources.concat(params.sources.map(item => path.resolve(cwd, item)));
if (params.assets !== undefined) this.assets = this.assets.concat(params.assets.map(item => path.resolve(cwd, item)));
if (params.sources !== undefined) this.sources = this.sources.concat(params.sources.map(Config.absolutePath));
if (params.assets !== undefined) this.assets = this.assets.concat(params.assets.map(Config.absolutePath));
if (params.libs !== undefined) this.libs = this.libs.concat(Array.isArray(params.libs) ? params.libs : Object.entries(params.libs).map(([k, v]) => ({name: k, version: v})));
if (params.macros !== undefined) this.macros = this.macros.concat(params.macros);
if (params.meta !== undefined) this.meta = {...this.meta, ...params.meta};
if (this.meta.icon) this.icon = path.resolve(cwd, this.meta.icon)
if (this.meta.icon) this.icon = Config.absolutePath(this.meta.icon);
}
branch(params) {

View File

@@ -19,9 +19,9 @@ class Haxe extends Sdk {
getBin(name) {
if (Sdk.System.isWindows) {
return `${this.binPath}/${name}.exe`;
return path.join(this.binPath, name + '.exe');
} else if (Sdk.System.isLinux) {
const binPath = `${this.binPath}/${name}`;
const binPath = path.join(this.binPath, name);
if (fs.existsSync(binPath)) {
fs.chmodSync(binPath, 0o755);
}
@@ -56,11 +56,13 @@ class Haxe extends Sdk {
activate() {
process.env.HAXE_VERSION = this.version;
process.env.HAXE_STD_PATH = `${this.binPath}/std`;
process.env.HAXE_STD_PATH = path.join(this.binPath, 'std');
process.env.HAXE_HOME = this.binPath;
if (process.env.PATH.indexOf(this.binPath) === -1) {
process.env.PATH = `${process.env.PATH}:${this.binPath}`;
console.log('process.env.PATH A', process.env.PATH);
if (process.env.PATH.split(path.delimiter).indexOf(this.binPath) === -1) {
process.env.PATH = [process.env.PATH, this.binPath].join(path.delimiter);
}
console.log('process.env.PATH B', process.env.PATH);
}
prepare() {
@@ -132,7 +134,7 @@ class Haxe extends Sdk {
}
install(packages) {
let promise = this.haxelib(['setup', `${this.path}/lib`]);
let promise = this.haxelib(['setup', path.join(this.path, 'lib')]);
const next = (args) => () => {
log(this.tag, colors.cyan('haxelib', 'install'), colors.magenta(args[1]));
return this.haxelib(args);
@@ -176,7 +178,7 @@ class Haxe extends Sdk {
}
upgrade() {
let promise = this.haxelib(['setup', `${this.path}/lib`]);
let promise = this.haxelib(['setup', path.join(this.path, 'lib')]);
promise = promise.then(() => this.haxelib(['upgrade', '--always']));
return promise;
}

View File

@@ -86,7 +86,13 @@ class HaxeBuilder extends Builder {
}
prepare() {
return this.haxe.prepare();
let result = this.haxe.prepare().then(() => this.haxe.install(this.config.libs));
/*if (this.buildSystem === BuildSystem.OPENFL) {
result = result.then(() => {
return this.haxe.haxelib(['run', 'openfl', 'setup', this.platform]);
});
}*/
return result;
}
call() {
@@ -294,6 +300,7 @@ class LinuxRunner extends Runner {
}
Runner.register(Platform.LINUX, LinuxRunner);
Runner.register(Platform.WINDOWS, LinuxRunner); //ToDo:
/**
*

View File

@@ -1,4 +1,5 @@
const os = require('os');
const path = require('path');
const fs = require('fs');
const ps = require('promise-streams');
const got = require('got');
@@ -41,11 +42,11 @@ class Sdk {
}
static get dir() {
return Sdk._dir || `${os.homedir()}/sdk`;
return Sdk._dir || path.join(os.homedir(), 'sdk');
}
static path(name, version) {
return `${this.dir}/${name}/${version}`;
return path.join(this.dir, name, version);
}
constructor(name, version) {
@@ -85,14 +86,13 @@ class Sdk {
let stream = got.stream(this.link);
stream = stream.on('downloadProgress', (p) => bar.update(p.percent));
if (this.link.endsWith('.zip')) {
const sep = '/';
stream = stream.pipe(unzip.Parse()).on('entry', (entry) => {
const filePath = entry.path.split(sep).slice(1).join(sep);
const filePath = entry.path.split('/').slice(1).join(path.sep);
if (filePath.length > 0) {
if (entry.type === 'Directory') {
mkdirp(this.path + sep + filePath);
mkdirp(path.join(this.path, path.normalize(filePath)));
} else if (entry.type === 'File') {
entry.pipe(fs.createWriteStream(this.path + sep + filePath));
entry.pipe(fs.createWriteStream(path.join(this.path, path.normalize(filePath))));
}
} else {
entry.autodrain();

View File

@@ -1,6 +1,6 @@
{
"name": "gulp-haxetool",
"version": "0.0.8",
"version": "0.0.9",
"description": "HaXe Tool for Gulp",
"main": "index.js",
"dependencies": {