Skip to content

Commit

Permalink
ENG-191: Create alternate sandbox script which copies Starter FE into…
Browse files Browse the repository at this point in the history
… app

Goal
----

As a `solidus_starter_frontend` contributor

I want an alternate sandbox script which copies Starter FE into the sandbox
application

So that I have an easy way to confirm if the Starter FE can generate a working
frontend for a Rails app.

Previous implementations
------------------------

* Fix sandbox script #166.

Relevant links
--------------

#167 (comment)
- discussion on having two strategies for generating the sandbox app: one with
the Starter FE running as an engine and other where Starter FE is generated
into the app.
  • Loading branch information
gsmendoza committed Jul 22, 2021
1 parent ec75feb commit 20c0ea5
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pkg
spec/dummy
spec/examples.txt
/sandbox
/sandbox-generated
.rvmrc
.ruby-version
.ruby-gemset
Expand Down
16 changes: 16 additions & 0 deletions bin/rails-sandbox-generated
Original file line number Diff line number Diff line change
@@ -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
27 changes: 21 additions & 6 deletions bin/sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 <<RUBY >> Gemfile
# By default, the solidus gem also includes the standard frontend via
# the solidus_frontend gem. To make this extension work, you need to
Expand All @@ -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

Expand Down Expand Up @@ -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!"
Expand Down
23 changes: 21 additions & 2 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -42,6 +49,18 @@ Use Ctrl-C to stop

Default username and password for admin are: `[email protected]` 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:
Expand Down

0 comments on commit 20c0ea5

Please sign in to comment.