Skip to content

Instantly share code, notes, and snippets.

@rozzzly
Created October 19, 2015 19:45
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 rozzzly/9961e0b1c6db64bf5b25 to your computer and use it in GitHub Desktop.
Save rozzzly/9961e0b1c6db64bf5b25 to your computer and use it in GitHub Desktop.
bash script to index bower components for fourseven:meteor-scss because meteor@1.2.0 had breaking changes to the build chain @see https://github.com/fourseven/meteor-scss/issues/138
```
#!/usr/bin/env bash
### first half of script iterates over local packages, cd's into each
echo "======[Curating Bower Dependencies]==============================="
# not -f because this is a -dIRECTORY!
if [ -d bower_components ]; then
echo "[Bower Dependency Indexer] Dependencies Found!"
# ensure we've got somewhere to put the indexes, and hide errors
mkdir indexes 2> /dev/null
deps="bower_components"
##curDir=${pwd}
cd "$deps"
# itterate over bower_components subdirs
for dir in $(find . -mindepth 1 -maxdepth 1 -type d); do
dir=$(echo "$dir" | grep -Po "(?<=\.\/).*")
echo -e " [+] Indexing \`$dir\`..."
# use this too often not to save as a var
indexFile="../indexes/${dir}.json"
# back up if theres something there
if [ -f "$indexFile" ]; then
# cleaning up if theres something backed up
rm -fr "../indexes/.${dir}.json~"
# do the backup
echo -e " [o] old index file found... backing up"
mv "$indexFile" "../indexes/.${dir}.json~"
fi
# create file
touch "$indexFile"
# open json doc
echo -e "[" >> "$indexFile"
# list files in cur dir, grep them
find "${PWD}/${dir}" | grep -Po "bower_components\/.*?\/_[\w-]*\.scss" | sed -e "s/^.*$/ \'&\',/" >> "$indexFile"
# trim last comma
#
# https://unix.stackexchange.com/questions/162377/sed-remove-the-very-last-occurrence-of-a-string-a-comma-in-a-file
#
#echo "$indexFile"
#sleep 0.500
#cat "$indexFile" | sed -n -e x -e '$ {s/,$//;p;x;}' -e '2,$ p' > "${indexFile}2"
#sed 's/, *$//' "$indexFile"
# sed '/\,/,$d' "$indexFile"
### TODO use sed to format paths, wrap with two 's and a ,
#
#
# Annnnnnnnnnnndddd... none of that works ( the trailing comma )
# close json doc
echo -e "]" >> "$indexFile"
done
# back to package's root
cd ../
fi
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment