public static function compile($file) { $baseDir = self::_getBaseDir(); $file = $baseDir . str_replace($baseDir, '', $file); if (file_exists($file) === false) { return false; } $srcFile = new SplFileInfo($file); $distFile = new SplFileInfo(self::_getDistFilePath($srcFile->getPathname(), $srcFile->getMTime())); if (file_exists($distFile) === false) { if (file_exists($distFile->getPath()) === false) { mkdir($distFile->getPath(), 0775, true); } if (static::_compile($srcFile, $distFile) === false) { return false; } } return str_replace(Config::getServerRootPath(), '', $distFile->getPathname()); }
public static function uglify($file) { $file = str_replace(self::_getBaseDir(), '', $file); $srcFiles = self::_loadSrcFiles($file); if (empty($srcFiles['files'])) { return false; } $distFilePath = self::_getDistFilePath($file, implode('', $srcFiles['hashes'])); if (file_exists($distFilePath) === false) { $distFile = new SplFileInfo($distFilePath); if (file_exists($distFile->getPath()) === false) { mkdir($distFile->getPath(), 0775, true); } if (static::_uglify($srcFiles['files'], $distFilePath) === false) { return false; } } return str_replace(Config::getServerRootPath(), '', $distFilePath); }
public function testCompile() { $compiledFilePath = Coffee::compile('users/people.coffee'); $this->assertFileEquals(Config::getServerRootPath() . '/expected/assets/javascripts/users/people.js', Config::getServerRootPath() . $compiledFilePath); }
public function testCompile() { $compiledFilePath = Scss::compile('home.scss'); $this->assertFileEquals(Config::getServerRootPath() . '/expected/assets/stylesheets/home.css', Config::getServerRootPath() . $compiledFilePath); }
public static function precompile(InputInterface $input, OutputInterface $output) { self::_initConfig($input); $files = Config::getPrecompile(); if (empty($files)) { return true; } $compiledFiles = array(); $serverRootPath = Config::getServerRootPath(); foreach ($files as $file) { $file = ltrim($file, DIRECTORY_SEPARATOR); $fileInfo = new SplFileInfo($file); $extName = strtolower($fileInfo->getExtension()); if ($extName !== 'js' && $extName !== 'css') { continue; } $uglifyClass = '\\Assets\\Uglify\\' . ucfirst($extName); $distFile = $uglifyClass::uglify($file); if ($distFile === false) { $output->writeln("<error>Can't compile file : {$file}</error>"); } else { $compiledFiles[$file] = $distFile; $output->writeln('<info>Create file</info> : ' . $serverRootPath . $distFile); } } if (!empty($compiledFiles)) { file_put_contents($serverRootPath . DIRECTORY_SEPARATOR . '.assetsrc', serialize($compiledFiles)); } $uglifiedPath = DIRECTORY_SEPARATOR . 'uglified' . DIRECTORY_SEPARATOR . 'assets'; $files = scandir($serverRootPath . $uglifiedPath); foreach ($files as $file) { if ($file === '.' || $file === '..') { continue; } $file = $uglifiedPath . DIRECTORY_SEPARATOR . $file; if (in_array($file, $compiledFiles)) { continue; } $file = $serverRootPath . $file; if (unlink($file)) { $output->writeln('<info>Remove unuseful file</info> : ' . $file); } } }
public function testCompile() { $uglifiedFilePath = Css::Uglify('home'); $this->assertFileEquals(Config::getServerRootPath() . '/expected/assets/stylesheets/home_uglified.css', Config::getServerRootPath() . $uglifiedFilePath); }
private static function _getCompiledDir() { return Config::getServerRootPath() . DIRECTORY_SEPARATOR . static::$_compiledDir . DIRECTORY_SEPARATOR . 'assets'; }
public function testCompile() { $uglifiedFilePath = Js::Uglify('base.js'); $this->assertFileEquals(Config::getServerRootPath() . '/expected/assets/javascripts/base_uglified.js', Config::getServerRootPath() . $uglifiedFilePath); }
public static function fontUrl($url) { return self::assetUrl($url, Config::getFontsPath()); }