Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(env): Allow disabling Typelizer with Rails development #19

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading