Skip to content

Instantly share code, notes, and snippets.

@r14r
Last active May 2, 2023 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r14r/7b409900b68c8d50d04a463e3a94c956 to your computer and use it in GitHub Desktop.
Save r14r/7b409900b68c8d50d04a463e3a94c956 to your computer and use it in GitHub Desktop.
Download all Angular Examples
#!/bin/bash
# Mac OS
CHROME=/Applications/Chromium.app/Contents/MacOS/Chromium
# Windows WSL
CHROME='/mnt/c/Program Files/Google/Chrome/Application/chrome.exe'
LISTOFZIPS=listofzips
do_get_list() {
"$CHROME" --headless --dump-dom https://angular.io/guide/example-apps-list | tr '>' '>\n ' >${LISTOFZIPS}.html
echo "##. Download List of Examples"
echo " #Examples: ($(grep 'href="guide/' listofzips.html | wc -l))"
}
do_extract() {
cat ${LISTOFZIPS}.html |\
tr ' ' '\n' |\
cut -d \" -f2 |\
grep -e '.zip$' > ${LISTOFZIPS}
echo "generated/zips/component-overview/component-overview.zip" >> ${LISTOFZIPS}
echo "##. Extract zip files ($(wc -l ${LISTOFZIPS}))"
echo " #Examples: ($(wc -l ${LISTOFZIPS}))"
}
do_download() {
echo "##. Download Zips"
(
rm -rf zip
mkdir -p zip
cd zip
cat ../$LISTOFZIPS | while read ZIP
do
echo "Download $ZIP"
if [ ! -f $ZIP ]; then
wget -q https://angular.io/$ZIP
fi
done
rm *.zip.1
)
}
do_unzip() {
echo "##. Unzip"
rm -rf src
mkdir -p src
find zip -type f -exec basename {} \; | \
while read FILE
do
FLDR=${FILE/.zip/}
echo unzip zip/$FILE -d src/$FLDR
unzip zip/$FILE -d src/$FLDR
done
}
do_upgrade() {
echo "##. Upgrade"
(
cd src
ls | \
while read FLDR
do
echo " $FLDR"
(
cd $FLDR
ncu -u
# "typescript": "~4.9.3"
sed -i -r '1,$s/"typescript": ".*"/"typescript": "~4.9.5"/' package.json
# pnpm install
)
done
)
}
case "$1" in
"get") do_get_list ;;
"extract") do_extract ;;
"download") do_download ;;
"unzip") do_unzip ;;
"upgrade") do_upgrade ;;
*)
echo "run $0 get|extract|download|unzip|upgrade";;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment