-
Notifications
You must be signed in to change notification settings - Fork 15
/
yamlFormatting.sh
executable file
·146 lines (112 loc) · 4.33 KB
/
yamlFormatting.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
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
#!/bin/bash
cd src
cd rest-client
cd src
DIRS=`ls -d ./*/`
for i in ${DIRS};do
echo "Entering directory=${i}model";
cd ${i}model;
FILES=`ls`
for j in ${FILES};do
model=${j%".js"}
# echo $model
# Changed model name from exports to acutal
sed -i "s/ exports/ ${model}/g" $j
# The formatting below converts the code format so that it can be used in caver-js-ext-kas.
cnt=$(grep -o 'import' $j | wc -l)
cmp=0
if [ ${cnt} -gt ${cmp} ]; then
# Use class and exports and also format class variable using "ModelName.prototype.varName"
sed -i "s/export default class /class /g" $j
tac $j | awk '/ }/ && ! seen {print "}"; seen=1} {print}' | tac > tmp && mv tmp $j
sed -i '$ s/}/module.exports = '${model}'/g' $j
sed -i "s/'\(.*\)' = \(.*\)/${model}.prototype.\1 = \2/g" $j
# Changed import to require
sed -i "s/import\(.*\);/import\1/g" $j
sed -i "s/import\(.*\)from \"\(.*\)\"/import\1from \'\2\'/g" $j
sed -i "s/import\(.*\)from \(.*\)/const\1= require(\2)/g" $j
fi
# Modified path
sed -i "s/'..\/ApiClient'/'..\/..\/ApiClient'/g" $j
sed -i "s/'ApiClient'/'..\/..\/ApiClient'/g" $j
sed -i "s/'model/'..\/model/g" $j
# Refined class name to simple version
sed -i "s/ model\// /g" $j
sed -i "s/module:model\///g" $j
# Add memberof tag to each methods and variables
cnt=$(grep -o 'memberof' $j | wc -l)
cmp=0
if [ ${cnt} -eq ${cmp} ]; then
sed -i '/return {'"$model"'}/ {a\
* @memberof '"$model"'
}' $j
sed -i '/member {/ {a\
* @memberof '"$model"'
}' $j
sed -i '/type {/ {a\
* @memberof '"$model"'
}' $j
fi
# Changed module to class
sed -i "s/@module/@class/g" $j
# Change tag from member to type for make it member variable
# If tag is @member with `AnchorBlockRequest.prototype.operator = undefined` format,
# jsDoc will generate docs with static variable.
members=$(grep -F '@member ' $j | rev | cut -d ' ' -f1 | rev)
for item in ${members};do
sed -i 's/} '"$item"'$/}/g' $j
done
sed -i "s/@member /@type /g" $j
# Format empty brace without newline
sed -i 'H;1h;$!d;x; s/{\n *}/{}/g' $j
# Use Object instead of wrong model for anyof(or oneOf) to use Object
sed -i "s/\[AnyOf\(.*\)Items\]/\[Object\]/g" $j
sed -i "/AnyOf\(.*\)Items.call(this)/D" $j
sed -i "s/{Models\(.*\)Yaml}/{Object}/g" $j
sed -i "s/\(.*\)Models\(.*\)Yaml.constructFromObject(\(.*\))/\1ApiClient.convertToType(\3, Object)/g" $j
sed -i "/Models\(.*\)Yaml/D" $j
# Modify invalid 'ModelObject'
sed -i "/const ModelObject/D" $j
sed -i "s/ApiClient.constructFromObject(data, obj, 'ModelObject')/ApiClient.constructFromObject(data, obj, Object)/g" $j
sed -i "s/{Array.<ModelObject>}/{Array.<Object>}/g" $j
sed -i "s/obj\(.*\) = ApiClient.convertToType(\(.*\), ModelObject)/obj\1 = ApiClient.convertToType(\2, Object)/g" $j
# Use Object instead of unused AccountUpdateKey model
sed -i "s/\(.*\)AccountUpdateKey.constructFromObject(\(.*\))/\1ApiClient.convertToType(\2, Object)/g" $j
done
cd ../../;
echo "Entering directory=${i}api";
cd ${i}api;
FILES=`ls`
for j in ${FILES};do
api=${j%".js"}
# echo $api
# Changed api name from exports to acutal
sed -i "s/ exports/ ${api}/g" $j
# The formatting below converts the code format so that it can be used in caver-js-ext-kas.
cnt=$(grep -o 'import\(.*\)from' $j | wc -l)
cmp=0
if [ ${cnt} -gt ${cmp} ]; then
# Use class and exports and also format class variable using "ModelName.prototype.varName"
sed -i "s/export default class /class /g" $j
echo "module.exports = ${api}" >> $j
# Changed import to require
sed -i "s/import\(.*\);/import\1/g" $j
sed -i "s/import\(.*\)from \"\(.*\)\"/import\1from \'\2\'/g" $j
sed -i "s/import\(.*\)from \(.*\)/const\1= require(\2)/g" $j
fi
# Modified path
sed -i "s/'..\/ApiClient'/'..\/..\/ApiClient'/g" $j
sed -i "s/'ApiClient'/'..\/..\/ApiClient'/g" $j
sed -i "s/'model/'..\/model/g" $j
# Refined class name to simple version
sed -i "s/module:api\///g" $j
sed -i "s/module:model\///g" $j
sed -i "s/ api\// /g" $j
sed -i "s/module://g" $j
# Changed module to class
sed -i "s/@module/@class/g" $j
# Format empty brace without newline
sed -i 'H;1h;$!d;x; s/{\n *}/{}/g' $j
done
cd ../../;
done