<commit_before>require 'xcodeproj'

module LaneKit
  class CLI < Thor
    
    include Thor::Actions
    
    desc "new APP_PATH [options]", "Create a new iOS app"
    def new(app_path)
      app_path = app_path.strip
      @app_path = app_path

      @app_name = LaneKit::derive_app_name(app_path)
      validate_message = LaneKit.validate_app_name(@app_name)
      if validate_message
        puts "***error: #{validate_message}"
        return
      end

      @app_path_full = File.expand_path app_path
      if File.exists?(@app_path_full)
        puts "Can't create a new LaneKit app in an existing folder: #{@app_path_full}"
        return
      end
      
      if !LaneKit.gem_available?('cocoapods')
        puts "The Ruby gem cocoapods is not installed. This gem is required by LaneKit.\nInstall command: gem install cocoapods"
        return
      end

      @project_path = File.join @app_path_full, @app_name
      @ios_template_name = "lanekit-ios-project"
      @ios_version = '6.0'
      @original_wd = Dir.pwd
        
      self.create_project
        
      self.change_filenames(@app_path_full, @app_name, @ios_template_name)
      
      self.add_cocoapods
    end
    
    no_tasks {
      #def create_xcodeproj_project
      #  proj = Xcodeproj::Project.new(File.join(@app_path, "#{@app_name}.xcodeproj"))
      #  app_target = proj.new_target(:application, @app_name, :ios, proj.products_group)
      #  proj.save
      #end
      
      def add_cocoapods
        Dir.chdir(@project_path) do
          puts "Installing CocoaPods for RestKit"
          system "pod install"
        end
      end
      
      def create_project
        source = @ios_template_name
        destination = @app_path
        directory(source, destination)
      end

      def source_paths
        [@@template_folder]
      end
      
      def change_filenames path, app_name, template_name
        
        Dir.foreach(path) do |file|
          if file == '..' || file == '.'
            next
          end
          
          old_path = File.join path, file
          new_path = old_path
      
          if file.start_with?(template_name)
            new_name = file.sub template_name, app_name<commit_msg>Removed the extra project that CocoaPods added to the workspace.<commit_after>require 'xcodeproj'

module LaneKit
  class CLI < Thor
    
    include Thor::Actions
    
    desc "new APP_PATH [options]", "Create a new iOS app"
    def new(app_path)
      app_path = app_path.strip
      @app_path = app_path

      @app_name = LaneKit::derive_app_name(app_path)
      validate_message = LaneKit.validate_app_name(@app_name)
      if validate_message
        puts "***error: #{validate_message}"
        return
      end

      @app_path_full = File.expand_path app_path
      if File.exists?(@app_path_full)
        puts "Can't create a new LaneKit app in an existing folder: #{@app_path_full}"
        return
      end
      
      if !LaneKit.gem_available?('cocoapods')
        puts "The Ruby gem cocoapods is not installed. This gem is required by LaneKit.\nInstall command: gem install cocoapods"
        return
      end

      @project_path = File.join @app_path_full, @app_name
      @ios_template_name = "lanekit-ios-project"
      @ios_version = '6.0'
      @original_wd = Dir.pwd
        
      self.create_project
      self.change_filenames(@app_path_full, @app_name, @ios_template_name)
      self.add_cocoapods
      self.clean_workspace
    end
    
    no_tasks {
      #def create_xcodeproj_project
      #  proj = Xcodeproj::Project.new(File.join(@app_path, "#{@app_name}.xcodeproj"))
      #  app_target = proj.new_target(:application, @app_name, :ios, proj.products_group)
      #  proj.save
      #end
      
      def clean_workspace
        # Remove the extra project that CocoaPods added to the workspace
        workspace_path = File.join(@app_path_full, "#{@app_name}.xcworkspace")
        say_status :clean, workspace_path, :yellow
        workspace = Xcodeproj::Workspace.new_from_xcworkspace(workspace_path)
        container = "container:#{@app_name}/#{@app_name}.xcodeproj"
        if workspace.include?(container)
          workspace.projpaths.delete(container)
          workspace.save_as(workspace_path)
        end
      end
      
      def add_cocoapods
        Dir.chdir(@project_path) do
          puts "Installing CocoaPods for RestKit"
          system "pod install"
        end
      end
      
      def create_project
        source = @ios_template_name
        destination = @app_path
        directory(source, destination)
      end

      def source_paths
        [@@template_folder]
      end
      
      def change_filenames path, app_name, template_name
        
        Dir.foreach(path) do |file|
          if file == '..' || file == '.'
            next
          end
          
          old_path = File.join path, file
          new_path = old_path
      
          if file.start_with?(template_name)
            new_name = file.sub template_name, app_name
{'fraction_non_alphanumeric': 0.08414561368609509, 'fraction_numerical': 0.0007957032027053909, 'mean_word_length': 2.202547770700637, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2051558', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1583, 'n_words': 352}