lib/ios/module/setup/ProjectManipulator.rb in shellboxCLI-0.1.3 vs lib/ios/module/setup/ProjectManipulator.rb in shellboxCLI-0.1.4
- old
+ new
@@ -1,289 +1,306 @@
require 'xcodeproj'
module IOS
- class ProjectManipulator
- attr_reader :configurator, :keep_demo, :module_type, :module_root_path, :module_path, :has_swiftgen, :has_interface, :has_test
+ class ProjectManipulator
+ attr_reader :configurator, :keep_demo, :module_type, :module_root_path, :module_path, :has_swiftgen, :has_interface, :has_test, :mock_network
- def self.perform(options)
- new(options).perform
- end
+ def self.perform(options)
+ new(options).perform
+ end
- def initialize(options)
- @configurator = options.fetch(:configurator)
- @keep_demo = options.fetch(:keep_demo)
- @module_type = options.fetch(:module_type)
- @has_swiftgen = options.fetch(:has_swiftgen)
- @has_interface = options.fetch(:has_interface)
- @has_test = options.fetch(:has_test)
- @module_root_path = ""
- end
+ def initialize(options)
+ @configurator = options.fetch(:configurator)
+ @keep_demo = options.fetch(:keep_demo)
+ @module_type = options.fetch(:module_type)
+ @has_swiftgen = options.fetch(:has_swiftgen)
+ @has_interface = options.fetch(:has_interface)
+ @has_test = options.fetch(:has_test)
+ @mock_network = options.fetch(:mock_network)
+ @module_root_path = ""
+ end
- def run
- createModulePath
+ def run
+ createModulePath
- createModuleImplFolder
- createModuleDummies
- createPodspec
+ createModuleImplFolder
+ createModuleDummies
+ createPodspec
- if @has_interface == :yes
- createModuleInterfaceFolder
- createModuleInterfaceDummies
- createPodspecInterface
- end
+ if @has_interface == :yes
+ createModuleInterfaceFolder
+ createModuleInterfaceDummies
+ createPodspecInterface
+ end
- if @has_test == :yes
- createTests
- end
+ if @has_test == :yes
+ createTests
+ end
- createSwiftgen if @has_swiftgen == :yes
- createExampleProject if @keep_demo == :yes
- end
+ createSwiftgen if @has_swiftgen == :yes
+ createExampleProject if @keep_demo == :yes
+ end
- 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
+ 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
- def module_folder
- return "FeatureModules" if @module_type == :feature
- "CoreModules"
- end
+ def module_folder
+ return "FeatureModules" if @module_type == :feature
+ "CoreModules"
+ end
- 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)
+ 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
+ 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 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
+ # 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
+ Dir.chdir @module_root_path
+ @configurator.printDone
+ end
- 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)
+ 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: '../'"
+ podDevInjection = "pod '${POD_NAME}', path: '../'"
- if @has_test == :yes
- podDevInjection = "pod '${POD_NAME}', path: '../', :testspecs => ['Tests']"
- end
+ if @has_test == :yes
+ podDevInjection = "pod '${POD_NAME}', path: '../', :testspecs => ['Tests']"
+ end
- if @has_interface == :yes
- podDevInjection += "\n pod '${POD_NAME}Interface', path: '../'"
- end
+ if @has_interface == :yes
+ podDevInjection += "\n pod '${POD_NAME}Interface', path: '../'"
+ end
- if @module_type == :feature
- podDevInjection += "\n\n pod 'SBFoundation', path: '../../../CoreModules/SBFoundation'"
- podDevInjection += "\n pod 'SBUIKit', path: '../../../CoreModules/SBUIKit'"
- podDevInjection += "\n pod 'SBRouterServiceInterface', path: '../../../CoreModules/SBRouterService'"
- podDevInjection += "\n pod 'SBDependencyInterface', path: '../../../CoreModules/SBDependency'"
- 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 'SBNetwork', path: '../../../CoreModules/SBNetwork'"
+ podDevInjection += "\n pod 'Fetcher', path: '../../../CoreModules/Fetcher'"
+ podDevInjection += "\n pod 'Flow', path: '../../../CoreModules/Flow'"
+ 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 => 'git@bitbucket.org:acelera/ios-ds-assets.git', :tag => '1.0.0'"
- 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
+ end
- 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
+ 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
- if @has_swiftgen == :yes
- FileUtils.mkdir_p File.join(@module_path, "Sources", "ModuleConfiguration")
- end
+ 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
- FileUtils.mkdir_p File.join(@module_path, "Resources")
- @configurator.printDone
- end
+ if @has_swiftgen == :yes
+ FileUtils.mkdir_p File.join(@module_path, "Sources", "ModuleConfiguration")
+ end
- 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
+ FileUtils.mkdir_p File.join(@module_path, "Resources")
+ @configurator.printDone
+ end
- 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}
+ 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
- # Info.plist
- FileUtils.cp(
- File.join(@configurator.template_path, "Feature", "Info_template"),
- File.join(@module_path, "Resources", "Info.plist")
- )
+ def createModuleDummies
+ @configurator.printMessage("Gerando arquivos de exemplo")
- 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
- )
+ 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
- text = File.read(bundleFilename)
- text.gsub!("${POD_NAME}", @configurator.pod_name)
- File.open(bundleFilename, "w") { |file| file.puts text}
+ # 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}
- # 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\";"
- }
+ # Info.plist
+ FileUtils.cp(
+ File.join(@configurator.template_path, "Feature", "Info_template"),
+ File.join(@module_path, "Resources", "Info.plist")
+ )
- # Assets
- FileUtils.mkdir_p(File.join(@module_path, "Resources", "Assets.xcassets"))
- end
+ 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
+ )
- @configurator.printDone
- end
+ text = File.read(bundleFilename)
+ text.gsub!("${POD_NAME}", @configurator.pod_name)
+ File.open(bundleFilename, "w") { |file| file.puts text}
- def createModuleInterfaceDummies
- @configurator.printMessage("Gerando arquivos de exemplo na Interface")
- FileUtils.touch File.join(@module_path + "Interface", "Sources", "DummyInterface.swift")
+ # 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\";"
+ }
- # Info.plist
- FileUtils.cp(
- File.join(@configurator.template_path, "Feature", "Info_template"),
- File.join(@module_path + "Interface", "Resources", "Info.plist")
- )
+ # Assets
+ FileUtils.mkdir_p(File.join(@module_path, "Resources", "Assets.xcassets"))
+ end
- # 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
- @configurator.printDone
- end
+ def createModuleInterfaceDummies
+ @configurator.printMessage("Gerando arquivos de exemplo na Interface")
+ FileUtils.touch File.join(@module_path + "Interface", "Sources", "DummyInterface.swift")
- 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
- )
+ # Info.plist
+ FileUtils.cp(
+ File.join(@configurator.template_path, "Feature", "Info_template"),
+ File.join(@module_path + "Interface", "Resources", "Info.plist")
+ )
- text = File.read(fileName)
- text.gsub!("${POD_NAME}", @configurator.pod_name)
+ # 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}
- File.open(fileName, "w") { |file| file.puts text}
- @configurator.printDone
- end
+ @configurator.printDone
+ end
- 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
+ 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
+ )
- podInternal = "s.dependency 'SBFoundation'"
+ text = File.read(fileName)
+ text.gsub!("${POD_NAME}", @configurator.pod_name)
- if @module_type == :feature
- podInternal += "\n s.dependency 'SBUIKit'"
- podInternal += "\n s.dependency 'SBDependencyInterface'"
- end
+ File.open(fileName, "w") { |file| file.puts text}
+ @configurator.printDone
+ end
- if @has_interface == :yes
- podInternal += "\n s.dependency '${POD_NAME}Interface'"
- end
+ 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
- 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
+ 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
- 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 = "s.dependency 'SBFoundation'"
- podInternal = ""
- if @module_type == :feature
- podInternal += "\n s.dependency 'SBRouterServiceInterface'"
- end
+ if @module_type == :feature
+ podInternal += "\n s.dependency 'SBUIKit'"
+ podInternal += "\n s.dependency 'SBDependencyInterface'"
+ 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
+ if @has_interface == :yes
+ podInternal += "\n s.dependency '${POD_NAME}Interface'"
+ end
- 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")
+ 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
- # Dummies
- FileUtils.touch File.join(@module_path + "Tests", "Sources", "DummyModel.swift")
- FileUtils.touch File.join(@module_path + "Tests", "Tests", "DummyTest.swift")
+ 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
- # Info.plist
- FileUtils.cp(
- File.join(@configurator.template_path, "Feature", "Info_template"),
- File.join(@module_path + "Tests", "Resources", "Info.plist")
- )
-
- @configurator.printDone
- end
+ podInternal = ""
+ if @module_type == :feature
+ podInternal += "\n s.dependency 'SBRouterServiceInterface'"
+ end
- end
-end
\ No newline at end of file
+ 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
+
+ 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
+
+ end
+end