-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert-ios.svg.sh
executable file
·106 lines (85 loc) · 2.42 KB
/
convert-ios.svg.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
set -euo pipefail
readonly in_dir="${1:-mounts/input}"
readonly out_dir="${2-mounts/output}"
if [ ! -d "${in_dir}" ]; then
echo "ERROR: input directory [${in_dir}] doesnt exist!"
exit 1
fi
################################################################################
# Helpers
################################################################################
# filename = mounts/input/ic_foo.svg
# echos "ic_foo"
function get_name_without_extension() {
local -r filename="${1%.*}"
echo "$(basename "${filename}")"
}
# infile = mounts/input/ic_foo.svg
# out_basename = ic_foo
function convert_to_svg() {
local -r infile="${1}"
local -r out_basename="${2}"
local -r tmp_file=$( mktemp )
cp "${infile}" "${tmp_file}"
write_imageset "${tmp_file}" "${out_basename}"
return 0
}
function detect_if_error() {
local -r outfile="${1}"
[ ! -s "${outfile}" ]
}
# infile = /tmp/foo.j2ojaoi.svg
# out_basename = ic_foo
function write_imageset() {
local -r infile="${1}"
local -r out_basename="${2}"
local -r imageset_path="${out_dir}/${out_basename}.imageset"
mkdir -p "${imageset_path}"
cat << EOF > "${imageset_path}/Contents.json"
{
"images": [
{
"filename": "${out_basename}.svg",
"idiom": "universal"
}
],
"info": {
"version": 1,
"author": "Svg2Vector"
},
"properties": {
"preserves-vector-representation": true
}
}
EOF
mv "${infile}" "${imageset_path}/${out_basename}.svg"
}
################################################################################
# DO WORK SON
################################################################################
function main() {
local numErrors=0
for filename in "${in_dir}"/*.svg; do
local raw_name=$(get_name_without_extension "${filename}")
local asset_name="${raw_name}.imageset"
if [ -f "${out_dir}/${asset_name}" ] || [ -d "${out_dir}/${asset_name}" ]; then
echo "[${asset_name}] already exists... skipping"
continue
fi
echo -n "Converting [$(basename ${filename})] to [${asset_name}]..."
if convert_to_svg "${filename}" "${raw_name}"; then
echo " done"
else
numErrors=$((numErrors+1))
echo " error"
fi
done
if [ $numErrors -eq 0 ]; then
echo 'Done!'
else
echo "Done with [${numErrors}] errors!"
fi
echo ""
}
main