Class: IOS::ProjectManipulator
- Inherits:
-
Object
- Object
- IOS::ProjectManipulator
- Defined in:
- lib/ios/module/setup/ProjectManipulator.rb
Instance Attribute Summary collapse
-
#configurator ⇒ Object
readonly
Returns the value of attribute configurator.
-
#has_interface ⇒ Object
readonly
Returns the value of attribute has_interface.
-
#has_swiftgen ⇒ Object
readonly
Returns the value of attribute has_swiftgen.
-
#has_test ⇒ Object
readonly
Returns the value of attribute has_test.
-
#keep_demo ⇒ Object
readonly
Returns the value of attribute keep_demo.
-
#mock_network ⇒ Object
readonly
Returns the value of attribute mock_network.
-
#module_path ⇒ Object
readonly
Returns the value of attribute module_path.
-
#module_root_path ⇒ Object
readonly
Returns the value of attribute module_root_path.
-
#module_type ⇒ Object
readonly
Returns the value of attribute module_type.
Class Method Summary collapse
Instance Method Summary collapse
- #createExampleProject ⇒ Object
- #createModuleDummies ⇒ Object
- #createModuleImplFolder ⇒ Object
- #createModuleInterfaceDummies ⇒ Object
- #createModuleInterfaceFolder ⇒ Object
- #createModulePath ⇒ Object
- #createPodspec ⇒ Object
- #createPodspecInterface ⇒ Object
- #createSwiftgen ⇒ Object
- #createTests ⇒ Object
-
#initialize(options) ⇒ ProjectManipulator
constructor
A new instance of ProjectManipulator.
- #module_folder ⇒ Object
- #project_folder ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(options) ⇒ ProjectManipulator
Returns a new instance of ProjectManipulator.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 11 def initialize() @configurator = .fetch(:configurator) @keep_demo = .fetch(:keep_demo) @module_type = .fetch(:module_type) @has_swiftgen = .fetch(:has_swiftgen) @has_interface = .fetch(:has_interface) @has_test = .fetch(:has_test) @mock_network = .fetch(:mock_network) @module_root_path = "" end |
Instance Attribute Details
#configurator ⇒ Object (readonly)
Returns the value of attribute configurator.
5 6 7 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 5 def configurator @configurator end |
#has_interface ⇒ Object (readonly)
Returns the value of attribute has_interface.
5 6 7 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 5 def has_interface @has_interface end |
#has_swiftgen ⇒ Object (readonly)
Returns the value of attribute has_swiftgen.
5 6 7 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 5 def has_swiftgen @has_swiftgen end |
#has_test ⇒ Object (readonly)
Returns the value of attribute has_test.
5 6 7 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 5 def has_test @has_test end |
#keep_demo ⇒ Object (readonly)
Returns the value of attribute keep_demo.
5 6 7 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 5 def keep_demo @keep_demo end |
#mock_network ⇒ Object (readonly)
Returns the value of attribute mock_network.
5 6 7 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 5 def mock_network @mock_network end |
#module_path ⇒ Object (readonly)
Returns the value of attribute module_path.
5 6 7 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 5 def module_path @module_path end |
#module_root_path ⇒ Object (readonly)
Returns the value of attribute module_root_path.
5 6 7 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 5 def module_root_path @module_root_path end |
#module_type ⇒ Object (readonly)
Returns the value of attribute module_type.
5 6 7 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 5 def module_type @module_type end |
Class Method Details
.perform(options) ⇒ Object
7 8 9 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 7 def self.perform() new().perform end |
Instance Method Details
#createExampleProject ⇒ Object
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 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 76 def createExampleProject @configurator.printMessage("Criando projeto Exemplo") projectFileName = File.join(@module_root_path, "Example") FileUtils.cp_r(File.join(@configurator.template_path, "/Example/Example"), @module_root_path) podDevInjection = "pod '${POD_NAME}', path: '../'" if @has_test == :yes podDevInjection = "pod '${POD_NAME}', path: '../', :testspecs => ['Tests']" end if @has_interface == :yes podDevInjection += "\n pod '${POD_NAME}Interface', path: '../'" end podDevInjection += "\n" podDevInjection += "\n pod 'SBFoundation', path: '../../../CoreModules/SBFoundation'" if @module_type == :feature podDevInjection += "\n pod 'SBUIKit', path: '../../../CoreModules/SBUIKit'" podDevInjection += "\n pod 'SBRouterService', path: '../../../CoreModules/SBRouterService'" podDevInjection += "\n pod 'SBRouterServiceInterface', path: '../../../CoreModules/SBRouterService'" podDevInjection += "\n pod 'SBDependency', path: '../../../CoreModules/SBDependency'" podDevInjection += "\n pod 'SBDependencyInterface', path: '../../../CoreModules/SBDependency'" podDevInjection += "\n pod 'SBAnalyticsInterface', path: '../../../CoreModules/SBAnalytics'" podDevInjection += "\n pod 'SBLoggerInterface', path: '../../../CoreModules/SBLogger'" if @mock_network == :yes podDevInjection += "\n pod 'SBUserSessionInterface', path: '../../../CoreModules/SBUserSession'" podDevInjection += "\n pod 'SBNetworkOld', path: '../../../CoreModules/SBNetworkOld'" podDevInjection += "\n pod 'Fetcher', path: '../../../CoreModules/Fetcher'" podDevInjection += "\n pod 'Flow', path: '../../../CoreModules/Flow'" podDevInjection += "\n pod 'SecFoundation', path: '../../../CoreModules/SecFoundation'" podDevInjection += "\n pod 'SBSecurity', path: '../../../CoreModules/SBSecurity'" podDevInjection += "\n pod 'SBSecurityInterface', path: '../../../CoreModules/SBSecurity'" podDevInjection += "\n pod 'SBFeatureTogglesKitInterface', path: '../../../CoreModules/SBFeatureTogglesKit'" end podDevInjection += "\n pod 'SBAssets', :git => '[email protected]:acelera/ios-ds-assets.git', :branch => 'master'" podDevInjection += "\n pod 'IDwallToolkit', :git => '[email protected]:acelera/ios-frameworks.git', :branch => 'master'" end text = File.read projectFileName + "/Podfile" text.gsub!("${DEV_PODS}", podDevInjection) text.gsub!("${POD_NAME}", @configurator.pod_name) File.open(projectFileName + "/Podfile", "w") { |file| file.puts text} @configurator.printDone end |
#createModuleDummies ⇒ Object
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 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 145 def createModuleDummies @configurator.printMessage("Gerando arquivos de exemplo") if @module_type == :feature FileUtils.touch File.join(@module_path, "Sources", "Features", "Dummy.swift") else FileUtils.touch File.join(@module_path, "Sources", "DummySource.swift") end # Header.h headerFilename = File.join(@module_path, "Resources", @configurator.pod_name + ".h") FileUtils.cp( File.join(@configurator.template_path, "Feature", "Header_template"), headerFilename ) text = File.read(headerFilename) text.gsub!("${POD_NAME}", @configurator.pod_name) File.open(headerFilename, "w") { |file| file.puts text} # Info.plist FileUtils.cp( File.join(@configurator.template_path, "Feature", "Info_template"), File.join(@module_path, "Resources", "Info.plist") ) if @has_swiftgen == :yes # Bundle bundleFilename = File.join(@module_path, "Sources", "ModuleConfiguration", "Bundle.swift") FileUtils.cp( File.join(@configurator.template_path, "Feature", "bundle_template"), bundleFilename ) text = File.read(bundleFilename) text.gsub!("${POD_NAME}", @configurator.pod_name) File.open(bundleFilename, "w") { |file| file.puts text} # Strings FileUtils.touch File.join(@module_path, "Resources", "Localizable.strings") File.open(File.join(@module_path, "Resources", "Localizable.strings"), "w") { |file| file.puts "\"example.title.text\" = \"EXAMPLE\";" } # Assets FileUtils.mkdir_p(File.join(@module_path, "Resources", "Assets.xcassets")) end @configurator.printDone end |
#createModuleImplFolder ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 123 def createModuleImplFolder @configurator.printMessage("Gerando pastas base") FileUtils.mkdir_p File.join(@module_path, "Sources") if @module_type == :feature FileUtils.mkdir_p File.join(@module_path, "Sources", "Features") end if @has_swiftgen == :yes FileUtils.mkdir_p File.join(@module_path, "Sources", "ModuleConfiguration") end FileUtils.mkdir_p File.join(@module_path, "Resources") @configurator.printDone end |
#createModuleInterfaceDummies ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 195 def createModuleInterfaceDummies @configurator.printMessage("Gerando arquivos de exemplo na Interface") FileUtils.touch File.join(@module_path + "Interface", "Sources", "DummyInterface.swift") # Info.plist FileUtils.cp( File.join(@configurator.template_path, "Feature", "Info_template"), File.join(@module_path + "Interface", "Resources", "Info.plist") ) # Header.h headerFilename = File.join(@module_path + "Interface", "Resources", @configurator.pod_name + ".h") FileUtils.cp( File.join(@configurator.template_path, "Feature", "Header_template"), headerFilename ) text = File.read(headerFilename) text.gsub!("${POD_NAME}", @configurator.pod_name) File.open(headerFilename, "w") { |file| file.puts text} @configurator.printDone end |
#createModuleInterfaceFolder ⇒ Object
138 139 140 141 142 143 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 138 def createModuleInterfaceFolder @configurator.printMessage("Gerando pastas de interface") FileUtils.mkdir_p File.join(@module_path + "Interface" , "Sources") FileUtils.mkdir_p File.join(@module_path + "Interface", "Resources") @configurator.printDone end |
#createModulePath ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 54 def createModulePath @configurator.printMessage("Criando estrutura do módulo") @module_root_path = File.join(project_folder, [module_folder, @configurator.pod_name]) @module_path = File.join(@module_root_path, @configurator.pod_name) # Create a new folder with pod name FileUtils.mkdir_p @module_path # Create a new folder with pod name interface if @has_interface == :yes FileUtils.mkdir_p @module_path + "Interface" end # Create a new folder with pod name test if @has_test == :yes FileUtils.mkdir_p @module_path + "Tests" end Dir.chdir @module_root_path @configurator.printDone end |
#createPodspec ⇒ Object
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 233 def createPodspec @configurator.printMessage("Configurando arquivo Podspec") podspecFilename = "#{module_root_path}/#{@configurator.pod_name}.podspec" FileUtils.cp(File.join(@configurator.template_path, "NAME.podspec"), podspecFilename) text = File.read podspecFilename podTests = "" if @has_test == :yes podTests = "# TESTS" podTests += "\n s.test_spec 'Tests' do |test_spec|" podTests += "\n test_spec.source_files = '${POD_NAME}Tests/**/*'" podTests += "\n test_spec.exclude_files = '${POD_NAME}Tests/Resources/*.plist'" podTests += "\n end" end podInternal = "s.dependency 'SBFoundation'" if @module_type == :feature podInternal += "\n s.dependency 'SBUIKit'" podInternal += "\n s.dependency 'SBDependencyInterface'" end if @has_interface == :yes podInternal += "\n s.dependency '${POD_NAME}Interface'" end text.gsub!("${FEATURE_INTERNAL}", podInternal) text.gsub!("${FEATURE_TEST}", podTests) text.gsub!("${POD_NAME}", @configurator.pod_name) text.gsub!("${USER_NAME}", @configurator.user_name) text.gsub!("${USER_EMAIL}", @configurator.user_email) File.open(podspecFilename, "w") { |file| file.puts text} @configurator.printDone end |
#createPodspecInterface ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 268 def createPodspecInterface @configurator.printMessage("Configurando arquivo Podspec Interface") podspecFilename = "#{module_root_path}/#{@configurator.pod_name}Interface.podspec" FileUtils.cp(File.join(@configurator.template_path, "NAMEInterface.podspec"), podspecFilename) text = File.read podspecFilename podInternal = "" if @module_type == :feature podInternal += "\n s.dependency 'SBRouterServiceInterface'" end text.gsub!("${FEATURE_INTERNAL}", podInternal) text.gsub!("${POD_NAME}", @configurator.pod_name) text.gsub!("${USER_NAME}", @configurator.user_name) text.gsub!("${USER_EMAIL}", @configurator.user_email) File.open(podspecFilename, "w") { |file| file.puts text} @configurator.printDone end |
#createSwiftgen ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 218 def createSwiftgen @configurator.printMessage("Criando arquivo swiftgen") fileName = File.join(@module_root_path, "swiftgen.yml") FileUtils.cp( File.join(@configurator.template_path, "swiftgen.yml"), fileName ) text = File.read(fileName) text.gsub!("${POD_NAME}", @configurator.pod_name) File.open(fileName, "w") { |file| file.puts text} @configurator.printDone end |
#createTests ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 287 def createTests @configurator.printMessage("Gerando pastas de testes") # Folders FileUtils.mkdir_p File.join(@module_path + "Tests" , "Resources") FileUtils.mkdir_p File.join(@module_path + "Tests" , "Sources") FileUtils.mkdir_p File.join(@module_path + "Tests" , "Tests") # Dummies FileUtils.touch File.join(@module_path + "Tests", "Sources", "DummyModel.swift") FileUtils.touch File.join(@module_path + "Tests", "Tests", "DummyTest.swift") # Info.plist FileUtils.cp( File.join(@configurator.template_path, "Feature", "Info_template"), File.join(@module_path + "Tests", "Resources", "Info.plist") ) @configurator.printDone end |
#module_folder ⇒ Object
49 50 51 52 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 49 def module_folder return "FeatureModules" if @module_type == :feature "CoreModules" end |
#project_folder ⇒ Object
43 44 45 46 47 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 43 def project_folder $basePath = `git rev-parse --show-toplevel`.chomp raise "Para rodar a rotina, você deve estar na raiz do projeto" if $basePath == "." return $basePath end |
#run ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ios/module/setup/ProjectManipulator.rb', line 22 def run createModulePath createModuleImplFolder createModuleDummies createPodspec if @has_interface == :yes createModuleInterfaceFolder createModuleInterfaceDummies createPodspecInterface end if @has_test == :yes createTests end createSwiftgen if @has_swiftgen == :yes createExampleProject if @keep_demo == :yes end |