public function warmupCaches() { if ($this->_contentsCache) { return; } $cmd = getcwd() . "/" . VENDOR_PATH . "/bin/node " . __DIR__ . "/build.js"; putenv("NODE_PATH=" . KWF_PATH . "/node_modules"); exec($cmd, $out, $ret); putenv("NODE_PATH="); if ($ret) { throw new Kwf_Exception("tinymce build failed: " . implode("\n", $out)); } if (!file_exists('temp/tinymce-build-out.js')) { throw new Kwf_Exception("TinyMce build not found"); } $buildFile = sys_get_temp_dir() . '/kwf-uglifyjs/tinymce/' . md5(file_get_contents('temp/tinymce-build-out.js')); if (!file_exists("{$buildFile}.min.js")) { $dir = dirname($buildFile); if (!file_exists($dir)) { mkdir($dir, 0777, true); } copy('temp/tinymce-build-out.js', $buildFile); Kwf_Assets_Dependency_Filter_UglifyJs::build($buildFile, 'temp/tinymce-build-out.js'); } $this->_contentsCache = file_get_contents("{$buildFile}"); $this->_contentsCachePacked = file_get_contents("{$buildFile}.min.js"); $this->_contentsCacheSourceMap = file_get_contents("{$buildFile}.min.js.map.json"); }
public function getContentsPacked() { $mtime = filemtime(__DIR__ . "/build.js"); $it = new RecursiveDirectoryIterator(getcwd() . '/' . VENDOR_PATH . '/bower_components/tinymce/js/tinymce'); $it = new RecursiveIteratorIterator($it); foreach ($it as $i) { $mtime = max($mtime, $i->getMTime()); } if (!file_exists('temp/tinymce-build-out.js.mtime') || file_get_contents('temp/tinymce-build-out.js.mtime') != $mtime) { $cmd = getcwd() . "/" . VENDOR_PATH . "/bin/node " . __DIR__ . "/build.js"; putenv("NODE_PATH=" . getcwd() . "/node_modules"); exec($cmd, $out, $ret); putenv("NODE_PATH="); if ($ret) { throw new Kwf_Exception("tinymce build failed: " . implode("\n", $out)); } if (!file_exists('temp/tinymce-build-out.js')) { throw new Kwf_Exception("TinyMce build not found"); } file_put_contents('temp/tinymce-build-out.js.mtime', $mtime); } $buildFile = sys_get_temp_dir() . '/kwf-uglifyjs/tinymce/v2-' . md5(file_get_contents('temp/tinymce-build-out.js')); if (!file_exists("{$buildFile}.min.js")) { $dir = dirname($buildFile); if (!file_exists($dir)) { mkdir($dir, 0777, true); } copy('temp/tinymce-build-out.js', $buildFile); Kwf_Assets_Dependency_Filter_UglifyJs::build($buildFile, '/assets/web/temp/tinymce-build-out.js'); } $ret = new Kwf_SourceMaps_SourceMap(file_get_contents("{$buildFile}.min.js.map.json"), file_get_contents("{$buildFile}.min.js")); $data = $ret->getMapContentsData(false); $data->{'_x_org_koala-framework_sourcesContent'}[0] = file_get_contents('temp/tinymce-build-out.js'); return $ret; }
public function warmupCaches() { if ($this->_contentsCache) { return; } $mtime = null; $it = new RecursiveDirectoryIterator(getcwd() . '/' . VENDOR_PATH . '/bower_components/tinymce/js/tinymce'); $it = new RecursiveIteratorIterator($it); foreach ($it as $i) { $mtime = max($mtime, $i->getMTime()); } if (!file_exists('temp/tinymce-build-out.js.mtime') || file_get_contents('temp/tinymce-build-out.js.mtime') != $mtime) { $cmd = getcwd() . "/" . VENDOR_PATH . "/bin/node " . __DIR__ . "/build.js"; putenv("NODE_PATH=" . KWF_PATH . "/node_modules"); exec($cmd, $out, $ret); putenv("NODE_PATH="); if ($ret) { throw new Kwf_Exception("tinymce build failed: " . implode("\n", $out)); } if (!file_exists('temp/tinymce-build-out.js')) { throw new Kwf_Exception("TinyMce build not found"); } file_put_contents('temp/tinymce-build-out.js.mtime', $mtime); } $buildFile = sys_get_temp_dir() . '/kwf-uglifyjs/tinymce/' . md5(file_get_contents('temp/tinymce-build-out.js')); if (!file_exists("{$buildFile}.min.js")) { $dir = dirname($buildFile); if (!file_exists($dir)) { mkdir($dir, 0777, true); } copy('temp/tinymce-build-out.js', $buildFile); Kwf_Assets_Dependency_Filter_UglifyJs::build($buildFile, 'temp/tinymce-build-out.js'); } $this->_contentsCache = file_get_contents("{$buildFile}"); $this->_contentsCachePacked = file_get_contents("{$buildFile}.min.js"); $this->_contentsCacheSourceMap = file_get_contents("{$buildFile}.min.js.map.json"); }
public function warmupCaches() { if (isset($this->_contentsCache)) { return; } $fileName = $this->getFileNameWithType(); $rawContents = $this->_getRawContents(null); $usesUniquePrefix = strpos($rawContents, 'kwfUp-') !== false; $pathType = $this->getType(); if ($pathType == 'ext2' && strpos($rawContents, 'ext2-gen') !== false) { $usesUniquePrefix = true; } if ($usesUniquePrefix) { //when contents contain .cssClass we must cache per app $buildFile = 'cache/uglifyjs/' . $fileName . '.v2' . md5(file_get_contents($this->getAbsoluteFileName()) . Kwf_Config::getValue('application.uniquePrefix')); } else { $buildFile = sys_get_temp_dir() . '/kwf-uglifyjs/' . $fileName . '.v2' . md5(file_get_contents($this->getAbsoluteFileName())); } $useTrl = $pathType != 'ext2'; if (substr($this->getAbsoluteFileName(), 0, 24) == 'vendor/bower_components/') { //dependencies loaded via bower never use kwf translation system $useTrl = false; } if (!file_exists("{$buildFile}.min.js") || $useTrl && !file_exists("{$buildFile}.min.js.trl")) { $dir = dirname($buildFile); if (!file_exists($dir)) { mkdir($dir, 0777, true); } file_put_contents($buildFile, $rawContents); $map = Kwf_Assets_Dependency_Filter_UglifyJs::build($buildFile, $this->getFileNameWithType()); $contents = file_get_contents("{$buildFile}.min.js"); $replacements = array(); if ($pathType == 'ext2') { $replacements['../images/'] = '/assets/ext2/resources/images/'; } else { if ($pathType == 'mediaelement') { $replacements['url('] = 'url(/assets/mediaelement/build/'; } } if ($usesUniquePrefix) { if ($pathType == 'ext2') { //hack for ext2 to avoid duplicated ids getting generated $uniquePrefix = Kwf_Config::getValue('application.uniquePrefix'); if ($uniquePrefix) { $map->stringReplace('ext2-gen', $uniquePrefix . '-ext2-gen'); } } if (strpos($rawContents, 'kwfUp-') !== false) { if (Kwf_Config::getValue('application.uniquePrefix')) { $replacements['kwfUp-'] = Kwf_Config::getValue('application.uniquePrefix') . '-'; } else { $replacements['kwfUp-'] = ''; } } } foreach ($replacements as $search => $replace) { $map->stringReplace($search, $replace); } $map->save("{$buildFile}.min.js.map.json", "{$buildFile}.min.js"); //adds last extension if ($useTrl) { file_put_contents("{$buildFile}.min.js.trl", serialize(Kwf_Trl_Parser_JsParser::parseContent($contents))); } } else { $map = new Kwf_SourceMaps_SourceMap(file_get_contents("{$buildFile}.min.js.map.json"), file_get_contents("{$buildFile}.min.js")); } $this->_contentsCache = $map; if ($useTrl) { $this->_parsedElementsCache = unserialize(file_get_contents("{$buildFile}.min.js.trl")); } else { $this->_parsedElementsCache = array(); } }
public function getContentsPacked() { $fileName = $this->getFileNameWithType(); $rawContents = file_get_contents($this->getAbsoluteFileName()); $usesUniquePrefix = strpos($rawContents, 'kwfUp-') !== false; $pathType = $this->getType(); if ($pathType == 'ext2' && strpos($rawContents, 'ext2-gen') !== false) { $usesUniquePrefix = true; } $useTrl = $pathType != 'ext2'; if (substr($this->getAbsoluteFileName(), 0, 24) == 'vendor/bower_components/') { //dependencies loaded via bower never use kwf translation system $useTrl = false; } if ($useTrl) { $useTrl = strpos($rawContents, 'trl') !== false && preg_match('#trl(c|p|cp)?(Kwf)?(Static)?\\(#', $rawContents); } $useBabel = strpos($rawContents, '"use es6";') !== false; if ($usesUniquePrefix || $useTrl || $useBabel) { //when contents contain .cssClass we must cache per app $buildFile = 'cache/uglifyjs/' . $fileName . '.v6' . md5(file_get_contents($this->getAbsoluteFileName()) . Kwf_Config::getValue('application.uniquePrefix')); } else { $buildFile = sys_get_temp_dir() . '/kwf-uglifyjs/' . $fileName . '.v6' . md5(file_get_contents($this->getAbsoluteFileName())); } if (!file_exists("{$buildFile}.min.js")) { $dir = dirname($buildFile); if (!file_exists($dir)) { mkdir($dir, 0777, true); } file_put_contents($buildFile, $rawContents); if ($useBabel) { $filter = new Kwf_Assets_Dependency_Filter_BabelJs($buildFile); $map = $filter->build(); file_put_contents($buildFile, $map->getFileContents()); //TODO: map support } $map = Kwf_Assets_Dependency_Filter_UglifyJs::build($buildFile, '/assets/' . $this->getFileNameWithType()); $data = $map->getMapContentsData(); $data->{'_x_org_koala-framework_masterFiles'} = array($this->getAbsoluteFileName()); $contents = file_get_contents("{$buildFile}.min.js"); $replacements = array(); if ($pathType == 'ext2') { $replacements['../images/'] = '/assets/ext2/resources/images/'; } else { if ($pathType == 'mediaelement') { $replacements['url('] = 'url(/assets/mediaelement/build/'; } } if ($usesUniquePrefix) { if ($pathType == 'ext2') { //hack for ext2 to avoid duplicated ids getting generated $uniquePrefix = Kwf_Config::getValue('application.uniquePrefix'); if ($uniquePrefix) { $map->stringReplace('ext2-gen', $uniquePrefix . '-ext2-gen'); } } if (strpos($rawContents, 'kwfUp-') !== false) { if (Kwf_Config::getValue('application.uniquePrefix')) { $replacements['kwfUp-'] = Kwf_Config::getValue('application.uniquePrefix') . '-'; } else { $replacements['kwfUp-'] = ''; } } } foreach ($replacements as $search => $replace) { $map->stringReplace($search, $replace); } if ($useTrl) { $trlData = array(); foreach (Kwf_TrlJsParser_JsParser::parseContent($contents) as $trlElement) { $d = Kwf_Assets_Util_Trl::getJsReplacement($trlElement); $map->stringReplace($d['before'], $d['replace']); $trlData[] = $d['trlElement']; } $data->{'_x_org_koala-framework_trlData'} = $trlData; } $map->save("{$buildFile}.min.js.map.json", "{$buildFile}.min.js"); //adds last extension } else { $map = new Kwf_SourceMaps_SourceMap(file_get_contents("{$buildFile}.min.js.map.json"), file_get_contents("{$buildFile}.min.js")); } return $map; }