[build] update gulp debug logger

This commit is contained in:
2017-12-20 17:53:58 +03:00
parent 69c2b735a0
commit 6345ddcd19
17 changed files with 212 additions and 77 deletions

View File

@@ -20,11 +20,17 @@ const log = (line) => {
module.exports = () => {
return through.obj(function (file, enc, callback) {
const debug = file.debug;
if (!file.debug) {
this.emit('end');
callback();
return;
}
const server = net.createServer((socket) => {
socket.on("data", (data) => {
const lines = data.toString().split('\n');
for (let line of lines) if (line.length > 2) {
log(line.substr(2));
log(line);
}
});
socket.on("close", () => {
@@ -34,7 +40,8 @@ module.exports = () => {
callback();
});
});
server.listen(5000);
gutil.log(col.green('[debug]'), col.cyan('listen on'), col.magenta(`${debug.host}:${debug.port}`));
server.listen(debug.port, debug.host);
})
};

View File

@@ -125,18 +125,18 @@ class FlashPlayer extends Sdk {
FlashPlayer.enableLog();
exec('.', [this.flashPlayerBin(debug), file.path].join(' ')).then(() => {
stream.emit('end');
//callback();
callback();
}).catch((error) => {
stream.emit('end');
//callback();
stream.emit('error', error);
stream.emit('error', new gutil.PluginError({plugin: this.tag, message: error}));
callback();
});
//stream.push(file);
// ToDo: watch when file is exists
// or create log file in FlashPlayer.enableLog()?
stream.push(new gutil.File({
/*stream.push(new gutil.File({
path: FlashPlayer.log
}));
}));*/
stream.push(file);
};
return stream = through.obj(bufferContents);

View File

@@ -10,6 +10,7 @@ const gulp = require('gulp');
const through = require('through2');
const col = gutil.colors;
const Sdk = require('./sdk');
const dateformat = require('dateformat');
class Haxe extends Sdk {
@@ -130,6 +131,12 @@ class Haxe extends Sdk {
* }
*/
openfl(params) {
params = Object.assign({
build: dateformat(new Date(), 'yyyy-mm-ddHH:MM:ss'),
macro: [],
debug: false,
}, params);
const files = [];
let stream = null;
@@ -156,12 +163,26 @@ class Haxe extends Sdk {
args.push(`--app-path=${dir}`);
args.push(`--app-file=${name}`);
if (params.version) args.push(`--meta-version=${params.version}`);
if (params.build) args.push(`--haxedef=BUILD="${params.build}"`);
//if (params.build) args.push(`--haxedef=BUILD="${params.build}"`);
args.push(`--haxeflag="--macro=CompilationOption.set('build','${params.build}')"`);
let debug = null;
if (params.debug) {
debug = {
host: 'localhost',
port: 6000 + Math.floor(Math.random() * 1000),
};
args.push(`--haxeflag="--macro=CompilationOption.set('debug.address','${debug.host}')"`);
args.push(`--haxeflag="--macro=CompilationOption.set('debug.port','${debug.port}')"`);
args.push('-debug');
}
//console.log('haxelib', args.join(' '));
this.haxelib(args).then(() => {
stream.push(new gutil.File({
const out = new gutil.File({
path: params.outputFile,
contents: fs.createReadStream(`${dir}/flash/bin/${name}.swf`)
}));
});
out.debug = debug;
stream.push(out);
callback();
}).catch((error) => {
stream.emit('error', new gutil.PluginError({plugin: this.name, message: error}));
@@ -185,9 +206,16 @@ class Haxe extends Sdk {
* src: [],
* main: 'Main.hx',
* outputFile: 'out.n',
* debug: true,
* }
*/
build(params) {
params = Object.assign({
build: dateformat(new Date(), 'yyyy-mm-ddHH:MM:ss'),
macro: [],
debug: false,
}, params);
const files = [];
let stream = null;
@@ -222,13 +250,25 @@ class Haxe extends Sdk {
const dir = path.dirname(tmpFile.path);
const name = path.basename(tmpFile.path);
args.push(`-${params.platform}`, tmpFile.path);
if (params.build) args.push(`--haxedef=BUILD="${params.build}"`);
args.push(`--macro "CompilationOption.set('build','${params.build}')"`);
let debug = null;
if (params.debug) {
debug = {
host: 'localhost',
port: 6000 + Math.floor(Math.random() * 1000),
};
args.push(`--macro "CompilationOption.set('debug.address','${debug.host}')"`);
args.push(`--macro "CompilationOption.set('debug.port','${debug.port}')"`);
args.push('-debug');
}
//console.log('haxe', args.join(' '));
this.haxe(args).then(() => {
stream.push(new gutil.File({
const out = new gutil.File({
path: params.outputFile,
contents: fs.createReadStream(tmpFile.path)
}));
});
out.debug = debug;
stream.push(out);
callback();
}).catch((error) => {
stream.emit('error', new gutil.PluginError({plugin: this.name, message: error}));