Created
March 4, 2012 15:56
-
-
Save clemos/1973647 to your computer and use it in GitHub Desktop.
server side haXe auto-compilation scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RewriteEngine on | |
RewriteRule ^(.*)\.hx\.js compilejs.php?cl=$1 [QSA] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-main JsCompiler | |
-php compilejs.php |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if php | |
import php.Web; | |
import php.Sys; | |
import php.Lib; | |
#end | |
class JsCompiler { | |
public static function main(){ | |
var params = Web.getParams(); | |
var cl = params.get('cl'); | |
var libs = params.get('libs'); | |
var src = cl + ".hx"; | |
var main = cl.split("/").join("."); | |
var js = main + ".tmp.hx.js"; | |
var args = [ "-main" , main , "-js" , js ]; | |
if( libs != null ){ | |
for( lib in libs.split(","){ | |
args.push("-lib"); | |
args.push( lib ); | |
} | |
} | |
if( Sys.command( "haxe" , args ) == 0 ){ | |
Web.setHeader( "Location" , js ); | |
}else{ | |
Web.setHeader( "Content-type" , "text/javascript" ); | |
Lib.write("(function(){ | |
var outp='Compilation failed : haxe " + args.join(" ") +"'; | |
try{ console.log( outp ); } catch ( e ){ alert( outp ); } | |
})();"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good script, thanks!