-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapi.rb
More file actions
142 lines (113 loc) · 4.61 KB
/
api.rb
File metadata and controls
142 lines (113 loc) · 4.61 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
# 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 = "api"
RAILS_REQUIREMENT = ">= 8.1.0"
TEMPLATE_METADATA = {
name: "api",
description: "Rails API-only application with essential setup",
features: %w[postgresql devcontainer rspec rubocop uuid i18n kamal solid_queue solid_cache solid_cable llm],
rails_version: RAILS_REQUIREMENT
}.freeze
#==============================================================================
# SHARED CODE - Embedded functions
#==============================================================================
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
if variant_name
variant_path = File.join(template_root, "variants", variant_name)
source_paths.unshift(variant_path) if File.directory?(variant_path)
end
shared_path = File.join(template_root, "variants", "shared")
source_paths.unshift(shared_path) if File.directory?(shared_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"
apply "src/shared/llm.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/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/shared/gems_lockbox.rb"
apply "src/shared/gems_shrine.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