Commit 537ddc5a authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Unify format of log messages.

Filenames in both warnings and log messages are converted to windows
style if platform is Windows.

Warnings begin again with "Warning: ".
parent e1269697
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ module JsDuck
    # Parses the files in parallel using as many processes as available CPU-s
    def parallel_parse(filenames)
      @parallel.map(filenames) do |fname|
        Logger.instance.log("Parsing #{fname} ...")
        Logger.instance.log("Parsing", fname)
        SourceFile.new(IO.read(fname), fname, @opts)
      end
    end
@@ -119,7 +119,7 @@ module JsDuck
    def aggregate(parsed_files)
      agr = Aggregator.new
      parsed_files.each do |file|
        Logger.instance.log("Aggregating #{file.filename} ...")
        Logger.instance.log("Aggregating", file.filename)
        agr.aggregate(file)
      end
      agr.classify_orphans
@@ -191,7 +191,7 @@ module JsDuck
      dir = @opts.output_dir + (@opts.export ? "" : "/output")
      @parallel.each(@relations.classes) do |cls|
        filename = dir + "/" + cls[:name] + (@opts.export ? ".json" : ".js")
        Logger.instance.log("Writing to #{filename} ...")
        Logger.instance.log("Writing docs", filename)
        data = exporter.export(cls)
        if @opts.export
          JsonDuck.write_json(filename, data)
@@ -210,7 +210,7 @@ module JsDuck
      # updates all the doc-objects related to the file
      parsed_files.each do |file|
        html_filename = src.write(file.to_html, file.filename)
        Logger.instance.log("Writing to #{html_filename} ...")
        Logger.instance.log("Writing source", html_filename)
        file.html_filename = File.basename(html_filename)
      end
    end
@@ -225,13 +225,13 @@ module JsDuck
    end

    def copy_template
      Logger.instance.log("Copying template files to #{@opts.output_dir}...")
      Logger.instance.log("Copying template files to", @opts.output_dir)
      FileUtils.cp_r(@opts.template_dir, @opts.output_dir)
      init_output_dirs
    end

    def link_template
      Logger.instance.log("Linking template files to #{@opts.output_dir}...")
      Logger.instance.log("Linking template files to", @opts.output_dir)
      FileUtils.mkdir(@opts.output_dir)
      Dir.glob(@opts.template_dir + "/*").each do |file|
        File.symlink(File.expand_path(file), @opts.output_dir+"/"+File.basename(file))
@@ -278,7 +278,7 @@ module JsDuck
    def write_template(filename, replacements)
      in_file = @opts.template_dir + '/' + filename
      out_file = @opts.output_dir + '/' + filename
      Logger.instance.log("Creating #{out_file}...")
      Logger.instance.log("Writing", out_file)
      html = IO.read(in_file)
      html.gsub!(/\{\w+\}/) do |key|
        replacements[key] ? replacements[key] : key
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ module JsDuck
      guide_file = in_dir + "/README.md"
      return Logger.instance.warn("README.md not found in #{in_dir}") unless File.exists?(guide_file)

      Logger.instance.log("Writing guide #{out_dir} ...")
      Logger.instance.log("Writing guide", out_dir)
      # Copy the whole guide dir over
      FileUtils.cp_r(in_dir, out_dir)

+1 −1
Original line number Diff line number Diff line
@@ -47,9 +47,9 @@ module JsDuck
        filename = path + "/" + img
        if map.has_key?(filename)
          dest = output_dir + "/" + img
          Logger.instance.log("Copying image", dest)
          FileUtils.makedirs(File.dirname(dest))
          FileUtils.cp(filename, dest)
          Logger.instance.log("Copy #{filename} to #{dest} ...")
          # mark file as used.
          map[filename] = true
          return true
+19 −10
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@ module JsDuck
      @shown_warnings = {}
    end

    # Prints log message
    def log(msg)
      puts msg if @verbose
    # Prints log message with optional filename appended
    def log(msg, filename=nil)
      if @verbose
        puts msg + " " + format(filename) + "..."
      end
    end

    # Prints warning message.
@@ -28,19 +30,26 @@ module JsDuck
    # warnings greatly also when run multiple processes.
    #
    # Optionally filename and line number will be inserted to message.
    def warn(msg, filename=nil, line=0)
      if filename
        filename.gsub!('/', '\\') if OS::windows?
        msg = "#{filename}:#{line}:Warning: #{msg}"
      else
        msg = "Warning: #{msg}"
      end
    def warn(msg, filename=nil, line=nil)
      msg = "Warning: " + format(filename, line) + " " + msg

      if @warnings && !@shown_warnings[msg]
        $stderr.puts msg
        @shown_warnings[msg] = true
      end
    end

    # Formats filename and line number for output
    def format(filename=nil, line=nil)
      out = ""
      if filename
        out = OS::windows? ? filename.gsub('/', '\\') : filename
        if line
          out += ":#{line}:"
        end
      end
      out
    end
  end

end