2017-02-05 22:58:38 +00:00
|
|
|
#!/usr/bin/php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
# Dependencies:
|
|
|
|
# - PHP
|
|
|
|
# - Uglifyjs (`npm install -g uglifyjs`)
|
|
|
|
# - Lessc (`npm install -g less`)
|
|
|
|
# - Lessc minifier (`npm install -g less-plugin-clean-css`)
|
|
|
|
# - HTML minifier (`npm install -g html-minifier`)
|
|
|
|
|
|
|
|
echo "Compressing/minifying web resources...\n";
|
|
|
|
|
|
|
|
if (is_dir('clientpack')) {
|
|
|
|
`rm -r clientpack`;
|
|
|
|
}
|
|
|
|
|
|
|
|
`cp -r client clientpack`;
|
|
|
|
|
|
|
|
// Toggle IIFE on
|
|
|
|
|
|
|
|
`sed -i -re 's~//IIFEMODE:~~g' clientpack/dcwebui.js`;
|
|
|
|
|
|
|
|
// Minify JS
|
|
|
|
|
|
|
|
`uglifyjs clientpack/dcwebui.js -o clientpack/dcwebui.min.js -c -m`;
|
|
|
|
|
|
|
|
// Minify CSS
|
|
|
|
|
|
|
|
`lessc --clean-css clientpack/dcwebui.css clientpack/dcwebui.min.css`;
|
|
|
|
|
|
|
|
// Embed css into HTML file
|
|
|
|
|
|
|
|
$html_content = file_get_contents('clientpack/index.htm');
|
2017-02-06 00:44:56 +00:00
|
|
|
|
|
|
|
$html_content = preg_replace_callback('~<link[^>]+dcwebui.css[^>]*>~', function() { return '<style type="text/css">'.file_get_contents('clientpack/dcwebui.min.css').'</style>'; }, $html_content);
|
2017-02-05 22:58:38 +00:00
|
|
|
|
|
|
|
// Embed JS into HTML file
|
|
|
|
|
2017-02-06 00:44:56 +00:00
|
|
|
$html_content = preg_replace_callback('~<script[^>]+dcwebui.js[^>]*>~', function() { return '<script type="text/javascript">'.file_get_contents('clientpack/dcwebui.min.js').'</script>'; }, $html_content);
|
2017-02-05 22:58:38 +00:00
|
|
|
|
|
|
|
// Embed socketio into HTML file
|
|
|
|
|
2017-02-06 00:44:56 +00:00
|
|
|
define('SIO_NAME', 'socket.io-1.7.2.js');
|
|
|
|
$html_content = preg_replace_callback('~<script[^>]+'.SIO_NAME.'[^>]*>~', function() { return '<script type="text/javascript">'.file_get_contents('clientpack/'.SIO_NAME).'</script>'; }, $html_content);
|
2017-02-05 22:58:38 +00:00
|
|
|
|
|
|
|
// Minify the combined file
|
|
|
|
|
|
|
|
file_put_contents('clientpack/index.htm', $html_content);
|
|
|
|
|
|
|
|
`html-minifier --collapse-whitespace -o clientpack/index.min.htm clientpack/index.htm`;
|
|
|
|
|
|
|
|
// Clean up files
|
|
|
|
|
|
|
|
`rm clientpack/{index.htm,dcwebui{.min,}.js,dcwebui{.min,}.css}`;
|
2017-02-06 00:44:56 +00:00
|
|
|
unlink('clientpack/'.SIO_NAME);
|
2017-02-05 22:58:38 +00:00
|
|
|
rename('clientpack/index.min.htm', 'clientpack/index.htm');
|