-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvipermodule.sh
More file actions
executable file
·215 lines (159 loc) · 5.11 KB
/
vipermodule.sh
File metadata and controls
executable file
·215 lines (159 loc) · 5.11 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env bash
# VIPER module generator with associated Storyboard
if [ $# -eq 0 ]; then
echo "Please enter a module name";
exit 1;
fi
MODULE="$1"
APPMODULE="My Project"
echo "Generating files for the module $MODULE..."
echo "${MODULE}View..."
cat << EOF > ${MODULE}ViewController.swift
//
// Viper Module
// ${MODULE}ViewController.swift
//
import Foundation
import UIKit
class ${MODULE}ViewController: UIViewController {
var presenter: ${MODULE}ViewOutput!
override func viewDidLoad() {
view.translatesAutoresizingMaskIntoConstraints = false
}
}
extension ${MODULE}ViewController: ${MODULE}ViewInput {
}
EOF
echo "${MODULE}Interactor..."
cat << EOF > ${MODULE}Interactor.swift
//
// Viper Module
// ${MODULE}Interactor.swift
//
import Foundation
class ${MODULE}Interactor {
weak var presenter: ${MODULE}InteractorOutput!
}
extension ${MODULE}Interactor: ${MODULE}InteractorInput {
}
EOF
echo "${MODULE}Presenter..."
cat << EOF > ${MODULE}Presenter.swift
//
// Viper Module
// ${MODULE}Presenter.swift
//
import Foundation
class ${MODULE}Presenter {
weak var view: ${MODULE}ViewInput!
var interactor: ${MODULE}InteractorInput!
var router: ${MODULE}RouterInput!
weak var output: ${MODULE}ModuleOutput!
}
extension ${MODULE}Presenter: ${MODULE}ModuleInput {
}
extension ${MODULE}Presenter: ${MODULE}InteractorOutput {
}
extension ${MODULE}Presenter: ${MODULE}ViewOutput {
}
EOF
echo "${MODULE}Assembly..."
cat << EOF > ${MODULE}Assembly.swift
//
// Viper Module
// ${MODULE}Assembly.swift
//
class ${MODULE}Assembly {
static let storyboard = "${MODULE}"
@discardableResult static func setup(_ viewController: ${MODULE}ViewController, delegate: ${MODULE}ModuleOutput? = nil) -> ${MODULE}ModuleInput {
let presenter = ${MODULE}Presenter()
let interactor = ${MODULE}Interactor()
let router = ${MODULE}Router()
viewController.presenter = presenter
interactor.presenter = presenter
presenter.view = viewController
presenter.interactor = interactor
presenter.router = router
presenter.output = delegate
router.viewController = viewController
return presenter
}
static func create() -> ${MODULE}ViewController {
return UIStoryboard(name: "${MODULE}", bundle: .main).instantiateInitialViewController() as! ${MODULE}ViewController
}
}
EOF
echo "${MODULE}Contract..."
cat << EOF > ${MODULE}Contract.swift
//
// Viper Module
// ${MODULE}Contract.swift
//
protocol ${MODULE}ModuleInput: class {
}
protocol ${MODULE}ModuleOutput: class {
}
protocol ${MODULE}ViewInput: class {
}
protocol ${MODULE}ViewOutput: class {
}
protocol ${MODULE}InteractorInput: class {
}
protocol ${MODULE}InteractorOutput: class {
}
protocol ${MODULE}RouterInput {
func unwindBack(_ completion: (() -> Void)?)
func unwindBack()
}
extension ${MODULE}RouterInput {
func unwindBack() { unwindBack(nil) }
}
EOF
echo "${MODULE}Router..."
cat << EOF > ${MODULE}Router.swift
//
// Viper Module
// ${MODULE}Router.swift
//
class ${MODULE}Router: ${MODULE}RouterInput {
weak var viewController: UIViewController!
func unwindBack(_ completion: (() -> Void)?) {
CATransaction.begin()
CATransaction.setCompletionBlock(completion)
viewController.navigationController?.popViewController(animated: true)
CATransaction.commit()
}
}
EOF
echo "${MODULE}Storyboard..."
cat << EOF > ${MODULE}.storyboard
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="4GP-Zt-UPk">
<device id="retina4_7" orientation="landscape">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!-- $MODULE -->
<scene sceneID="Y2N-Pa-oqu">
<objects>
<viewController id="4GP-Zt-UPk" customClass="${MODULE}ViewController" customModule="$APPMODULE" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="cGo-z7-B9y">
<rect key="frame" x="0.0" y="0.0" width="667" height="375"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<viewLayoutGuide key="safeArea" id="Nqe-Eo-wNv"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="had-1g-y9r" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-338" y="108"/>
</scene>
</scenes>
</document>
EOF