Sha256: c58f4f3edd0a9eb87e5bcfe6e180bed5dd5362a179ed0e9bc2317405db46d377
Contents?: true
Size: 1.47 KB
Versions: 6
Compression:
Stored size: 1.47 KB
Contents
# frozen_string_literal: true require "rails/railtie" class TypesFromSerializers::Railtie < Rails::Railtie railtie_name :types_from_serializers # Automatically generates code whenever a serializer is loaded. if defined?(Rails.env) && Rails.env.development? require_relative "generator" initializer "types_from_serializers.reloader" do |app| if Gem.loaded_specs["listen"] require "listen" app.config.after_initialize do app.reloaders << TypesFromSerializers.track_changes end app.config.to_prepare do TypesFromSerializers.generate_changed end else app.config.to_prepare do TypesFromSerializers.generate end Rails.logger.warn "Add 'listen' to your Gemfile to automatically generate code on serializer changes." end end end # Suitable when triggering code generation manually. rake_tasks do |app| namespace :types_from_serializers do desc "Generates TypeScript interfaces for each serializer in the app." task generate: :environment do require_relative "generator" start_time = Time.zone.now print "Generating TypeScript interfaces..." serializers = TypesFromSerializers.generate(force: true) puts "completed in #{(Time.zone.now - start_time).round(2)} seconds.\n" puts "Found #{serializers.size} serializers:" puts serializers.map { |s| "\t#{s.name}" }.join("\n") end end end end
Version data entries
6 entries across 6 versions & 1 rubygems