/** * @param string[] $mainPaths * @param string[] $sourcePaths * @param bool $generateSourceMaps * @return string */ protected function _browserify(array $mainPaths, array $sourcePaths, $generateSourceMaps) { if (!count($mainPaths)) { return ''; } $involvedFiles = []; foreach ($sourcePaths as $sourcePath) { $involvedFiles = array_merge($involvedFiles, CM_Util::rglob('*.js', $sourcePath)); } foreach ($mainPaths as $mainPath) { $involvedFiles[] = $mainPath; } $cacheKeyContent = \Functional\reduce_left(array_unique($involvedFiles), function ($path, $index, $collection, $carry) { return md5($carry . (new CM_File($path))->read()); }, ''); $cacheKeyMainPaths = \Functional\reduce_left($mainPaths, function ($path, $index, $collection, $carry) { return md5($carry . $path); }, ''); $cache = CM_Cache_Persistent::getInstance(); $cacheKey = $cache->key(__METHOD__, $cacheKeyContent, $cacheKeyMainPaths, $generateSourceMaps); return $cache->get($cacheKey, function () use($mainPaths, $sourcePaths, $generateSourceMaps) { $args = $mainPaths; if ($generateSourceMaps) { $args[] = '--debug'; } return CM_Util::exec('NODE_PATH="' . implode(':', $sourcePaths) . '" browserify', $args); }); }
public function iconRefresh() { /** @var CM_File[] $svgFileList */ $svgFileList = array(); foreach (CM_Bootloader::getInstance()->getModules() as $moduleName) { $iconPath = CM_Util::getModulePath($moduleName) . 'layout/default/resource/img/icon/'; foreach (glob($iconPath . '*.svg') as $svgPath) { $svgFile = new CM_File($svgPath); $svgFileList[strtolower($svgFile->getFileName())] = $svgFile; } } if (0 === count($svgFileList)) { throw new CM_Exception_Invalid('Cannot process `0` icons'); } $this->_getStreamOutput()->writeln('Processing ' . count($svgFileList) . ' unique icons...'); $dirWork = CM_File::createTmpDir(); $dirBuild = $dirWork->joinPath('/build'); foreach ($svgFileList as $fontFile) { $fontFile->copyToFile($dirWork->joinPath($fontFile->getFileName())); } CM_Util::exec('fontcustom', array('compile', $dirWork->getPathOnLocalFilesystem(), '--no-hash', '--autowidth', '--font-name=icon-webfont', '--output=' . $dirBuild->getPathOnLocalFilesystem())); $cssFile = $dirBuild->joinPath('/icon-webfont.css'); $less = preg_replace('/url\\("(?:.*?\\/)(.+?)(\\??#.+?)?"\\)/', 'url(urlFont("\\1") + "\\2")', $cssFile->read()); CM_File::create(DIR_PUBLIC . 'static/css/library/icon.less', $less); foreach (glob($dirBuild->joinPath('/icon-webfont.*')->getPathOnLocalFilesystem()) as $fontPath) { $fontFile = new CM_File($fontPath); $fontFile->rename(DIR_PUBLIC . 'static/font/' . $fontFile->getFileName()); } $dirWork->delete(true); $this->_getStreamOutput()->writeln('Created web-font and stylesheet.'); }
/** * @param string $content * @return string */ protected function _minify($content) { $md5 = md5($content); $cacheKey = CM_CacheConst::App_Resource . '_md5:' . $md5; $cache = new CM_Cache_Storage_File(); if (false === ($contentMinified = $cache->get($cacheKey))) { $uglifyCommand = 'uglifyjs --no-copyright'; /** * Quote keys in literal objects, otherwise some browsers break. * E.g. "select2.js" on "Android 4.0.4" */ $uglifyCommand .= ' --beautify beautify=false,quote-keys=true'; $contentMinified = CM_Util::exec($uglifyCommand, null, $content); $cache->set($cacheKey, $contentMinified); } return $contentMinified; }
protected function _partition() { CM_Util::exec('sgdisk', ['-o', $this->_path]); $startSector = CM_Util::exec('sgdisk', ['-F', $this->_path]); $endSector = CM_Util::exec('sgdisk', ['-E', $this->_path]); CM_Util::exec('sgdisk', ['-n', '1:' . $startSector . ':' . $endSector, $this->_path]); $this->_path .= '1'; }
/** * @param string $content * @return string */ private function _compileAutoprefixer($content) { $command = 'autoprefixer'; $args = []; if (null !== $this->_autoprefixerBrowsers) { $args[] = '--browsers'; $args[] = $this->_autoprefixerBrowsers; } return CM_Util::exec($command, $args, $content); }
/** * @return int[] * @throws CM_Exception */ private function _getChildrenPidList() { $psCommand = 'ps axo pid,ppid,args'; $psOutput = CM_Util::exec($psCommand); if (false === preg_match_all('/^\\s*(?<pid>\\d+)\\s+(?<ppid>\\d+)\\s+(?<args>.+)$/m', $psOutput, $matches, PREG_SET_ORDER)) { throw new CM_Exception('Cannot parse ps output `' . $psOutput . '`.'); } $pid = CM_Process::getInstance()->getProcessId(); $pidList = array(); foreach ($matches as $match) { if ($match['ppid'] == $pid && false === strpos($match['args'], $psCommand)) { $pidList[] = (int) $match['pid']; } } return $pidList; }
/** * @return int */ public function getHostId() { return (int) hexdec(CM_Util::exec('hostid')); }
/** * @param string $dbName * @param CM_File $dump */ public static function runDump($dbName, CM_File $dump) { $client = CM_Service_Manager::getInstance()->getDatabases()->getMaster(); $args = array(); $args[] = '--host=' . $client->getHost(); $args[] = '--port=' . $client->getPort(); $args[] = '--user='******'--password='******'mysql', $args, null, $dump->getPath()); }
public function testFreeMemory() { $getMemoryUsage = function () { $pid = CM_Process::getInstance()->getProcessId(); $memory = CM_Util::exec('ps', ['-o', 'rss', '--no-headers', '--pid', $pid]); return (int) $memory; }; $imageOriginal = new CM_File_Image(DIR_TEST_DATA . 'img/test.jpg'); $image = CM_File_Image::createTmp(null, $imageOriginal->read()); $memoryUsage = $getMemoryUsage(); $memoryUsageMaxExpected = $memoryUsage + 20 * 1000; $image->resizeSpecific(3000, 3000); $this->assertGreaterThan($memoryUsageMaxExpected, $getMemoryUsage()); $image->freeMemory(); $this->assertLessThan($memoryUsageMaxExpected, $getMemoryUsage()); $image->validateImage(); }