Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues #10 and #12 #13

Merged
merged 10 commits into from
Dec 4, 2019
51 changes: 27 additions & 24 deletions template.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# encoding: utf-8

require "fileutils"
require "shellwords"

RAILS_REQUIREMENT = "~> 6.0.0".freeze

def apply_template!
Expand Down Expand Up @@ -36,39 +39,39 @@ def apply_template!
apply "public/template.rb"
apply "spec/template.rb"

git :init unless preexisting_git_repo?
empty_directory ".git/safe"
# The block passed to "after_bundle" seems to run after `bundle install`
# but also after `webpacker:install` and after Rails has initialized the git
# repo
after_bundle do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diff is a bit messy but basically I moved lots of commands inside the after_bundle hook. This allowed me to remove our git repo setup and our call to webpacker:install.

run_with_clean_bundler_env "bin/setup"

apply "variants/frontend-base/template.rb"

run_with_clean_bundler_env "bin/setup"
run_with_clean_bundler_env "bin/rails webpacker:install"
create_initial_migration
create_initial_migration

# Apply variants after setup and initial install, but before commit
apply "variants/accessibility/template.rb"
apply "variants/frontend-base/template.rb"
apply "variants/frontend-foundation/template.rb" if apply_variant?(:foundation)
# Apply variants after setup and initial install, but before commit
apply "variants/accessibility/template.rb"
apply "variants/frontend-foundation/template.rb" if apply_variant?(:foundation)

binstubs = %w[
brakeman bundler bundler-audit rubocop sidekiq
]
run_with_clean_bundler_env "bundle binstubs #{binstubs.join(' ')} --force"
binstubs = %w[
brakeman bundler bundler-audit rubocop sidekiq
]
run_with_clean_bundler_env "bundle binstubs #{binstubs.join(' ')} --force"

template "rubocop.yml.tt", ".rubocop.yml"
run_rubocop_autocorrections
template "rubocop.yml.tt", ".rubocop.yml"
run_rubocop_autocorrections

unless any_local_git_commits?
git add: "-A ."
git commit: "-n -m 'Set up project'"
if git_repo_specified?
git remote: "add origin #{git_repo_url.shellescape}"
git push: "-u origin --all"
unless any_local_git_commits?
git add: "-A ."
git commit: "-n -m 'Set up project'"
if git_repo_specified?
git remote: "add origin #{git_repo_url.shellescape}"
git push: "-u origin --all"
end
end
end
end

require "fileutils"
require "shellwords"

# Add this template directory to source_paths so that Thor actions like
# copy_file and template resolve against our source files. If this file was
# invoked remotely via HTTP, that means the files are not present locally.
Expand Down
3 changes: 3 additions & 0 deletions variants/frontend-base/template.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
source_paths.unshift(File.dirname(__FILE__))

run "mv app/assets app/frontend"
run "mkdir app/assets"
run "mv app/frontend/config app/assets/config"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This moves app/assets/config/manifest.js back to the place Sprockets requires it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that just Sprockets? I did find putting things in app/frontend to be by far the most brittle part of this template, so I wonder if we should just stick with Rails defaults.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sprockets hard codes this path. rails/sprockets-rails#369 is open to see if it can be made customisable. I take your point on the defaults. I'm loathe to give it up because the default feels gross but accepting the default might be the most pragmatic.


run "mv app/javascript/* app/frontend"
run "rm -rf app/javascript"
apply "config/template.rb"
Expand Down