Skip to content

Commit

Permalink
Create a new rake task to support refreshing all generated types (#17)
Browse files Browse the repository at this point in the history
* create a new rake task to support refreshing all generated types

* updated syntax to support older versions of ruby
  • Loading branch information
patvice authored Nov 7, 2024
1 parent 3568f84 commit 40baff4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion lib/tasks/generate.rake
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
namespace :typelizer do
desc "Generate TypeScript interfaces from serializers"
task generate: :environment do
benchmark do
Typelizer::Generator.call
end
end

desc "Removes all files in output folder and refreshs all generate TypeScript interfaces from serializers"
task "generate:refresh": :environment do
benchmark do
Typelizer::Generator.call(force: true)
end
end

def benchmark(&block)
require "benchmark"

ENV["DISABLE_TYPELIZER"] = "false"

puts "Generating TypeScript interfaces..."
serializers = []
time = Benchmark.realtime do
serializers = Typelizer::Generator.call
serializers = block.call
end

puts "Finished in #{time} seconds"
Expand Down
4 changes: 2 additions & 2 deletions lib/typelizer/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

module Typelizer
class Generator
def self.call
new.call
def self.call(**args)
new.call(**args)
end

def initialize(config = Typelizer::Config)
Expand Down

0 comments on commit 40baff4

Please sign in to comment.