[project] fixes

This commit is contained in:
2018-04-25 16:13:11 +03:00
parent 744874aa61
commit 373ee7703d
2 changed files with 89 additions and 88 deletions

View File

@@ -38,4 +38,4 @@ class Debug {
}
}
module.exports = Debug;
module.exports = new Debug();

View File

@@ -9,7 +9,7 @@ const fse = require('fs-extra');
//const template = require('gulp-template');
const Haxe = require('./haxe');
const FlashPlayer = require('./flashplayer');
const Debug = require('./debug');
const debug = require('./debug');
const webserver = require('gulp-webserver');
const run = require('../run/index');
const tail = require('./tail');
@@ -34,12 +34,14 @@ const streamToPromise = (stream) => {
*/
class Target {
constructor() {
constructor(config, platform) {
this.config = config;
this.platform = platform;
this.target = 'target';
}
targetPath(name, platform) {
return path.resolve(this.target, name, platform);
get targetPath() {
return path.resolve(this.target, this.config.name, this.platform);
}
}
@@ -48,16 +50,17 @@ class Target {
*/
class Builder extends Target {
constructor(buildSystem) {
super();
constructor(config, platform, buildSystem, debug) {
super(config, platform);
this.buildSystem = buildSystem;
this.debug = debug;
}
prepare() {
return Promise.resolve();
}
call(debug) {
call() {
throw 'Not Implemented';
}
@@ -65,8 +68,8 @@ class Builder extends Target {
Builder.factory[buildSystem] = builder;
}
static new(buildSystem) {
return new Builder.factory[buildSystem](buildSystem);
static new(config, platform, buildSystem, debug) {
return new Builder.factory[buildSystem](config, platform, buildSystem, debug);
}
}
@@ -77,8 +80,8 @@ Builder.factory = {};
*/
class HaxeBuilder extends Builder {
constructor(buildSystem) {
super(buildSystem);
constructor(config, platform, buildSystem, debug) {
super(config, platform, buildSystem, debug);
this.haxe = new Haxe();
}
@@ -86,14 +89,14 @@ class HaxeBuilder extends Builder {
return this.haxe.prepare();
}
call(platform, config, debug) {
const target = this.targetPath(config.name, platform);
call() {
const target = this.targetPath;
switch (this.buildSystem) {
case BuildSystem.OPENFL:
return this.haxe.openfl('build', platform, config, debug)
return this.haxe.openfl('build', this.platform, this.config, this.debug)
.then(result => streamToPromise(result.pipe(vfs.dest(target))));
case BuildSystem.HAXE:
return this.haxe.build(platform, config, debug)
return this.haxe.build(this.platform, this.config, this.debug)
.then(result => streamToPromise(result.pipe(vfs.dest(target))));
}
}
@@ -107,16 +110,11 @@ Builder.register(BuildSystem.OPENFL, HaxeBuilder);
*/
class Packer extends Target {
constructor(platform) {
super();
this.platform = platform;
}
prepare() {
return Promise.resolve();
}
call(config) {
call() {
throw 'Not Implemented';
}
@@ -124,8 +122,8 @@ class Packer extends Target {
Packer.factory[platform] = packer;
}
static new(platform) {
return new Packer.factory[platform]();
static new(config, platform) {
return new Packer.factory[platform](config);
}
}
@@ -136,14 +134,14 @@ Packer.factory = {};
*/
class FlashPacker extends Packer {
constructor() {
super(Platform.FLASH);
constructor(config) {
super(config, Platform.FLASH);
}
call(config) {
const target = this.targetPath(config.name, this.platform);
call() {
const target = this.targetPath;
const indexTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/flash/index.html')));
const index = indexTemplate(config);
const index = indexTemplate(this.config);
fs.writeFileSync(path.resolve(target, 'index.html'), index);
fs.copyFileSync(path.resolve(__dirname, '..', 'template/flash/swf.js'), path.resolve(target, 'swf.js'));
return Promise.resolve();
@@ -157,27 +155,27 @@ Packer.register(Platform.FLASH, FlashPacker);
*/
class LinuxPacker extends Packer {
constructor() {
super(Platform.LINUX);
constructor(config) {
super(config, Platform.LINUX);
}
call(config) {
const target = this.targetPath(config.name, this.platform);
const buildDir = path.join(os.tmpdir(), 'build', config.name, 'debian');
call() {
const target = this.targetPath;
const buildDir = path.join(os.tmpdir(), 'build', this.config.name, 'debian');
const desktopTemplate = template(fs.readFileSync(path.resolve(__dirname, '..', 'template/linux/app.desktop')));
const desktop = desktopTemplate(config);
const desktop = desktopTemplate(this.config);
mkdirp.sync(`${buildDir}/usr/share/applications`);
fs.writeFileSync(`${buildDir}/usr/share/applications/${config.meta.filename}.desktop`, desktop);
fse.copySync(`${target}`, `${buildDir}/usr/share/${config.meta.filename}/`);
fs.writeFileSync(`${buildDir}/usr/share/applications/${this.config.meta.filename}.desktop`, desktop);
fse.copySync(`${target}`, `${buildDir}/usr/share/${this.config.meta.filename}/`);
return gulp.src(`${buildDir}/*`)
.pipe(deb({
package: config.meta.filename,
version: config.meta.version,
package: this.config.meta.filename,
version: this.config.meta.version,
section: 'base',
priority: 'optional',
architecture: 'all',
maintainer: config.meta.author,
description: config.meta.title,
maintainer: this.config.meta.author,
description: this.config.meta.title,
changelog: [],
postinst: [
'if [ "$1" = "configure" ] && [ -x "`which update-menus 2>/dev/null`" ] ; then\n' +
@@ -199,37 +197,32 @@ Packer.register(Platform.LINUX, LinuxPacker);
*/
class Runner extends Target {
constructor(platform, name) {
super();
this.platform = platform;
this.name = name;
constructor(config, platform, debug) {
super(config, platform);
this.debug = debug;
}
prepare() {
return Promise.resolve();
}
call(debug) {
call() {
throw 'Not Implemented';
}
targetPath() {
return super.targetPath(this.name, this.platform);
}
log(stream) {
stream
.pipe(tail(new Debug().log))
.pipe(tail(debug.log))
.pipe(rename('out.log'))
.pipe(gulp.dest(this.targetPath()));
.pipe(gulp.dest(this.targetPath));
}
static register(platform, builder) {
Runner.factory[platform] = builder;
static register(platform, runner) {
Runner.factory[platform] = runner;
}
static new(platform, name) {
return new Runner.factory[platform](platform, name);
static new(config, platform, debug) {
return new Runner.factory[platform](config, debug);
}
}
@@ -240,8 +233,8 @@ Runner.factory = {};
*/
class FlashRunner extends Runner {
constructor(platform, name) {
super(platform, name);
constructor(config, debug) {
super(config, Platform.FLASH, debug);
this.player = new FlashPlayer();
}
@@ -249,10 +242,10 @@ class FlashRunner extends Runner {
return this.player.prepare();
}
call(debug) {
const target = this.targetPath();
const filename = path.resolve(target, this.name+'.swf');
const player = this.player.flashPlayerBin(debug);
call() {
const target = this.targetPath;
const filename = path.resolve(target, this.config.meta.filename+'.swf');
const player = this.player.flashPlayerBin(this.debug);
FlashPlayer.trust(filename);
fs.writeFileSync(FlashPlayer.log, '');
const result = gulp.src(filename).pipe(run(player + " <%=file.basename%>", {cwd: target}));
@@ -267,8 +260,12 @@ Runner.register(Platform.FLASH, FlashRunner);
*/
class Html5Runner extends Runner {
call(debug) {
return gulp.src(this.targetPath())
constructor(config, debug) {
super(config, Platform.HTML5, debug);
}
call() {
return gulp.src(this.targetPath)
.pipe(webserver({
host: 'localhost', port: 3000,
open: true,
@@ -284,9 +281,13 @@ Runner.register(Platform.HTML5, Html5Runner);
*/
class LinuxRunner extends Runner {
call(debug) {
const target = this.targetPath();
const filename = path.resolve(target, this.name);
constructor(config, debug) {
super(config, Platform.LINUX, debug);
}
call() {
const target = this.targetPath;
const filename = path.resolve(target, this.config.meta.filename);
const result = gulp.src(filename).pipe(run("./<%=file.basename%>", {cwd: target}));
return this.log(result);
}
@@ -299,9 +300,13 @@ Runner.register(Platform.LINUX, LinuxRunner);
*/
class NekoRunner extends Runner {
call(debug) {
const target = this.targetPath();
const filename = path.resolve(target, this.name+'.n');
constructor(config, debug) {
super(config, Platform.NEKO, debug);
}
call() {
const target = this.targetPath;
const filename = path.resolve(target, this.config.meta.filename+'.n');
const result = gulp.src(filename).pipe(run("neko <%=file.path%>", {cwd: target}));
return this.log(result);
}
@@ -317,38 +322,34 @@ class Project {
constructor(buildSystem, platforms, config) {
this.buildSystem = buildSystem;
this.platforms = platforms;
this.platforms = Array.isArray(platforms) ? platforms : [platforms];
this.config = config;
}
build(platform) {
const builder = Builder.new(this.buildSystem);
const config = this.config;
const builder = Builder.new(this.config, platform, this.buildSystem, false);
return [
function prepare() { return builder.prepare() },
function build() { return builder.call(platform, config) },
builder.prepare.bind(builder),
builder.call.bind(builder),
];
}
run(platform) {
const builder = Builder.new(this.buildSystem);
const runner = Runner.new(platform, this.config.name);
const config = this.config;
const debug = new Debug();
const builder = Builder.new(this.config, platform, this.buildSystem, debug);
const runner = Runner.new(this.config, platform, debug);
return [
function prepare() { return builder.prepare() },
function build() { return builder.call(platform, config, debug) },
function prepare() { return runner.prepare() },
function run() { return runner.call(debug) },
builder.prepare.bind(builder),
builder.call.bind(builder),
runner.prepare.bind(runner),
runner.call.bind(runner),
];
}
pack(platform) {
const config = this.config;
const packer = Packer.new(platform);
const packer = Packer.new(this.config, platform);
return [
function prepare() { return packer.prepare() },
function pack() { return packer.call(config) },
packer.prepare.bind(packer),
packer.call.bind(packer),
];
}
@@ -358,7 +359,7 @@ class Project {
module.exports[`${this.config.name}:${platform}:build`] = _gulp.series(this.build(platform));
module.exports[`${this.config.name}:${platform}:run`] = _gulp.series(this.run(platform));
if (Packer.factory[platform]) {
module.exports[`${this.config.name}:${platform}:pack`] = _gulp.series(this.pack(platform, _gulp));
module.exports[`${this.config.name}:${platform}:pack`] = _gulp.series(this.pack(platform));
}
}
return this;