From fb0dbf6b04815023c894c3bd4aa8fbde7a122573 Mon Sep 17 00:00:00 2001 From: Patrick Vice Date: Thu, 31 Oct 2024 09:14:54 -0400 Subject: [PATCH 1/2] create a new rake task to support refreshing all generated types --- lib/tasks/generate.rake | 15 ++++++++++++++- lib/typelizer/generator.rb | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/tasks/generate.rake b/lib/tasks/generate.rake index 19a74f4..82a8fb2 100644 --- a/lib/tasks/generate.rake +++ b/lib/tasks/generate.rake @@ -1,6 +1,19 @@ 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["TYPELIZER"] = "true" @@ -8,7 +21,7 @@ namespace :typelizer do puts "Generating TypeScript interfaces..." serializers = [] time = Benchmark.realtime do - serializers = Typelizer::Generator.call + serializers = block.call end puts "Finished in #{time} seconds" diff --git a/lib/typelizer/generator.rb b/lib/typelizer/generator.rb index f2ebde5..31ae29f 100644 --- a/lib/typelizer/generator.rb +++ b/lib/typelizer/generator.rb @@ -2,8 +2,8 @@ module Typelizer class Generator - def self.call - new.call + def self.call(**) + new.call(**) end def initialize(config = Typelizer::Config) From 8694baa0aab4aa2c883fb878fca08a11bd962ec6 Mon Sep 17 00:00:00 2001 From: Patrick Vice Date: Thu, 31 Oct 2024 09:30:00 -0400 Subject: [PATCH 2/2] updated syntax to support older versions of ruby --- lib/typelizer/generator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/typelizer/generator.rb b/lib/typelizer/generator.rb index 31ae29f..9ac4224 100644 --- a/lib/typelizer/generator.rb +++ b/lib/typelizer/generator.rb @@ -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)