[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

3
.gitignore vendored
View File

@@ -9,4 +9,5 @@ out/
.idea/ .idea/
config.json config.json
package-lock.json package-lock.json
/node_modules /node_modules
/log

View File

@@ -5,33 +5,19 @@ const tail = require('../tasks/tail');
const Haxe = require('../tasks/haxe'); const Haxe = require('../tasks/haxe');
const FlashPlayer = require('../tasks/flashplayer'); const FlashPlayer = require('../tasks/flashplayer');
const version = require('./version'); const version = require('./version');
const dateformat = require('dateformat');
const prepare = require('./prepare'); const prepare = require('./prepare');
const debug = require('../tasks/debug'); const debug = require('../tasks/debug');
const build = (params) => function build() { const build = () => function build() {
params = params || {};
const argv = yargs.argv; const argv = yargs.argv;
const values = {
build: dateformat(new Date(), 'yyyy-mm-dd HH:MM:ss'),
};
let outputFile = 'tankz.swf';
if (params.outputFile) {
outputFile = params.outputFile;
}
if (argv.dev) {
values.dev = true;
if (!values['dev.address']) values['dev.address'] = argv['dev-address'] || 'localhost';
if (!values['dev.port']) values['dev.port'] = argv['dev-port'] || 5000;
}
return gulp.src('.') return gulp.src('.')
.pipe(new Haxe().openfl({ .pipe(new Haxe().openfl({
command: 'build', command: 'build',
platform: 'flash', platform: 'flash',
version: version, version: version,
values: values, outputFile: 'tankz.swf',
outputFile: outputFile, debug: argv.dev,
})) }))
.pipe(gulp.dest('target')); .pipe(gulp.dest('target'));
}; };
@@ -40,7 +26,8 @@ const test = (build) => function test() {
const argv = yargs.argv; const argv = yargs.argv;
return build() return build()
.pipe(new FlashPlayer().run(argv.dev)) .pipe(new FlashPlayer().run(argv.dev))
.pipe(tail(debug.log)); //.pipe(tail(debug.log));
.pipe(debug());
}; };

View File

@@ -6,47 +6,29 @@ const Haxe = require('../tasks/haxe');
const FlashPlayer = require('../tasks/flashplayer'); const FlashPlayer = require('../tasks/flashplayer');
const Neko = require('../tasks/neko'); const Neko = require('../tasks/neko');
const version = require('./version'); const version = require('./version');
const dateformat = require('dateformat');
const prepare = require('./prepare'); const prepare = require('./prepare');
const debug = require('../tasks/debug'); const debug = require('../tasks/debug');
const build = (params) => function build() { const build = () => function build() {
params = params || {};
const argv = yargs.argv; const argv = yargs.argv;
const values = {
build: dateformat(new Date(), 'yyyy-mm-dd h:MM:ss'),
};
let outputFile = 'tankz.n';
if (params.outputFile) {
outputFile = params.outputFile;
}
if (argv.dev) {
values.dev = true;
if (!values['dev.address']) values['dev.address'] = argv['dev-address'] || 'localhost';
if (!values['dev.port']) values['dev.port'] = argv['dev-port'] || 5000;
}
return gulp.src('.') return gulp.src('.')
.pipe(new Haxe().build({ .pipe(new Haxe().build({
platform: 'neko', platform: 'neko',
version: version, version: version,
values: values,
lib: [ lib: [
'protohx', 'protohx',
'orm', 'orm',
'haxework', 'haxework:git',
], ],
cp: [ cp: [
'src/common/haxe', 'src/common/haxe',
'src/server/haxe', 'src/server/haxe',
'src-gen/haxe', 'src-gen/haxe',
], ],
macro: [
`CompilationOption.set('debug.address','${values['dev.address']}')`,
`CompilationOption.set('debug.port','${values['dev.port']}')`,
],
main: 'ru.m.tankz.server.Server', main: 'ru.m.tankz.server.Server',
outputFile: outputFile, outputFile: 'tankz.n',
debug: argv.dev,
})) }))
.pipe(gulp.dest('target')); .pipe(gulp.dest('target'));
}; };

5
capfile Normal file
View File

@@ -0,0 +1,5 @@
require 'capistrano/setup'
require 'capistrano/deploy'
require 'airbrussh/capistrano'
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

44
config/deploy.rb Normal file
View File

@@ -0,0 +1,44 @@
require_relative 'service'
app = 'tankz'
user = 'adman'
set :scm, :git
set :application, app
set :repo_url, "git@bitbucket.org:shmyga/#{app}.git"
set :user, user
set :deploy_to, "/home/#{user}/repo/#{app}"
namespace :build do
task :lib do
on roles(:app) do
execute "mkdir ~/haxelib 2>/dev/null || :"
execute "haxelib setup ~/haxelib"
execute "haxelib install lime"
execute "haxelib install openfl"
execute "haxelib install protohx"
execute "haxelib install orm"
execute "haxelib git haxework git@bitbucket.org:shmyga/haxework.git"
end
end
task :gen do
on roles(:app) do
execute "cd #{release_path} && haxelib run protohx generate protohx.json"
execute "cd #{release_path} && haxelib run orm mysql://shmyga:xkbp8jh9z2@localhost:3306/armageddon -s src-gen/haxe -c ru.m.tankz.db -a ru.m.tankz.db"
end
end
task :run do
on roles(:app) do
execute "cd #{release_path} && openfl build html5"
execute "cd #{release_path} && openfl build flash"
execute "cd #{release_path} && haxe server.hxml"
end
end
end
before 'build:run', 'build:lib'
before 'build:run', 'build:gen'
before 'deploy:updated', 'build:run'

10
config/deploy/develop.rb Normal file
View File

@@ -0,0 +1,10 @@
role :app, %w{localhost}
role :web, %w{localhost}
role :db, %w{localhost}
user = fetch(:user)
server 'localhost', ssh_options: { port: 22, user: user, forward_agent: true }
set :tmp_dir, "/home/#{user}/tmp"
set :branch, 'master'

View File

@@ -0,0 +1,10 @@
role :app, %w{test.instreamatic.com}
role :web, %w{test.instreamatic.com}
role :db, %w{test.instreamatic.com}
user = fetch(:user)
server 'test.instreamatic.com', ssh_options: { port: 3607, user: user, forward_agent: true }
set :tmp_dir, "/home/#{user}/tmp"
set :branch, 'master'

52
config/service.rb Normal file
View File

@@ -0,0 +1,52 @@
module Service
class Manager
def initialize(env)
@env = env
end
def execute(action, command)
Airbrussh.configure do |config|
config.command_output = true
end
service_role = "service_role_#{action}".to_sym
role = fetch(service_role)
on roles(role) do
execute :sudo, "/bin/systemctl #{command} #{action}"
end
end
end
end
services = %w{tankz}
namespace :service do
task :restart, :param do |task, args|
services = args[:param] ? [args[:param]] : services
services.each { |service|
Service::Manager.new(self).execute(service, 'restart')
}
end
task :stop, :param do |task, args|
services = args[:param] ? [args[:param]] : services
services.each { |service|
Service::Manager.new(self).execute(service, 'stop')
}
end
task :start, :param do |task, args|
services = args[:param] ? [args[:param]] : services
services.each { |service|
Service::Manager.new(self).execute(service, 'start')
}
end
task :status, :param do |task, args|
services = args[:param] ? [args[:param]] : services
services.each { |service|
Service::Manager.new(self).execute(service, 'status')
}
end
end
set :service_role_tankz, :app

View File

@@ -2,14 +2,13 @@
<project> <project>
<meta title="Tank'z" package="ru.m.tankz" version="0.0.0" company="MegaLoMania"/> <meta title="Tank'z" package="ru.m.tankz" version="0.0.0" company="MegaLoMania"/>
<app main="ru.m.tankz.Client" path="target" file="tankz"/> <app main="ru.m.tankz.Client" path="target" file="tankz"/>
<haxeflag name="--macro" value="CompilationOption.set('build','${build}')"/>
<source path="src/common/haxe"/> <source path="src/common/haxe"/>
<source path="src/client/haxe"/> <source path="src/client/haxe"/>
<source path="src-gen/haxe"/> <source path="src-gen/haxe"/>
<assets path="src/client/resources" rename="resources" include="*"/> <assets path="src/client/resources" rename="resources" include="*"/>
<haxelib name="openfl"/> <haxelib name="openfl"/>
<haxelib name="protohx"/> <haxelib name="protohx"/>
<haxelib name="haxework"/> <haxelib name="haxework" version="git"/>
<window width="760" height="600"/> <window width="760" height="600"/>
<haxeflag name="-D" value="swf-gpu"/> <haxeflag name="-D" value="swf-gpu"/>
<haxeflag name="-D" value="native-trace"/> <haxeflag name="-D" value="native-trace"/>
@@ -17,11 +16,4 @@
<haxeflag name="-dce" value="no"/> <haxeflag name="-dce" value="no"/>
<!--<template path="src/client/webapp/index_template.html" rename="index.html"/>--> <!--<template path="src/client/webapp/index_template.html" rename="index.html"/>-->
<section if="dev">
<haxeflag name="-debug"/>
<haxeflag name="--macro" value="CompilationOption.set('debug.address','${dev.address}')"/>
<haxeflag name="--macro" value="CompilationOption.set('debug.port','${dev.port}')"/>
<!--<haxeflag name="-D" value="proto_debug"/>-->
</section>
</project> </project>

View File

@@ -1,11 +0,0 @@
-main ru.m.tankz.server.Server
-lib protohx
-lib orm
-lib haxework
-cp src/common/haxe
-cp src/server/haxe
-cp src-gen/haxe
--macro CompilationOption.set('debug.address','localhost')
--macro CompilationOption.set('debug.port','5000')
-neko target/server.n
# -D proto_debug

View File

@@ -1,2 +0,0 @@
#!/bin/bash
haxe server.hxml && neko target/server.n

View File

@@ -1,5 +1,6 @@
package ru.m.tankz; package ru.m.tankz;
import haxework.log.SocketLogger;
import haxework.resources.Resources; import haxework.resources.Resources;
import haxework.resources.IResources; import haxework.resources.IResources;
import haxework.gui.VGroupView; import haxework.gui.VGroupView;
@@ -31,6 +32,9 @@ class Client implements IConnectionHandler {
#if flash #if flash
L.push(new JSLogger()); L.push(new JSLogger());
#end #end
#if debug
L.push(new SocketLogger());
#end
Const.init(); Const.init();
L.d(TAG, "Debug: " + Const.DEBUG); L.d(TAG, "Debug: " + Const.DEBUG);
L.i(TAG, "Version: " + Const.VERSION); L.i(TAG, "Version: " + Const.VERSION);

View File

@@ -38,8 +38,11 @@ class Server extends ThreadServer<Session, Bytes> {
public static function main() { public static function main() {
L.push(new TraceLogger()); L.push(new TraceLogger());
#if debug
L.push(new SocketLogger()); L.push(new SocketLogger());
#end
L.d(TAG, "Running"); L.d(TAG, "Running");
L.i(TAG, "Build: " + CompilationOption.get("build"));
Provider.set(IPacketBuilder, new PacketBuilder()); Provider.set(IPacketBuilder, new PacketBuilder());
var wserver = new Server(); var wserver = new Server();
wserver.run("localhost", 5001); wserver.run("localhost", 5001);

11
tankz.service Normal file
View File

@@ -0,0 +1,11 @@
[Unit]
Description=Tankz server
[Service]
WorkingDirectory=/home/adman/repo/tankz/current/target
ExecStart=/usr/bin/neko tankz.n
Restart=always
[Install]
WantedBy=multi-user.target
Alias=tankz.service

View File

@@ -20,11 +20,17 @@ const log = (line) => {
module.exports = () => { module.exports = () => {
return through.obj(function (file, enc, callback) { return through.obj(function (file, enc, callback) {
const debug = file.debug;
if (!file.debug) {
this.emit('end');
callback();
return;
}
const server = net.createServer((socket) => { const server = net.createServer((socket) => {
socket.on("data", (data) => { socket.on("data", (data) => {
const lines = data.toString().split('\n'); const lines = data.toString().split('\n');
for (let line of lines) if (line.length > 2) { for (let line of lines) if (line.length > 2) {
log(line.substr(2)); log(line);
} }
}); });
socket.on("close", () => { socket.on("close", () => {
@@ -34,7 +40,8 @@ module.exports = () => {
callback(); 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(); FlashPlayer.enableLog();
exec('.', [this.flashPlayerBin(debug), file.path].join(' ')).then(() => { exec('.', [this.flashPlayerBin(debug), file.path].join(' ')).then(() => {
stream.emit('end'); stream.emit('end');
//callback(); callback();
}).catch((error) => { }).catch((error) => {
stream.emit('end'); stream.emit('error', new gutil.PluginError({plugin: this.tag, message: error}));
//callback(); callback();
stream.emit('error', error);
}); });
//stream.push(file); //stream.push(file);
// ToDo: watch when file is exists // ToDo: watch when file is exists
// or create log file in FlashPlayer.enableLog()? // or create log file in FlashPlayer.enableLog()?
stream.push(new gutil.File({ /*stream.push(new gutil.File({
path: FlashPlayer.log path: FlashPlayer.log
})); }));*/
stream.push(file);
}; };
return stream = through.obj(bufferContents); return stream = through.obj(bufferContents);

View File

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