-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.sh
executable file
·72 lines (61 loc) · 2.3 KB
/
generator.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
#!/bin/bash
create_yml() {
echo "
key.request: source.request.editor.open.interface
key.name: \"47398610-AF42-4F99-B6F2-25A587793CEB\"
key.compilerargs:
- \"-target\"
- \"arm64-apple-ios10.0\"
- \"-sdk\"
- \"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk\"
- \"-I\"
- \"-Xcc\"
key.modulename: \"$1\"
key.toolchains:
- \"com.apple.dt.toolchain.XcodeDefault\"
" > temp.yml
}
get_class() {
class=$1
create_yml $class
sanitized_class_name=`echo $class | sed "s/.*\.//"`
framework=`echo $class | sed "s/\..*//"`
if [ ! -d "/tmp/Chainable/Intermediates/$framework" ]; then
mkdir -p "/tmp/Chainable/Intermediates/$framework"
fi
sourcekitten request --yaml temp.yml |
grep "\"key.sourcetext\" : " |
cut -c 22- |
perl -pe 's/\\n/\n/g' |
sed -e 's/\\\/\\\//\/\//g' -e 's/\\\/\*/\/\*/' -e 's/\*\\\//\*\//' -e 's/^"//' -e 's/"$//' > /tmp/Chainable/Intermediates/$framework/$sanitized_class_name.swift
echo /tmp/Chainable/Intermediates/$framework/$sanitized_class_name.swift
}
get_module() {
if [ -f "/tmp/Chainable/Intermediates/$1/$1.swift" ]; then
return
fi
get_class $1
grep "import [A-Za-z0-9. ]*" /tmp/Chainable/Intermediates/$1/$1.swift | sed -e "s/import //g" -e "s/ //g" -e "s/:.*//g" | while read -r class ; do
if [[ "$class" =~ $1 ]]; then
get_class $class
fi
done
}
# rm -rf "/tmp/Chainable/Intermediates/"
# grep "extension [A-Za-z0-9. ]*:[ ]*NeedChainable" ./Chainable.swift | sed -e "s/extension //g" -e "s/ //g" -e "s/:.*//g" | while read -r class ; do
# file=$(get_class $class)
# echo $file
# class_name=`echo $class | sed "s/.*\.//"`
# echo "extension $class_name: NeedChainable {}" >> "$file"
# done
rm -rf ./EGChainable/Classes/Generated/*
for framework in `ls /tmp/Chainable/Intermediates`; do
echo "framework: $framework"
cp Chainable.swift /tmp/Chainable/Intermediates/$framework
if [ ! -z "$1" -a "$1" == "-w" ]; then
sourcery --sources /tmp/Chainable/Intermediates/$framework --templates ./Chainable.stencil --output "./EGChainable/Classes/Generated/" --args framework=$framework --verbose --wath
else
sourcery --sources /tmp/Chainable/Intermediates/$framework --templates ./Chainable.stencil --output "./EGChainable/Classes/Generated/" --args framework=$framework --verbose
fi
done
rm temp.yml