forked from justalever/kickoff_tailwind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.rb
More file actions
135 lines (106 loc) · 3.29 KB
/
template.rb
File metadata and controls
135 lines (106 loc) · 3.29 KB
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
=begin
Template Name: Kickstart application template - Tailwind CSS
Author: Andy Leverenz
Author URI: https://web-crunch.com
Instructions: $ rails new myapp -d <postgresql, mysql, sqlite> -m template.rb
=end
def source_paths
[File.expand_path(File.dirname(__FILE__))]
end
def add_gems
gem 'devise', '~> 4.4', '>= 4.4.3'
gem 'friendly_id', '~> 5.2', '>= 5.2.4'
gem 'foreman', '~> 0.84.0'
gem 'sidekiq', '~> 5.1', '>= 5.1.3'
gem 'tailwindcss', '~> 0.2.0'
gem 'webpacker', '~> 3.5', '>= 3.5.3'
gem_group :development, :test do
gem 'better_errors'
end
end
def set_application_name
# Ask user for application name
application_name = ask("What is the name of your application? Default: Kickoff")
# Checks if application name is empty and add default Kickoff.
application_name = application_name.present? ? application_name : "Kickoff"
# Add Application Name to Config
environment "config.application_name = '#{application_name}'"
# Announce the user where he can change the application name in the future.
puts "Your application name is #{application_name}. You can change this later on: ./config/application.rb"
end
def add_users
# Install Devise
generate "devise:install"
# Configure Devise
environment "config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }",
env: 'development'
route "root to: 'home#index'"
# Create Devise User
generate :devise, "User", "username", "name", "admin:boolean"
# set admin boolean to false by default
in_root do
migration = Dir.glob("db/migrate/*").max_by{ |f| File.mtime(f) }
gsub_file migration, /:admin/, ":admin, default: false"
end
end
def add_webpack
rails_command "webpacker:install"
end
# references generator here: https://github.com/IcaliaLabs/tailwindcss-rails/blob/master/lib/generators/tailwindcss/install_generator.rb with some tweaks
def add_tailwind
run "yarn --ignore-engines add tailwindcss"
run "mkdir app/javascript/stylesheets"
run "./node_modules/.bin/tailwind init app/javascript/stylesheets/tailwind.js"
append_to_file "app/javascript/packs/application.js", 'import "stylesheets/application"'
inject_into_file "./.postcssrc.yml", "\n tailwindcss: './app/javascript/stylesheets/tailwind.js'", after: "postcss-cssnext: {}"
run "mkdir app/javascript/stylesheets/components"
run "rm -r app/javascript/css"
end
# Remove Application CSS
def remove_app_css
run "rm app/assets/stylesheets/application.css"
end
def copy_templates
directory "app", force: true
end
def add_sidekiq
environment "config.active_job.queue_adapter = :sidekiq"
insert_into_file "config/routes.rb",
"require 'sidekiq/web'\n\n",
before: "Rails.application.routes.draw do"
end
def add_foreman
copy_file "Procfile"
end
def add_friendly_id
generate "friendly_id"
insert_into_file(
Dir["db/migrate/**/*friendly_id_slugs.rb"].first,
"[5.2]",
after: "ActiveRecord::Migration"
)
end
def stop_spring
run "spring stop"
end
# Main setup
source_paths
add_gems
after_bundle do
set_application_name
stop_spring
add_users
add_webpack
add_friendly_id
remove_app_css
add_sidekiq
add_foreman
add_tailwind
copy_templates
# Migrate
rails_command "db:create"
rails_command "db:migrate"
git :init
git add: "."
git commit: %Q{ -m "Initial commit" }
end