diff --git a/.gitignore b/.gitignore index 22fd22c7d..71b04871c 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ pkg spec/dummy spec/examples.txt /sandbox +/sandbox-generated .rvmrc .ruby-version .ruby-gemset diff --git a/bin/rails-sandbox-generated b/bin/rails-sandbox-generated new file mode 100755 index 000000000..14544bee5 --- /dev/null +++ b/bin/rails-sandbox-generated @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby + +app_root = 'sandbox-generated' + +unless File.exist? "#{app_root}/bin/rails" + warn "Creating the #{app_root} app..." + Dir.chdir "#{__dir__}/.." do + system "GENERATE_FRONTEND=1 #{__dir__}/sandbox" or begin + warn "Automatic creation of the #{app_root} app failed" + exit 1 + end + end +end + +Dir.chdir app_root +exec 'bin/rails', *ARGV diff --git a/bin/sandbox b/bin/sandbox index ee8d28b72..a76a80c20 100755 --- a/bin/sandbox +++ b/bin/sandbox @@ -33,13 +33,23 @@ fi extension_name="solidus_starter_frontend" +if [[ -z $GENERATE_FRONTEND ]]; then + sandbox_name='sandbox' + extension_gem_line="gem '$extension_name', path: '..'" +else + sandbox_name='sandbox-generated' + extension_gem_line="" +fi + +sandbox_path="./${sandbox_name}" + # Stay away from the bundler env of the containing extension. function unbundled { ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@ } -rm -rf ./sandbox -unbundled bundle exec rails new sandbox --database="$RAILSDB" \ +rm -rf ${sandbox_path} +unbundled bundle exec rails new ${sandbox_name} --database="$RAILSDB" \ --skip-bundle \ --skip-git \ --skip-keeps \ @@ -48,12 +58,12 @@ unbundled bundle exec rails new sandbox --database="$RAILSDB" \ --skip-test \ --skip-javascript -if [ ! -d "sandbox" ]; then +if [ ! -d "${sandbox_name}" ]; then echo 'sandbox rails application failed' exit 1 fi -cd ./sandbox +cd ${sandbox_path} cat <> Gemfile # By default, the solidus gem also includes the standard frontend via # the solidus_frontend gem. To make this extension work, you need to @@ -71,7 +81,7 @@ gem 'solidus_sample', github: solidus_repo, branch: solidus_branch gem 'solidus_i18n', github: solidus_i18n_repo, branch: solidus_i18n_branch gem 'rails-i18n' -gem '$extension_name', path: '..' +${extension_gem_line} gem 'solidus_auth_devise' RUBY @@ -109,7 +119,12 @@ unbundled bundle exec rails generate solidus:install \ $@ unbundled bundle exec rails generate solidus:auth:install --auto-run-migrations -unbundled bundle exec rails g solidus_starter_frontend:install + +if [[ -z $GENERATE_FRONTEND ]]; then + unbundled bundle exec rails g solidus_starter_frontend:install +else + unbundled ../exe/${extension_name} --auto-accept +fi echo echo "🚀 Sandbox app successfully created for $extension_name!" diff --git a/docs/development.md b/docs/development.md index 388ee100e..c71ab67e5 100644 --- a/docs/development.md +++ b/docs/development.md @@ -26,8 +26,15 @@ require 'solidus_starter_frontend/factories' ``` ### Running the sandbox -To run this extension in a sandboxed Solidus application, you can run -`bin/sandbox`. The path for the sandbox app is `./sandbox` and `bin/rails` will + +You can create two kinds of Solidus applications to test this project: an app +where this gem runs as an engine, and an app where the storefront is generated +with this gem. + +#### App with gem running as engine + +To run this extension as an engine in a sandboxed Solidus application, you can run +`bin/sandbox`. The path for the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands to `sandbox/bin/rails`. Here's an example: @@ -42,6 +49,18 @@ Use Ctrl-C to stop Default username and password for admin are: `admin@example.com` and `test123`. +#### App with storefront generated by the gem + +To create a sandboxed Solidus application where the storefront is generated with +this gem, run `GENERATE_FRONTEND=1 bin/sandbox`. The path for the sandbox app +is `./sandbox-generated`. Unlike the previous `./sandbox` app, you'll need to +`cd` to the `./sandbox-generated` directory in order to run the application. + +As a shortcut, you can run `bin/rails-sandbox-generated` to create the app and +then run the Rails server. + + + ### Updating the changelog Before and after releases the changelog should be updated to reflect the up-to-date status of the project: