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

Last commit: Sun Oct 13 13:17:32 2024 +0200	Jan Dankert	New Minifier for CSS and JS: Leave JS Linebreaks as they are (for better debugging); Exploded CSS files (instead of a combined one), LESS is necessary but should be avoided in the future.
1 <?php 2 3 namespace cms\ui\themes; 4 5 use util\FileUtils; 6 use util\Less; 7 use util\ui\minifier\JSMinifier; 8 use util\ui\minifier\CSSMinifier; 9 use template_engine\TemplateEngineInfo; 10 11 /** 12 * Theme-Compiler. 13 * 14 * @author Jan Dankert 15 */ 16 class ThemeCompiler 17 { 18 public function compileAll() { 19 $this->compileStyles(); 20 $this->compileScripts(); 21 22 } 23 24 public function compileStyles() 25 { 26 $css = []; 27 28 $styleFiles = FileUtils::readDir( __DIR__.'/default/style','less'); 29 foreach( $styleFiles as $styleFile ) { 30 $css[] = __DIR__.'/default/style'.'/'.substr($styleFile,0,-5); 31 } 32 33 // Komponentenbasiertes CSS 34 foreach (TemplateEngineInfo::getComponentList() as $c) 35 { 36 $componentCssFile = 'template_engine/components/html/component_' . $c . '/' . $c; 37 if (is_file( __DIR__.'/../../../'. $componentCssFile . '.less')) 38 $css[] = __DIR__.'/../../../'.$componentCssFile; 39 if (is_file( __DIR__.'/../../../'. $componentCssFile . '.css')) 40 $css[] = __DIR__.'/../../../'.$componentCssFile; 41 } 42 43 foreach ($css as $cssF) 44 { 45 $lessFile = $cssF . '.less'; 46 //$cssFile = $cssF . '.css'; 47 48 $parser = new Less(array( 49 'compress' => false, 50 'sourceMap' => false, 51 'indentation' => ' ' 52 )); 53 $parser->parseFile($lessFile); 54 $source = $parser->getCss(); 55 $outFilename = $cssF.'.css'; 56 file_put_contents( $outFilename, $source."\n"); 57 echo 'Created file '.$outFilename ."\n"; 58 59 60 $parser = new Less(array( 61 'compress' => true, 62 'sourceMap' => false, 63 'indentation' => '' 64 )); 65 $parser->parseFile($lessFile); 66 $source = $parser->getCss(); 67 68 //$minifier = new CSSMinifier(); 69 70 //$minifier->addSourceFile( $lessFile ); 71 //$source = $minifier->getCompressedContent(); 72 73 $outFilename = $cssF.'.min.css'; 74 file_put_contents( $outFilename, $source."\n"); 75 echo 'Created file '.$outFilename ."\n"; 76 } 77 78 } 79 80 81 82 public function compileScripts() 83 { 84 $js = []; 85 86 // Jquery-Plugins 87 $js[] = __DIR__.'/default/script/plugin/jquery-plugin-toggleAttr'; 88 $js[] = __DIR__.'/default/script/plugin/jquery-plugin-orSearch'; 89 $js[] = __DIR__.'/default/script/plugin/jquery-plugin-orLinkify'; 90 $js[] = __DIR__.'/default/script/plugin/jquery-plugin-orButton'; 91 $js[] = __DIR__.'/default/script/plugin/jquery-plugin-orTree'; 92 $js[] = __DIR__.'/default/script/plugin/jquery-plugin-orAutoheight'; 93 94 // OpenRat internal JS - als letztes, damit die vorigen bereits geladen sind. 95 $js[] = __DIR__.'/default/script/openrat/api'; 96 $js[] = __DIR__.'/default/script/openrat/callback'; 97 $js[] = __DIR__.'/default/script/openrat/components'; 98 $js[] = __DIR__.'/default/script/openrat/dialog'; 99 $js[] = __DIR__.'/default/script/openrat/form'; 100 $js[] = __DIR__.'/default/script/openrat/init'; 101 $js[] = __DIR__.'/default/script/openrat/navigator'; 102 $js[] = __DIR__.'/default/script/openrat/notice'; 103 $js[] = __DIR__.'/default/script/openrat/view'; 104 $js[] = __DIR__.'/default/script/openrat/workbench'; 105 106 $js[] = __DIR__.'/default/script/Oquery'; 107 $js[] = __DIR__.'/default/script/jquery-global'; 108 109 // Komponentenbasiertes Javascript 110 foreach ( TemplateEngineInfo::getComponentList() as $c) 111 { 112 $componentJsFile = __DIR__.'/../../../template_engine/components/html/component_' . $c . '/' . $c; 113 if (is_file($componentJsFile . '.js')) 114 $js[] = $componentJsFile; 115 } 116 117 foreach ($js as $jsFile) 118 { 119 $jsFileMin = $jsFile . '.min.js'; 120 $jsFileNormal = $jsFile . '.js'; 121 122 if( is_file($jsFileNormal) ) 123 { 124 // Minify.... 125 $minifier = new JSMinifier( 126 JSMinifier::FLAG_IMPORT_MIN_JS + 127 JSMinifier::FLAG_REMOVE_MULTILINE_COMMENT + 128 JSMinifier::FLAG_REMOVE_LINE_COMMENTS + 129 JSMinifier::FLAG_REMOVE_TABS + 130 JSMinifier::FLAG_REMOVE_INDENTING_SPACES ); 131 $minifier->addSourceFile( $jsFileNormal ); 132 file_put_contents($jsFileMin, $minifier->getCompressedContent()); 133 134 echo 'Minified to '.$jsFileMin."\n"; 135 } else { 136 throw new \LogicException('Missing javascript: '.$jsFile ); 137 } 138 } 139 } 140 141 }
Download modules/cms/ui/themes/ThemeCompiler.class.php
History Sun, 13 Oct 2024 13:17:32 +0200 Jan Dankert New Minifier for CSS and JS: Leave JS Linebreaks as they are (for better debugging); Exploded CSS files (instead of a combined one), LESS is necessary but should be avoided in the future. 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].