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