Skip to content

Commit

Permalink
feat(env): Allow disabling Typelizer with Rails development
Browse files Browse the repository at this point in the history
We faced an issue which is resolved by disabling Typelizer.
Disabling was hard when Rails env is development, so this commit
changed env name from `TYPELIZER` to `DISABLE_TYPELIZER` and
the logic for disabling.
This commit also adds a description of this environment variable
to README.
  • Loading branch information
okuramasafumi authored and skryukov committed Nov 7, 2024
1 parent ce0365f commit 3568f84
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ When [Listen](https://github.com/guard/listen) is installed, Typelizer automatic
Typelizer.listen = false
```

### Disabling Typelizer

Sometimes we want to use Typelizer only with manual generation. To disable Typelizer during development, we can set `DISABLE_TYPELIZER` environment variable to true. This doesn't affect manual generation.

## Configuration

### Global Configuration
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/generate.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace :typelizer do
task generate: :environment do
require "benchmark"

ENV["TYPELIZER"] = "true"
ENV["DISABLE_TYPELIZER"] = "false"

puts "Generating TypeScript interfaces..."
serializers = []
Expand Down
4 changes: 3 additions & 1 deletion lib/typelizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
module Typelizer
class << self
def enabled?
ENV["RAILS_ENV"] == "development" || ENV["RACK_ENV"] == "development" || ENV["TYPELIZER"] == "true"
return false if ENV["DISABLE_TYPELIZER"] == "true" || ENV["DISABLE_TYPELIZER"] == "1"

ENV["RAILS_ENV"] == "development" || ENV["RACK_ENV"] == "development" || ENV["DISABLE_TYPELIZER"] == "false"
end

attr_accessor :dirs
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

ENV["TYPELIZER"] = "true"
ENV["DISABLE_TYPELIZER"] = "false"
ENV["RAILS_ENV"] = "test"
require File.expand_path("app/config/environment", __dir__)

Expand Down

0 comments on commit 3568f84

Please sign in to comment.