[gulp] move project to gulp-haxetool
This commit is contained in:
@@ -1,81 +0,0 @@
|
|||||||
const net = require('net');
|
|
||||||
const through = require('through2');
|
|
||||||
const colors = require('ansi-colors');
|
|
||||||
const log = require('fancy-log');
|
|
||||||
|
|
||||||
|
|
||||||
const _colors = {
|
|
||||||
'[DEBUG]': colors.white,
|
|
||||||
'[INFO]': colors.cyan,
|
|
||||||
'[ERROR]': colors.red,
|
|
||||||
'[WARNING]': colors.yellow,
|
|
||||||
};
|
|
||||||
|
|
||||||
const getColor = (line) => {
|
|
||||||
for (const [tag, color] of Object.entries(_colors)) {
|
|
||||||
if (line.indexOf(tag) > -1) {
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;// colors.reset;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class Debug {
|
|
||||||
|
|
||||||
static log (line, color) {
|
|
||||||
if (color === undefined) {
|
|
||||||
color = getColor(line) || colors.white;
|
|
||||||
}
|
|
||||||
if (line[0] === '\t') {
|
|
||||||
console.log(color(line));
|
|
||||||
} else {
|
|
||||||
const result = line.split(' ');
|
|
||||||
console.log(colors.gray(result.slice(0, 4).join(' ')) + ' ' + color(result.slice(4).join(' ')));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.host = 'localhost';
|
|
||||||
this.port = 6000 + Math.floor(Math.random() * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
macro() {
|
|
||||||
return [
|
|
||||||
`CompilationOption.set('debug.address','${this.host}')`,
|
|
||||||
`CompilationOption.set('debug.port','${this.port}')`,
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
run() {
|
|
||||||
const debug = this;
|
|
||||||
return through.obj(function (file, enc, callback) {
|
|
||||||
if (this.disabled) {
|
|
||||||
this.emit('end');
|
|
||||||
callback();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let color = colors.white;
|
|
||||||
const server = net.createServer((socket) => {
|
|
||||||
socket.on("data", (data) => {
|
|
||||||
const lines = data.toString().split('\n');
|
|
||||||
for (let line of lines) if (line.length > 2) {
|
|
||||||
const newColor = getColor(line);
|
|
||||||
if (newColor != null) color = newColor;
|
|
||||||
Debug.log(line, color);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
socket.on("close", () => {
|
|
||||||
socket.destroy();
|
|
||||||
server.close();
|
|
||||||
this.emit('end');
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
log(colors.green('[debug]'), colors.cyan('listen on'), colors.magenta(`${debug.host}:${debug.port}`));
|
|
||||||
server.listen(debug.port, debug.host);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Debug;
|
|
||||||
295
build/project.js
295
build/project.js
@@ -1,295 +0,0 @@
|
|||||||
const gulp = require('gulp');
|
|
||||||
const concat = require('gulp-concat');
|
|
||||||
const uglify = require('gulp-uglify');
|
|
||||||
const babel = require('gulp-babel');
|
|
||||||
const template = require('gulp-template');
|
|
||||||
const {Haxe, FlashPlayer, Neko} = require('gulp-haxetool');
|
|
||||||
const Debug = require('./debug');
|
|
||||||
const webserver = require('gulp-webserver');
|
|
||||||
const run = require('gulp-run');
|
|
||||||
const tail = require('./tail');
|
|
||||||
const deb = require('gulp-debian');
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
const Platform = {
|
|
||||||
FLASH: 'flash',
|
|
||||||
HTML5: 'html5',
|
|
||||||
LINUX: 'linux',
|
|
||||||
NEKO: 'neko',
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class Config {
|
|
||||||
|
|
||||||
constructor({title, pack, company, name, version, lib=[], cp=[], asset=[], main=null, values={}, macro=[]}) {
|
|
||||||
this.title = title;
|
|
||||||
this.pack = pack;
|
|
||||||
this.company = company;
|
|
||||||
this.name = name;
|
|
||||||
this.version = version;
|
|
||||||
this.lib = lib;
|
|
||||||
this.cp = cp;
|
|
||||||
this.asset = asset;
|
|
||||||
this.main = main;
|
|
||||||
this.values = values;
|
|
||||||
this.macro = macro;
|
|
||||||
}
|
|
||||||
|
|
||||||
update({name, version, lib=[], cp=[], asset=[], main=null, values={}, macro=[]}) {
|
|
||||||
return new Config({
|
|
||||||
title: this.title,
|
|
||||||
pack: this.pack,
|
|
||||||
company: this.company,
|
|
||||||
name: name || this.name,
|
|
||||||
version: version || this.version,
|
|
||||||
//lib: this.lib.concat(lib), //ToDo: check if object
|
|
||||||
lib: this.lib,
|
|
||||||
cp: this.cp.concat(cp),
|
|
||||||
asset: this.asset.concat(asset),
|
|
||||||
main: main || this.main,
|
|
||||||
values: {...this.values, ...values},
|
|
||||||
macro: this.macro.concat(macro),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Builder {
|
|
||||||
|
|
||||||
constructor(platform, config) {
|
|
||||||
this.platform = platform;
|
|
||||||
this.config = config;
|
|
||||||
this.haxe = new Haxe();
|
|
||||||
this.target = 'target';
|
|
||||||
}
|
|
||||||
|
|
||||||
prepare() {
|
|
||||||
return this.haxe.prepare();
|
|
||||||
}
|
|
||||||
|
|
||||||
macro(debug) {
|
|
||||||
let macro = [];
|
|
||||||
if (debug) {
|
|
||||||
macro = macro.concat(debug.macro());
|
|
||||||
}
|
|
||||||
return macro.concat(this.config.macro);
|
|
||||||
}
|
|
||||||
|
|
||||||
call(debug) {
|
|
||||||
throw 'Not Implemented';
|
|
||||||
}
|
|
||||||
|
|
||||||
static register(platform, builder) {
|
|
||||||
Builder.factory[platform] = builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
static new(platform, config) {
|
|
||||||
return new Builder.factory[platform](platform, config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Builder.factory = {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class OpenFLBuilder extends Builder {
|
|
||||||
|
|
||||||
call(debug) {
|
|
||||||
return gulp.src('.')
|
|
||||||
.pipe(this.haxe.openfl({
|
|
||||||
command: 'build',
|
|
||||||
platform: this.platform,
|
|
||||||
title: this.config.title,
|
|
||||||
pack: this.config.pack,
|
|
||||||
company: this.config.company,
|
|
||||||
version: this.config.version,
|
|
||||||
lib: this.config.lib,
|
|
||||||
cp: this.config.cp,
|
|
||||||
asset: this.config.asset,
|
|
||||||
main: this.config.main,
|
|
||||||
debug: debug,
|
|
||||||
values: this.config.values,
|
|
||||||
macro: this.macro(debug),
|
|
||||||
outputFile: this.config.name,
|
|
||||||
}))
|
|
||||||
.pipe(gulp.dest(`${this.target}/${this.platform}`));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Builder.register(Platform.FLASH, OpenFLBuilder);
|
|
||||||
Builder.register(Platform.HTML5, OpenFLBuilder);
|
|
||||||
Builder.register(Platform.LINUX, OpenFLBuilder);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class HaxeBuilder extends Builder {
|
|
||||||
|
|
||||||
call(debug) {
|
|
||||||
return gulp.src('.')
|
|
||||||
.pipe(new Haxe().build({
|
|
||||||
platform: this.platform,
|
|
||||||
version: this.config.version,
|
|
||||||
lib: this.config.lib,
|
|
||||||
cp: this.config.cp,
|
|
||||||
main: this.config.main,
|
|
||||||
debug: debug,
|
|
||||||
values: this.config.values,
|
|
||||||
macro: this.macro(debug),
|
|
||||||
outputFile: this.config.name + '.n', // ToDo: for neko only
|
|
||||||
}))
|
|
||||||
.pipe(gulp.dest(`${this.target}/${this.platform}`));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Builder.register(Platform.NEKO, HaxeBuilder);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Runner {
|
|
||||||
|
|
||||||
constructor(platform, name) {
|
|
||||||
this.platform = platform;
|
|
||||||
this.name = name;
|
|
||||||
this.target = 'target';
|
|
||||||
}
|
|
||||||
|
|
||||||
prepare() {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
call(debug) {
|
|
||||||
throw 'Not Implemented';
|
|
||||||
}
|
|
||||||
|
|
||||||
static register(platform, builder) {
|
|
||||||
Runner.factory[platform] = builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
static new(platform, name) {
|
|
||||||
return new Runner.factory[platform](platform, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Runner.factory = {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class FlashRunner extends Runner {
|
|
||||||
|
|
||||||
constructor(platform, name) {
|
|
||||||
super(platform, name);
|
|
||||||
this.player = new FlashPlayer();
|
|
||||||
}
|
|
||||||
|
|
||||||
prepare() {
|
|
||||||
return this.player.prepare();
|
|
||||||
}
|
|
||||||
|
|
||||||
call(debug) {
|
|
||||||
return gulp.src(`${this.target}/${this.platform}/${this.name}.swf`)
|
|
||||||
.pipe(this.player.run(true))
|
|
||||||
.pipe(debug.run());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Runner.register(Platform.FLASH, FlashRunner);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Html5Runner extends Runner {
|
|
||||||
|
|
||||||
call(debug) {
|
|
||||||
return gulp.src(`${this.target}/${this.platform}`)
|
|
||||||
.pipe(webserver({
|
|
||||||
host: 'localhost', port: 3000,
|
|
||||||
open: true,
|
|
||||||
fallback: 'index.html'
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Runner.register(Platform.NEKO, NekoRunner);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class Project {
|
|
||||||
|
|
||||||
constructor(config, platforms=[]) {
|
|
||||||
this.config = config;
|
|
||||||
this.platforms = platforms;
|
|
||||||
}
|
|
||||||
|
|
||||||
build(platform) {
|
|
||||||
const builder = Builder.new(platform, this.config);
|
|
||||||
return gulp.series(
|
|
||||||
() => builder.prepare(),
|
|
||||||
() => builder.call()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
run(platform) {
|
|
||||||
const builder = Builder.new(platform, this.config);
|
|
||||||
const runner = Runner.new(platform, this.config.name);
|
|
||||||
const debug = new Debug();
|
|
||||||
return gulp.series(
|
|
||||||
() => builder.prepare(),
|
|
||||||
() => builder.call(debug),
|
|
||||||
() => runner.prepare(),
|
|
||||||
() => runner.call(debug)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
bind(module) {
|
|
||||||
for (const platform of this.platforms) {
|
|
||||||
module.exports[`${this.config.name}:${platform}:build`] = this.build(platform);
|
|
||||||
module.exports[`${this.config.name}:${platform}:run`] = this.run(platform);
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Project.Platform = Platform;
|
|
||||||
Project.Config = Config;
|
|
||||||
Project.Builder = Builder;
|
|
||||||
Project.Runner = Runner;
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = Project;
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
const through = require('through2');
|
|
||||||
const colors = require('ansi-colors');
|
|
||||||
const log = require('fancy-log');
|
|
||||||
|
|
||||||
const TAG = colors.green('[tail]');
|
|
||||||
|
|
||||||
|
|
||||||
const { Writable } = require('stream');
|
|
||||||
const { StringDecoder } = require('string_decoder');
|
|
||||||
|
|
||||||
|
|
||||||
class StringWritable extends Writable {
|
|
||||||
constructor(handler, options) {
|
|
||||||
super(options);
|
|
||||||
this.handler = handler;
|
|
||||||
const state = this._writableState;
|
|
||||||
this._decoder = new StringDecoder(state.defaultEncoding);
|
|
||||||
this.data = '';
|
|
||||||
}
|
|
||||||
_write(chunk, encoding, callback) {
|
|
||||||
if (encoding === 'buffer') {
|
|
||||||
chunk = this._decoder.write(chunk);
|
|
||||||
for (const line of chunk.split('\n')) if (line.length) {
|
|
||||||
this.handler(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.data += chunk;
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
_final(callback) {
|
|
||||||
this.data += this._decoder.end();
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = (handler) => {
|
|
||||||
return through.obj(function (file, enc, callback) {
|
|
||||||
file.contents.pipe(new StringWritable(handler));
|
|
||||||
this.push(file);
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
73
gulpfile.js
73
gulpfile.js
@@ -2,10 +2,9 @@
|
|||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
const clean = require('gulp-clean');
|
const clean = require('gulp-clean');
|
||||||
const Config = require('./config.json');
|
const Config = require('./config.json');
|
||||||
const Project = require('./build/project');
|
|
||||||
const version = require('./build/version');
|
const version = require('./build/version');
|
||||||
const packageInfo = require('./package.json');
|
const packageInfo = require('./package.json');
|
||||||
const {Sdk, Haxe} = require('gulp-haxetool');
|
const {Sdk, Haxe, Project} = require('gulp-haxetool');
|
||||||
const dateformat = require('dateformat');
|
const dateformat = require('dateformat');
|
||||||
|
|
||||||
|
|
||||||
@@ -41,12 +40,14 @@ exports.install = () => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const config = new Project.Config({
|
const config = new Project.Config({
|
||||||
title: 'Tank\'z',
|
meta: {
|
||||||
pack: 'ru.m.tankz',
|
title: 'Tank\'z',
|
||||||
company: 'MegaLoMania',
|
pack: 'ru.m.tankz',
|
||||||
version: version,
|
company: 'MegaLoMania',
|
||||||
lib: packageInfo.haxeDependencies,
|
version: version,
|
||||||
cp: [
|
},
|
||||||
|
libs: packageInfo.haxeDependencies,
|
||||||
|
sources: [
|
||||||
'src/common/haxe',
|
'src/common/haxe',
|
||||||
'src-gen/haxe',
|
'src-gen/haxe',
|
||||||
],
|
],
|
||||||
@@ -58,36 +59,42 @@ const config = new Project.Config({
|
|||||||
/**
|
/**
|
||||||
* client
|
* client
|
||||||
*/
|
*/
|
||||||
const client = new Project(config.update({
|
const client = new Project(
|
||||||
name: 'client',
|
Project.BuildSystem.OPENFL,[
|
||||||
cp: ['src/client/haxe'],
|
Project.Platform.FLASH,
|
||||||
asset: ['src/client/resources'],
|
Project.Platform.HTML5,
|
||||||
main: 'ru.m.tankz.Client',
|
Project.Platform.LINUX,
|
||||||
}), [
|
], config.branch({
|
||||||
Project.Platform.FLASH,
|
name: 'client',
|
||||||
Project.Platform.HTML5,
|
sources: ['src/client/haxe'],
|
||||||
Project.Platform.LINUX,
|
assets: ['src/client/resources'],
|
||||||
]).bind(module);
|
main: 'ru.m.tankz.Client',
|
||||||
|
})
|
||||||
|
).bind(module, gulp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* editor
|
* editor
|
||||||
*/
|
*/
|
||||||
const editor = new Project(config.update({
|
const editor = new Project(
|
||||||
name: 'editor',
|
Project.BuildSystem.OPENFL, [
|
||||||
cp: ['src/client/haxe', 'src/editor/haxe'],
|
Project.Platform.FLASH
|
||||||
asset: ['src/client/resources'],
|
], config.branch({
|
||||||
main: 'ru.m.tankz.editor.Editor',
|
name: 'editor',
|
||||||
}), [
|
sources: ['src/client/haxe', 'src/editor/haxe'],
|
||||||
Project.Platform.FLASH,
|
assets: ['src/client/resources'],
|
||||||
]).bind(module);
|
main: 'ru.m.tankz.editor.Editor',
|
||||||
|
})
|
||||||
|
).bind(module, gulp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* server
|
* server
|
||||||
*/
|
*/
|
||||||
const server = new Project(config.update({
|
const server = new Project(
|
||||||
name: 'server',
|
Project.BuildSystem.HAXE, [
|
||||||
cp: ['src/server/haxe'],
|
Project.Platform.NEKO
|
||||||
main: 'ru.m.tankz.server.Server',
|
], config.branch({
|
||||||
}), [
|
name: 'server',
|
||||||
Project.Platform.NEKO,
|
sources: ['src/server/haxe'],
|
||||||
]).bind(module);
|
main: 'ru.m.tankz.server.Server',
|
||||||
|
})
|
||||||
|
).bind(module, gulp);
|
||||||
|
|||||||
13
package.json
13
package.json
@@ -3,19 +3,10 @@
|
|||||||
"version": "0.7.3",
|
"version": "0.7.3",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-core": "^6.26.0",
|
|
||||||
"babel-preset-es2015": "^6.24.1",
|
|
||||||
"dateformat": "^3.0.3",
|
"dateformat": "^3.0.3",
|
||||||
"gulp": "github:gulpjs/gulp#4.0",
|
"gulp": "^4.0.0",
|
||||||
"gulp-babel": "^7.0.1",
|
|
||||||
"gulp-clean": "^0.4.0",
|
"gulp-clean": "^0.4.0",
|
||||||
"gulp-concat": "^2.6.1",
|
"gulp-haxetool": "file:../../gulp-haxetool"
|
||||||
"gulp-debian": "^0.1.9",
|
|
||||||
"gulp-haxetool": "file:/opt/repo/gulp-haxetool",
|
|
||||||
"gulp-run": "^1.7.1",
|
|
||||||
"gulp-template": "^5.0.0",
|
|
||||||
"gulp-uglify": "^3.0.0",
|
|
||||||
"gulp-webserver": "^0.9.1"
|
|
||||||
},
|
},
|
||||||
"haxeDependencies": {
|
"haxeDependencies": {
|
||||||
"lime": "6.0.1",
|
"lime": "6.0.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user