-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathayli.sh
executable file
·80 lines (72 loc) · 2.02 KB
/
ayli.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
#!/bin/bash
set -euo pipefail
if [[ "$(which realpath)" =~ "which: no realpath in" ]]; then
echo "ERROR: Dependency missing, please install realpath"
exit 1
fi
WORKSPACE="$(dirname "$(realpath "$BASH_SOURCE")")"
mkdir -p "$WORKSPACE"/alias
get_template() {
if [[ -z "${1-}" ]]; then
echo "ERROR: fn get_template requires 1 argument"
exit 1
fi
if [[ "$1" == "default" ]]; then
echo "Use default template"
fi
if [[ -d "$WORKSPACE"/templates/"$1" ]]; then
template="$1"
elif [[ -f "$WORKSPACE"/alias/"$1" && -d "$WORKSPACE"/templates/"$(cat "$WORKSPACE"/alias/"$1")" ]]; then
template="$(cat "$WORKSPACE"/alias/"$1")"
else
if [[ "${2-}" != "fail-silent" ]]; then
echo "ERROR: template $1 not found"
fi
return 1
fi
}
if [[ -z "${1-}" ]]; then
get_template default
else
{
get_template "$1" fail-silent && path="${2-}"
} || {
get_template default
path="$1"
}
fi
if [[ -z "${path-}" ]]; then
read -rp "Path to new package folder: " path
fi
if [[ -f "$WORKSPACE"/config ]]; then
. "$WORKSPACE"/config
fi
cp -R "$WORKSPACE"/templates/"$template" "$path"
cd "$path"
git init
name="$(basename "$path")"
echo "# $name" >README.md
if [[ -f package.json ]]; then
echo "Config yarn package"
sed -i "s|\$name|$name|g" package.json
if [[ -n "${REPOSITORY-}" ]]; then
sed -i "s|\$repository|$REPOSITORY|g" package.json
fi
if [[ -n "${AUTHOR-}" ]]; then
sed -i "s|\$author|$AUTHOR|g" package.json
fi
for file in .git/hooks/*; do
filename="$(basename "$file")"
if [[ ! "$filename" =~ "." ]]; then
if [[ -f .husky/"$filename" ]]; then
tmp="$(cat .husky/"$filename")"
cp .git/hooks/"$filename" .husky/
echo >>.husky/"$filename"
echo "$tmp" >>.husky/"$filename"
else
cp .git/hooks/"$filename" .husky/
fi
fi
done
yarn init
fi