-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator
executable file
·162 lines (127 loc) · 5.29 KB
/
generator
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
project=blank
license=MIT
platform=
docs=docs
name=
update=
for arg in "$@"; do
case "$arg" in
--name=*)
name=`echo $arg | sed 's/--name=//'`
;;
--project=*)
project=`echo $arg | sed 's/--project=//'`
;;
--license=*)
license=`echo $arg | sed 's/--license=//'`
;;
--platform=*)
platform=`echo $arg | sed 's/--platform=//'`
;;
--update*)
update=`echo true | sed 's/--update//'`
;;
--help)
echo 'usage: ./generator [options]'
echo ''
echo 'options:'
echo ' --name=<name>: name of project'
echo ' --project=<project>: target project (blank, html, php-library, sylius-plugin)'
echo ' --license=<license>: license (AGPLv3, EUPLv1.2, GPLv3, MIT)'
echo ' --platform=<platform>: platform (gitlab, github)'
echo ' --update'
echo ''
echo 'All invalid options are silently ignored!'
exit 0
;;
esac
done
if [ ! $(command -v jq) &> /dev/null ]; then
echo "jq must be present on your system"
exit 0
fi
if [ $update ]; then
data=$(cat ./templates.json)
for k in $(jq -c '.templates[]' <<< $data); do
rname=$(echo $k | jq -r '.name' )
rm -Rf ./templates/projects/$rname
git clone --branch $(echo $k | jq -r '.branch' ) --depth 1 $(echo $k | jq -r '.url' ) ./templates/projects/$rname
rm -Rf ./templates/projects/$rname/.git
if [ $rname = "sylius-plugin" ]; then
cat ./templates/default/README.md >> ./templates/projects/$rname/README.md
sed -i "s|Modern Plugin Skeleton|{name}|g" ./templates/projects/$rname/README.md
sed -i "s|pocky/modern-plugin-skeleton|{php.name}|g" ./templates/projects/$rname/composer.json
sed -i "s|Acme example plugin for modern Sylius.|{php.description}|g" ./templates/projects/$rname/composer.json
sed -i "s|MIT|{license}|g" ./templates/projects/$rname/composer.json
sed -i "s|Acme\\\\\\\SyliusExamplePlugin\\\\\\\|{php.psr4}|g" ./templates/projects/$rname/composer.json
sed -i "s|Acme\\\\\\\Tests\\\\\\\SyliusExamplePlugin\\\\\\\|{php.psr4tests}|g" ./templates/projects/$rname/composer.json
echo "$(jq '. + {"authors": [{"name": "{author.name}","email": "{author.email}"}]}' ./templates/projects/$rname/composer.json)" > ./templates/projects/$rname/composer.json
rm -Rf ./templates/projects/$rname/.github
fi
done
fi
if [ -z $name ]; then
echo "You must specify name option"
exit 0
fi
if [ -d ./generated/$name ]; then
echo "Directory already exist"
exit 0
fi
echo "Generating project $name..."
cp -rT ./templates/default/ ./generated/$name
if [ $project != "blank" ]; then
if [ -d ./templates/configure/$project/ ]; then
cp -rT ./templates/configure/$project/ ./generated/$name
fi
if [ -d ./templates/projects/$project/ ]; then
cp -rT ./templates/projects/$project/ ./generated/$name
fi
fi
echo "Add license $license..."
cp ./templates/LICENSE/$license ./generated/$name/LICENSE
documentation=./generated/$name/$docs
if [ ! -z $platform ]; then
docs=.$platform
documentation=./generated/$name/$docs
if [ -d ./templates/CI/$project/$platform/ ]; then
cp -rT ./templates/CI/$project/$platform/ $documentation
fi
fi
cp -rT ./templates/docs/ $documentation
echo "Replace content in files.."
sed -i "s|{name}|$name|g" ./generated/$name/README.md
sed -i "s|{license}|$license|g" ./generated/$name/README.md
sed -i "s|{license}|$license|g" $documentation/CONTRIBUTING.md
sed -i "s|{docs.path}|$docs|g" ./generated/$name/README.md
if [ -f "./data.json" ]; then
data=$(cat ./data.json)
sed -i "s|{author.name}|$(echo $data | jq -r '.author.name')|g" ./generated/$name/README.md
sed -i "s|{author.website}|$(echo $data | jq -r '.author.website' )|g" ./generated/$name/README.md
sed -i "s|{author.email}|$(echo $data | jq -r '.author.email' )|g" $documentation/CODE_OF_CONDUCT.md
sed -i "s|{author.nickname}|$(echo $data | jq -r '.author.nickname')|g" $documentation/CODEOWNERS
counter=2
for k in $(jq -c '.support[]' <<< $data); do
sed -i "$(awk "/^Is it possible to contact us by/{ print NR + $counter; exit }" $documentation/SUPPORT.md)s,.*,- [$(echo $k | jq -r '.name' )]($(echo $k | jq -r '.url' ))\\n," $documentation/SUPPORT.md
counter=$((counter + 1))
done
if [ $project = "html" ]; then
sed -i "s|{name}|$name|g" ./generated/$name/infrastructure/docker/autoconf/Makefile.dist
fi
if [ $project = "php-library" ] || [ $project = "sylius-plugin" ]; then
sed -i "s|{php.name}|$(echo $data | jq -r '.php.name')|g" ./generated/$name/composer.json
sed -i "s|{php.description}|$(echo $data | jq -r '.php.description')|g" ./generated/$name/composer.json
sed -i "s|{php.type}|$(echo $data | jq -r '.php.type')|g" ./generated/$name/composer.json
sed -i "s|{license}|$license|g" ./generated/$name/composer.json
sed -i "s|{author.name}|$(echo $data | jq -r '.author.name')|g" ./generated/$name/composer.json
sed -i "s|{author.email}|$(echo $data | jq -r '.author.email')|g" ./generated/$name/composer.json
sed -i "s|{php.psr4}|$(echo $data | jq -r '.php.psr4'| sed 's/\\/\\\\\\\\/g')|g" ./generated/$name/composer.json
sed -i "s|{php.psr4tests}|$(echo $data | jq -r '.php.psr4tests'| sed 's/\\/\\\\\\\\/g')|g" ./generated/$name/composer.json
fi
else
echo ""
echo "⚠️⚠️⚠️ If you want to pimp your documentation files, copy data.json.dist to data.json and add changes your data!"
echo ""
fi
echo "Configuration complete"