Commit 00e1de3c authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Replace --stdout and --json options with --export.

Additionally one can now use: --output -
This will produce output to stdout.

Old --json    is now  --export=json
Old --stdout  is now  --export=json --output=-
parent 9b991b1f
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -52,14 +52,15 @@ module JsDuck
      @examples = Examples.create(@opts.examples)
      @categories = Categories.create(@opts.categories_path, DocFormatter.new(@relations, @opts), @relations)

      if @opts.export == :stdout
      if @opts.export == :json
        format_classes
        if @opts.output_dir == :stdout
          puts JsonDuck.generate(@relations.classes)
      elsif @opts.export == :json
        format_classes
        else
          FileUtils.rm_rf(@opts.output_dir)
          cw = ClassWriter.new(@relations, @opts)
          cw.write(@opts.output_dir, ".json")
        end
      else
        FileUtils.rm_rf(@opts.output_dir)
        TemplateDir.new(@opts).write
+14 −9
Original line number Diff line number Diff line
@@ -129,8 +129,9 @@ module JsDuck

        opts.on('-o', '--output=PATH',
          "Directory to output all this amazing documentation.",
          "This option MUST be specified (unless --stdout).", " ") do |path|
          @output_dir = canonical(path)
          "This option MUST be specified (unless --stdout).",
          "Use dash '-' to write docs to STDOUT (only export).", " ") do |path|
          @output_dir = path == "-" ? :stdout : canonical(path)
        end

        opts.on('--ignore-global', "Turns off the creation of global class.", " ") do
@@ -253,12 +254,10 @@ module JsDuck
          @img_tpl = tpl
        end

        opts.on('--json', "Produces JSON export instead of HTML documentation.", " ") do
          @export = :json
        end

        opts.on('--stdout', "Writes JSON export to STDOUT instead of writing to the filesystem", " ") do
          @export = :stdout
        opts.on('--export=FORMAT',
          "Instead of HTML docs, exports docs in FORMAT:",
          "* json - JSON export of all docs.", " ") do |format|
          @export = format.to_sym
        end

        opts.on('--seo', "Creates index.php that handles search engine traffic.", " ") do
@@ -406,7 +405,13 @@ module JsDuck
      if @input_files.length == 0 && !@welcome && !@guides && !@videos && !@examples
        puts "You should specify some input files, otherwise there's nothing I can do :("
        exit(1)
      elsif @export != :stdout
      elsif @output_dir == :stdout && !@export
        puts "Output to STDOUT only works when using --export option."
        exit(1)
      elsif ![nil, :json].include?(@export)
        puts "Unknown export format: #{@export}"
        exit(1)
      elsif @output_dir != :stdout
        if !@output_dir
          puts "You should also specify an output directory, where I could write all this amazing documentation."
          exit(1)