Skip to content

Instantly share code, notes, and snippets.

@clemos
Created March 4, 2012 15:56
Show Gist options
  • Select an option

  • Save clemos/1973647 to your computer and use it in GitHub Desktop.

Select an option

Save clemos/1973647 to your computer and use it in GitHub Desktop.
server side haXe auto-compilation scripts
RewriteEngine on
RewriteRule ^(.*)\.hx\.js compilejs.php?cl=$1 [QSA]
-main JsCompiler
-php compilejs.php
#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 ); }
})();");
}
}
}
@lexoyo
Copy link
Copy Markdown

lexoyo commented Apr 11, 2012

Good script, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment