/** * Compile an asset collection. * * @param Basset\Collection $collection * @return void */ protected function compile(Collection $collection) { $force = isset($_SERVER['CLI']['FORCE']); // If the compile path does not exist attempt to create it. if (!File::exists($this->compilePath)) { File::mkdir($this->compilePath); } $groups = $collection->getAssets(); if (empty($groups)) { echo "The collection '{$collection->getName()}' has no assets to compile.\n"; } foreach ($groups as $group => $assets) { $path = $this->compilePath . '/' . $collection->getCompiledName($group); // We only compile a collection if a compiled file doesn't exist yet or if a change to one of the assets // in the collection is detected by comparing the last modified times. if (File::exists($path) and File::modified($path) >= $collection->lastModified($group)) { // If the force flag has been set then we'll recompile, otherwise this collection does not need // to be changed. if (!$force) { echo "The {$group}s for the collection '{$collection->getName()}' do not need to be compiled.\n"; continue; } } $compiled = $collection->compile($group); echo "Successfully compiled {$collection->getCompiledName($group)}\n"; File::put($path, $compiled); } }
public static function cleanCache($force = false) { $cacheFiles = glob(CACHE_PATH . DS . '*', GLOB_NOSORT); // $cacheFiles += glob(TMP_PUBLIC_PATH . DS . '*', GLOB_NOSORT); $minToKeep = !$force ? time() - 12 * 3600 : time(); foreach ($cacheFiles as $cacheFile) { $age = File::modified($cacheFile); if ($age < $minToKeep) { $tabFile = explode(DS, $cacheFile); ThinLog(Arrays::last($tabFile) . ' => ' . date('d/m/Y H:i:s', $age), null, 'suppression cache'); File::delete($cacheFile); } } }
protected function expired() { $viewRedis = container()->getViewRedis(); if (true !== $viewRedis) { if (!File::exists($this->compiled()) || !File::exists($this->_viewFile)) { return true; } return File::modified($this->_viewFile) > File::modified($this->compiled()); } else { $key = sha1($this->_viewFile) . '::age'; $age = context()->redis()->get($key); if (strlen($age)) { $age = (int) $age; return File::modified($this->_viewFile) || File::modified(__FILE__) > $age; } return true; } }
$path = dirname($file) . '/' . $import; if (File::exists($path) || File::exists($path .= '.less')) { $paths[] = $path; $paths = array_merge($paths, $imports($path)); } } return $paths; }; $compile = function ($input_file, $output_file) use($imports) { try { $latest = File::modified($input_file); foreach ($imports($input_file) as $import) { $import_modified = File::modified($import); $latest = $import_modified > $latest ? $import_modified : $latest; } if (!File::exists($output_file) || $latest > File::modified($output_file)) { $cache = lessc::cexecute($input_file); File::put($output_file, $cache['compiled']); } } catch (Exception $ex) { exit('lessc fatal error:<br />' . $ex->getMessage()); } }; if (isset($config['directories'])) { foreach ($config['directories'] as $less_dir => $css_dir) { $less_dir = rtrim($less_dir, '/') . '/'; foreach (glob($less_dir . '*.[Ll][Ee][Ss][Ss]') as $less) { $css = rtrim($css_dir, '/') . '/' . basename($less, '.less') . '.css'; $compile($less, $css); } }
$config = Config::get('composeur'); $my_bundle = function () { if (!Request::cli()) { return false; } foreach ($_SERVER['argv'] as $key => $val) { if (strpos($val, 'composeur::') === 0) { echo 'my bundle'; return true; } } return false; }; if (!$my_bundle() && isset($config['auto_update']) && $config['auto_update']) { require dirname(__FILE__) . '/tasks/setup.php'; $cli = new Composeur_Setup_Task(); if (!$cli->test()) { $cli->run(); } if (!$cli->has_lock()) { $cli->install(array()); } if (File::modified($cli->dir() . 'composer.json') < File::modified(path('app') . 'config/composeur.php')) { $cli->update(array()); } ob_clean(); } $composer_autoload = path('base') . 'vendor/autoload.php'; if (File::exists($composer_autoload)) { require $composer_autoload; }
<?php Route::get('(:bundle)/rejigger.js', array('as' => 'rejigger_js', function () { return View::make('rejigger::js'); })); Route::get('(:bundle)/version', array('as' => 'rejigger_version', function () { // Don't let the controller mistake this for a regular AJAX call unset($_SERVER['HTTP_X_REQUESTED_WITH']); $uri = \Rejigger\URI::resolve(Input::get('uri')); $route = \Laravel\Routing\Router::route('GET', $uri); $response = $route->call(); $version = md5($response->content); // Parse out resources (css & script) preg_match_all('/\\<script[^\\>]+src=\\"(?P<src>[^\\"]+)\\"[^\\>]*\\>/i', $response->content, $scripts); preg_match_all('/\\<link[^\\>]+href=\\"(?P<href>[^\\"]+)\\"[^\\>]*\\>/i', $response->content, $styles); preg_match_all('/\\<img[^\\>]+src=\\"(?P<src>[^\\"]+)\\"[^\\>]*\\>/i', $response->content, $images); $resources = array_merge($scripts['src'], $styles['href'], $images['src']); $public = path('public'); foreach ($resources as $resource) { $resource = $public . str_replace(\Laravel\URL::base(), '', $resource); if (\Laravel\File::exists($resource)) { $version .= File::modified($resource); } } return '{ "version": "' . md5($version) . '" }'; }));