Last active
February 24, 2022 17:50
-
-
Save mariochavez/f54bcc6ca4049a25f9b6142108c2d4da to your computer and use it in GitHub Desktop.
Templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
remove_file "bin/setup" | |
create_file "bin/setup" do | |
<<~EOF | |
#!/usr/bin/env ruby | |
require "fileutils" | |
# path to your application root. | |
APP_ROOT = File.expand_path('..', __dir__) | |
def system!(*args) | |
system(*args) || abort("\\n== Command #{args} failed ==") | |
end | |
FileUtils.chdir APP_ROOT do | |
# This script is a way to set up or update your development environment automatically. | |
# This script is idempotent, so that you can run it at any time and get an expectable outcome. | |
# Add necessary setup steps to this file. | |
puts '== Installing Ruby dependencies ==' | |
system! 'gem install bundler --conservative' | |
system('bundle check') || system!('bundle install') | |
puts "\\n== Copying sample files ==" | |
unless File.exist?('config/database.yml') | |
FileUtils.cp 'config/database.yml.sample', 'config/database.yml' | |
end | |
puts "\\n== Preparing database ==" | |
system! 'bin/rails db:prepare' | |
puts "\\n== Removing old logs and tempfiles ==" | |
system! 'bin/rails log:clear tmp:clear' | |
puts "\\n== Restarting application server ==" | |
if File.exist?('.overmind.sock') | |
system! 'overmind restart' | |
end | |
end | |
EOF | |
end | |
run "chmod +x bin/setup" | |
create_file "bin/ci" do | |
<<~EOF | |
# bin/ci | |
#!/usr/bin/env bash | |
set -e | |
echo "Running Unit Tests" | |
bin/rails test | |
echo "Running System Tests" | |
bin/rails test:system | |
echo "Linting Ruby code with StandardRb." | |
echo "It will not autofix issues." | |
bundle exec standardrb | |
echo "Analyzing code for security vulnerabilities." | |
echo "Output will be in tmp/brakeman.html, which" | |
echo "can be opened in your browser." | |
bundle exec brakeman -q -o tmp/brakeman.html | |
echo "Analyzing Ruby gems for" | |
echo "security vulnerabilities" | |
bundle exec bundle audit check --update | |
echo "Analyzing Node modules" | |
echo "for security vulnerabilities" | |
EOF | |
end | |
run "chmod +x bin/ci" | |
system 'mv config/database.yml config/database.yml.sample' | |
append_to_file(".gitignore", %(\n/config/database.yml\n)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def do_bundle | |
# Custom bundle command ensures dependencies are correctly installed | |
Bundler.with_unbundled_env { run "bundle install" } | |
end | |
gem_group :development do | |
gem "standard" | |
gem "brakeman" | |
gem "bundle-audit" | |
end | |
do_bundle | |
create_file ".standard.yml" do | |
<<~EOF | |
fix: false # default: false | |
parallel: true # default: false | |
format: progress # default: Standard::Formatter | |
ruby_version: 2.7.2 # default: RUBY_VERSION | |
default_ignores: false # default: true | |
ignore: # default: [] | |
- 'node_modules/**/*' | |
- 'db/migrate/**/*' | |
- 'db/schema.rb' | |
- 'bin/**/*' | |
- 'Gemfile' | |
- 'config/environments/**/*' | |
- 'config/application.rb' | |
- 'config/boot.rb' | |
- 'config/puma.rb' | |
EOF | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create_file "Procfile" do | |
<<~EOF | |
web: bundle exec puma -C config/puma.rb | |
EOF | |
end | |
port = ask "Default port for your app?" | |
port ||= "3000" | |
gsub_file "Procfile.dev", "-p 3000", "-p #{port}" | |
create_file ".overmind.env" do | |
<<~EOF | |
OVERMIND_PROCFILE=Procfile.dev | |
EOF | |
end | |
puts "### Install overmind from https://github.com/DarthSim/overmind#installation ####" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def do_bundle | |
# Custom bundle command ensures dependencies are correctly installed | |
Bundler.with_unbundled_env { run "bundle install" } | |
end | |
# Disable CSS files creation with generators | |
initializer("generators.rb") do | |
<<~EOF | |
Rails.application.config.generators do |g| | |
g.stylesheets false | |
end | |
EOF | |
end | |
# Add Letter Opener gem | |
gem "letter_opener", group: :development | |
# Add Lograge gem | |
gem "lograge" | |
do_bundle | |
# lograge initializer | |
initializer("lograge.rb") do | |
<<~EOF | |
Rails.application.configure do | |
config.lograge.enabled = !Rails.env.development? || ENV["LOGRAGE_IN_DEVELOPMENT"] == "true" | |
end | |
EOF | |
end | |
# Configure environments | |
environment(nil, env: "development") do | |
<<~EOF | |
# Update port number with yours application port | |
config.default_url_options = {host: "localhost:3000"} | |
config.action_mailer.delivery_method = :letter_opener | |
config.action_mailer.perform_deliveries = true | |
EOF | |
end | |
environment(nil, env: "production") do | |
<<~EOF | |
# Update this value with real domain name | |
config.default_url_options = {host: "my-app.com"} | |
EOF | |
end | |
# Setup the app | |
run "bin/setup" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment