<commit_before>require "rails/generators"

module RorGenerators
  module Generators
    class NewGenerator < Rails::Generators::NamedBase
      source_root File.expand_path('../templates', __FILE__)
    
      def module_name 
        @module_name ||= "#{file_name}"
      end
    
      def client_dest_prefix 
        "client/app/bundles/#{module_name}/"
      end
    
      def create_react_directories
        dirs = %w[components containers startup]
        dirs.each { |name| empty_directory("#{client_dest_prefix}/#{name}") }
      end
    
      def create_redux_directories
        dirs = %w[actions constants reducers store]
        dirs.each { |name| empty_directory("#{client_dest_prefix}/#{name}") }
      end
    
      def copy_template_files 
        client_template_files.each do |file|
          file_name = file[2] ? module_name.capitalize : module_name
          template "client/#{file[0]}/#{file[1]}", 
            "#{client_dest_prefix}/#{file[0]}/#{file_name}#{file[1].gsub('.erb', '')}"
        end
      end
    
      def add_route 
        route "resources :#{module_name.downcase.pluralize}, only: :index"
      end
    
      def copy_server_files
        empty_directory("app/views/#{module_name}")
        template "server/controller.rb", "app/controllers/#{module_name.pluralize}_controller.rb"
        template "server/index.html.erb", "app/views/#{module_name.pluralize}/index.html.erb"
        template "server/layout.html.erb", "app/views/layouts/#{module_name}.html.erb"
      end
      
      def copy_config_files 
        template "client/startup/registration.jsx.erb", "#{client_dest_prefix}/startup/registration.jsx"
      end

      def copy_webpack_config
        if dest_file_exists?("client/webpack.config.json")
          inject_into_file "client/webpack.config.js.erb", after: "'babel-polyfill',\n" do <<-'RUBY'
            puts "'./app/bundles/#{module_name}/startup/registration',"
          RUBY
          end
        else
          template "client/webpack.config.js.erb", "client/webpack.config.js"
        end
      end

      def copy_package_json <commit_msg>fix bug in copy_webpack_config<commit_after>require "rails/generators"

module RorGenerators
  module Generators
    class NewGenerator < Rails::Generators::NamedBase
      source_root File.expand_path('../templates', __FILE__)
    
      def module_name 
        @module_name ||= "#{file_name}"
      end
    
      def client_dest_prefix 
        "client/app/bundles/#{module_name}/"
      end
    
      def create_react_directories
        dirs = %w[components containers startup]
        dirs.each { |name| empty_directory("#{client_dest_prefix}/#{name}") }
      end
    
      def create_redux_directories
        dirs = %w[actions constants reducers store]
        dirs.each { |name| empty_directory("#{client_dest_prefix}/#{name}") }
      end
    
      def copy_template_files 
        client_template_files.each do |file|
          file_name = file[2] ? module_name.capitalize : module_name
          template "client/#{file[0]}/#{file[1]}", 
            "#{client_dest_prefix}/#{file[0]}/#{file_name}#{file[1].gsub('.erb', '')}"
        end
      end
    
      def add_route 
        route "resources :#{module_name.downcase.pluralize}, only: :index"
      end
    
      def copy_server_files
        empty_directory("app/views/#{module_name}")
        template "server/controller.rb", "app/controllers/#{module_name.pluralize}_controller.rb"
        template "server/index.html.erb", "app/views/#{module_name.pluralize}/index.html.erb"
        template "server/layout.html.erb", "app/views/layouts/#{module_name}.html.erb"
      end
      
      def copy_config_files 
        template "client/startup/registration.jsx.erb", "#{client_dest_prefix}/startup/registration.jsx"
      end

      def copy_webpack_config
        if dest_file_exists?("client/webpack.config.js.erb")
          inject_into_file "client/webpack.config.js.erb", after: "'babel-polyfill',\n" do <<-'RUBY'
            puts "'./app/bundles/#{module_name}/startup/registration',"
          RUBY
          end
        else
          template "client/webpack.config.js.erb", "client/webpack.config.js"
        end
      end

      def copy_package_json 
{'fraction_non_alphanumeric': 0.12579355748883142, 'fraction_numerical': 0.0023512814483893723, 'mean_word_length': 2.577796467619849, 'pattern_counts': {'":': 0, '<': 9, '<?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': '1076637', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1339, 'n_words': 213}