<commit_before>module ArchitectureJS
  module Command
    def watch(path = nil)
      require "fssm"

      path ||= File.expand_path(Dir.getwd)

      puts ArchitectureJS::Notification.log "ArchitectureJS are watching for changes. Press Ctrl-C to stop."
      project = ArchitectureJS::Project.init_with_config
      project.update
      watch_hash = Hash.new

      project.watch_directories.each do |dir|
        watch_hash["#{path}/#{dir}"] = "**/*.js"
      end

      watch_hash[path] = "**/*.conf"
      watch_hash["#{ArchitectureJS::BASE_DIR}/repository"] = "**/*.js"

      FSSM.monitor do
        watch_hash.each do |dir, g|
          path "#{dir}" do
            glob g

            update do |base, relative|
              puts ArchitectureJS::Notification.event "change detected in #{relative}"
              project.config.read if relative.match(/conf$/)
              project.update
            end

            create do |base, relative|
              puts ArchitectureJS::Notification.event "#{relative} created"
              project.update
            end
          end
        end
      end
    end # watch

    def create(config = nil)
      settings = {
        name: nil,
        root: File.expand_path(Dir.getwd)
      }

      settings.merge!(config) unless config.nil?

      raise 'you must specify a project name: architect create ProjectName' if settings[:name].nil?

      project = ArchitectureJS::Project.new({ name: settings[:name] }, settings[:root])# TODO add settings[:framework]
      project.create
    end

    def compile(options = nil)
      settings = {
        force_compress: false,
        path: File.expand_path(Dir.getwd)
      }

      settings.merge!(options) if options

      project = ArchitectureJS::create_project_from_config(settings[:path])
      project.config[:output] = 'compressed' if settings[:force_compress]
      project.update
    end

    # TODO make generate generic to accept a type, look up in either local templates or master, and pass it options and flags parsed for use in erb files
    def generate(config)
      conf_path = "#{config[:project].root}/ninjs.conf"
      raise "ninjs.conf was not located in #{conf_path}" unless File.exists? conf_path
      generator = ArchitectureJS::Generator.new(config)
      generator.generate
    end

    module_function :create,
                    :watch,
                    :compile,
                    :generate
  end
end
<commit_msg>Remove init_with_config call in command.rb. Replace with project.read_config<commit_after>module ArchitectureJS
  module Command
    def watch(path = nil)
      require "fssm"

      path ||= File.expand_path(Dir.getwd)

      puts ArchitectureJS::Notification.log "ArchitectureJS are watching for changes. Press Ctrl-C to stop."
      project = ArchitectureJS::Project.new({ name: 'unknown' }, path)
      project.read_config
      project.update
      watch_hash = Hash.new

      project.watch_directories.each do |dir|
        watch_hash["#{path}/#{dir}"] = "**/*.js"
      end

      watch_hash[path] = "**/*.conf"
      watch_hash["#{ArchitectureJS::BASE_DIR}/repository"] = "**/*.js" # check changes to the repository as well

      FSSM.monitor do
        watch_hash.each do |dir, g|
          path "#{dir}" do
            glob g

            update do |base, relative|
              puts ArchitectureJS::Notification.event "change detected in #{relative}"
              project.config.read if relative.match(/conf$/)
              project.update
            end

            create do |base, relative|
              puts ArchitectureJS::Notification.event "#{relative} created"
              project.update
            end
          end
        end
      end
    end # watch

    def create(config = nil)
      settings = {
        name: nil,
        root: File.expand_path(Dir.getwd)
      }

      settings.merge!(config) unless config.nil?

      raise 'you must specify a project name: architect create ProjectName' if settings[:name].nil?

      project = ArchitectureJS::Project.new({ name: settings[:name] }, settings[:root])# TODO add settings[:framework]
      project.create
    end

    def compile(options = nil)
      settings = {
        force_compress: false,
        path: File.expand_path(Dir.getwd)
      }

      settings.merge!(options) if options

      project = ArchitectureJS::create_project_from_config(settings[:path])
      project.config[:output] = 'compressed' if settings[:force_compress]
      project.update
    end

    # TODO make generate generic to accept a type, look up in either local templates or master, and pass it options and flags parsed for use in erb files
    def generate(config)
      conf_path = "#{config[:project].root}/ninjs.conf"
      raise "ninjs.conf was not located in #{conf_path}" unless File.exists? conf_path
      generator = ArchitectureJS::Generator.new(config)
      generator.generate
    end

    module_function :create,
                    :watch,
                    :compile,
                    :generate
  end
end

{'fraction_non_alphanumeric': 0.10041592394533572, 'fraction_numerical': 0.0, 'mean_word_length': 2.3028122956180512, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2861262', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1346, 'n_words': 384}