[gulp] move tasks to gulp-haxetool package

This commit is contained in:
2018-04-03 15:12:53 +03:00
parent 92a2628e90
commit 836eebaf11
15 changed files with 34 additions and 967 deletions

View File

@@ -4,15 +4,15 @@ const uglify = require('gulp-uglify');
const babel = require('gulp-babel');
const template = require('gulp-template');
const yargs = require('yargs');
const Haxe = require('../tasks/haxe');
const FlashPlayer = require('../tasks/flashplayer');
const Haxe = require('gulp-haxetool').Haxe;
const FlashPlayer = require('gulp-haxetool').FlashPlayer;
const version = require('./version');
const prepare = require('./prepare');
const generate = prepare.generate;
const debug = require('../tasks/debug');
const debug = require('./debug');
const webserver = require('gulp-webserver');
const run = require('gulp-run');
const tail = require('../tasks/tail');
const tail = require('./tail');
const deb = require('gulp-debian');
@@ -121,7 +121,7 @@ const testLinux = gulp.series(
() => gulp.src('target/linux/tankz')
.pipe(run('./tankz', {cwd: 'target/linux', verbosity: 1}))
.pipe(tail(debug.log))
.pipe(gulp.dest('target/log'))
//.pipe(gulp.dest('target/log'))
);

64
build/debug.js Executable file
View File

@@ -0,0 +1,64 @@
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;
};
const _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(' ')));
}
};
module.exports = () => {
return through.obj(function (file, enc, callback) {
const debug = file.debug;
if (!file.debug) {
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;
_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.log = _log;

View File

@@ -1,10 +1,10 @@
const gulp = require('gulp');
const yargs = require('yargs');
const Haxe = require('../tasks/haxe');
const FlashPlayer = require('../tasks/flashplayer');
const Haxe = require('gulp-haxetool').Haxe;
const FlashPlayer = require('gulp-haxetool').FlashPlayer;
const version = require('./version');
const prepare = require('./prepare');
const debug = require('../tasks/debug');
const debug = require('./debug');
const build = (platform) => function build() {

View File

@@ -1,18 +1,16 @@
const AdobeAir = require('../tasks/adobeAir');
const Haxe = require('../tasks/haxe');
const FlashPlayer = require('../tasks/flashplayer');
const ht = require('gulp-haxetool');
const packageInfo = require('../package.json');
const prepareOne = (value) => {
switch (value) {
case Haxe.ID:
const haxe = new Haxe();
case ht.Haxe.ID:
const haxe = new ht.Haxe();
return haxe.prepare().then(() => haxe.install(packageInfo.haxeDependencies));
case AdobeAir.ID:
return new AdobeAir().prepare();
case FlashPlayer.ID:
return new FlashPlayer().prepare();
case ht.AdobeAir.ID:
return new ht.AdobeAir().prepare();
case ht.FlashPlayer.ID:
return new ht.FlashPlayer().prepare();
default:
throw Error(`Unknown target: ${value}`)
}
@@ -24,11 +22,11 @@ const prepare = (...targets) => function prepare() {
};
const update = () => {
return new Haxe().upgrade();
return new ht.Haxe().upgrade();
};
const generate = () => function generate() {
return new Haxe().haxelib([
return new ht.Haxe().haxelib([
'run', 'protohx', 'generate', 'protohx.json'
]);
};

View File

@@ -1,18 +1,16 @@
const gulp = require('gulp');
const yargs = require('yargs');
const Haxe = require('../tasks/haxe');
const FlashPlayer = require('../tasks/flashplayer');
const Neko = require('../tasks/neko');
const hx = require('gulp-haxetool');
const version = require('./version');
const prepare = require('./prepare');
const generate = prepare.generate;
const debug = require('../tasks/debug');
const debug = require('./debug');
const build = () => function build() {
const argv = yargs.argv;
return gulp.src('.')
.pipe(new Haxe().build({
.pipe(new hx.Haxe().build({
platform: 'neko',
version: version,
lib: [
@@ -40,10 +38,10 @@ const build = () => function build() {
const test = (build) => function test() {
const argv = yargs.argv;
return build()
.pipe(new Neko().run('localhost'))
.pipe(new hx.Neko().run('localhost'))
.pipe(debug());
};
exports['server'] = gulp.series(prepare(Haxe.ID), generate(), build());
exports['server:test'] = gulp.series(prepare(Haxe.ID), generate(), test(build()));
exports['server'] = gulp.series(prepare(hx.Haxe.ID), generate(), build());
exports['server:test'] = gulp.series(prepare(hx.Haxe.ID), generate(), test(build()));

43
build/tail.js Normal file
View File

@@ -0,0 +1,43 @@
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();
});
};