Skip to content

Fix template detection for scaffolds #202

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

Merged
merged 1 commit into from
Apr 1, 2025
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
8 changes: 5 additions & 3 deletions lib/inertia_rails/generators/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ module InertiaRails
module Generators
module Helper
class << self
def guess_the_default_framework(package_json_path = Rails.root.join('package.json'))
DEFAULT_PACKAGE_PATH = Rails.root.join('package.json')

def guess_the_default_framework(package_json_path = DEFAULT_PACKAGE_PATH)
package_json = JSON.parse(package_json_path.read)
dependencies = package_json['dependencies'] || {}

Expand All @@ -25,8 +27,8 @@ def guess_typescript
Rails.root.join('tsconfig.json').exist?
end

def guess_inertia_template
if Rails.root.join('tailwind.config.js').exist? || Rails.root.join('tailwind.config.ts').exist?
def guess_inertia_template(package_json_path = DEFAULT_PACKAGE_PATH)
if package_json_path.read.include?('"tailwindcss"')
'inertia_tw_templates'
else
'inertia_templates'
Expand Down
5 changes: 5 additions & 0 deletions spec/fixtures/package_json_files/tailwind_package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"tailwindcss": "4.0.0"
}
}
15 changes: 15 additions & 0 deletions spec/generators/generators_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,19 @@
end
end
end

describe '#guess_inertia_template' do
let(:package_json_path) { Pathname.new(File.expand_path("spec/fixtures/package_json_files/#{fixture_file_name}", Dir.pwd)) }

shared_examples 'template detection' do |file_name, expected_template|
let(:fixture_file_name) { file_name }

it "returns #{expected_template.inspect} when inspect \"#{file_name}\"" do
expect(described_class.guess_inertia_template(package_json_path)).to eq(expected_template)
end
end

it_behaves_like 'template detection', 'tailwind_package.json', 'inertia_tw_templates'
it_behaves_like 'template detection', 'empty_package.json', 'inertia_templates'
end
end