2016-02-28 22:35:24 +01:00
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* helper to update EGroupware Gruntfile.js
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2018-12-12 17:00:14 +01:00
|
|
|
* @author Ralf Becker <rb@egroupware.org>
|
|
|
|
* @copyright (c) 2016-18 by Ralf Becker <rb@egroupware.org>
|
2016-02-28 22:35:24 +01:00
|
|
|
*/
|
|
|
|
|
2016-04-30 11:29:54 +02:00
|
|
|
use EGroupware\Api\Framework;
|
2016-04-07 22:42:06 +02:00
|
|
|
use EGroupware\Api\Framework\Bundle;
|
|
|
|
|
2016-02-28 22:35:24 +01:00
|
|
|
if (php_sapi_name() !== 'cli') die("This is a commandline ONLY tool!\n");
|
|
|
|
|
2018-12-12 17:00:14 +01:00
|
|
|
// force a domain for MServer install
|
|
|
|
$_REQUEST['domain'] = 'boulder.egroupware.org';
|
2016-02-28 22:35:24 +01:00
|
|
|
$GLOBALS['egw_info'] = array(
|
|
|
|
'flags' => array(
|
|
|
|
'currentapp' => 'login',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
include(__DIR__.'/header.inc.php');
|
|
|
|
|
|
|
|
$gruntfile = __DIR__.'/Gruntfile.js';
|
|
|
|
if (!($content = @file_get_contents($gruntfile)))
|
|
|
|
{
|
|
|
|
die("\nFile '$gruntfile' not found!\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!preg_match('/grunt\.initConfig\(({.+})\);/s', $content, $matches) ||
|
|
|
|
!($json = preg_replace('/^(\s*)([a-z0-9_-]+):/mi', '$1"$2":', $matches[1])) ||
|
|
|
|
!($config = json_decode($json, true)))
|
|
|
|
{
|
|
|
|
die("\nCan't parse $path!\n\n");
|
|
|
|
}
|
|
|
|
//print_r($config); exit;
|
|
|
|
|
2016-03-01 10:57:39 +01:00
|
|
|
$uglify =& $config['uglify'];
|
2016-02-28 22:35:24 +01:00
|
|
|
|
2018-12-12 17:00:14 +01:00
|
|
|
// some files are not in a bundle, because loaded otherwise or are big enough themselfs
|
|
|
|
$exclude = array(
|
|
|
|
// api/js/jsapi/egw.js loaded via own tag, and we must not load it twice!
|
|
|
|
'api/js/jsapi/egw.js',
|
|
|
|
// TinyMCE is loaded separate before the bundle
|
2019-03-20 12:05:20 +01:00
|
|
|
'vendor/tinymce/tinymce/tinymce.min.js',
|
2018-12-12 17:00:14 +01:00
|
|
|
);
|
|
|
|
|
2016-04-07 22:42:06 +02:00
|
|
|
foreach(Bundle::all() as $name => $files)
|
2016-02-28 22:35:24 +01:00
|
|
|
{
|
|
|
|
if ($name == '.ts') continue; // ignore timestamp
|
|
|
|
|
|
|
|
// remove leading / from file-names
|
|
|
|
array_walk($files, function(&$path)
|
|
|
|
{
|
|
|
|
if ($path[0] == '/') $path = substr($path, 1);
|
|
|
|
});
|
|
|
|
|
2018-12-12 17:00:14 +01:00
|
|
|
// some files are not in a bundle, because they are big enough themselfs
|
|
|
|
foreach($exclude as $file)
|
2016-03-02 15:34:01 +01:00
|
|
|
{
|
2018-12-12 17:00:14 +01:00
|
|
|
if (($key = array_search($file, $files))) unset($files[$key]);
|
2016-03-02 15:34:01 +01:00
|
|
|
}
|
2016-03-01 21:45:31 +01:00
|
|
|
|
2016-02-28 22:35:24 +01:00
|
|
|
//var_dump($name, $files);
|
2016-03-01 10:57:39 +01:00
|
|
|
if (isset($uglify[$name]))
|
2016-02-28 22:35:24 +01:00
|
|
|
{
|
2016-03-01 10:57:39 +01:00
|
|
|
list($target) = each($uglify[$name]['files']);
|
|
|
|
$uglify[$name]['files'][$target] = array_values($files);
|
2016-02-28 22:35:24 +01:00
|
|
|
}
|
2016-03-01 10:57:39 +01:00
|
|
|
elseif (isset($uglify[$append = substr($name, 0, -1)]))
|
2016-02-28 22:35:24 +01:00
|
|
|
{
|
2016-03-01 21:45:31 +01:00
|
|
|
reset($uglify[$append]['files']);
|
|
|
|
list($target) = each($uglify[$append]['files']);
|
2016-03-01 10:57:39 +01:00
|
|
|
$uglify[$append]['files'][$target] = array_merge($uglify[$append]['files'][$target], array_values($files));
|
2016-02-28 22:35:24 +01:00
|
|
|
}
|
2016-03-01 21:45:31 +01:00
|
|
|
else // create new bundle using last file as target
|
2016-02-28 22:35:24 +01:00
|
|
|
{
|
2016-03-01 21:45:31 +01:00
|
|
|
$target = str_replace('.js', '.min.js', end($files));
|
|
|
|
$uglify[$name]['files'][$target] = array_values($files);
|
2016-02-28 22:35:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-30 11:29:54 +02:00
|
|
|
// add css for all templates and themes
|
|
|
|
$cssmin =& $config['cssmin'];
|
2018-12-12 17:00:14 +01:00
|
|
|
$GLOBALS['egw_info']['flags']['currentapp'] = '*grunt*'; // to not find any app.css files
|
2016-04-30 11:29:54 +02:00
|
|
|
$GLOBALS['egw_info']['server']['debug_minify'] = 'True'; // otherwise we would only get minified file
|
|
|
|
foreach(array('pixelegg','jdots')/*array_keys(Framework::list_templates())*/ as $template)
|
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['server']['template_set'] = $template;
|
|
|
|
$tpl = Framework::factory();
|
|
|
|
$themes = $tpl->list_themes();
|
|
|
|
if ($template == 'pixelegg') $themes[] = 'fw_mobile'; // this is for mobile devices
|
2018-12-12 17:00:14 +01:00
|
|
|
foreach(array_keys($themes) as $theme)
|
2016-04-30 11:29:54 +02:00
|
|
|
{
|
|
|
|
// skip not working cssmin of pixelegg/traditional: Broken @import declaration of "../../etemplate/templates/default/etemplate2.css"
|
|
|
|
if ($template == 'pixelegg' && $theme == 'traditional') continue;
|
|
|
|
$GLOBALS['egw_info']['user']['preferences']['common']['theme'] = $theme;
|
|
|
|
// empty include list by not-existing file plus last true
|
|
|
|
Framework\CssIncludes::add('*grunt*', null, true, true);
|
|
|
|
$tpl->_get_css();
|
|
|
|
$dest = substr($tpl->template_dir, 1).($theme == 'fw_mobile' ? '/mobile/' : '/css/').$theme.'.min.css';
|
|
|
|
$cssmin[$template]['files'][$dest] =
|
|
|
|
// remove leading slash from src path
|
|
|
|
array_map(function($path)
|
|
|
|
{
|
|
|
|
return substr($path, 1);
|
|
|
|
},
|
|
|
|
// filter out all dynamic css, like categories.php
|
|
|
|
array_values(array_filter(Framework\CssIncludes::get(true), function($path)
|
|
|
|
{
|
|
|
|
return strpos($path, '.php?') === false;
|
|
|
|
})));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-28 22:35:24 +01:00
|
|
|
$new_json = str_replace("\n", "\n\t",
|
|
|
|
preg_replace_callback('/^( *)/m', function($matches)
|
|
|
|
{
|
|
|
|
return str_repeat("\t", strlen($matches[1])/4);
|
2016-05-05 10:04:57 +02:00
|
|
|
}, json_encode($config, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES)));
|
2016-02-28 22:35:24 +01:00
|
|
|
|
|
|
|
$new_content = preg_replace('/^(\s*)"([a-z0-9]+)":/mi', '$1$2:', $new_json);
|
|
|
|
//die($new_content."\n");
|
|
|
|
|
|
|
|
rename($gruntfile, $gruntfile.'.old');
|
2018-12-12 17:00:14 +01:00
|
|
|
file_put_contents($gruntfile, str_replace($matches[1], $new_content, $content));
|