Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Speed up dummy app generation (#12977)

Damian Legawiecced62d78e172
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 1695482caf..012a4d7796 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -74,7 +74,6 @@ jobs:
- checkout
- attach_workspace:
at: /tmp
- - install_libvips
- bundle_install
- run:
name: Run tests
diff --git a/api/lib/spree/api/engine.rb b/api/lib/spree/api/engine.rb
index 0b48b38a49..9700d51c0e 100644
--- a/api/lib/spree/api/engine.rb
+++ b/api/lib/spree/api/engine.rb
@@ -15,7 +15,7 @@ module Spree
end
initializer 'spree.api.checking_migrations' do
- Migrations.new(config, engine_name).check
+ Migrations.new(config, engine_name).check unless Rails.env.test?
end
def self.root
diff --git a/bin/dev b/bin/dev
new file mode 100755
index 0000000000..81fa0a9907
--- /dev/null
+++ b/bin/dev
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+if [ ! -d "./sandbox" ]; then
+ echo "Sandbox not found. Creating sandbox..."
+ ./bin/sandbox.sh
+fi
+
+cd ./sandbox && exec bin/dev
diff --git a/bin/sandbox.sh b/bin/sandbox.sh
index 4eab3023e4..eba4f924cc 100755
--- a/bin/sandbox.sh
+++ b/bin/sandbox.sh
@@ -33,7 +33,14 @@ bundle exec rails new sandbox --database="$RAILSDB" \
--skip-keeps \
--skip-rc \
--skip-test \
- --skip-asset-pipeline
+ --skip-asset-pipeline \
+ --skip-docker \
+ --skip-rubocop \
+ --skip-brakeman \
+ --skip-ci \
+ --skip-kamal \
+ --skip-devcontainer \
+ --skip-solid \
if [ ! -d "sandbox" ]; then
echo 'sandbox rails application failed'
@@ -76,9 +83,7 @@ RUBY
bundle update
bundle install --gemfile Gemfile --path ../vendor/bundle
-bin/rails importmap:install
-bin/rails turbo:install
-bin/rails stimulus:install
+bin/rails importmap:install turbo:install stimulus:install
bin/rails db:drop || true
bin/rails db:create
diff --git a/core/lib/generators/spree/dummy/dummy_generator.rb b/core/lib/generators/spree/dummy/dummy_generator.rb
index 3a21c68583..f853fc7723 100644
--- a/core/lib/generators/spree/dummy/dummy_generator.rb
+++ b/core/lib/generators/spree/dummy/dummy_generator.rb
@@ -39,6 +39,13 @@ module Spree
opts[:skip_test] = true
opts[:skip_bootsnap] = true
opts[:skip_asset_pipeline] = true # skip installing propshaft, we're still using sprockets as a dependency
+ opts[:skip_docker] = true
+ opts[:skip_rubocop] = true
+ opts[:skip_brakeman] = true
+ opts[:skip_ci] = true
+ opts[:skip_kamal] = true
+ opts[:skip_devcontainer] = true
+ opts[:skip_solid] = true
puts 'Generating dummy Rails application...'
invoke Rails::Generators::AppGenerator,
@@ -73,46 +80,11 @@ module Spree
end
end
- def test_dummy_clean
- inside dummy_path do
- remove_file '.gitignore'
- remove_file 'doc'
- remove_file 'Gemfile'
- remove_file 'lib/tasks'
- remove_file 'app/assets/images/rails.png'
- remove_file 'app/assets/javascripts/application.js'
- remove_file 'public/index.html'
- remove_file 'public/robots.txt'
- remove_file 'README'
- remove_file 'test'
- remove_file 'vendor'
- remove_file 'spec'
- end
- end
-
- def inject_content_security_policy
- inside dummy_path do
- inject_into_file 'config/initializers/content_security_policy.rb', %Q[
- p.script_src :self, :https, :unsafe_inline, :http, :unsafe_eval
- ], before: /^end/, verbose: true
- end
- end
-
attr_reader :lib_name
attr_reader :database
protected
- def inject_require_for(requirement)
- inject_into_file 'config/application.rb', %Q[
-begin
- require '#{requirement}'
-rescue LoadError
- # #{requirement} is not available.
-end
- ], before: /require '#{@lib_name}'/, verbose: true
- end
-
def inject_yaml_permitted_classes
inside dummy_path do
inject_into_file 'config/application.rb', %Q[
@@ -140,10 +112,6 @@ end
end
alias store_application_definition! application_definition
- def camelized
- @camelized ||= name.gsub(/\W/, '_').squeeze('_').camelize
- end
-
def remove_directory_if_exists(path)
remove_dir(path) if File.directory?(path)
end
diff --git a/core/lib/generators/spree/install/install_generator.rb b/core/lib/generators/spree/install/install_generator.rb
index ece1ecf2f2..77b6b92d45 100644
--- a/core/lib/generators/spree/install/install_generator.rb
+++ b/core/lib/generators/spree/install/install_generator.rb
@@ -46,24 +46,6 @@ module Spree
template 'config/initializers/spree.rb', 'config/initializers/spree.rb'
end
- def additional_tweaks
- return unless File.exist? 'public/robots.txt'
-
- append_file 'public/robots.txt', <<-ROBOTS.strip_heredoc
- User-agent: *
- Disallow: /checkout
- Disallow: /cart
- Disallow: /orders
- Disallow: /user
- Disallow: /account
- Disallow: /api
- Disallow: /password
- Disallow: /api_tokens
- Disallow: /cart_link
- Disallow: /account_link
- ROBOTS
- end
-
# Currently we only support devise, in the future we will also add support for default Rails authentication
def install_authentication
if @authentication == 'devise'
@@ -121,7 +103,6 @@ module Spree
say_status :copying, 'migrations'
silence_stream(STDOUT) do
silence_warnings { rake 'active_storage:install:migrations' }
- silence_warnings { rake 'action_mailbox:install:migrations' }
silence_warnings { rake 'action_text:install:migrations' }
silence_warnings { rake 'spree:install:migrations' }
silence_warnings { rake 'spree_api:install:migrations' }
diff --git a/core/lib/spree/core/engine.rb b/core/lib/spree/core/engine.rb
index acc752c817..073e766bbe 100644
--- a/core/lib/spree/core/engine.rb
+++ b/core/lib/spree/core/engine.rb
@@ -301,7 +301,7 @@ module Spree
end
initializer 'spree.core.checking_migrations' do
- Migrations.new(config, engine_name).check
+ Migrations.new(config, engine_name).check unless Rails.env.test?
end
initializer 'spree.core.assets' do |app|
diff --git a/core/lib/spree/testing_support/common_rake.rb b/core/lib/spree/testing_support/common_rake.rb
index 8d0cffdc9b..9da4c7b8c5 100644
--- a/core/lib/spree/testing_support/common_rake.rb
+++ b/core/lib/spree/testing_support/common_rake.rb
@@ -21,16 +21,16 @@ namespace :common do
skip_javascript = ['spree/api', 'spree/core', 'spree/sample', 'spree/emails'].include?(ENV['LIB_NAME'])
- Spree::DummyGenerator.start [
- "--lib_name=#{ENV['LIB_NAME']}",
- "--skip_javascript=#{skip_javascript}"
+ dummy_app_args = [
+ "--lib_name=#{ENV['LIB_NAME']}"
]
+ if skip_javascript
+ dummy_app_args << '--skip_javascript'
+ end
+ Spree::DummyGenerator.start dummy_app_args
- # install frontend libraries
unless skip_javascript
- system('bin/rails importmap:install')
- system('bin/rails turbo:install')
- system('bin/rails stimulus:install')
+ system('bin/rails importmap:install turbo:install stimulus:install')
end
# install devise if it's not the legacy user, useful for testing storefront
diff --git a/storefront/lib/generators/spree/storefront/install/install_generator.rb b/storefront/lib/generators/spree/storefront/install/install_generator.rb
index af60a43d0b..6d20466d1e 100644
--- a/storefront/lib/generators/spree/storefront/install/install_generator.rb
+++ b/storefront/lib/generators/spree/storefront/install/install_generator.rb
@@ -38,6 +38,9 @@ module Spree
else
append_to_file 'app/assets/config/manifest.js', "\n//= link_tree ../builds" unless File.read('app/assets/config/manifest.js').include?('//= link_tree ../builds')
end
+
+ # remove static robots.txt as we use robots.txt.erb
+ remove_file Rails.root.join('public/robots.txt') if Rails.root && Rails.root.join('public/robots.txt').exist?
end
end
end