Class: Moku6::Generate

Inherits:
Object
  • Object
show all
Defined in:
lib/moku6/generate.rb

Constant Summary collapse

GENERATORS =

subcommand => [generator name, default output path]

{
  "docs" => [:docs, "generated/docs/audit-events.md"],
  "schema" => [:json_schema, "generated/schema"],
  "typescript" => [:typescript, "generated/typescript/audit-events.ts"],
  "ruby" => [:ruby, "generated/ruby/audit_events.rb"],
  "bigquery" => [:bigquery, "generated/bigquery/audit_events.sql"],
  "cloudevents" => [:cloudevents, "generated/cloudevents"],
  "eventcatalog" => [:eventcatalog, "generated/eventcatalog"],
  "openapi" => [:openapi, "generated/openapi/audit-events.yaml"],
  "rails" => [:rails, "generated/rails/audit_events.rb"],
  "outbox" => [:outbox, "generated/outbox"],
  "examples" => [:example, "examples/generated"]
}.freeze
ALL =
%w[docs schema typescript ruby bigquery examples].freeze
<<~TEXT
  Usage: moku6 generate SUBCOMMAND [options]

  Subcommands:
    docs               Generate Markdown documentation
    schema             Generate runtime JSON Schema
    typescript         Generate TypeScript types
    ruby               Generate Ruby constants
    bigquery           Generate BigQuery DDL
    cloudevents        Generate CloudEvents JSON Schema
    eventcatalog       Generate EventCatalog event docs
    openapi            Generate an OpenAPI 3.1 document
    rails              Generate a Ruby/Rails emitter SDK
    outbox             Generate a sample Rails outbox
    examples           Generate sample events
    all                Generate all artifacts (#{ALL.join(", ")})

  Options:
    --out PATH         Output path
    --catalog DIR      Catalog directory (default: catalog)
    --config FILE      Config file (default: .moku6.yml)
TEXT

Instance Method Summary collapse

Instance Method Details

#start(argv) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/moku6/generate.rb', line 47

def start(argv)
  argv = argv.dup
  sub = argv.shift
  case sub
  when nil, "help", "-h", "--help"
    puts BANNER
  when "all"
    options = parse_options(argv, "generate all")
    ALL.each { |name| run(name, options) }
  else
    unless GENERATORS.key?(sub)
      warn "Unknown generate subcommand: #{sub}"
      warn BANNER
      exit 2
    end
    options = parse_options(argv, "generate #{sub}")
    run(sub, options)
  end
end