init commit
This commit is contained in:
7
skins/larry/bin/build.sh
Normal file
7
skins/larry/bin/build.sh
Normal file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
PWD=`dirname "$0"`
|
||||
|
||||
$PWD/jsshrink.sh && $PWD/cssshrink.sh && $PWD/cssimages.sh
|
55
skins/larry/bin/cssimages.sh
Normal file
55
skins/larry/bin/cssimages.sh
Normal file
@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
foreach (get_files(__DIR__ . '/..') as $file) {
|
||||
print "Processing $file\n";
|
||||
|
||||
$content = file_get_contents($file);
|
||||
$regexp = "#url\(['\"]?([a-zA-Z0-9_./-]+)(\?v=[a-f0-9-\.]+)?['\"]?\)#";
|
||||
|
||||
if (preg_match_all($regexp, $content, $matches)) {
|
||||
$seen = [];
|
||||
|
||||
foreach ($matches[1] as $idx => $image) {
|
||||
if (!in_array($image, $seen) && preg_match('/\.(gif|ico|png|jpg|jpeg)$/', $image)) {
|
||||
$filepath = pathinfo($file, PATHINFO_DIRNAME) . "/$image";
|
||||
|
||||
if (file_exists($filepath)) {
|
||||
$sum = substr(md5_file($filepath), 0, 4) . '.' . filesize($filepath);
|
||||
}
|
||||
else {
|
||||
print "ERROR: Missing image: $filepath\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$content = str_replace($matches[0][$idx], "url($image?v=$sum)", $content);
|
||||
}
|
||||
|
||||
$seen[] = $image;
|
||||
}
|
||||
|
||||
file_put_contents($file, $content);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function get_files($dir)
|
||||
{
|
||||
$files = [];
|
||||
$dh = opendir($dir);
|
||||
|
||||
while ($file = readdir($dh)) {
|
||||
if (preg_match('/^(.+)\.min\.css$/', $file, $m)) {
|
||||
$files[] = "$dir/$file";
|
||||
}
|
||||
else if ($file[0] != '.' && is_dir("$dir/$file")) {
|
||||
foreach (get_files("$dir/$file") as $f) {
|
||||
$files[] = $f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir($dh);
|
||||
|
||||
return $files;
|
||||
}
|
44
skins/larry/bin/cssshrink.sh
Normal file
44
skins/larry/bin/cssshrink.sh
Normal file
@ -0,0 +1,44 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
PWD=`dirname "$0"`
|
||||
|
||||
do_shrink() {
|
||||
rm -f "$2"
|
||||
csso $1 -o $2 --no-restructure
|
||||
}
|
||||
|
||||
if which csso > /dev/null 2>&1; then
|
||||
:
|
||||
else
|
||||
echo "csso not found. Please install e.g. 'npm install -g csso-cli'."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# compress single file from argument
|
||||
if [ $# -gt 0 ]; then
|
||||
CSS_FILE="$1"
|
||||
|
||||
echo "Shrinking $CSS_FILE"
|
||||
minfile=`echo $CSS_FILE | sed -e 's/\.css$/\.min\.css/'`
|
||||
do_shrink "$CSS_FILE" "$minfile"
|
||||
exit
|
||||
fi
|
||||
|
||||
DIRS="$PWD/.. $PWD/../plugins/*"
|
||||
# default: compress application scripts
|
||||
for dir in $DIRS; do
|
||||
for file in $dir/*.css; do
|
||||
if echo "$file" | grep -q -e '.min.css$'; then
|
||||
continue
|
||||
fi
|
||||
if [ ! -f "$file" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "Shrinking $file"
|
||||
minfile=`echo $file | sed -e 's/\.css$/\.min\.css/'`
|
||||
do_shrink "$file" "$minfile"
|
||||
done
|
||||
done
|
51
skins/larry/bin/jsshrink.sh
Normal file
51
skins/larry/bin/jsshrink.sh
Normal file
@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
PWD=`dirname "$0"`
|
||||
LANG_IN='ECMASCRIPT5'
|
||||
|
||||
do_shrink() {
|
||||
rm -f "$2"
|
||||
# copy the first comment block with license information for LibreJS
|
||||
grep -q '@lic' $1 && sed -n '/\/\*/,/\*\// { p; /\*\//q; }' $1 > $2
|
||||
uglifyjs --compress --mangle -- $1 >> $2
|
||||
}
|
||||
|
||||
if which uglifyjs > /dev/null 2>&1; then
|
||||
:
|
||||
else
|
||||
echo "uglifyjs not found. Please install e.g. 'npm install -g uglify-js'."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# compress single file from argument
|
||||
if [ $# -gt 0 ]; then
|
||||
JS_FILE="$1"
|
||||
|
||||
if [ $# -gt 1 ]; then
|
||||
LANG_IN="$2"
|
||||
fi
|
||||
|
||||
echo "Shrinking $JS_FILE"
|
||||
minfile=`echo $JS_FILE | sed -e 's/\.js$/\.min\.js/'`
|
||||
do_shrink "$JS_FILE" "$minfile" "$LANG_IN"
|
||||
exit
|
||||
fi
|
||||
|
||||
DIRS="$PWD/.. $PWD/../plugins/*"
|
||||
# default: compress application scripts
|
||||
for dir in $DIRS; do
|
||||
for file in $dir/*.js; do
|
||||
if echo "$file" | grep -q -e '.min.js$'; then
|
||||
continue
|
||||
fi
|
||||
if [ ! -f "$file" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "Shrinking $file"
|
||||
minfile=`echo $file | sed -e 's/\.js$/\.min\.js/'`
|
||||
do_shrink "$file" "$minfile" "$LANG_IN"
|
||||
done
|
||||
done
|
Reference in New Issue
Block a user