-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathimportmap_tailwind.rb
More file actions
157 lines (126 loc) · 5.38 KB
/
importmap_tailwind.rb
File metadata and controls
157 lines (126 loc) · 5.38 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# frozen_string_literal: true
#==============================================================================
# CONSTANTS - Template configuration and shared values
#==============================================================================
REPO_LINK = "https://github.com/alec-c4/kickstart.git"
AVAILABLE_TEMPLATE_NAMES = %w[api importmap_tailwind esbuild_tailwind inertia_svelte inertia_react inertia_vue].freeze
TEMPLATE_NAME = "importmap_tailwind"
RAILS_REQUIREMENT = ">= 8.1.0"
TEMPLATE_METADATA = {
name: "importmap_tailwind",
description: "Rails app with Importmap and Tailwind CSS for modern frontend development",
features: %w[postgresql devcontainer rspec rubocop uuid i18n tailwind importmap turbo stimulus kamal solid_queue
solid_cache solid_cable],
rails_version: RAILS_REQUIREMENT
}.freeze
#==============================================================================
# SHARED CODE - Embedded functions (auto-generated, do not edit manually)
#==============================================================================
require "rails/all"
def assert_minimum_rails_version
requirement = Gem::Requirement.new(RAILS_REQUIREMENT)
rails_version = Gem::Version.new(Rails::VERSION::STRING)
return if requirement.satisfied_by?(rails_version)
prompt = "This template requires Rails #{RAILS_REQUIREMENT}. "\
"You are using #{rails_version}. Continue anyway?"
exit 1 if no?(prompt)
end
def gemfile_requirement(name)
@original_gemfile ||= IO.read("Gemfile")
req = @original_gemfile[/gem\s+['"]#{name}['"]\s*(,[><~= \t\d.\w'"]*)?.*$/, 1]
req && req.tr("'", %(")).strip.sub(/^,\s*"/, ', "')
end
def add_template_repository_to_source_path
if __FILE__.match?(%r{\Ahttps?://})
require "tmpdir"
source_paths.unshift(tempdir = Dir.mktmpdir("kickstart-tmp"))
at_exit { FileUtils.remove_entry(tempdir) }
git clone: [
"--quiet",
REPO_LINK,
tempdir
].map(&:shellescape).join(" ")
# Check for specific branch in URL path (e.g., /kickstart/branch_name/template.rb)
template_pattern = "(?:#{AVAILABLE_TEMPLATE_NAMES.join('|')})"
if (branch = __FILE__[%r{kickstart/(.+)/#{template_pattern}\.rb}, 1])
Dir.chdir(tempdir) { git checkout: branch }
end
else
# For local files, add the template root directory
template_root = File.dirname(__FILE__)
source_paths.unshift(template_root)
end
end
def set_variant_source_path(variant_name = nil)
template_root = if __FILE__.match?(%r{\Ahttps?://})
source_paths.first
else
File.dirname(__FILE__)
end
# 1. Universal shared (lowest priority)
shared_path = File.join(template_root, "variants", "shared")
source_paths.unshift(shared_path) if File.directory?(shared_path)
# 2. Classic shared (medium priority)
classic_shared_path = File.join(template_root, "variants", "classic_shared")
source_paths.unshift(classic_shared_path) if File.directory?(classic_shared_path)
# 3. Variant-specific (highest priority)
return unless variant_name
variant_path = File.join(template_root, "variants", variant_name)
source_paths.unshift(variant_path) if File.directory?(variant_path)
end
def show_post_install_message
say "\n
#########################################################################################
Rails application '#{app_name}' created successfully!
Next steps:
$ cd #{app_name}
$ bundle install
$ rails db:create db:migrate
$ rails parallel:create # Creates parallel test databases (ignore 'already exists' message)
$ bin/dev
#########################################################################################
💡 AI-Powered Development Tip:
To enable full Rails-aware features for AI assistants, install Rails MCP server:
$ gem install rails-mcp-server
#########################################################################################
", :green
end
#==============================================================================
# TEMPLATE LOGIC - Template-specific configuration and workflow
#==============================================================================
assert_minimum_rails_version
add_template_repository_to_source_path
set_variant_source_path(TEMPLATE_NAME)
apply "src/shared/general.rb"
apply "src/shared/packages.rb"
after_bundle do
apply "src/shared/init_generators.rb"
apply "src/shared/init_db_cli.rb"
apply "src/shared/solid_queue_setup.rb"
apply "src/shared/init_i18n.rb"
apply "src/classic_shared/routes.rb"
apply "src/classic_shared/app_static_pages.rb"
apply "src/classic_shared/custom_error_pages.rb"
apply "src/shared/env_rubocop.rb"
apply "src/shared/migrations_uuid.rb"
apply "src/shared/gems_anyway_config.rb"
apply "src/shared/gems_pagy.rb"
apply "src/shared/gems_active_interaction.rb"
apply "src/shared/gems_rspec.rb"
apply "src/shared/gems_i18n_tasks.rb"
apply "src/classic_shared/gems_better_html.rb"
apply "src/classic_shared/gems_erblint.rb"
apply "src/shared/gems_lockbox.rb"
apply "src/shared/gems_shrine.rb"
apply "src/shared/e2e.rb"
apply "src/classic_shared/gems_view_component.rb"
apply "src/classic_shared/helpers.rb"
apply "src/shared/gems_madmin.rb"
apply "src/shared/ci.rb"
apply "src/shared/github.rb"
apply "src/shared/docs.rb"
apply "src/shared/staging_env.rb"
apply "src/shared/run_rubocop.rb"
apply "src/shared/git_init.rb"
show_post_install_message
end