big update
This commit is contained in:
@@ -1,28 +1,52 @@
|
||||
const gulp = require('gulp');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
//const concat = require('gulp-concat');
|
||||
//const uglify = require('gulp-uglify');
|
||||
//const babel = require('gulp-babel');
|
||||
//const template = require('gulp-template');
|
||||
const Haxe = require('./haxe');
|
||||
const FlashPlayer = require('./flashplayer');
|
||||
const Neko = require('./neko');
|
||||
const Debug = require('./debug');
|
||||
const webserver = require('gulp-webserver');
|
||||
const run = require('gulp-run');
|
||||
const run = require('../run/index');
|
||||
const tail = require('./tail');
|
||||
//const deb = require('gulp-debian');
|
||||
const {BuildSystem, Platform, Config} = require('./core');
|
||||
const vfs = require('vinyl-fs');
|
||||
const rename = require('gulp-rename');
|
||||
|
||||
|
||||
const streamToPromise = (stream) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
stream.on("end", resolve);
|
||||
stream.on("error", reject);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Builder {
|
||||
class Target {
|
||||
|
||||
constructor() {
|
||||
this.target = 'target';
|
||||
}
|
||||
|
||||
targetPath(name, platform) {
|
||||
return path.resolve(this.target, name, platform);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Builder extends Target {
|
||||
|
||||
constructor(buildSystem) {
|
||||
super();
|
||||
this.buildSystem = buildSystem;
|
||||
this.target = 'target';
|
||||
}
|
||||
|
||||
prepare() {
|
||||
@@ -59,10 +83,14 @@ class HaxeBuilder extends Builder {
|
||||
}
|
||||
|
||||
call(platform, config, debug) {
|
||||
const target = this.targetPath(config.name, platform);
|
||||
switch (this.buildSystem) {
|
||||
case BuildSystem.OPENFL:
|
||||
return this.haxe.openfl('build', platform, config, debug)
|
||||
.then(result => result.pipe(vfs.dest(`${this.target}/${platform}`)));
|
||||
.then(result => streamToPromise(result.pipe(vfs.dest(target))));
|
||||
case BuildSystem.HAXE:
|
||||
return this.haxe.build(platform, config, debug)
|
||||
.then(result => streamToPromise(result.pipe(vfs.dest(target))));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,12 +101,12 @@ Builder.register(BuildSystem.OPENFL, HaxeBuilder);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Runner {
|
||||
class Runner extends Target {
|
||||
|
||||
constructor(platform, name) {
|
||||
super();
|
||||
this.platform = platform;
|
||||
this.name = name;
|
||||
this.target = 'target';
|
||||
}
|
||||
|
||||
prepare() {
|
||||
@@ -89,6 +117,17 @@ class Runner {
|
||||
throw 'Not Implemented';
|
||||
}
|
||||
|
||||
targetPath() {
|
||||
return super.targetPath(this.name, this.platform);
|
||||
}
|
||||
|
||||
log(stream) {
|
||||
stream
|
||||
.pipe(tail(new Debug().log))
|
||||
.pipe(rename('out.log'))
|
||||
.pipe(gulp.dest(this.targetPath()));
|
||||
}
|
||||
|
||||
static register(platform, builder) {
|
||||
Runner.factory[platform] = builder;
|
||||
}
|
||||
@@ -115,9 +154,13 @@ class FlashRunner extends Runner {
|
||||
}
|
||||
|
||||
call(debug) {
|
||||
return gulp.src(`${this.target}/${this.platform}/${this.name}.swf`)
|
||||
.pipe(this.player.run(true))
|
||||
.pipe(debug.run());
|
||||
const target = this.targetPath();
|
||||
const filename = path.resolve(target, this.name+'.swf');
|
||||
const player = this.player.flashPlayerBin(debug);
|
||||
FlashPlayer.trust(filename);
|
||||
fs.writeFileSync(FlashPlayer.log, '');
|
||||
const result = gulp.src(filename).pipe(run(player + " <%=file.basename%>", {cwd: target}));
|
||||
return this.log(gulp.src(FlashPlayer.log));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +172,7 @@ Runner.register(Platform.FLASH, FlashRunner);
|
||||
class Html5Runner extends Runner {
|
||||
|
||||
call(debug) {
|
||||
return gulp.src(`${this.target}/${this.platform}`)
|
||||
return gulp.src(this.targetPath())
|
||||
.pipe(webserver({
|
||||
host: 'localhost', port: 3000,
|
||||
open: true,
|
||||
@@ -146,9 +189,10 @@ Runner.register(Platform.HTML5, Html5Runner);
|
||||
class LinuxRunner extends Runner {
|
||||
|
||||
call(debug) {
|
||||
return gulp.src(`${this.target}/${this.platform}/${this.name}`)
|
||||
.pipe(run(`./${this.name}`, {cwd: `target/${this.platform}`, verbosity: 1}))
|
||||
.pipe(tail(Debug.log));
|
||||
const target = this.targetPath();
|
||||
const filename = path.resolve(target, this.name);
|
||||
const result = gulp.src(filename).pipe(run("./<%=file.basename%>", {cwd: target}));
|
||||
return this.log(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,9 +204,10 @@ Runner.register(Platform.LINUX, LinuxRunner);
|
||||
class NekoRunner extends Runner {
|
||||
|
||||
call(debug) {
|
||||
return gulp.src(`${this.target}/${this.platform}/${this.name}.n`)
|
||||
.pipe(new Neko().run())
|
||||
.pipe(debug.run());
|
||||
const target = this.targetPath();
|
||||
const filename = path.resolve(target, this.name+'.n');
|
||||
const result = gulp.src(filename).pipe(run("neko <%=file.path%>", {cwd: target}));
|
||||
return this.log(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,10 +245,10 @@ class Project {
|
||||
];
|
||||
}
|
||||
|
||||
bind(module, gulp /* ToDo: spike */) {
|
||||
bind(module, external_gulp /* ToDo: spike */) {
|
||||
for (const platform of this.platforms) {
|
||||
module.exports[`${this.config.name}:${platform}:build`] = gulp.series(this.build(platform));
|
||||
module.exports[`${this.config.name}:${platform}:run`] = gulp.series(this.run(platform));
|
||||
module.exports[`${this.config.name}:${platform}:build`] = (external_gulp || gulp).series(this.build(platform));
|
||||
module.exports[`${this.config.name}:${platform}:run`] = (external_gulp || gulp).series(this.run(platform));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user