function Scaffold() { //Validation if (empty($this->args['name'])) { return Mojo::exception('Provide a full mojo path in your params string, ie: name=mojo.rules.myRules'); } if (strpos($this->args['name'], 'rules.') < 1) { return Mojo::exception('Please use correct rules path, ie: name=mojo.rules.myRules'); } $source = self::Source(); $file = self::makeNewFile($this->args['name'], 'rules'); MojoFile::write($file, MojoFile::editStream($this->args, $source)); Mojo::prompt('Generated Rules Scaffolding to ' . $file); }
function Scaffold() { //Replace this with a validation method if (empty($this->args['name'])) { return Mojo::prompt('Provide a full mojo path in your params string, ie: name=mojo.behavior.myBehavior'); } if (strpos($this->args['name'], 'behavior.') < 1) { return Mojo::prompt('The name you provided for your Behavior appears to be incorrect. ' . 'Please use full Behavior path, ie: name=mojo.behavior.myBehavior'); } $source = self::Source(); $file = self::makeNewFile($this->args['name'], 'behavior'); MojoFile::write($file, MojoFile::editStream($this->args, $source)); Mojo::prompt('Generated Behavior Scaffolding to ' . $file); }
function Compress() { global $bc; define('JS_DEBUG', false); include "phpjs/js.php"; $controllers = $rules = $dependencies = array(); $app = isset($this->args['app']) ? $this->args['app'] : ''; $js_dir = explode(DIRECTORY_SEPARATOR, MojoConfig::get('mojo_js_dir')); $js_dir = array_slice($js_dir, 0, count($js_dir) - 2); $js_dir = join(DIRECTORY_SEPARATOR, $js_dir) . DIRECTORY_SEPARATOR; $dependencies = array(); //============================================== //============================================== $base = MojoConfig::get('mojo_' . (!empty($app) ? strtolower(trim($app)) . '_' : '') . 'base_dependencies'); if (isset($base)) { $base = str_replace("/", DIRECTORY_SEPARATOR, $base); $base = explode(',', $base); foreach ($base as $dependent) { $dependencies[] = $js_dir . trim($dependent); } } //============================================== //============================================== $sitemap = MojoConfig::get('mojo_js_dir') . 'SiteMap' . $app . '.js'; $src = file_get_contents($sitemap); jsc::compile($src); //============================================== //============================================== foreach ($bc['.'] as $k => $v) { #print_r($v); if (isset($v[9])) { if (isset($v[9][2][1])) { //controllers $controller = str_replace("'", "", $v[9][2][1]); $controller = $js_dir . join(DIRECTORY_SEPARATOR, explode('.', $controller)) . '.js'; $controllers[] = $controller; if (!array_search($controller, $dependencies)) { $dependencies[] = $controller; } } } if (isset($v[7])) { //sitemap entries if (isset($v[7][2][1])) { //controllers $controller = str_replace("'", "", $v[7][2][1]); $controller = $js_dir . join(DIRECTORY_SEPARATOR, explode('.', $controller)) . '.js'; $controllers[] = $controller; if (!array_search($controller, $dependencies)) { $dependencies[] = $controller; } } if (isset($v[7][6][0][1]) && isset($v[7][6][2][1])) { //rules if ($v[7][6][0][1] == 'formrules') { $rule = str_replace("'", "", $v[7][6][2][1]); $rule = $js_dir . join(DIRECTORY_SEPARATOR, explode('.', $rule)) . '.js'; $rules[] = $rule; } if ($v[7][6][0][1] == 'metricsmap') { $controller = str_replace("'", "", $v[7][6][2][1]); $controller = $js_dir . join(DIRECTORY_SEPARATOR, explode('.', $controller)) . '.js'; $controllers[] = $controller; if (!array_search($controller, $dependencies)) { $dependencies[] = $controller; } } } } } //============================================== //============================================== $locale = !empty($this->args['locale']) ? $this->args['locale'] : 'en_US'; $i18n = MojoFile::getAll(MojoConfig::get('mojo_js_dir') . '_i18n' . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR); foreach ($rules as $rule) { $c = file_get_contents($rule); preg_match_all("/\\.locale[^\"]*\"\\.([^\"]*)\"/", $c, $matches); foreach ($i18n as $files => $file) { $f = $js_dir . MojoConfig::get('mojo_app_name') . DIRECTORY_SEPARATOR . '_i18n' . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $file; if (strpos($file, $matches[1][0]) > -1 && !array_search($f, $dependencies)) { $dependencies[] = $f; } } if (!array_search($rule, $dependencies)) { $dependencies[] = $rule; } } //============================================== //============================================== foreach ($controllers as $controller) { //commands $c = file_get_contents($controller); preg_match_all("/addCommand[^,]*[^\"']*('|\")([^'\"]*)('|\")/", $c, $matches); foreach ($matches[2] as $commands => $command) { $command = $js_dir . join(DIRECTORY_SEPARATOR, explode('.', $command)) . '.js'; if (!empty($command) && !array_search($command, $dependencies)) { $dependencies[] = $command; } } } //============================================== //=============================================== $js = ""; foreach ($dependencies as $dependency) { $js .= file_get_contents($dependency); } $js = preg_replace('/dojo\\.require\\("[^\\)]+"\\);/i', '', $js); $js = preg_replace("/dojo\\.require\\('[^\\)]+'\\);/i", '', $js); $config = !empty($app) ? $js_dir . MojoConfig::get('mojo_app_name') . '.' . strtolower($app) . '.config.js' : $js_dir . MojoConfig::get('mojo_app_name') . '.config.js'; $js .= file_get_contents($sitemap); $js .= file_get_contents($config); $dependencies[] = $sitemap; $dependencies[] = $config; if (isset($this->args['debug'])) { print_r($dependencies); } //=============================================== //=============================================== $app = !empty($app) ? $app . '.' : 'main.'; $locale = strtolower($locale) . '.'; $build = MojoConfig::get('mojo_build_number'); $build = !empty($build) ? $build : '0'; if (!isset($this->args['overwrite'])) { $build++; } if (!is_dir($js_dir . 'dist' . DIRECTORY_SEPARATOR)) { mkdir($js_dir . 'dist' . DIRECTORY_SEPARATOR); } if (!is_dir($js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR)) { mkdir($js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR); } MojoConfig::set('mojo_build_number', $build); if (MojoFile::write($js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR . 'application.' . $app . $locale . 'uncompressed.js', $js)) { Mojo::prompt('application.' . $app . $locale . 'uncompressed.js written to ' . $js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR . 'application.' . $app . $locale . 'uncompressed.js'); } Mojo::prompt('YUI Compressing application.' . $app . $locale . 'uncompressed.js to ' . $js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR . 'application.' . $app . $locale . 'js'); passthru('java -jar ' . MojoConfig::get('mojo_bin_dir') . 'yui.jar ' . $js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR . 'application.' . $app . $locale . 'uncompressed.js -o ' . $js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR . 'application.' . $app . $locale . 'js --charset UTF-8') . "\n"; if ($this->args['deploy']) { Mojo::prompt('Copying to deploy directory: ' . $js_dir . DIRECTORY_SEPARATOR . $this->args['deploy']); passthru('cp ' . $js_dir . 'dist' . DIRECTORY_SEPARATOR . $build . DIRECTORY_SEPARATOR . 'application.' . $app . $locale . 'js ' . $js_dir . DIRECTORY_SEPARATOR . $this->args['deploy']); } //=============================================== }
public function Setup($prompt = true) { $config = array(); foreach ($_SESSION as $k => $v) { $config[$k] = $v; } if ($prompt) { $config['mojo_js_dir'] = promptUser('Please provide the full system path to your Mojo installation ' . '- This is directory that contains SiteMap.js - (Include trailing slash)'); $arr = explode(DIRECTORY_SEPARATOR, $config['mojo_js_dir']); $config['mojo_app_name'] = $arr[count($arr) - 2]; } $arr = explode(DIRECTORY_SEPARATOR, self::get('mojo_task_lib')); $config['mojo_bin_dir'] = join(DIRECTORY_SEPARATOR, array_slice($arr, 0, count($arr) - 2)) . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR; foreach ($config as $key => $value) { switch ($key) { case 'mojo_js_dir': $sitemap = getFile('SiteMap.js', $value); if ($sitemap) { $value = str_replace(basename($sitemap), "", $sitemap); } else { self::Clear(false); Mojo::exception('SiteMap.js not found at ' . $value); } break; } $_SESSION[$key] = $value; if ($prompt) { Mojo::prompt('Updated config for ' . $key . ' to ' . $value); } } MojoFile::write(self::get('mojo_task_lib') . 'mojo.config', json_encode($_SESSION)); if (array_key_exists('mojo_js_dir', $config) && $prompt) { Mojo::prompt('Congratulations, your project is now setup, please read the docs below:'); MojoHelp::Docs(); } }