Skip to content

Instantly share code, notes, and snippets.

@Awea
Created March 23, 2018 07:14
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 Awea/00a6e047ca3e447df8d7b3353d6ba7dc to your computer and use it in GitHub Desktop.
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
#!/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