Created
March 23, 2018 07:14
-
-
Save Awea/00a6e047ca3e447df8d7b3353d6ba7dc to your computer and use it in GitHub Desktop.
Snippet: output list of assets to an assets.json file for batch loading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script used in combinaison with https://github.com/ianmcgregor/assets-loader | |
# Assign find result to an array see: | |
# https://stackoverflow.com/questions/23356779/how-can-i-store-find-command-result-as-arrays-in-bash/23357277#23357277 | |
assets=() | |
while IFS= read -r -d $'\0'; do | |
# Remove static/ from asset path | |
assets+=("${REPLY//static\//}") | |
# Find with multiple exclude see: | |
# http://www.liamdelahunty.com/tips/linux_find_exclude_multiple_directories.php | |
# Ignore file starting with static/fonts and .* files | |
done < <(find static \( -path static/fonts -o -name ".*" \) -prune -o -type f -print0) | |
# Format an array to json see: | |
# https://stackoverflow.com/questions/26808855/how-to-format-a-bash-array-as-a-json-array | |
printf '%s\n' "${assets[@]}" | jq -R . | jq -s . > src/json/assets.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment