public static function run($pluginsInitCode, Kwf_SourceMaps_SourceMap $sourcemap) { $js = "\n require('es6-promise').polyfill(); //required for older nodejs\n var postcss = require('postcss');\n var plugins = [];\n " . $pluginsInitCode . "\n var instance = postcss( plugins );\n var css = '';\n process.stdin.setEncoding('utf-8')\n process.stdin.on('data', function(buf) { css += buf.toString(); });\n process.stdin.on('end', function() {\n instance.process(css).then(function (result) {\n process.stdout.write(result.css);\n }).catch(function(e) {\n console.log(e);\n process.exit(1);\n });\n });\n process.stdin.resume();\n "; $runfile = tempnam("temp/", 'postcss'); file_put_contents($runfile, $js); putenv("NODE_PATH=" . getcwd() . "/node_modules" . PATH_SEPARATOR . getcwd() . "/" . KWF_PATH . PATH_SEPARATOR . getcwd() . "/"); $cmd = getcwd() . "/" . VENDOR_PATH . "/bin/node " . $runfile; $cmd .= " 2>&1"; $process = new Symfony\Component\Process\Process($cmd); $mapData = $sourcemap->getMapContentsData(false); $hasSourcemap = !!$mapData->mappings; if ($hasSourcemap) { $process->setInput($sourcemap->getFileContentsInlineMap(false)); } else { $process->setInput($sourcemap->getFileContents()); } if ($process->run() !== 0) { throw new Kwf_Exception("Process '{$cmd}' failed with " . $process->getExitCode() . "\n" . $process->getOutput()); } putenv("NODE_PATH="); unlink($runfile); $out = $process->getOutput(); if (Kwf_SourceMaps_SourceMap::hasInline($out)) { $ret = Kwf_SourceMaps_SourceMap::createFromInline($out); } else { $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($out); $ret->setMimeType('text/css'); } $ret->setSources($sourcemap->getSources()); return $ret; }
public function getContentsPacked($language) { $paths = self::_getAllPaths(); $pathType = $this->getType(); $f = $paths[$pathType] . substr($this->_builtFile, strpos($this->_builtFile, '/')); $contents = file_get_contents($f); $contents = rtrim($contents); $contents = explode("\n", $contents); if (substr($contents[count($contents) - 1], 0, 21) == '//# sourceMappingURL=') { //remove sourceMappingURL comment unset($contents[count($contents) - 1]); } $contents = implode("\n", $contents); $paths = self::_getAllPaths(); $pathType = $this->getType(); $f = $paths[$pathType] . substr($this->_sourceMapFile, strpos($this->_sourceMapFile, '/')); $mapContents = file_get_contents($f); $cacheFile = sys_get_temp_dir() . '/kwf-uglifyjs/' . $this->getFileNameWithType() . '.map.' . md5($mapContents); if (!file_exists($cacheFile)) { $map = new Kwf_SourceMaps_SourceMap($mapContents, $contents); if (!is_dir(dirname($cacheFile))) { mkdir(dirname($cacheFile), 0777, true); } $data = $map->getMapContentsData(); if (count($data->sources) != 1) { throw new Kwf_Exception('map must consist only of a single source'); } $data->sources = array($this->getFileNameWithType()); $map->save($cacheFile); } else { $map = new Kwf_SourceMaps_SourceMap(file_get_contents($cacheFile), $contents); } return $map; }
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 static function build($buildFile, $sourceFileUrl) { $uglifyjs = getcwd() . "/" . VENDOR_PATH . "/bin/node " . getcwd() . '/node_modules/uglify-js/bin/uglifyjs'; $cmd = "{$uglifyjs} "; $cmd .= "--source-map " . escapeshellarg("{$buildFile}.min.js.map.json") . ' '; $cmd .= "--prefix 2 "; $cmd .= "--output " . escapeshellarg("{$buildFile}.min.js") . ' '; $cmd .= escapeshellarg($buildFile); $cmd .= " 2>&1"; $out = array(); exec($cmd, $out, $retVal); if ($retVal) { throw new Kwf_Exception("uglifyjs failed: " . implode("\n", $out)); } $contents = file_get_contents("{$buildFile}.min.js"); $contents = str_replace("\n//# sourceMappingURL={$buildFile}.min.js.map.json", '', $contents); $mapData = json_decode(file_get_contents("{$buildFile}.min.js.map.json"), true); if (count($mapData['sources']) > 1) { throw new Kwf_Exception("uglifyjs must not return multiple sources, " . count($mapData['sources']) . " returned for '{$buildFile}'"); } unset($mapData['file']); $mapData['sources'][0] = $sourceFileUrl; file_put_contents("{$buildFile}.min.js.map.json", json_encode($mapData)); $map = new Kwf_SourceMaps_SourceMap(file_get_contents("{$buildFile}.min.js.map.json"), $contents); $mappings = $map->getMappings(); foreach ($mappings as $k => $m) { $mappings[$k]['originalName'] = null; } $map->setMappings($mappings); $map->save("{$buildFile}.min.js.map.json", "{$buildFile}.min.js"); //adds last extension return $map; }
public function save(Kwf_SourceMaps_SourceMap $map, $cacheId) { $this->_cache[$cacheId] = $map; $cacheFile = 'cache/assetdeps/' . md5($cacheId) . 'v2'; $data = $map->getMapContentsData(true); //this will trigger _generateMappings file_put_contents($cacheFile, serialize($map)); $masterFiles = array(); if (isset($data->{'_x_org_koala-framework_masterFiles'})) { foreach ($data->{'_x_org_koala-framework_masterFiles'} as $f) { $masterFiles[] = array('file' => $f, 'hash' => $this->_hashFile($f)); } } file_put_contents($cacheFile . '.masterFiles', serialize($masterFiles)); }
public function getContentsPacked() { $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($this->getContentsSourceString()); $map = $ret->getMapContentsData(false); $map->{'_x_org_koala-framework_masterFiles'} = array($this->getAbsoluteFileName()); return $ret; }
public function getContentsPacked() { $basePath = 'vendor/bower_components/'; if (file_exists($basePath . $this->_path . "/fonts/{$this->_name}.eot")) { //eg icomoon, ionicons $fontsPath = "/assets/{$this->_path}/fonts/{$this->_name}"; } else { if (file_exists($basePath . $this->_path . "/fonts/" . strtolower($this->_name) . "-webfont.eot")) { //eg Font-Awesome $fontsPath = "/assets/{$this->_path}/fonts/" . strtolower($this->_name) . "-webfont"; } else { throw new Kwf_Exception("Can't detect path of font"); } } $ret = ""; $ret .= "@font-face {\n"; $ret .= " font-family: '" . $this->_name . "';\n"; $ret .= " src: url('" . $fontsPath . ".eot');\n"; $ret .= " src: url('" . $fontsPath . ".eot?#iefix') format('eot'),\n"; $ret .= " url('" . $fontsPath . ".woff') format('woff'),\n"; $ret .= " url('" . $fontsPath . ".ttf') format('truetype'),\n"; $ret .= " url('" . $fontsPath . ".svg') format('svg');\n"; $ret .= "}\n"; return Kwf_SourceMaps_SourceMap::createEmptyMap($ret); }
public function getContentsPacked($language) { $c = $this->_dep->getContentsPacked($language); $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($this->_getPrependCode()); $ret->concat($c); return $ret; }
public function getContentsPacked() { $contents = file_get_contents($this->getAbsoluteFileName()); $useTrl = strpos($contents, 'trl') !== false && preg_match('#trl(c|p|cp)?(Kwf)?(Static)?\\(#', $contents); $trlData = array(); if ($useTrl) { foreach (Kwf_TrlJsParser_UnderscoreTemplateParser::parseContent($contents) as $trlElement) { $d = Kwf_Assets_Util_Trl::getJsReplacement($trlElement); $contents = str_replace($d['before'], $d['replace'], $contents); $trlData[] = $d['trlElement']; } } $contents = str_replace("\n", '\\n', $contents); $contents = str_replace("'", "\\'", $contents); $contents = "var _ = require('underscore');\n" . "module.exports = _.template('" . $contents . "');\n"; $replacements = array(); if (strpos($contents, 'kwfUp-') !== false) { if (Kwf_Config::getValue('application.uniquePrefix')) { $replacements['kwfUp-'] = Kwf_Config::getValue('application.uniquePrefix') . '-'; } else { $replacements['kwfUp-'] = ''; } } foreach ($replacements as $search => $replace) { $contents = str_replace($search, $replace, $contents); } $map = Kwf_SourceMaps_SourceMap::createEmptyMap($contents); $data = $map->getMapContentsData(); $data->{'_x_org_koala-framework_masterFiles'} = array($this->getAbsoluteFileName()); if ($trlData) { $data->{'_x_org_koala-framework_trlData'} = $trlData; } return $map; }
public function getContentsPacked() { if (!$this->_features) { return null; } $modernizrPath = getcwd() . '/node_modules/modernizr'; $outputFile = tempnam('./temp', 'modernizr'); $configAll = json_decode(file_get_contents($modernizrPath . '/lib/config-all.json'), true); $allFeatureDetects = $configAll['feature-detects']; $options = array(); foreach ($configAll['options'] as $i) { $options[$i] = false; } $options['mq'] = true; $options['setClasses'] = true; $featureDetects = array(); foreach ($this->_features as $f) { if (isset($options[strtolower($f)])) { //for prefixed $options[strtolower($f)] = true; } else { $filter = new Zend_Filter_Word_CamelCaseToSeparator('/'); $fFiltered = strtolower($filter->filter($f)); if (!in_array($fFiltered, $allFeatureDetects)) { throw new Kwf_Exception("Invalid Modernizr Dependency, test doesn't exist: '" . $f . "'"); } $featureDetects[] = $fFiltered; } } foreach ($options as $k => $i) { if (!$i) { unset($options[$k]); } } $options = array_keys($options); $classPrefix = ''; if (Kwf_Config::getValue('application.uniquePrefix')) { $classPrefix = Kwf_Config::getValue('application.uniquePrefix') . '-'; } $config = array('classPrefix' => $classPrefix, 'options' => $options, 'feature-detects' => $featureDetects); $configFile = tempnam('temp/', 'modernizrbuild'); unlink($configFile); $configFile .= '.json'; file_put_contents($configFile, json_encode($config, JSON_PRETTY_PRINT)); $cmd = getcwd() . "/" . VENDOR_PATH . "/bin/node {$modernizrPath}/bin/modernizr --config {$configFile} --uglify --dest " . $outputFile; exec($cmd, $out, $retVar); if ($retVar) { throw new Kwf_Exception("modernizr failed: " . implode("\n", $out)); } $ret = file_get_contents($outputFile); unlink($configFile); unlink($outputFile); //remove comments containing selected tests $ret = preg_replace("#\n/\\*!\n\\{.*?\\}\n!\\*/\n#s", '', $ret); $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($ret); $map = $ret->getMapContentsData(false); $map->{'_x_org_koala-framework_masterFiles'} = array(getcwd() . '/node_modules/modernizr/package.json'); return $ret; }
public function getContentsPacked() { if (!Kwf_Config::getValue('ravenJs.dsn')) { throw new Kwf_Exception('ravenJS.dsn config setting is required'); } $data = array('dsn' => Kwf_Config::getValue('ravenJs.dsn')); $ret = "Kwf.RavenJsConfig = " . json_encode($data) . ";"; return Kwf_SourceMaps_SourceMap::createEmptyMap($ret); }
public function getContentsPacked() { $config = array('providerList' => get_class($this->_providerList)); $ret = ""; $ret .= "if (!window.Kwf) window.Kwf = {};\n"; $ret .= "if (!window.Kwf.Loader) window.Kwf.Loader = {};\n"; $ret .= "window.Kwf.Loader.config = " . json_encode($config) . ";\n"; return Kwf_SourceMaps_SourceMap::createEmptyMap($ret); }
public static function filter($map, $uniquePrefix) { $head = ' (function() { if (!window.' . $uniquePrefix . ') window.' . $uniquePrefix . ' = {}; var kwfUp = window.' . $uniquePrefix . '; var kwfNamespaces = ["Kwf", "Kwc", "Ext2", "Ext", "$", "jQuery", "Modernizr", "require", "define", "_kwfTrl", "_kwfTrlp"]; var kwfOrigExports = {}; for (var i=0; i<kwfNamespaces.length; i++) { var name = kwfNamespaces[i]; kwfOrigExports[name] = window[name]; if (kwfUp[name]) { window[name] = kwfUp[name]; } else { window[name] = undefined; try { delete window[name]; } catch (e) { } } } if (!window.Ext2) window.Ext2 = {}; '; $foot = ' for (var i=0; i<kwfNamespaces.length; i++) { var name = kwfNamespaces[i]; try { kwfUp[name] = window[name] || eval(name); } catch(e) { } if (kwfOrigExports[name]) { window[name] = kwfOrigExports[name]; } else { window[name] = undefined; try { delete window[name]; } catch (e) { } } eval("var "+name+" = kwfUp."+name+";"); } })(); '; $ret = Kwf_SourceMaps_SourceMap::createEmptyMap(''); $ret->concat(Kwf_SourceMaps_SourceMap::createEmptyMap($head)); $ret->concat($map); $ret->concat(Kwf_SourceMaps_SourceMap::createEmptyMap($foot)); $mapData = $map->getMapContentsData(false); if (isset($mapData->{'_x_org_koala-framework_sourcesContent'})) { $retData = $ret->getMapContentsData(false); $retData->{'_x_org_koala-framework_sourcesContent'} = $mapData->{'_x_org_koala-framework_sourcesContent'}; } return $ret; }
public function testGetMappings() { $map = new Kwf_SourceMaps_SourceMap(Kwf_SourceMaps_TestData::$testMap, Kwf_SourceMaps_TestData::$testGeneratedCode); $mappings = $map->getMappings(); $this->assertEquals(count($mappings), 13); $this->assertEquals($mappings[0], array('generatedLine' => 1, 'generatedColumn' => 1, 'originalSource' => '/the/root/one.js', 'originalLine' => 1, 'originalColumn' => 1, 'originalName' => null)); $this->assertEquals($mappings[1], array('generatedLine' => 1, 'generatedColumn' => 5, 'originalSource' => '/the/root/one.js', 'originalLine' => 1, 'originalColumn' => 5, 'originalName' => null)); $this->assertEquals($mappings[2], array('generatedLine' => 1, 'generatedColumn' => 9, 'originalSource' => '/the/root/one.js', 'originalLine' => 1, 'originalColumn' => 11, 'originalName' => null)); $this->assertEquals($mappings[3], array('generatedLine' => 1, 'generatedColumn' => 18, 'originalSource' => '/the/root/one.js', 'originalLine' => 1, 'originalColumn' => 21, 'originalName' => 'bar')); $this->assertEquals($mappings[4], array('generatedLine' => 1, 'generatedColumn' => 21, 'originalSource' => '/the/root/one.js', 'originalLine' => 2, 'originalColumn' => 3, 'originalName' => null)); $this->assertEquals($mappings[5], array('generatedLine' => 1, 'generatedColumn' => 28, 'originalSource' => '/the/root/one.js', 'originalLine' => 2, 'originalColumn' => 10, 'originalName' => 'baz')); $this->assertEquals($mappings[6], array('generatedLine' => 1, 'generatedColumn' => 32, 'originalSource' => '/the/root/one.js', 'originalLine' => 2, 'originalColumn' => 14, 'originalName' => 'bar')); $this->assertEquals($mappings[7], array('generatedLine' => 2, 'generatedColumn' => 1, 'originalSource' => '/the/root/two.js', 'originalLine' => 1, 'originalColumn' => 1, 'originalName' => null)); $this->assertEquals($mappings[8], array('generatedLine' => 2, 'generatedColumn' => 5, 'originalSource' => '/the/root/two.js', 'originalLine' => 1, 'originalColumn' => 5, 'originalName' => null)); $this->assertEquals($mappings[9], array('generatedLine' => 2, 'generatedColumn' => 9, 'originalSource' => '/the/root/two.js', 'originalLine' => 1, 'originalColumn' => 11, 'originalName' => null)); $this->assertEquals($mappings[10], array('generatedLine' => 2, 'generatedColumn' => 18, 'originalSource' => '/the/root/two.js', 'originalLine' => 1, 'originalColumn' => 21, 'originalName' => 'n')); $this->assertEquals($mappings[11], array('generatedLine' => 2, 'generatedColumn' => 21, 'originalSource' => '/the/root/two.js', 'originalLine' => 2, 'originalColumn' => 3, 'originalName' => null)); $this->assertEquals($mappings[12], array('generatedLine' => 2, 'generatedColumn' => 28, 'originalSource' => '/the/root/two.js', 'originalLine' => 2, 'originalColumn' => 10, 'originalName' => 'n')); }
public static function filter($map, $uniquePrefix) { $head = ' (function() { if (!window.' . $uniquePrefix . ') window.' . $uniquePrefix . ' = {}; var kwfUp = window.' . $uniquePrefix . '; var kwfNamespaces = ["Kwf", "Kwc", "Ext2", "$", "jQuery", "Modernizr", "require", "trl", "trlp"]; var kwfOrigExports = {}; for (var i=0; i<kwfNamespaces.length; i++) { var name = kwfNamespaces[i]; kwfOrigExports[name] = window[name]; if (kwfUp[name]) { window[name] = kwfUp[name]; } else { try { delete window[name]; } catch (e) { window[name] = undefined; } } } if (!window.Ext2) window.Ext2 = {}; '; $foot = ' for (var i=0; i<kwfNamespaces.length; i++) { var name = kwfNamespaces[i]; try { kwfUp[name] = window[name] || eval(name); } catch(e) { continue; } if (kwfOrigExports[name]) { window[name] = kwfOrigExports[name]; } else { try { delete window[name]; } catch (e) { window[name] = undefined; } } eval("var "+name+" = kwfUp."+name+";"); } })(); '; $ret = Kwf_SourceMaps_SourceMap::createEmptyMap(''); $ret->concat(Kwf_SourceMaps_SourceMap::createEmptyMap($head)); $ret->concat($map); $ret->concat(Kwf_SourceMaps_SourceMap::createEmptyMap($foot)); return $ret; }
public function getContentsPacked() { $paths = $this->_providerList->getPathTypes(); $pathType = $this->getType(); $f = $paths[$pathType] . substr($this->_builtFile, strpos($this->_builtFile, '/')); $contents = file_get_contents($f); $contents = rtrim($contents); $contents = explode("\n", $contents); if (substr($contents[count($contents) - 1], 0, 21) == '//# sourceMappingURL=') { //remove sourceMappingURL comment unset($contents[count($contents) - 1]); } $contents = implode("\n", $contents); $pathType = $this->getType(); $f = $paths[$pathType] . substr($this->_sourceMapFile, strpos($this->_sourceMapFile, '/')); $mapContents = file_get_contents($f); $cacheFile = sys_get_temp_dir() . '/kwf-uglifyjs/' . $this->getFileNameWithType() . '.map.v3.' . md5($mapContents); if (!file_exists($cacheFile)) { $map = new Kwf_SourceMaps_SourceMap($mapContents, $contents); $mappings = $map->getMappings(); foreach ($mappings as $k => $m) { $mappings[$k]['originalName'] = null; } $map->setMappings($mappings); if (!is_dir(dirname($cacheFile))) { mkdir(dirname($cacheFile), 0777, true); } $data = $map->getMapContentsData(); if (count($data->sources) != 1) { throw new Kwf_Exception('map must consist only of a single source'); } $data->sources = array('/assets/' . $this->getFileNameWithType()); $data->{'_x_org_koala-framework_masterFiles'} = array($this->getAbsoluteFileName()); $map->save($cacheFile); } else { $map = new Kwf_SourceMaps_SourceMap(file_get_contents($cacheFile), $contents); } return $map; }
public function filter(Kwf_SourceMaps_SourceMap $sourcemap) { putenv("NODE_PATH=" . getcwd() . "/node_modules"); $cmd = getcwd() . "/" . VENDOR_PATH . "/bin/node " . __DIR__ . "/CssChunks.js"; $cmd .= " 2>&1"; $process = new Symfony\Component\Process\Process($cmd); $process->setInput($sourcemap->getFileContentsInlineMap(false)); $process->mustRun(); $out = $process->getOutput(); $out = explode("\n/* ***** NEXT CHUNK ***** */\n", $out); $ret = array(); foreach ($out as $chunk) { if (Kwf_SourceMaps_SourceMap::hasInline($chunk)) { $mapChunk = Kwf_SourceMaps_SourceMap::createFromInline($chunk); } else { $mapChunk = Kwf_SourceMaps_SourceMap::createEmptyMap($chunk); $mapChunk->setMimeType('text/css'); } $ret[] = $mapChunk; } return $ret; }
public function testAdd() { $map = new Kwf_SourceMaps_SourceMap(Kwf_SourceMaps_TestData::$testMap, Kwf_SourceMaps_TestData::$testGeneratedCode); $mappings = $map->getMappings(); $map->addSource('three.js'); $sources = $map->getSources(); $this->assertEquals(array('one.js', 'two.js', 'three.js'), $sources); $c = $map->getFileContentsInlineMap(false); $map = Kwf_SourceMaps_SourceMap::createFromInline($c); $this->assertEquals(array('one.js', 'two.js', 'three.js'), $sources); $map->addMapping(1, 1, 1, 1, 'one.js'); $c = $map->getFileContentsInlineMap(false); $this->assertEquals(array('one.js', 'two.js', 'three.js'), $sources); }
public function getContentsPacked($language) { if (!isset($this->_cacheContents)) { $contents = $this->getContents($language); $contents = str_replace("\r", "\n", $contents); // remove comments //$contents = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $contents); // multiple whitespaces $contents = str_replace("\t", " ", $contents); $contents = preg_replace('/(\\n)\\n+/', '$1', $contents); $contents = preg_replace('/(\\n)\\ +/', '$1', $contents); $contents = preg_replace('/(\\ )\\ +/', '$1', $contents); $this->_cacheContents = $contents; } return Kwf_SourceMaps_SourceMap::createEmptyMap($this->_cacheContents); }
public function testRemoveReplacedMapping() { //0 1 2 3 4 //01234567890123456789012345678901234567890123456789 $map = Kwf_SourceMaps_SourceMap::createEmptyMap('(function($,window,document,undefined){var x=1;});'); $map->addMapping(1, 1, 1, 1, 'foo.js'); $map->addMapping(1, 10, 1, 11, 'foo.js', '$'); $map->addMapping(1, 12, 1, 14, 'foo.js', 'window'); $map->addMapping(1, 19, 1, 22, 'foo.js', 'document'); $map->addMapping(1, 28, 1, 32, 'foo.js', 'undefined'); $map->addMapping(1, 43, 2, 5, 'foo.js', 'x'); $map->stringReplace('(function($,window,document,undefined){', "var \$=jQuery=require('jQuery');"); $mappings = $map->getMappings(); $this->assertEquals(2, count($mappings)); $this->assertEquals($mappings[0], array('generatedLine' => 1, 'generatedColumn' => 1, 'originalSource' => 'foo.js', 'originalLine' => 1, 'originalColumn' => 1, 'originalName' => null)); $this->assertEquals($mappings[1], array('generatedLine' => 1, 'generatedColumn' => 43 + 31 - 39, 'originalSource' => 'foo.js', 'originalLine' => 2, 'originalColumn' => 5, 'originalName' => 'x')); }
public function getContentsPacked() { $ret = Kwf_SourceMaps_SourceMap::createEmptyMap(''); $trlData = array(); $masterFiles = array(); foreach ($this->_componentDependencies as $dep) { $c = $dep->getContentsPacked(); $data = $c->getMapContentsData(false); if (isset($data->{'_x_org_koala-framework_trlData'})) { $trlData = array_merge($trlData, $data->{'_x_org_koala-framework_trlData'}); } if (isset($data->{'_x_org_koala-framework_masterFiles'})) { $masterFiles = array_merge($masterFiles, $data->{'_x_org_koala-framework_masterFiles'}); } $sourcesCount = 0; $packageData = $ret->getMapContentsData(false); if (isset($packageData->sources)) { $sourcesCount = count($packageData->sources); } unset($packageData); if (Kwf_Config::getValue('application.uniquePrefix')) { $c->stringReplace('kwcBem--', $this->_getKwcClass() . '--'); $c->stringReplace('kwcBem__', $this->_getKwcClass() . '__'); } else { $c->stringReplace('kwcBem--', ''); $c->stringReplace('kwcBem__', ''); } $c->stringReplace('.kwcClass', '.' . $this->_getKwcClass()); $ret->concat($c); //copy sourcesContent to packageMap with $sourcesCount offset $packageData = $ret->getMapContentsData(false); if (isset($data->{'_x_org_koala-framework_sourcesContent'})) { if (!isset($packageData->{'_x_org_koala-framework_sourcesContent'})) { $packageData->{'_x_org_koala-framework_sourcesContent'} = array(); } foreach ($data->{'_x_org_koala-framework_sourcesContent'} as $k => $i) { $packageData->{'_x_org_koala-framework_sourcesContent'}[$k + $sourcesCount] = $i; } } unset($packageData); } $ret->getMapContentsData(false)->{'_x_org_koala-framework_trlData'} = $trlData; $ret->getMapContentsData(false)->{'_x_org_koala-framework_masterFiles'} = $masterFiles; $ret->setMimeType('text/javascript'); return $ret; }
public function getContentsPacked() { $ret = Kwf_SourceMaps_SourceMap::createEmptyMap(''); $masterFiles = array(); foreach ($this->_componentDependencies as $dep) { $c = $dep->getContentsPacked(); $data = $c->getMapContentsData(false); if (isset($data->{'_x_org_koala-framework_masterFiles'})) { $masterFiles = array_merge($masterFiles, $data->{'_x_org_koala-framework_masterFiles'}); } $sourcesCount = 0; $packageData = $ret->getMapContentsData(false); if (isset($packageData->sources)) { $sourcesCount = count($packageData->sources); } unset($packageData); $replacements = array(); if (Kwf_Config::getValue('application.uniquePrefix')) { $replacements['kwcBem--'] = $this->_getKwcClass() . '--'; $replacements['kwcBem__'] = $this->_getKwcClass() . '__'; } else { $replacements['kwcBem--'] = ''; $replacements['kwcBem__'] = ''; } $replacements['kwcClass'] = $this->_getKwcClass(); $filter = new Kwf_Assets_Filter_Css_SelectorReplace($replacements); $c = $filter->filter($c); $ret->concat($c); //copy sourcesContent to packageMap with $sourcesCount offset $packageData = $ret->getMapContentsData(false); if (isset($data->{'_x_org_koala-framework_sourcesContent'})) { if (!isset($packageData->{'_x_org_koala-framework_sourcesContent'})) { $packageData->{'_x_org_koala-framework_sourcesContent'} = array(); } foreach ($data->{'_x_org_koala-framework_sourcesContent'} as $k => $i) { $packageData->{'_x_org_koala-framework_sourcesContent'}[$k + $sourcesCount] = $i; } } unset($packageData); } $ret->getMapContentsData(false)->{'_x_org_koala-framework_masterFiles'} = $masterFiles; $ret->setMimeType('text/css'); return $ret; }
public function getPackageContents($mimeType, $language, $includeSourceMapComment = true) { $ret = parent::getPackageContents($mimeType, $language, $includeSourceMapComment); if ($mimeType == 'text/javascript; defer') { $uniquePrefix = Kwf_Config::getValue('application.uniquePrefix'); if ($uniquePrefix) { $uniquePrefix = $uniquePrefix . '.'; } $foot = ' if (' . $uniquePrefix . 'Kwf._loadDeferred) ' . $uniquePrefix . 'Kwf._loadDeferred.forEach(function(i) { i(); }); ' . $uniquePrefix . 'Kwf._loadDeferred = "done"; '; $map = Kwf_SourceMaps_SourceMap::createEmptyMap(''); $map->concat($ret); $map->concat(Kwf_SourceMaps_SourceMap::createEmptyMap($foot)); $ret = $map; } return $ret; }
public function getContentsPacked() { $contents = $this->getContentsSourceString(); $contents = str_replace("\r", "\n", $contents); $contents = $this->_processContents($contents); // remove comments //$contents = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $contents); // multiple whitespaces $contents = str_replace("\t", " ", $contents); $contents = preg_replace('/(\\n)\\n+/', '$1', $contents); $contents = preg_replace('/(\\n)\\ +/', '$1', $contents); $contents = preg_replace('/(\\ )\\ +/', '$1', $contents); $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($contents); $data = $ret->getMapContentsData(); $data->{'_x_org_koala-framework_masterFiles'} = array($this->getAbsoluteFileName()); $data->sources = array('/assets/' . $this->getFileNameWithType()); $ret->setMimeType('text/css'); return $ret; }
public static function filter($ret) { $uniquePrefix = Kwf_Config::getValue('application.uniquePrefix'); if ($uniquePrefix) { $uniquePrefix = $uniquePrefix . '.'; } $head = ' ' . $uniquePrefix . 'Kwf.loadDeferred(function() { '; $foot = ' }); '; $map = Kwf_SourceMaps_SourceMap::createEmptyMap(''); $map->concat(Kwf_SourceMaps_SourceMap::createEmptyMap($head)); $map->concat($ret); $map->concat(Kwf_SourceMaps_SourceMap::createEmptyMap($foot)); $ret = $map; return $ret; }
public function build() { $babel = getcwd() . "/" . VENDOR_PATH . "/bin/node " . getcwd() . '/node_modules/babel-cli/bin/babel.js'; $cmd = "{$babel} "; $arguments = implode(' ', array_values($this->_getArguments())); $cmd .= "{$arguments} "; $cmd .= escapeshellarg($this->_sourceFile); $cmd .= " 2>&1"; $out = array(); $nodePath = implode(PATH_SEPARATOR, $this->_getNodePath()); putenv("NODE_PATH={$nodePath}"); exec($cmd, $out, $retVal); putenv("NODE_PATH="); if ($retVal) { throw new Kwf_Exception("babel failed: " . implode("\n", $out)); } $contents = implode("\n", $out); return Kwf_SourceMaps_SourceMap::createFromInline($contents); }
public function filter(Kwf_SourceMaps_SourceMap $sourcemap) { $temp = tempnam('temp/', 'commonjs'); file_put_contents($temp, $sourcemap->getFileContents()); $parsedFile = Kwf_Assets_CommonJs_ModuleDepsParser::parse($temp); unlink($temp); $newSourceMap = Kwf_SourceMaps_SourceMap::createEmptyMap($parsedFile['source']); if (isset($sourcemap->getMapContentsData(false)->{'_x_org_koala-framework_trlData'})) { $newSourceMap->getMapContentsData(false)->{'_x_org_koala-framework_trlData'} = $sourcemap->getMapContentsData(false)->{'_x_org_koala-framework_trlData'}; } if (isset($sourcemap->getMapContentsData(false)->{'_x_org_koala-framework_masterFiles'})) { $newSourceMap->getMapContentsData(false)->{'_x_org_koala-framework_masterFiles'} = $sourcemap->getMapContentsData(false)->{'_x_org_koala-framework_masterFiles'}; } return $newSourceMap; }
public function getContentsPacked() { if (!Kwf_Config::getValue('googleMapsApiKey') && !Kwf_Config::getValueArray('googleMapsApiKeys')) { throw new Kwf_Exception('googleMapsApiKey is required in config.ini'); } if (Kwf_Config::getValue('googleMapsApiKey')) { $json = Kwf_Config::getValue('googleMapsApiKey'); if (Kwf_Config::getValueArray('googleMapsApiKeys')) { throw new Kwf_Exception('Don\'t use googleMapsApiKeys and googleMapsApiKey together, remove googleMapsApiKeys'); } } else { //legacy $json = Kwf_Config::getValueArray('googleMapsApiKeys'); } $json = json_encode($json); $ret = "module.exports = {$json};"; $ret = Kwf_SourceMaps_SourceMap::createEmptyMap($ret); $data = $ret->getMapContentsData(); $data->{'_x_org_koala-framework_masterFiles'} = array('config.ini'); return $ret; }
public function filter(Kwf_SourceMaps_SourceMap $sourcemap) { $sourcemap->stringReplace('$red', '#ff0000'); $sourcemap->stringReplace('$blue', '#0000ff'); return $sourcemap; }
public function getContentsPacked() { $ret = "require('kwf/responsive-el')('" . $this->_selector . "', " . json_encode($this->_breakpoints) . ");\n"; return Kwf_SourceMaps_SourceMap::createEmptyMap($ret); }