-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgodot-pkg.sh
executable file
·87 lines (72 loc) · 2.47 KB
/
godot-pkg.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
#!/bin/sh
# godot-package helper
# @author Erodozer <[email protected]>
#
# Simple Bach Script that fetches and merges standard godot addon repositories from github
# to your project. You can use this instead of Godot's Asset Library if you wish to
# include dependencies in your projects while developing, but not include them in your git.
#
# Run this from the root directory of your project
#
# It parses a json file called godot_packages.json with the following schema
#
# [
# {
# "git": "<user>/<repo>",
# "branch" ?: string, # main is the default
# "tag" ?: string, # only set this if you want to lock to a specific published version
# },
# ...
# ]
#
# Downloaded addons are merged into your project's addon's folder.
# If the addon as a LICENSE file in the root of the repo, it is copied to the addon's nested folder
# .gitignore files are also added to the nested folder.
#
#
# Requires:
# unzip
# jq
# wget
TMP_DIR=".godot-addon-tmp"
mkdir -p $TMP_DIR
for row in $(jq -c '.[]' godot_packages.json); do
# parse record
_jq() {
echo "${row}" | jq -r "${1}"
}
git=$(_jq '.git')
outfile=$(echo "$git" | tr "/" _)
user=$(echo "$git" | cut -d "/" -f 1)
repo=$(echo "$git" | cut -d "/" -f 2)
branch=$(_jq ".branch // \"main\"" )
version=$(_jq '.tag // empty')
echo "$version"
if [ ! -z "$version" ]; then
wget -O "$TMP_DIR/$outfile.zip" "https://github.com/$user/$repo/archive/refs/tags/$version.zip"
else
wget -O "$TMP_DIR/$outfile.zip" "https://github.com/$user/$repo/archive/refs/heads/$branch.zip"
fi
unzip -d $TMP_DIR/$user "$TMP_DIR/$outfile.zip"
package_folder="$TMP_DIR/$user/$repo-main"
include=$(_jq '.include // empty')
echo $include
if [ ! -z "$include" ]; then
echo "$include" | jq -cr ".[]" | while read d; do
src_folder=$(echo "$d" | cut -d ">" -f 1)
dst_folder=$(echo "$d" | cut -d ">" -f 2)
echo "copying $package_folder/addons/$src_folder to ./addons/$dst_folder"
rm -r "./addons/$dst_folder"
mv "$package_folder/addons/$src_folder" "./addons/$dst_folder"
echo "*" > "./addons/$dst_folder/.gitignore"
done;
else
addons_folder="$package_folder/addons"
for dir in $(ls -d $addons_folder/*); do
echo "*" > "$dir/.gitignore"
cp "$package_folder/LICENSE" "$dir/LICENSE"
done
cp -r "$addons_folder" "."
fi
done
rm -r $TMP_DIR