angular-cn/scripts/cache.sh

75 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e -o pipefail
BASE="public/docs/ts"
LATEST="$BASE/latest"
CACHE="$BASE/_cache"
FILES="
guide/architecture.jade
guide/attribute-directives.jade
guide/component-styles.jade
guide/dependency-injection.jade
guide/displaying-data.jade
guide/hierarchical-dependency-injection.jade
guide/lifecycle-hooks.jade
guide/pipes.jade
guide/security.jade
guide/server-communication.jade
guide/structural-directives.jade
guide/template-syntax.jade
quickstart.jade
tutorial/toh-pt6.jade"
function cacheRefresh() {
local FILE_PATTERN="*"
if [[ -n "$1" ]]; then
FILE_PATTERN="$1"
else
echo "Argument missing: specify shell file glob pattern of files to be refreshed."
exit 1;
fi
local allFound=true;
for f in $FILES; do
local srcPath="$LATEST/$f";
local destPath="$CACHE/$f";
local destDir=`dirname $destPath`;
if [[ -e $srcPath ]]; then
[[ -d "$destDir" ]] || (set -x; mkdir $destDir);
case "$f" in
($FILE_PATTERN)
(set -x; cp $srcPath $destPath);;
(*)
echo "SKIPPED $f";;
esac
else
echo Cannot find $srcPath
allFound=false;
fi
done
[[ $allFound ]] || exit 1;
}
function cacheDiff() {
diff -qr -x "_*.*" "$CACHE/" "$LATEST/" | \
grep -v "^Only in"
}
function usage() {
echo "Usage: cache.sh [-d | -l | -r pattern]"
echo " -d diff cache and latest subdirectories"
echo " -l list files subject to caching"
echo " -r pat refresh files in cache matching pattern"
}
case "$1" in
(-r) shift; cacheRefresh $@;;
(-d) shift; cacheDiff $@;;
(-l) shift; printf "$FILES\n\n";;
(*) usage;
esac