<commit_before>require '/Users/Albert/Repos/Scripts/ruby/lib/utilities.rb'
require '/Users/Albert/Repos/Scripts/ruby/nimzo/nimzo.rb'

class NimzoRewriter

    # Determines the route on instantion.
    def initialize(type)

        # Make sure the particular controller type is valid.
        # This error cannot be reached through incorrect user input.
        unless inArray(%w(app modal overlay system widget), type)
            puts("\x1B[33m#{@type}\x1B[0m is not a valid controller type. There is an error in your bash script, not your input.")
            exit
        end

        @type = type.downcase
        @routes = Array.new

        # Get all the routes (for this content type).
        paths = Dir.glob("#{$PATH_TO_PHP}#{@type}/controllers/**/")
        paths.each { |route|
            route = route.sub("#{$PATH_TO_PHP}#{@type}/controllers/", '')[0..-2]
            unless route == ''
                @routes.push(route)
            end
        }

        self.rewriteLess
        self.rewriteReferences

    end

    # Re-write import-*.less file.
    def rewriteLess
        File.open("#{$PATH_TO_DEV}lib/less/imports/import-#{@type}.less", 'w') { |file|
            count = 0
            @routes.each { |route|
                filename = ''
                route.split('/').each { |routeParameter|
                    routeParameter[0] = routeParameter.upcase[0..0]
                    filename = "#{filename}#{routeParameter}"
                }
                filename[0] = filename.downcase[0..0]
                importLess = "@import '../../../#{@type}/#{route}/#{filename}';"
                count = count + 1
                if count < @routes.size
                    file.puts importLess
                else
                    file.write importLess
                end
            }
        }
    end

    # Re-write (App, Modal, Overlay, System, Widget) reference file.
    def rewriteReferences
    end

end

if ARGV[0] == 'rewrite'
    if ARGV[1] != nil
        NimzoRewriter.new(ARGV[1])
    else
        NimzoRewriter.new('app')<commit_msg>Now checking that file actually exists before attempting to re-write it.<commit_after>require '/Users/Albert/Repos/Scripts/ruby/lib/utilities.rb'
require '/Users/Albert/Repos/Scripts/ruby/nimzo/nimzo.rb'

class NimzoRewriter

    # Determines the route on instantion.
    def initialize(type)

        # Make sure the particular controller type is valid.
        # This error cannot be reached through incorrect user input.
        unless inArray(%w(app modal overlay system widget), type)
            puts("\x1B[33m#{@type}\x1B[0m is not a valid controller type. There is an error in your bash script, not your input.")
            exit
        end

        @type = type.downcase
        @routes = Array.new

        # Get all the routes (for this content type).
        paths = Dir.glob("#{$PATH_TO_PHP}#{@type}/controllers/**/")
        paths.each { |route|
            route = route.sub("#{$PATH_TO_PHP}#{@type}/controllers/", '')[0..-2]
            unless route == ''
                @routes.push(route)
            end
        }

        self.rewriteLess
        self.rewriteReferences

    end

    # Re-write import-*.less file.
    def rewriteLess
        file = "#{$PATH_TO_DEV}lib/less/imports/import-#{@type}.less"
        if File.file?(file)
            File.open(file, 'w') { |file|
                count = 0
                @routes.each { |route|
                    filename = ''
                    route.split('/').each { |routeParameter|
                        routeParameter[0] = routeParameter.upcase[0..0]
                        filename = "#{filename}#{routeParameter}"
                    }
                    filename[0] = filename.downcase[0..0]
                    importLess = "@import '../../../#{@type}/#{route}/#{filename}';"
                    count = count + 1
                    if count < @routes.size
                        file.puts importLess
                    else
                        file.write importLess
                    end
                }
            }
        end
    end

    # Re-write (App, Modal, Overlay, System, Widget) reference file.
    def rewriteReferences
    end

end

if ARGV[0] == 'rewrite'
    if ARGV[1] != nil
        NimzoRewriter.new(ARGV[1])
    else
        NimzoRewriter.new('app')
{'fraction_non_alphanumeric': 0.12186132227597328, 'fraction_numerical': 0.0082930200414651, 'mean_word_length': 1.6251511487303507, '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': '799391', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1234, 'n_words': 298}