-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate-asset-macros.sh
executable file
·37 lines (33 loc) · 1.12 KB
/
generate-asset-macros.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh
find_cmd() {
find assets -path assets/originals -prune -o -name '.*' -prune -o -not -type d -print
}
(
echo '#![allow(irrefutable_let_patterns)]'
echo '#![allow(non_upper_case_globals)]'
echo '#![allow(dead_code)]'
echo
echo 'pub enum Asset {'
find_cmd | rev | cut -d. -f1 | sort | uniq | rev \
| sed "s/^\(.\)\(.*\)$/ \u\1\L\2\E(\&'static [u8]),/"
echo '}'
echo
echo 'impl Asset {'
find_cmd | rev | cut -d. -f1 | sort | uniq | rev | while read -r EXT; do
[ -z "${EXT}" ] && continue
EXT_TITLE_CASE="$(echo "${EXT}" | sed 's/^\(.\)\(.*\)$/\u\1\L\2/')"
sed 's/^ //' <<EOF
pub fn ${EXT}_data(&self) -> &'static [u8] {
if let Asset::${EXT_TITLE_CASE}(data) = self {
data
} else {
panic!("unwrapped asset as wrong file type");
}
}
EOF
done | head -n-1
echo '}'
echo
find_cmd | tr -c '.[:alnum:]\n' '_' | sort \
| sed 's/^assets_\(.*\)\.\(.\)\(.*\)$/pub const \1: Asset = Asset::\u\2\L\3\E(include_bytes!("..\/assets\/\1.\2\3"));/'
) | tee src/assets.rs