From 2ec357266f1c1a3e6b96acd5862db2b0569ac81a Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Tue, 29 Dec 2015 10:56:29 +0800 Subject: [PATCH 1/2] Fix compilation on nodejs put `--macro allowPackage('sys')` in your hxml --- src/ufront/tasks/UFTaskSet.hx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/ufront/tasks/UFTaskSet.hx b/src/ufront/tasks/UFTaskSet.hx index 5c54348..574bcfe 100644 --- a/src/ufront/tasks/UFTaskSet.hx +++ b/src/ufront/tasks/UFTaskSet.hx @@ -1,6 +1,5 @@ package ufront.tasks; -#if sys import mcli.CommandLine; import mcli.Dispatch; import minject.Injector; @@ -47,23 +46,34 @@ class UFTaskSet extends CommandLine { **/ @:skip public function useCLILogging( ?logFile:String ):UFTaskSet { + var logFilePath = null; var file:FileOutput = null; if ( logFile!=null ) { var contentDir:String = injector.getInstance( String, "contentDirectory" ); - var logFilePath = contentDir.addTrailingSlash()+logFile; + logFilePath = contentDir.addTrailingSlash()+logFile; var logFileDirectory = logFilePath.directory(); if ( FileSystem.exists(logFileDirectory)==false ) FileSystem.createDirectory( logFileDirectory ); - file = File.append( logFilePath ); + var line = '${Date.now()} [UFTask Runner] ${Sys.args()}'; - file.writeString( '$line\n' ); + + #if nodejs + js.node.Fs.appendFileSync( logFilePath, '$line\n' ); + #else + file = File.append( logFilePath ); + file.writeString( '$line\n' ); + #end + } function onMessage( msg:Message ) { var line = FileLogger.format( msg ); Sys.println( line ); - if ( file!=null ) { - file.writeString( '\t$line\n' ); - } + + #if nodejs + if ( logFilePath!=null ) js.node.Fs.appendFileSync( logFilePath, '\t$line\n' ); + #else + if ( file!=null ) file.writeString( '\t$line\n' ); + #end } haxe.Log.trace = function(msg:Dynamic,?pos:PosInfos) onMessage({ msg: msg, pos: pos, type:MTrace }); injector.map( MessageList ).toValue( new MessageList(onMessage) ); @@ -141,4 +151,3 @@ class UFTaskSet extends CommandLine { **/ @:noCompletion inline function ufError( msg:Dynamic, ?pos:PosInfos ) messages.push({ msg: msg, pos: pos, type:MError }); } -#end From 55243e9ce764c04b80134fc7ef60d4e55bc9ba30 Mon Sep 17 00:00:00 2001 From: Kevin Leung Date: Wed, 9 Mar 2016 10:55:26 +0800 Subject: [PATCH 2/2] Fix file logger for nodejs --- src/ufront/tasks/UFTaskSet.hx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/ufront/tasks/UFTaskSet.hx b/src/ufront/tasks/UFTaskSet.hx index 574bcfe..212526b 100644 --- a/src/ufront/tasks/UFTaskSet.hx +++ b/src/ufront/tasks/UFTaskSet.hx @@ -11,6 +11,7 @@ import ufront.log.MessageList; import ufront.api.UFApi; import haxe.PosInfos; using haxe.io.Path; +using StringTools; class UFTaskSet extends CommandLine { @@ -58,6 +59,7 @@ class UFTaskSet extends CommandLine { var line = '${Date.now()} [UFTask Runner] ${Sys.args()}'; #if nodejs + // hxnodejs has no FileInput implemention (yet) js.node.Fs.appendFileSync( logFilePath, '$line\n' ); #else file = File.append( logFilePath ); @@ -67,13 +69,14 @@ class UFTaskSet extends CommandLine { } function onMessage( msg:Message ) { var line = FileLogger.format( msg ); - Sys.println( line ); - #if nodejs - if ( logFilePath!=null ) js.node.Fs.appendFileSync( logFilePath, '\t$line\n' ); - #else - if ( file!=null ) file.writeString( '\t$line\n' ); - #end + Sys.println( line ); +#if nodejs + // hxnodejs has no FileInput implemention (yet) + if ( logFilePath!=null ) js.node.Fs.appendFileSync( logFilePath, '\t$line\n' ); +#else + if ( file!=null ) file.writeString( '\t$line\n' ); +#end } haxe.Log.trace = function(msg:Dynamic,?pos:PosInfos) onMessage({ msg: msg, pos: pos, type:MTrace }); injector.map( MessageList ).toValue( new MessageList(onMessage) );