-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimal
165 lines (135 loc) · 5.33 KB
/
minimal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
run "if uname | grep -q 'Darwin'; then pgrep spring | xargs kill -9; fi"
# GEMFILE
########################################
inject_into_file 'Gemfile', before: 'group :development, :test do' do
<<~RUBY
gem 'autoprefixer-rails'
gem 'font-awesome-sass'
gem 'simple_form'
RUBY
end
inject_into_file 'Gemfile', after: 'group :development, :test do' do
<<-RUBY
gem 'pry-byebug'
gem 'pry-rails'
gem 'dotenv-rails'
gem 'pry-byebug'
gem 'better_errors'
gem 'binding_of_caller'
gem 'faker'
gem 'letter_opener'
RUBY
end
# Procfile
########################################
file 'Procfile', <<~YAML
web: bundle exec puma -C config/puma.rb
YAML
# Assets
########################################
run 'rm -rf app/assets/stylesheets'
run 'rm -rf vendor'
run 'curl -L https://github.com/lewagon/stylesheets/archive/master.zip > stylesheets.zip'
run 'unzip stylesheets.zip -d app/assets && rm stylesheets.zip && mv app/assets/rails-stylesheets-master app/assets/stylesheets'
# Dev environment
########################################
gsub_file('config/environments/development.rb', /config\.assets\.debug.*/, 'config.assets.debug = false')
# Layout
########################################
if Rails.version < "6"
scripts = <<~HTML
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload', defer: true %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
HTML
gsub_file('app/views/layouts/application.html.erb', "<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>", scripts)
else
gsub_file('app/views/layouts/application.html.erb', "<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>", "<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload', defer: true %>")
end
gsub_file('app/views/layouts/application.html.erb', "<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>", "<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload', defer: true %>")
style = <<~HTML
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
HTML
gsub_file('app/views/layouts/application.html.erb', "<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>", style)
# README
########################################
markdown_file_content = <<~MARKDOWN
Rails app generated with [lewagon/rails-templates](https://github.com/lewagon/rails-templates), created by the [Le Wagon coding bootcamp](https://www.lewagon.com) team.
MARKDOWN
file 'README.md', markdown_file_content, force: true
# Generators
########################################
generators = <<~RUBY
config.generators do |generate|
generate.assets false
generate.helper false
generate.test_framework :test_unit, fixture: false
end
RUBY
environment generators
########################################
# AFTER BUNDLE
########################################
after_bundle do
# Generators: db + simple form + pages controller
########################################
rails_command 'db:drop db:create db:migrate'
generate('simple_form:install', '--bootstrap')
generate(:controller, 'pages', 'home', '--skip-routes', '--no-test-framework')
# Routes
########################################
route "root to: 'pages#home'"
# Git ignore
########################################
append_file '.gitignore', <<~TXT
# Ignore .env file containing credentials.
.env*
# Ignore Mac and Linux file system files
*.swp
.DS_Store
TXT
# Webpacker / Yarn
########################################
run 'yarn add popper.js jquery bootstrap'
append_file 'app/javascript/packs/application.js', <<~JS
// ----------------------------------------------------
// Note(lewagon): ABOVE IS RAILS DEFAULT CONFIGURATION
// WRITE YOUR OWN JS STARTING FROM HERE 👇
// ----------------------------------------------------
// External imports
import "bootstrap";
// Internal imports, e.g:
// import { initSelect2 } from '../components/init_select2';
document.addEventListener('turbolinks:load', () => {
// Call your functions here, e.g:
// initSelect2();
});
JS
inject_into_file 'config/webpack/environment.js', before: 'module.exports' do
<<~JS
const webpack = require('webpack');
// Preventing Babel from transpiling NodeModules packages
environment.loaders.delete('nodeModules');
// Bootstrap 4 has a dependency over jQuery & Popper.js:
environment.plugins.prepend('Provide',
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
Popper: ['popper.js', 'default']
})
);
JS
end
# Dotenv
########################################
run 'touch .env'
# Rubocop
########################################
run 'curl -L https://raw.githubusercontent.com/lewagon/rails-templates/master/.rubocop.yml > .rubocop.yml'
# Git
########################################
git add: '.'
git commit: "-m 'Initial commit with minimal template from https://github.com/lewagon/rails-templates'"
# Fix puma config
gsub_file('config/puma.rb', 'pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }', '# pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }')
end