File modules/cms/ui/themes/ThemeCompiler.class.php

Last commit: Sat Dec 18 03:47:23 2021 +0100	dankert	New: Every ES6-Module should have a minified version for performance reasons. Bad: The Minifier "Jsqueeze" is unable to minify ES6-modules, so we had to implement a simple JS-Minifier which strips out all comments.
1 <?php 2 3 namespace cms\ui\themes; 4 5 use util\FileUtils; 6 use util\JSMinifier; 7 use util\JSqueeze; 8 use logger\Logger; 9 use template_engine\TemplateEngineInfo; 10 use util\Less; 11 12 /** 13 * Theme-Compiler. 14 * 15 * @author Jan Dankert 16 */ 17 class ThemeCompiler 18 { 19 public function compileAll() { 20 $this->compileStyles(); 21 $this->compileScripts(); 22 23 } 24 25 public function compileStyles() 26 { 27 $combinedCssFile = __DIR__.'/default/'.Theme::STYLE_FILENAME; 28 $combinedCssFileMin = __DIR__.'/default/'.Theme::STYLE_MINIFIED_FILENAME; 29 30 file_put_contents($combinedCssFile ,''); 31 file_put_contents($combinedCssFileMin,''); 32 33 $css = []; 34 35 $styleFiles = FileUtils::readDir( __DIR__.'/default/style','less'); 36 foreach( $styleFiles as $styleFile ) { 37 $css[] = __DIR__.'/default/style'.'/'.substr($styleFile,0,-5); 38 } 39 40 // Komponentenbasiertes CSS 41 foreach (TemplateEngineInfo::getComponentList() as $c) 42 { 43 $componentCssFile = 'template_engine/components/html/component_' . $c . '/' . $c; 44 if (is_file( __DIR__.'/../../../'. $componentCssFile . '.less')) 45 $css[] = __DIR__.'/../../../'.$componentCssFile; 46 } 47 48 //$css[] = __DIR__.'/../../../editor/simplemde/simplemde'; 49 //$css[] = __DIR__.'/../../../editor/trumbowyg/ui/trumbowyg'; 50 //$css[] = __DIR__.'/../../../editor/codemirror/lib/codemirror'; 51 52 foreach ($css as $cssF) 53 { 54 $lessFile = $cssF . '.less'; 55 56 file_put_contents($combinedCssFile, '/* Include style: '.substr($cssF,strlen(__DIR__)).' */'."\n",FILE_APPEND); 57 58 // Den absoluten Pfad zur LESS-Datei ermitteln. Dieser wird vom LESS-Parser für den korrekten Link 59 // auf die LESS-Datei in der Sourcemap benötigt. 60 $pfx = substr(realpath($lessFile),0,0-strlen(basename($lessFile))); 61 62 $parser = new Less(array( 63 'sourceMap' => true, 64 'indentation' => ' ', 65 'outputSourceFiles' => false, 66 'sourceMapBasepath' => $pfx 67 )); 68 69 70 $parser->parseFile( $lessFile ); 71 $source = $parser->getCss(); 72 73 file_put_contents($combinedCssFile, $source."\n",FILE_APPEND); 74 75 $parser = new Less(array( 76 'compress' => true, 77 'sourceMap' => false, 78 'indentation' => '' 79 )); 80 $parser->parseFile($lessFile); 81 $source = $parser->getCss(); 82 83 file_put_contents($combinedCssFileMin, $source."\n",FILE_APPEND); 84 85 echo 'Copied source from less source file '.$lessFile."\n"; 86 } 87 88 echo 'Created file '.$combinedCssFileMin."\n"; 89 echo 'Created file '.$combinedCssFile ."\n"; 90 91 } 92 93 94 95 public function compileScripts() 96 { 97 $js = []; 98 99 // Jquery-Plugins 100 $js[] = __DIR__.'/default/script/plugin/jquery-plugin-toggleAttr'; 101 $js[] = __DIR__.'/default/script/plugin/jquery-plugin-orSearch'; 102 $js[] = __DIR__.'/default/script/plugin/jquery-plugin-orLinkify'; 103 $js[] = __DIR__.'/default/script/plugin/jquery-plugin-orButton'; 104 $js[] = __DIR__.'/default/script/plugin/jquery-plugin-orTree'; 105 $js[] = __DIR__.'/default/script/plugin/jquery-plugin-orAutoheight'; 106 107 // OpenRat internal JS - als letztes, damit die vorigen bereits geladen sind. 108 $js[] = __DIR__.'/default/script/openrat/api'; 109 $js[] = __DIR__.'/default/script/openrat/callback'; 110 $js[] = __DIR__.'/default/script/openrat/components'; 111 $js[] = __DIR__.'/default/script/openrat/dialog'; 112 $js[] = __DIR__.'/default/script/openrat/form'; 113 $js[] = __DIR__.'/default/script/openrat/init'; 114 $js[] = __DIR__.'/default/script/openrat/navigator'; 115 $js[] = __DIR__.'/default/script/openrat/notice'; 116 $js[] = __DIR__.'/default/script/openrat/view'; 117 $js[] = __DIR__.'/default/script/openrat/workbench'; 118 119 $js[] = __DIR__.'/default/script/Oquery'; 120 $js[] = __DIR__.'/default/script/jquery-global'; 121 122 // Komponentenbasiertes Javascript 123 foreach ( TemplateEngineInfo::getComponentList() as $c) 124 { 125 $componentJsFile = __DIR__.'/../../../template_engine/components/html/component_' . $c . '/' . $c; 126 if (is_file($componentJsFile . '.js')) 127 $js[] = $componentJsFile; 128 } 129 130 foreach ($js as $jsFile) 131 { 132 $jsFileMin = $jsFile . '.min.js'; 133 $jsFileNormal = $jsFile . '.js'; 134 135 if( is_file($jsFileNormal) ) 136 { 137 // Minify.... 138 $jz = new JSMinifier( 139 JSMinifier::FLAG_IMPORT_MIN_JS + 140 JSMinifier::FLAG_REMOVE_MULTILINE_COMMENT + 141 JSMinifier::FLAG_REMOVE_BLANK_LINES + 142 JSMinifier::FLAG_REMOVE_LINE_COMMENTS + 143 JSMinifier::FLAG_REMOVE_WHITESPACE ); 144 file_put_contents($jsFileMin, $jz->minify(file_get_contents($jsFileNormal))); 145 146 echo 'Minified to '.$jsFileMin."\n"; 147 } else { 148 throw new \LogicException('Missing javascript: '.$jsFile ); 149 } 150 } 151 } 152 153 }
Download modules/cms/ui/themes/ThemeCompiler.class.php
History Sat, 18 Dec 2021 03:47:23 +0100 dankert New: Every ES6-Module should have a minified version for performance reasons. Bad: The Minifier "Jsqueeze" is unable to minify ES6-modules, so we had to implement a simple JS-Minifier which strips out all comments. Mon, 12 Apr 2021 23:46:06 +0200 Jan Dankert New: Smaller CSS-Files, because third-party-CSS (editors...) is loaded dynamically if necessary. Thu, 1 Apr 2021 23:54:54 +0200 Jan Dankert Removed: jquery-hotkeys (not necessary any more) Sat, 27 Mar 2021 10:43:47 +0100 Jan Dankert Removed the generated bundle openrat.js, this is not necessary any more. Sat, 27 Mar 2021 05:14:11 +0100 Jan Dankert Refactoring: Converting all script files to ES6 modules (work in progress); removed jquery-ui (drag and drop will be replaced by HTML5, sortable by a small lib) Wed, 17 Mar 2021 22:27:33 +0100 Jan Dankert Refactoring: Using ES6-Modules (experimental) Tue, 16 Mar 2021 23:52:22 +0100 Jan Dankert Refactoring: Use ES6 classes. Sat, 6 Mar 2021 20:44:40 +0100 Jan Dankert Fix: Filenames of CSS-Files should be identically on all platforms. Sat, 6 Mar 2021 15:38:14 +0100 Jan Dankert New: Submenus in Lists. Wed, 17 Feb 2021 02:34:51 +0100 Jan Dankert Refactoring: Extract Dialog into a separate js class Wed, 17 Feb 2021 00:37:45 +0100 Jan Dankert Refactoring: Extract Notices into a separate js class Tue, 1 Dec 2020 00:07:39 +0100 Jan Dankert New: Visibility-Button for password fields, fix: QR-code button for mobile devices. Wed, 21 Oct 2020 23:13:01 +0200 Jan Dankert Externalize constants. Sat, 17 Oct 2020 02:14:49 +0200 Jan Dankert Fix: JS und CSS was a little bit broken since the last components refactoring. Sun, 4 Oct 2020 23:53:25 +0200 Jan Dankert New: The tree is now hidable with a dedicated button. No more hover effect in the navigation. Sun, 27 Sep 2020 00:48:43 +0200 Jan Dankert Fix: Treeaction is an UI action, so ist is not available via the API. Now there is an ugly workaround for that, we have to create a template for this calls. Sat, 26 Sep 2020 01:41:20 +0200 Jan Dankert Refactoring: Removing old require.php files. With class autoloading, they are not necessary any more. Sun, 23 Aug 2020 00:23:18 +0200 Jan Dankert Fixing the minified JS :-O Fri, 21 Aug 2020 00:22:13 +0200 Jan Dankert Refactoring: Collect all frontend compiler scripts in update.php. Compiling of CSS and JS was extracted to a new TemplateCompiler. JS and CSS is now collected in a new openrat.[min.][js|css].