1 decade ago by BlackDolphinMedia
config:
Actual deployment Script:
the code is far away from beeing optimized or secure .. but its a good start .. if someone wana join me to make that even better .. feel free to hook up over skype : "aspfreak" or pop in to IMPACT IRC
cheers
<?php // GAME RELATED CONFIG // SVN SERVER SETTINGS $SVN_USERNAME = "USER"; $SVN_PASSWORD = "PWD"; $SVN_URL = "http://svn.............../zelda/"; // DEPLOYMENT RELATED CONFIG $PATH_MAIN = "/....../zelda"; $PATH_TO_CHECKOUT = $PATH_MAIN . "/svn"; $PATH_TO_EXPORT = $PATH_MAIN . "/"; ?>
Actual deployment Script:
<?php /* * REQUIRES http://pecl.php.net/package/svn * + subversion on the server */ if(!file_exists("config.php")) { echo "YOU NEET TO RENAME config.php.sample to config.php + set the correct Parameters"; die(); } include_once 'config.php'; svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_USERNAME, $SVN_USERNAME); svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_PASSWORD, $SVN_PASSWORD); svn_auth_set_parameter(PHP_SVN_AUTH_PARAM_IGNORE_SSL_VERIFY_ERRORS, true); svn_auth_set_parameter(SVN_AUTH_PARAM_NON_INTERACTIVE, true); svn_auth_set_parameter(SVN_AUTH_PARAM_NO_AUTH_CACHE, true); svn_checkout($SVN_URL, $PATH_TO_CHECKOUT); svn_export($PATH_TO_CHECKOUT, $PATH_TO_EXPORT); $inFiles = array("lib/impact/impact.js", "lib/game/main.js"); $outFile = "game.min.js"; $baker = new Baker( Baker::MINIFIED ); $baker->bake( $inFiles, $outFile ); $gamefile = file_get_contents($outFile); class Baker { const PLAIN = 0; const MINIFIED = 1; const GZIPPED = 2; protected $base = 'lib/'; protected $format = 0; protected $loaded = array(); protected $currentInput = 'Command Line'; protected $fileCount = 0, $bytesIn = 0, $bytesOut = 0; public function __construct( $format = 0 ) { $this->format = $format; echo "CONSTRUCTOR"; if( $this->format & self::MINIFIED ) { require_once( 'tools/jsmin.php' ); } } public function bake( $inFiles, $outFile ) { $this->fileCount = 0; $this->bytesIn = 0; // $out = "/*! Built with IMPACT - impactjs.com */\n\n"; $out = ""; foreach( $inFiles as $f ) { $out .= $this->load( $f ); } $bytesOut = strlen($out); $bytesOutZipped = 0; echo "writing $outFile\n"; @file_put_contents( $outFile, $out ) or die("ERROR: Couldn't write to $outFile\n"); if( $this->format & self::GZIPPED ) { $gzFile = "$outFile.gz"; echo "writing $gzFile\n"; $fh = gzopen( $gzFile, 'w9' ) or die("ERROR: Couldn't write to $gzFile\n"); gzwrite( $fh, $out ); gzclose( $fh ); $bytesOutZipped = filesize( $gzFile ); } echo "\nbaked {$this->fileCount} files: ". round($this->bytesIn/1024,1)."kb -> ".round($bytesOut/1024,1)."kb" . ( $this->format & self::GZIPPED ? " (".round($bytesOutZipped/1024,1)."kb gzipped)\n" : "\n" ); } protected function load( $path ) { if( $this->loaded[$path] ) { return ''; } if( !file_exists($path) ) { die("ERROR: Couldn't load $path required from {$this->currentInput}\n"); } echo "loading $path \n"; $this->loaded[$path] = true; $this->currentInput = $path; $code = file_get_contents( $path ); $this->bytesIn += strlen($code); $this->fileCount++; if( $this->format & self::MINIFIED ) { $code = trim(JSMin::minify($code)); } // Naively probe the file for 'ig.module().requires().defines()' code; // the 'requries()' part will be handled by the regexp callback $this->definesModule = false; $code = preg_replace_callback( '/ig\s* \.\s*module\s*\((.*?)\)\s* (\.\s*requires\s*\((.*?)\)\s*)? \.\s*defines\s*\( /smx', array($this,'loadCallback'), $code ); // All files should define a module; maybe we just missed it? Print a // friendly reminder :) if( !$this->definesModule ) { echo "WARNING: file $path seems to define no module!\n"; } return $code; } protected function loadCallback( $matches ) { $currentInput = $this->currentInput; $this->definesModule = true; $moduleName = $matches[1]; $requiredFiles = $matches[3]; $requiredCode = ''; if( $requiredFiles ) { // Explode the module names and map them to file names. Ignore the // dom.ready module if present $moduleFiles = array_diff( explode( ',', preg_replace( '/[\s\'"]|\/\/.*|\/\*.*\*\//', // strip quotes and spaces '', str_replace('.', '/', $requiredFiles ) // . to / ) ), array('dom/ready') ); foreach( $moduleFiles as $f ) { $requiredCode .= $this->load( $this->base . $f.'.js' ); } } return $requiredCode . "\n" . 'ig.baked=true;' . 'ig.module('.$moduleName.')' . ( $requiredFiles ? '.requires('.$requiredFiles.')' : '' ) . '.defines('; } } ?>
the code is far away from beeing optimized or secure .. but its a good start .. if someone wana join me to make that even better .. feel free to hook up over skype : "aspfreak" or pop in to IMPACT IRC
cheers