require 'thor' require 'fwtoolkit/cli/xcode' require 'fwtoolkit/cli/cocoapods' require 'fwtoolkit/cli/git' require 'fwtoolkit/cli/bitrise' require 'fwtoolkit/projectfile' require 'fwtoolkit/git_client' require 'fwtoolkit/cli/thorutils' module FWToolkit class Project < Thor include Thor::Actions include FWToolkit::ThorUtils source_root_templates! desc "proj new [swift|objc] [PROJECT NAME] [CLASS PREFIX]", "Create a new Xcode project with FW's settings. Language is either objc or swift" def new(project_language, project_name, class_prefix) unless project_language == "swift" or project_language == "objc" say_status :error, "Project language should be either swift or objc", :red return end destination_root = File.join(Dir.pwd, project_name) say "Creating new project in: #{File.expand_path destination_root}" invoke :conf_rvm, [project_language, destination_root] invoke FWToolkit::Bitrise, 'new', [destination_root, project_name, class_prefix.upcase] invoke FWToolkit::Xcode, 'new', [project_language, project_name, class_prefix.upcase, File.join(Dir.pwd, project_name)] invoke FWToolkit::Cocoapods, 'install', [destination_root] git_repo = GitClient::Repository.new destination_root # gitignore is included on xcode new.. for now if(git_repo.initialized?) say_status :skip, 'The git repository is already initialized', :yellow else invoke FWToolkit::Git, 'new', [destination_root] end end desc "proj conf_rvm [PROJECT_DIR]", "Configure rvm/gem environment on a project's folder" def conf_rvm(project_language, project_root=Dir.pwd) @project_name = File.basename(project_root) @ruby_version = Config.ruby_version destination_root = project_root say 'Configuring rvm' directory "templates/default_project/rvm", destination_root inside(destination_root) do run! "rvm install ruby-#{Config.ruby_version}" run! "rvm ruby-#{Config.ruby_version} do rvm gemset create #{@project_name}" bundle_update run! "rvm #{Config.ruby_version} do rvm --ruby-version --create ruby-#{Config.ruby_version}@#{@project_name}", {:capture => true} end end desc "proj update [PROJECT_DIR]", "Update project's pods/gems and submodules" def update(project_root=Dir.pwd) bundle_update invoke FWToolkit::Git, 'update', [project_root] invoke FWToolkit::Cocoapods, 'install', [project_root] end private def bundle_update if File.exists? 'Gemfile' begin retried ||= false run! "rvm ruby-#{Config.ruby_version}@#{@project_name} do gem update --system" run! "rvm ruby-#{Config.ruby_version}@#{@project_name} do gem cleanup" run! "rvm ruby-#{Config.ruby_version}@#{@project_name} do gem install bundler" run! "rvm ruby-#{Config.ruby_version}@#{@project_name} do bundle" rescue Thor::Error retried = true retry unless retried end end end end end