Skip to content

Commit fc0b3ae

Browse files
committed
refactor(): use env var to toggle between sprockets and webpacker
closes #339
1 parent 5a5ac34 commit fc0b3ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+69125
-37
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ gemspec
1414
# gem "debugger"
1515
gem "activeadmin"
1616
gem "mimemagic", github: "mimemagicrb/mimemagic", ref: "01f92d86d15d85cfd0f20dabd025dcbd36a8a60f"
17+
18+
gem "webpacker", "~> 5.0", require: ENV["SPROCKETS"] != "true"

Gemfile.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ GEM
202202
puma (5.3.1)
203203
nio4r (~> 2.0)
204204
rack (2.2.2)
205+
rack-proxy (0.6.5)
206+
rack
205207
rack-test (1.1.0)
206208
rack (>= 1.0, < 3)
207209
rails (5.2.4.1)
@@ -286,6 +288,7 @@ GEM
286288
selenium-webdriver (3.142.7)
287289
childprocess (>= 0.5, < 4.0)
288290
rubyzip (>= 1.2.2)
291+
semantic_range (3.0.0)
289292
shellany (0.0.1)
290293
shoulda-matchers (4.2.0)
291294
activesupport (>= 4.2.0)
@@ -309,6 +312,11 @@ GEM
309312
nokogiri (~> 1.6)
310313
rubyzip (>= 1.3.0)
311314
selenium-webdriver (>= 3.0, < 4.0)
315+
webpacker (5.3.0)
316+
activesupport (>= 5.2)
317+
rack-proxy (>= 0.6.1)
318+
railties (>= 5.2)
319+
semantic_range (>= 2.3.0)
312320
websocket-driver (0.7.1)
313321
websocket-extensions (>= 0.1.0)
314322
websocket-extensions (0.1.4)
@@ -341,6 +349,7 @@ DEPENDENCIES
341349
shoulda-matchers
342350
sqlite3
343351
webdrivers
352+
webpacker (~> 5.0)
344353

345354
BUNDLED WITH
346355
2.1.4

Rakefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ RDoc::Task.new(:rdoc) do |rdoc|
1515
end
1616

1717
task :tests do
18-
sh "bin/setup"
19-
sh "rspec"
20-
sh "bin/setup --use_webpacker"
21-
sh "rspec"
18+
system "export SPROCKETS=true; rspec ./spec/features"
19+
system "export SPROCKETS=false; rspec"
2220
end
2321

2422
Bundler::GemHelper.install_tasks

bin/setup

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,6 @@ set -e
77
gem install bundler --conservative
88
bundle check || bundle install
99

10-
git restore -s@ -SW spec/dummy
11-
12-
if [ "$1" = "--use_webpacker" ]; then
13-
yarn prepublishOnly
14-
fi
15-
1610
cd spec/dummy
17-
git checkout .
18-
git clean -f -d
1911
bundle exec rake db:setup
20-
bundle config frozen false
21-
if [ "$1" = "--use_webpacker" ]; then
22-
bundle add webpacker --version "~>5.0"
23-
bundle exec rails webpacker:install
24-
bundle exec rails generate active_admin:install --skip-users --skip-comments --use_webpacker
25-
else
26-
set +e
27-
bundle remove webpacker
28-
yarn remove @activeadmin/activeadmin @rails/webpacker activeadmin_addons webpack-dev-server
29-
set -e
30-
bundle exec rails generate active_admin:install --skip-users --skip-comments
31-
fi
32-
bundle exec rails g activeadmin_addons:install
3312

34-
if [ "$1" = "--use_webpacker" ]; then
35-
yarn add file:./../..
36-
rm -rf node_modules/activeadmin_addons/spec
37-
rm -rf node_modules/activeadmin_addons/vendor
38-
cd ../..
39-
fi

docs/CONTRIBUTING.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,20 @@ rails s
3939
The gem is tested using [rspec](https://github.com/rspec/rspec-rails), [capybara](https://github.com/teamcapybara/capybara#using-capybara-with-rspec) and [selenium-webdriver](https://github.com/SeleniumHQ/selenium/tree/master/rb) with chrome. So, **you need to have chromedriver installed**.
4040
If you're using homebrew on OS X you can do: `brew install chromedriver`.
4141

42-
To run the tests you can do, in the root of the gem,
42+
To run the tests you can do, in the root of the gem:
4343

4444
```
4545
# For running the full setup (sprockets and webpacker)
4646
bundle exec rake tests
4747
48-
# For running in the current environment
48+
# For running with webpacker only
4949
bundle exec rspec
5050
```
5151

52+
# For running with webpacker only
53+
export SPROCKETS=true; bundle exec rspec
54+
```
55+
5256
- The addons specs we put them inside `/spec/features`.
5357
- The helper classes specs we put them inside `/spec/lib`.
5458

spec/dummy/.browserslistrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
defaults

spec/dummy/app/admin/dashboard.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
ActiveAdmin.register_page "Dashboard" do
2+
menu priority: 1, label: proc { I18n.t("active_admin.dashboard") }
3+
4+
content title: proc { I18n.t("active_admin.dashboard") } do
5+
div class: "blank_slate_container", id: "dashboard_default_message" do
6+
span class: "blank_slate" do
7+
span I18n.t("active_admin.dashboard_welcome.welcome")
8+
small I18n.t("active_admin.dashboard_welcome.call_to_action")
9+
end
10+
end
11+
12+
# Here is an example of a simple dashboard with columns and panels.
13+
#
14+
# columns do
15+
# column do
16+
# panel "Recent Posts" do
17+
# ul do
18+
# Post.recent(5).map do |post|
19+
# li link_to(post.title, admin_post_path(post))
20+
# end
21+
# end
22+
# end
23+
# end
24+
25+
# column do
26+
# panel "Info" do
27+
# para "Welcome to ActiveAdmin."
28+
# end
29+
# end
30+
# end
31+
end # content
32+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
//= require active_admin/base
2+
//= require activeadmin_addons/all
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@import 'activeadmin_addons/all';
2+
// SASS variable overrides must be declared before loading up Active Admin's styles.
3+
//
4+
// To view the variables that Active Admin provides, take a look at
5+
// `app/assets/stylesheets/active_admin/mixins/_variables.scss` in the
6+
// Active Admin source.
7+
//
8+
// For example, to change the sidebar width:
9+
// $sidebar-width: 242px;
10+
11+
// Active Admin's got SASS!
12+
@import "active_admin/mixins";
13+
@import "active_admin/base";
14+
15+
// Overriding any non-variable SASS must be done after the fact.
16+
// For example, to change the default status-tag color:
17+
//
18+
// .status_tag { background: #6090DB; }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Load Active Admin's styles into Webpacker,
2+
// see `active_admin.scss` for customization.
3+
import "../stylesheets/active_admin";
4+
5+
import "@activeadmin/activeadmin";
6+
import "activeadmin_addons"

0 commit comments

Comments
 (0)