-
Notifications
You must be signed in to change notification settings - Fork 5
/
generate
executable file
·110 lines (100 loc) · 3.86 KB
/
generate
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
#!/usr/bin/env bash
# Copyright (C) 2018 - TODAY Raphael Valyi - Akretion
# MIT-LICENSE
set -eo pipefail
SCHEMA_NAME=$1
PLUGIN=$2
VERSION=$3
ZIP_URL=$4
FILE_FILTER=$5
export ROOT_DIR=$(pwd)
if [[ -z $GENERATEDS_HOME ]]; then
gends_bin=$(which generateDS.py)
if [[ -z $gends_bin ]]; then
echo "WARNING! You should install generateDS!"
echo "Or alternatively you should inform where it is located with:"
echo "export GENERATEDS_HOME=<your_generateds_folder>"
exit 1
fi
export GENERATEDS_HOME=$(dirname $gends_bin)
fi
plugin_hook() {
local cmd=$1
local cmd_file
shift
echo ""
if [[ -f "$ROOT_DIR"/scripts/$SCHEMA_NAME/$PLUGIN/"$cmd" ]]; then
cmd_file="$ROOT_DIR"/scripts/$SCHEMA_NAME/$PLUGIN/"$cmd"
echo "running specific plugin command:"
else
cmd_file=~/.edoc-gen/cache/scripts/"$PLUGIN"/"$cmd"
fetch_remote_plugin_cmd $PLUGIN $cmd
echo "running generic plugin command:"
echo "(you can override it with a local scripts/$SCHEMA_NAME/$PLUGIN/$cmd file)"
fi
echo "$cmd_file | bash -s $@ || echo ''"
cat $cmd_file | bash -s $@ || echo ""
}
fetch_remote_plugin_cmd() {
local plugin=$1
local cmd=$2
local plugin_dir=~/.edoc-gen/cache/scripts/"$plugin"
local cmd_file="$plugin_dir/$cmd"
mkdir -p $plugin_dir
if [[ ! -f "$cmd_file" ]]; then
echo "fetching default repo plugin $plugin/$cmd command and caching it locally in $plugin_dir"
echo "curl -s https://raw.githubusercontent.com/akretion/edoc-gen/master/scripts/$plugin/$cmd" -o "$cmd_file"
curl -s https://raw.githubusercontent.com/akretion/edoc-gen/master/scripts/"$plugin"/"$cmd" -o "$cmd_file"
fi
sed -i '/404: Not Found/d' "$cmd_file"
}
prepare_schemas() {
local version=$1
local schemas_url=$2
local lib_name="$SCHEMA_NAME"lib
local gen_path="$SCHEMA_NAME"lib/"$version"
mkdir -p schemas
[ ! -f /tmp/schemas.zip ] && curl $schemas_url -k -L -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9' --compressed --output - > /tmp/schemas.zip
rm -rf schemas/$SCHEMA_NAME
unzip -o /tmp/schemas.zip -d schemas/$SCHEMA_NAME
rm -f /tmp/schemas.zip
unzip_path=$(ls schemas/$SCHEMA_NAME | head -n1)
if [ -d schemas/"$SCHEMA_NAME/$unzip_path" ]; then # unwrap nesting
mv schemas/"$SCHEMA_NAME/$unzip_path" "schemas/$SCHEMA_NAME/$version"
else # edfreinf and nfse have no nesting for instance
mkdir "schemas/$SCHEMA_NAME/$version"
mv schemas/"$SCHEMA_NAME"/*.* "schemas/$SCHEMA_NAME/$version"
fi
}
generate() {
local version=$1
local lib_name="$SCHEMA_NAME"lib
local gen_path="$SCHEMA_NAME"lib/"$version"
local current_dir=$(pwd)
rm -rf $gen_path/*.*
plugin_hook prepare $SCHEMA_NAME $version
plugin_hook after_prepare $SCHEMA_NAME $version
mkdir -p "schemas/$SCHEMA_NAME/$version"
cd "schemas/$SCHEMA_NAME/$version"
for f in *.xsd;
do
local name=$(echo "$f" | sed 's/\.xsd//g' | sed 's/\./_/g' | sed "s/_$version//g")
local module_name=$(echo $name | tr "/" "\n" | tail -n1 | tr "-" "\n" | head -n1)
if [[ $FILE_FILTER != "" ]]; then
keep=$([[ "$module_name" =~ ^($FILE_FILTER)$ ]] && echo true || echo false)
else
keep=true
fi
if [[ ! $module_name =~ ^tipos.*$ ]] && [[ ! $module_name =~ ^xmldsig.*$ ]] && [ "$keep" = true ] ; then
echo ""
echo "processing file $f ...";
plugin_hook generate_file $SCHEMA_NAME $version $module_name "$f"
fi
done
cd "$current_dir"
plugin_hook finish $SCHEMA_NAME $version
}
prepare_schemas "$VERSION" "$ZIP_URL"
generate "$VERSION"
# TODO make a flag to enable docs generation:
# cd docs && make html && cd ..