Skip to content

Commit

Permalink
Merge pull request solidusio#5798 from mamhoff/support-tailwind-in-du…
Browse files Browse the repository at this point in the history
…mmy-app

Support Tailwind CSS in core dummy app
  • Loading branch information
tvdeyen authored Jun 20, 2024
2 parents 97f9f69 + 1d2d045 commit b555db8
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 11 deletions.
1 change: 1 addition & 0 deletions admin/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require 'rake'
require 'rake/testtask'
require 'rspec/core/rake_task'
require 'spree/testing_support/dummy_app/rake_tasks'
require 'solidus_admin/testing_support/dummy_app/rake_tasks'
require 'bundler/gem_tasks'

namespace :tailwindcss do
Expand Down
10 changes: 10 additions & 0 deletions admin/lib/solidus_admin/testing_support/admin_assets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

RSpec.configure do |config|
config.when_first_matching_example_defined(solidus_admin: true) do
config.before(:suite) do
system('bin/rails solidus_admin:tailwindcss:build') or abort 'Failed to build Tailwind CSS'
Rails.application.precompiled_assets
end
end
end
60 changes: 60 additions & 0 deletions admin/lib/solidus_admin/testing_support/dummy_app/rake_tasks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: true

namespace :solidus_admin do
namespace :tailwindcss do
desc "Build Tailwind CSS"
task build: :dummy_environment do
require "solidus_admin"
require "tailwindcss/commands"

config_file = <<~JS
const adminRoot = "#{SolidusAdmin::Engine.root}"
const solidusAdmin = require(`${adminRoot}/config/tailwind.config.js`)
module.exports = {
// Read how to use TailwindCSS presets: https://tailwindcss.com/docs/presets.
presets: [solidusAdmin],
content: [
// Include paths coming from SolidusAdmin.
...solidusAdmin.content,
// Include paths to your own components.
`${__dirname}/../../../../app/components/admin/**/*`,
`${__dirname}/../../../../lib/components/admin/**/*`,
],
}
JS
FileUtils.mkdir_p(DummyApp::Application.root.join("config"))
File.write(DummyApp::Application.root.join("config/tailwind.config.js"), config_file)
FileUtils.mkdir_p(DummyApp::Application.root.join("app/assets/stylesheets/solidus_admin"))
FileUtils.cp(
SolidusAdmin::Engine.root.join("app/assets/stylesheets/solidus_admin/application.tailwind.css"),
DummyApp::Application.root.join("app/assets/stylesheets/solidus_admin/application.tailwind.css")
)

tailwindcss = Tailwindcss::Commands.executable

tailwindcss_command = [
tailwindcss,
"--config", DummyApp::Application.root.join("config/tailwind.config.js"),
"--input", DummyApp::Application.root.join("app/assets/stylesheets/solidus_admin/application.tailwind.css"),
"--output", DummyApp::Application.root.join("assets/builds/solidus_admin/tailwind.css")
]

sh tailwindcss_command.shelljoin
end
end
end

# Attach Tailwind CSS build to other tasks.
%w[
assets:precompile
test:prepare
spec:prepare
db:test:prepare
].each do |task_name|
next unless Rake::Task.task_defined?(task_name)

Rake::Task[task_name].enhance(["solidus_admin:tailwindcss:build"])
end
9 changes: 4 additions & 5 deletions admin/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@
mount Spree::Core::Engine, at: '/'
end

unless SolidusAdmin::Engine.root.join('app/assets/builds/solidus_admin/tailwind.css').exist?
Dir.chdir(SolidusAdmin::Engine.root) do
system 'bundle exec rake tailwindcss:build' or abort 'Failed to build Tailwind CSS'
end
end
require "solidus_admin/testing_support/admin_assets"

# RAILS
require "rspec/rails"
Expand Down Expand Up @@ -111,6 +107,9 @@
config.before do
Rails.cache.clear
end
config.define_derived_metadata(file_path: %r{spec/features}) do |metadata|
metadata[:solidus_admin] = true
end

config.include FactoryBot::Syntax::Methods

Expand Down
1 change: 1 addition & 0 deletions legacy_promotions/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require 'rake'
require 'rake/testtask'
require 'rspec/core/rake_task'
require 'spree/testing_support/dummy_app/rake_tasks'
require 'solidus_admin/testing_support/dummy_app/rake_tasks'
require 'bundler/gem_tasks'

RSpec::Core::RakeTask.new
Expand Down
7 changes: 1 addition & 6 deletions legacy_promotions/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@
}
mount Spree::Core::Engine, at: "/"
end

unless SolidusAdmin::Engine.root.join('app/assets/builds/solidus_admin/tailwind.css').exist?
Dir.chdir(SolidusAdmin::Engine.root) do
system 'bundle exec rake tailwindcss:build' or abort 'Failed to build Tailwind CSS'
end
end
require "solidus_admin/testing_support/admin_assets"

require 'rails-controller-testing'
require 'rspec/rails'
Expand Down

0 comments on commit b555db8

Please sign in to comment.