-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.rb
104 lines (91 loc) · 2.63 KB
/
template.rb
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
require 'fileutils'
require 'shellwords'
def apply_template!
add_template_repository_to_source_path
remove_unwanted_gems
add_gems
setup_generators
setup_databaseyml
after_bundle do
# setup rspec
run 'bundle exec rspec --init'
copy_file 'spec_rails_helper.rb', 'spec/rails_helper.rb'
generate 'rswag:install'
template 'Dockerfile.dev.tt'
# prepare project structure
run 'mkdir backend'
backend_files = Dir.entries('.') - %w[. .. .git backend .gitignore]
run "mv #{backend_files.join(' ')} -t backend"
file 'frontend/README.md'
file 'devops/README.md'
template 'docker-compose.yml'
template './Makefile.tt'
copy_file 'gitignore_core', '.gitignore'
# git init, 'first commit'
git :init
git add: '-- .'
git commit: "-a -m 'Initial commit'"
end
end
def add_gems
gem 'fast_jsonapi'
gem 'rswag-api'
gem 'rswag-ui'
gem 'rails_12factor'
gem 'tzinfo-data'
gem_group :development, :test do
gem 'pry'
gem 'pry-byebug'
gem 'pry-rails'
gem 'awesome_print'
gem 'rspec-rails'
gem 'rswag'
gem 'rswag-specs'
gem 'factory_bot_rails'
gem 'database_cleaner'
end
end
def setup_generators
environment <<~CODE, env: 'production'
config.generators do |g|
g.assets false
g.helper false
g.javascript_engine :js
g.orm :active_record
g.test_framework :rspec
g.stylesheets false
end
CODE
end
def setup_databaseyml
# run 'rm config/database.yml'
template 'database.yml.tt', 'config/database.yml', force: true
end
# TODO: bad design, will be better to make own Gemfile template
def remove_unwanted_gems
%w[coffee-rails jbuilder tzinfo-data].each do |unwanted_gem|
gsub_file('Gemfile', /gem '#{unwanted_gem}'.*\n/, '')
end
end
# 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.
# In that case, use `git clone` to download them to a local temporary dir.
def add_template_repository_to_source_path
if __FILE__ =~ %r{\Ahttps?://}
require "tmpdir"
source_paths.unshift(tempdir = Dir.mktmpdir("rails-template-"))
at_exit { FileUtils.remove_entry(tempdir) }
git clone: [
"--quiet",
"https://github.com/qelphybox/react-rails-template.git",
tempdir
].map(&:shellescape).join(" ")
if (branch = __FILE__[%r{rails-template/(.+)/template.rb}, 1])
Dir.chdir(tempdir) { git checkout: branch }
end
else
source_paths.unshift(__dir__)
end
end
apply_template!