Sha256: 8a5aba460ccb27a0145263fae605051890fd63fc36687826fa78f4c696813a60

Contents?: true

Size: 1.58 KB

Versions: 22

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

namespace :praxis do
  namespace :docs do
    desc 'Generate OpenAPI 3 docs for a Praxis App'
    task generate: [:environment] do |_t, _args|
      require 'fileutils'

      Praxis::Blueprint.caching_enabled = false
      generator = Praxis::Docs::OpenApiGenerator.instance
      generator.configure_root(Dir.pwd)
      generator.save!
    end

    desc 'Preview (and Generate) OpenAPI 3 docs for a Praxis App'
    task preview: [:generate] do |_t, _args|
      require 'webrick'
      docs_port = 9090
      root = "#{Dir.pwd}/docs/openapi/"
      wb = Thread.new do
        s = WEBrick::HTTPServer.new(Port: docs_port, DocumentRoot: root)
        trap('INT') { s.shutdown }
        s.start
      end
      # If there is only 1 version we'll feature it and open the browser onto it
      versions = Dir.children(root)
      featured_version = versions.size < 2 ? "#{versions.first}/" : ''
      `open http://localhost:#{docs_port}/#{featured_version}`
      wb.join
    end
    desc 'Generate and package all OpenApi Docs into a zip, ready for a Web server (like S3...) to present it'
    task package: [:generate] do |_t, _args|
      docs_root = "#{Dir.pwd}/docs/openapi/"
      zip_file = "#{Dir.pwd}/docs/openapi.zip"
      `rm -f #{zip_file}`
      # NOTE: This assumes the "zip" utility is installed, supporting the recursive flag.
      `zip -r #{zip_file} #{docs_root}`
      puts
      puts "Left packaged API docs in #{zip_file}"
      puts ' --> To view the docs, unzip the file under a web server (or S3...) and access the index.hml files from a browser'
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
praxis-2.0.0 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.40 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.39 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.38 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.37 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.36 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.35 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.34 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.33 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.32 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.31 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.30 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.29 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.28 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.27 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.26 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.25 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.24 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.23 lib/praxis/tasks/api_docs.rb
praxis-2.0.pre.22 lib/praxis/tasks/api_docs.rb