Commit c69a2441 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Make --stdout always produce JSON.

The other possibility is pretty useless.

Plus the code is now re-using the @export property for STDOUT export.
parent 4aac6dee
Loading
Loading
Loading
Loading
+25 −23
Original line number Diff line number Diff line
@@ -121,8 +121,8 @@ opts = OptionParser.new do | opts |
    app.export = :json
  end

  opts.on('--stdout', "Sends the output to STDOUT instead of writing to the filesystem", " ") do
    app.output_to_stdout = true
  opts.on('--stdout', "Writes JSON export to STDOUT instead of writing to the filesystem", " ") do
    app.export = :stdout
  end

  opts.separator "Debugging:"
@@ -179,27 +179,29 @@ app.input_files = js_files
if app.input_files.length == 0
  puts "You should specify some input files, otherwise there's nothing I can do :("
  exit(1)
elsif !app.output_to_stdout and !app.output_dir
elsif app.export != :stdout
  if !app.output_dir
    puts "You should also specify an output directory, where I could write all this amazing documentation."
    exit(1)
elsif !app.output_to_stdout and File.exists?(app.output_dir) && !File.directory?(app.output_dir)
  elsif File.exists?(app.output_dir) && !File.directory?(app.output_dir)
    puts "Oh noes!  The output directory is not really a directory at all :("
    exit(1)
elsif !app.output_to_stdout and !File.exists?(File.dirname(app.output_dir))
  elsif !File.exists?(File.dirname(app.output_dir))
    puts "Oh noes!  The parent directory for #{app.output_dir} doesn't exist."
    exit(1)
elsif !app.output_to_stdout and !File.exists?(app.template_dir + "/extjs")
  elsif !File.exists?(app.template_dir + "/extjs")
    puts "Oh noes!  The template directory does not contain extjs/ directory :("
    puts "Please copy ExtJS over to template/extjs or create symlink."
    puts "For example:"
    puts "    $ cp -r /path/to/ext-4.0.0 " + app.template_dir + "/extjs"
    exit(1)
elsif !app.output_to_stdout and !File.exists?(app.template_dir + "/resources/css")
  elsif !File.exists?(app.template_dir + "/resources/css")
    puts "Oh noes!  CSS files for custom ExtJS theme missing :("
    puts "Please compile SASS files in template/resources/sass with compass."
    puts "For example:"
    puts "    $ compass compile " + app.template_dir + "/resources/sass"
    exit(1)
  end
end

app.run()
+3 −17
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ module JsDuck
  # The main application logic of jsduck
  class App
    # These are basically input parameters for app
    attr_accessor :output_to_stdout
    attr_accessor :output_dir
    attr_accessor :template_dir
    attr_accessor :guides_dir
@@ -44,7 +43,6 @@ module JsDuck
    attr_accessor :append_html

    def initialize
      @output_to_stdout = false
      @output_dir = nil
      @template_dir = nil
      @guides_dir = nil
@@ -111,9 +109,9 @@ module JsDuck
        end
      end

      clear_dir(@output_dir) unless @output_to_stdout
      if @output_to_stdout
        @timer.time(:generating) { output_classes(relations) }
      clear_dir(@output_dir) unless @export == :stdout
      if @export == :stdout
        @timer.time(:generating) { puts JSON.generate(relations.classes) }
      elsif @export == :json
        FileUtils.mkdir(@output_dir)
        init_output_dirs(@output_dir)
@@ -222,18 +220,6 @@ module JsDuck
      File.open(filename, 'w') {|f| f.write(js) }
    end

    # Writes each class to STDOUT
    def output_classes(relations)
      if @export == :json
        puts JSON.generate(relations.classes)
      else
        exporter = Exporter.new(relations, get_doc_formatter(relations))
        @parallel.each(relations.classes) do |cls|
          puts exporter.export(cls)
        end
      end
    end

    # Writes JsonP export file for each class
    def write_classes(path, relations)
      exporter = Exporter.new(relations, get_doc_formatter(relations))