Instantly share code, notes, and snippets.

Embed
What would you like to do?
Snippet: output list of assets to an assets.json file for batch loading
#!/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