Files
gulp-haxetool/haxetool/core.js
2018-08-09 17:41:33 +03:00

81 lines
2.3 KiB
JavaScript

const os = require('os');
const path = require('path');
const BuildSystem = {
HAXE: 'haxe',
OPENFL: 'openfl',
ADOBE_AIR: 'adobe_air',
};
const Platform = {
FLASH: 'flash',
HTML5: 'html5',
LINUX: 'linux',
WINDOWS: 'windows',
ANDROID: 'android',
NEKO: 'neko',
};
class Config {
constructor(params) {
this._params = [];
this.name = null;
this.main = null;
this.sources = [];
this.assets = [];
this.libs = [];
this.macros = [];
this.flags = [];
this.icon = null;
this.meta = {
title: null,
filename: null,
icon: null,
version: null,
pack: null,
author: null,
company: null
};
if (params) {
this.update(params);
}
}
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;
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.flags !== undefined) this.flags = this.flags.concat(params.flags);
if (params.meta !== undefined) this.meta = {...this.meta, ...params.meta};
if (this.meta.icon) this.icon = Config.absolutePath(this.meta.icon);
}
branch(params) {
const result = new Config();
for (const params of this._params) {
result.update(params);
}
result.update(params);
return result;
}
}
module.exports = {
BuildSystem: BuildSystem,
Platform: Platform,
Config: Config,
};