forked from XeKr/xkdeco
-
Notifications
You must be signed in to change notification settings - Fork 14
/
jsondiff.sh
42 lines (35 loc) · 1005 Bytes
/
jsondiff.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
#!/bin/bash
# requires npm package json-diff
echo "You need to install json-diff, by running"
echo "npm install -g json-diff"
if [ -z "$1" ]; then
echo "Usage: jsondiff.sh <path1> <path2> ..."
echo "All paths are relative to assets, such as 'examplemod/blockstates'"
fi
assetMain="./src/main/resources/assets"
assetGen="./src/generated/resources/assets"
while [ -n "$1" ]; do
dir="$1"
pathMain="$assetMain/$dir"
pathGen="$assetGen/$dir"
fileSame="./jsondiff/$dir/same.txt"
pathDiff="./jsondiff/$dir"
if [ -f "$fileSame" ]; then
rm "$fileSame"
fi
if [ -d "$pathDiff" ]; then
rm -r "$pathDiff"
fi
mkdir -p "$pathDiff"
for filename in $(ls -1 "$pathMain"); do
if [ -f "$pathGen/$filename" ]; then
diff=$(json-diff "$pathMain/$filename" "$pathGen/$filename")
if [ -z "$diff" ]; then
echo "$pathMain/$filename" "$pathGen/$filename" >> "$fileSame"
else
echo "$diff" >"$pathDiff/$filename.diff"
fi
fi
done
shift 1
done