#!/usr/bin/php $srcFiles) { array_push($JSTarget, $dstFile); } $CompressedFiles = implode(' ', array_keys($ConfigDefine)); $Makefile = << $dstConfig) { if(isSet($ConfigDefine[$dstFile]['JSfiles']) && isSet($ConfigDefine[$dstFile]['params'])) { $Makefile .= $dstFile . ': config.depends ' . implode(' ', $ConfigDefine[$dstFile]['JSfiles']) . "\n"; $Makefile .= "\t$(JS_COMPILER) " . $ConfigDefine[$dstFile]['params'] . " -d ". $dstFile ." \"\$(shell pwd)/config.depends\"\n\n"; } else { $Makefile .= $dstFile . ': config.depends ' . implode(' ', $dstConfig) . "\n"; $Makefile .= "\t$(JS_COMPILER) -d ". $dstFile ." \$(shell pwd)/config.depends\n\n"; } } return $Makefile; } function Usage() { global $argv; echo << $a ) { while ( $k = array_search( "-" . $o, $argv ) ) { if ( $k ) { unset( $argv[$k] ); $argc--; } if ( preg_match( "/^.*".$o.":.*$/i", $options ) ) { unset( $argv[$k+1] ); $argc--; } } } $argv = array_merge( $argv ); return $opts; } $opts = GetOptions(); if (FALSE === $opts || $argc < 2 || $argc > 3) { Usage(); exit(1); } /* Compress package's js, css to gzip */ $UseCompressGzip="yes"; if (file_exists("/lnxscripts")) { $UseCompressGzip = "no"; } else if (isSet($opts['c'])) { switch ($opts['c']) { case "yes": $UseCompressGzip = "yes"; break; case "no": $UseCompressGzip = "no"; break; default: echo "Error: Invalid Transpiler Option.\n"; Usage(); exit(1); } } if (!is_dir($argv[1])) { echo "Error: {$argv[1]} is not a directory.\n"; exit(1); } $CWD = getcwd(); chdir($argv[1]); $InputFiles = array( 'debug' => 'config.debug', 'define' => 'config.define', 'auto_debug'=> 'auto_config.debug', 'depend' => 'config.depends' ); $OutputFiles = array( 'config' => 'config', 'makefile' => 'Makefile.js.inc', 'style' => 'style.css', 'scss' => 'scss/style.scss', 'compass_config' => 'scss/config.rb' ); if (file_exists("app.config") && file_exists("config.debug")) { echo "Error > app.config and config.debug should not both exist\n"; exit(1); } $define_path = $InputFiles['define']; if (file_exists($define_path)) { $ConfigDefine = DecodeJsonFile($define_path); } else { echo "Skip parsing: config.define not exist\n"; $ConfigDefine = array(); } if (!is_array($ConfigDefine)) { exit(1); } /* Generate files */ file_put_contents($OutputFiles['makefile'], GenerateMakefile($UseCompressGzip)); // generate config.rb for compass if scss file exists if (file_exists($OutputFiles['scss'])) { file_put_contents($OutputFiles['compass_config'], GenerateCompassConfig()); } chdir($CWD); ?>