-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.rb
118 lines (98 loc) · 3.03 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
require 'fileutils'
require 'shellwords'
OUTPUT_COLOR = :blue
# Copied from: https://github.com/mattbrictson/rails-template
# 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-tailwinded-'))
at_exit { FileUtils.remove_entry(tempdir) }
git clone: [
'--quiet',
'https://github.com/beyode/rails-tailwinded.git',
tempdir
].map(&:shellescape).join(' ')
if (branch = __FILE__[%r{rails-tailwinded/(.+)/template.rb}, 1])
Dir.chdir(tempdir) { git checkout: branch }
end
else
source_paths.unshift(File.dirname(__FILE__))
end
end
def install_taiwindcss
# run "yarn add tailwindcss"
run 'yarn add tailwindcss@yarn:@tailwindcss/postcss7-compat'
run 'yarn add @tailwindcss/forms @tailwindcss/typography @tailwindcss/aspect-ratio'
run 'mkdir app/javascript/stylesheets'
run 'touch app/javascript/stylesheets/application.scss'
inject_into_file 'app/javascript/stylesheets/application.scss' do
<<~EOF
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
EOF
end
run 'npx tailwindcss init'
inject_into_file 'app/javascript/packs/application.js', after: 'import "channels"' do
<<~EOF
import "stylesheets/application.scss"
EOF
end
inject_into_file 'postcss.config.js', before: "require('postcss-import')" do
<<~EOF
require('tailwindcss'),
require('autoprefixer'),
EOF
end
gsub_file 'tailwind.config.js', /purge:\s\[\],/, <<-PURGE
purge: [
'./app/**/*.html.erb',
'./app/helpers/**/*.rb',
'./src/**/*.html',
'./src/**/*.js',
'./src/**/*.jsx',
],
PURGE
gsub_file 'tailwind.config.js', /plugins:\s\[\],/, <<-PLUGINS
plugins: [
require('@tailwindcss/forms'),
require('@tailwindcss/typography'),
require('@tailwindcss/aspect-ratio'),
],
PLUGINS
inject_into_file 'app/views/layouts/application.html.erb',
before: "<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>" do
<<~EOF
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
EOF
end
end
def copy_templates
# Apply template from lib/template.rb
apply 'lib/template.rb'
copy_file 'Procfile'
copy_file 'Procfile.dev'
copy_file '.foreman'
end
# Start (Main)
add_template_repository_to_source_path
after_bundle do
run 'spring stop'
install_taiwindcss
copy_templates
git :init
git add: '.'
begin
git commit: %(-m "first commit")
rescue StandardError => e
puts e.message
end
say
say 'Application generated sucessfully', OUTPUT_COLOR
say
say "cd #{app_name} to switch to app", OUTPUT_COLOR
end