roda-project 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/roda/project/bin/generator.rb +11 -0
- data/lib/roda/project/bin/generators/migration.rb +51 -0
- data/lib/roda/project/bin/generators/routes.rb +107 -0
- data/lib/roda/project/bin/generators.rb +36 -0
- data/lib/roda/project/cli.rb +17 -31
- data/lib/roda/project/generator.rb +19 -0
- data/lib/roda/project/helpers/ids.rb +34 -1
- data/lib/roda/project/helpers/{input.rb → interactive_input.rb} +14 -2
- data/lib/roda/project/helpers/template.rb +9 -5
- data/lib/roda/project/{context.rb → main_context.rb} +27 -10
- data/lib/roda/{templates → project/templates}/base/app/app.rb.erb +10 -7
- data/lib/roda/{templates → project/templates}/base/minimal/Gemfile.erb +1 -1
- data/lib/roda/{templates → project/templates}/base/minimal/app.rb +4 -1
- data/lib/roda/project/templates/base/minimal/bin/roda.erb +47 -0
- data/lib/roda/{templates → project/templates}/base/scaffold/Gemfile.erb +8 -7
- data/lib/roda/{templates → project/templates}/base/scaffold/app/config/config.rb.erb +2 -13
- data/lib/roda/project/templates/base/scaffold/bin/roda.erb +153 -0
- data/lib/roda/project/templates/front-end/app/views/layout.erb +23 -0
- data/lib/roda/{templates → project/templates}/front-end/esbuild.js +6 -6
- data/lib/roda/project/version.rb +2 -2
- data/lib/roda/project.rb +23 -12
- metadata +79 -62
- data/lib/roda/templates/base/minimal/Rakefile.erb +0 -51
- data/lib/roda/templates/base/scaffold/Rakefile.erb +0 -210
- data/lib/roda/templates/front-end/app/views/foo/html.rb +0 -6
- data/lib/roda/templates/front-end/app/views/html.rb +0 -38
- data/lib/roda/templates/front-end/app/views/layout.erb +0 -15
- /data/lib/roda/{templates → project/templates}/base/minimal/AGENTS.md +0 -0
- /data/lib/roda/{templates → project/templates}/base/minimal/Gemfile.lock +0 -0
- /data/lib/roda/{templates → project/templates}/base/minimal/Guardfile +0 -0
- /data/lib/roda/{templates → project/templates}/base/minimal/README.md +0 -0
- /data/lib/roda/{templates → project/templates}/base/minimal/boot.rb +0 -0
- /data/lib/roda/{templates → project/templates}/base/minimal/config.ru +0 -0
- /data/lib/roda/{templates → project/templates}/base/minimal/public/exception_page.css +0 -0
- /data/lib/roda/{templates → project/templates}/base/scaffold/AGENTS.md +0 -0
- /data/lib/roda/{templates → project/templates}/base/scaffold/Guardfile +0 -0
- /data/lib/roda/{templates → project/templates}/base/scaffold/README.md +0 -0
- /data/lib/roda/{templates → project/templates}/base/scaffold/app/config/locales/en.yml +0 -0
- /data/lib/roda/{templates → project/templates}/base/scaffold/app/config/locales/foo/en.yml +0 -0
- /data/lib/roda/{templates → project/templates}/base/scaffold/app/config/locales/foo/pt-br.yml +0 -0
- /data/lib/roda/{templates → project/templates}/base/scaffold/app/config/locales/pt-br.yml +0 -0
- /data/lib/roda/{templates → project/templates}/base/scaffold/app/config/providers/logger.rb +0 -0
- /data/lib/roda/{templates → project/templates}/base/scaffold/app/config/providers/mailer.rb +0 -0
- /data/lib/roda/{templates → project/templates}/base/scaffold/app/routes/foo.rb.erb +0 -0
- /data/lib/roda/{templates → project/templates}/base/scaffold/boot.rb.erb +0 -0
- /data/lib/roda/{templates → project/templates}/base/scaffold/config.ru.erb +0 -0
- /data/lib/roda/{templates → project/templates}/base/scaffold/public/exception_page.css +0 -0
- /data/lib/roda/{templates → project/templates}/database/app/config/providers/db/conn.rb +0 -0
- /data/lib/roda/{templates → project/templates}/database/db/seeds.rb +0 -0
- /data/lib/roda/{templates → project/templates}/front-end/app/assets/css/app.css +0 -0
- /data/lib/roda/{templates → project/templates}/front-end/app/assets/js/app.js +0 -0
- /data/lib/roda/{templates → project/templates}/front-end/app/assets/js/some/foo.js +0 -0
- /data/lib/roda/{templates → project/templates}/front-end/app/views/foo/bar.erb +0 -0
- /data/lib/roda/{templates → project/templates}/front-end/app/views/index.erb +0 -0
- /data/lib/roda/{templates → project/templates}/front-end/package.json +0 -0
- /data/lib/roda/{templates → project/templates}/front-end/public/assets/app.css +0 -0
- /data/lib/roda/{templates → project/templates}/front-end/public/assets/app.js +0 -0
- /data/lib/roda/{templates → project/templates}/front-end/public/images/roda-project.png +0 -0
- /data/lib/roda/{templates → project/templates}/rodauth/app/models/account.rb +0 -0
- /data/lib/roda/{templates → project/templates}/rodauth/app/views/create-account.erb +0 -0
- /data/lib/roda/{templates → project/templates}/rodauth/db/migrations/001_add_rodauth.rb +0 -0
- /data/lib/roda/{templates → project/templates}/tests/minimal/minitest/spec/app_spec.rb +0 -0
- /data/lib/roda/{templates → project/templates}/tests/minimal/minitest/spec/spec_helper.rb.erb +0 -0
- /data/lib/roda/{templates → project/templates}/tests/minimal/rspec/spec/app_spec.rb +0 -0
- /data/lib/roda/{templates → project/templates}/tests/minimal/rspec/spec/spec_helper.rb +0 -0
- /data/lib/roda/{templates → project/templates}/tests/minitest/spec/app/app_spec.rb.erb +0 -0
- /data/lib/roda/{templates → project/templates}/tests/minitest/spec/app/routes/foo_spec.rb +0 -0
- /data/lib/roda/{templates → project/templates}/tests/minitest/spec/app/routes/test_branch_spec.rb +0 -0
- /data/lib/roda/{templates → project/templates}/tests/minitest/spec/app/views/html_spec.rb +0 -0
- /data/lib/roda/{templates → project/templates}/tests/minitest/spec/spec_helper.rb.erb +0 -0
- /data/lib/roda/{templates → project/templates}/tests/rspec/spec/app/app_spec.rb.erb +0 -0
- /data/lib/roda/{templates → project/templates}/tests/rspec/spec/app/routes/foo_spec.rb +0 -0
- /data/lib/roda/{templates → project/templates}/tests/rspec/spec/app/routes/test_branch_spec.rb +0 -0
- /data/lib/roda/{templates → project/templates}/tests/rspec/spec/app/views/html_spec.rb +0 -0
- /data/lib/roda/{templates → project/templates}/tests/rspec/spec/spec_helper.rb.erb +0 -0
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
# Rakefile
|
|
2
|
-
|
|
3
|
-
require "fileutils"
|
|
4
|
-
|
|
5
|
-
task :default do
|
|
6
|
-
system("rake -T")
|
|
7
|
-
end
|
|
8
|
-
<% if context.database? %>
|
|
9
|
-
namespace :db do
|
|
10
|
-
desc "Migrate the database. Optional: provide target version, e.g., 'rake db:migrate[123]'"
|
|
11
|
-
task :migrate, [:target] do |t, args|
|
|
12
|
-
require_relative "boot"
|
|
13
|
-
require "sequel"
|
|
14
|
-
require "sequel/extensions/migration"
|
|
15
|
-
|
|
16
|
-
Sequel.extension :migration
|
|
17
|
-
db = Providers::DB::Conn.get
|
|
18
|
-
if args[:target]
|
|
19
|
-
Sequel::Migrator.run(db, "db/migrations", target: args[:target].to_i)
|
|
20
|
-
else
|
|
21
|
-
Sequel::Migrator.run(db, "db/migrations")
|
|
22
|
-
end
|
|
23
|
-
puts "Database migration complete."
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
<% end %>
|
|
27
|
-
desc "Open a console with application context (alias: rake c)"
|
|
28
|
-
task :console do
|
|
29
|
-
system("irb -r ./boot.rb")
|
|
30
|
-
end
|
|
31
|
-
task c: :console
|
|
32
|
-
|
|
33
|
-
desc "Run lint"
|
|
34
|
-
task :lint do
|
|
35
|
-
system("bundle exec standardrb")
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
desc "Auto fix lint warnings"
|
|
39
|
-
task "lint:fix" do
|
|
40
|
-
system("bundle exec standardrb --fix")
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
desc "Run tests"
|
|
44
|
-
task :test do<% if context.rspec? %>
|
|
45
|
-
system("RACK_ENV=test bundle exec rspec")<% else %>
|
|
46
|
-
system("RACK_ENV=test bundle exec minitest spec/")<% end %>
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
desc "Exec development server"
|
|
50
|
-
task :server do
|
|
51
|
-
if ENV["RACK_ENV"] == "production"<% if context.database? %>
|
|
52
|
-
if ENV["DATABASE_URL"].nil?
|
|
53
|
-
puts("DATABASE_URL is empty")
|
|
54
|
-
exit 1
|
|
55
|
-
end<% end %>
|
|
56
|
-
if ENV["SESSION_SECRET"].nil?
|
|
57
|
-
puts("SESSION_SECRET is empty")
|
|
58
|
-
exit 1
|
|
59
|
-
end
|
|
60
|
-
system("RUBYOPT=--yjit RUBY_YJIT_ENABLE=1 RACK_ENV=production bundle exec puma --port 4000")
|
|
61
|
-
else
|
|
62
|
-
system("RACK_ENV=development bundle exec puma --port 4000")
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
desc "Exec development server watching for changes"
|
|
67
|
-
task "dev" do
|
|
68
|
-
system("RACK_ENV=development bundle exec guard")
|
|
69
|
-
end
|
|
70
|
-
<% if context.fullstack? %>
|
|
71
|
-
desc "Compile assets"
|
|
72
|
-
task :assets do
|
|
73
|
-
system("npm i && npm run build")
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
desc "Watch and compile assets"
|
|
77
|
-
task "dev:assets" do
|
|
78
|
-
system("npm i && npm run build:watch")
|
|
79
|
-
end
|
|
80
|
-
<% end %>
|
|
81
|
-
|
|
82
|
-
desc "Exec production server"
|
|
83
|
-
task :prod do
|
|
84
|
-
if ENV["DATABASE_URL"].nil?
|
|
85
|
-
puts("DATABASE_URL is empty")
|
|
86
|
-
exit 1
|
|
87
|
-
end
|
|
88
|
-
if ENV["SESSION_SECRET"].nil?
|
|
89
|
-
puts("SESSION_SECRET is empty")
|
|
90
|
-
exit 1
|
|
91
|
-
end
|
|
92
|
-
system("RUBYOPT=--yjit RUBY_YJIT_ENABLE=1 RACK_ENV=production bundle exec puma --port 4000")
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
namespace :g do<% if context.database? %>
|
|
96
|
-
desc "Generate an empty Sequel migration. Usage: 'rake generate:migration[migration_name]'"
|
|
97
|
-
task :migration, [:migration_name] do |t, args|
|
|
98
|
-
migration_name = args[:migration_name]
|
|
99
|
-
if migration_name.nil? || migration_name.empty?
|
|
100
|
-
puts "Usage: rake generate:migration[migration_name]"
|
|
101
|
-
exit 1
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
migrations_path = File.expand_path("./db/migrations", __dir__)
|
|
105
|
-
FileUtils.mkdir_p(migrations_path) unless File.directory?(migrations_path)
|
|
106
|
-
|
|
107
|
-
existing_migrations = Dir.glob(File.join(migrations_path, "*.rb"))
|
|
108
|
-
max_number = existing_migrations.map do |file|
|
|
109
|
-
File.basename(file).match(/^(\d+)/)&.captures&.first.to_i
|
|
110
|
-
end.max || 0
|
|
111
|
-
next_number = (max_number + 1).to_s.rjust(3, "0")
|
|
112
|
-
|
|
113
|
-
filename = File.join(migrations_path, "#{next_number}_#{migration_name}.rb")
|
|
114
|
-
|
|
115
|
-
content = <<~RUBY
|
|
116
|
-
Sequel.migration do
|
|
117
|
-
up do
|
|
118
|
-
# add your migration here
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
down do
|
|
122
|
-
# remove your migration here
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
RUBY
|
|
126
|
-
|
|
127
|
-
File.write(filename, content)
|
|
128
|
-
puts "Created migration: #{filename}"
|
|
129
|
-
end
|
|
130
|
-
<% end %>
|
|
131
|
-
desc "Generate routes and tests, also generate views if views directory is present. Usage: 'rake generate:routes[branch_name,route1,method:route2]'"
|
|
132
|
-
task :routes, [:branch_name, :routes] do |t, args|
|
|
133
|
-
branch_name = args.branch_name
|
|
134
|
-
routes_list = [args.routes].concat(args.extras)
|
|
135
|
-
|
|
136
|
-
if branch_name.nil? || branch_name.empty? || routes_list.nil? || routes_list.empty?
|
|
137
|
-
puts "Usage: rake generate:routes[branch_name,route1,route2:method]"
|
|
138
|
-
exit 1
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
must_generate_views = Dir.exist?(File.expand_path("./app/views", __dir__))
|
|
142
|
-
ensure_and_get_path = proc do |path|
|
|
143
|
-
base_path = File.expand_path(path, __dir__)
|
|
144
|
-
full_path_dir = File.join(base_path, File.dirname(branch_name))
|
|
145
|
-
FileUtils.mkdir_p(full_path_dir) unless File.directory?(full_path_dir)
|
|
146
|
-
|
|
147
|
-
base_path
|
|
148
|
-
end
|
|
149
|
-
parse_route_string = proc do |route_str|
|
|
150
|
-
name, method = route_str.split(":", 2)
|
|
151
|
-
method ||= "get"
|
|
152
|
-
[method, name]
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
# Generate routes
|
|
156
|
-
filename = File.join(ensure_and_get_path.call("./app/routes"), "#{branch_name}.rb")
|
|
157
|
-
route_definitions = routes_list.map do |route_str|
|
|
158
|
-
method, name = parse_route_string.call(route_str)
|
|
159
|
-
view_line = (method == "get" && must_generate_views) ? "\n view('#{name}')" : ""
|
|
160
|
-
" r.#{method} \"#{name}\" do#{view_line}\n end"
|
|
161
|
-
end.join("\n\n")
|
|
162
|
-
|
|
163
|
-
content = <<~RUBY
|
|
164
|
-
class <%= context.const_project_name %>
|
|
165
|
-
hash_branch "#{branch_name}" do |r|
|
|
166
|
-
#{route_definitions}
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
RUBY
|
|
170
|
-
File.write(filename, content)
|
|
171
|
-
puts "Created routes file: #{filename}"
|
|
172
|
-
|
|
173
|
-
# Generate views
|
|
174
|
-
if must_generate_views
|
|
175
|
-
branch_views_dir = File.join(File.expand_path("./app/views", __dir__), branch_name)
|
|
176
|
-
FileUtils.mkdir_p(branch_views_dir)
|
|
177
|
-
routes_list.each do |route_str|
|
|
178
|
-
method, name = parse_route_string.call(route_str)
|
|
179
|
-
if method == "get"
|
|
180
|
-
view_filename = File.join(branch_views_dir, "#{name}.erb")
|
|
181
|
-
File.write(view_filename, "")
|
|
182
|
-
puts "Created view file: #{view_filename}"
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
# Generate tests
|
|
188
|
-
test_filename = File.join(ensure_and_get_path.call("./spec/app/routes"), "#{branch_name}_spec.rb")
|
|
189
|
-
nesting_level = branch_name.count("/")
|
|
190
|
-
relative_spec_helper_path = "../" * (2 + nesting_level) + "spec_helper"
|
|
191
|
-
|
|
192
|
-
test_route_definitions = routes_list.map do |route_str|
|
|
193
|
-
method, name = parse_route_string.call(route_str)
|
|
194
|
-
" it \"responds to #{method.upcase} /#{branch_name}/#{name}\" do\n" \
|
|
195
|
-
" #{method} \"/#{branch_name}/#{name}\"\n" \
|
|
196
|
-
" expect(last_response.status).to eq(200)\n" \
|
|
197
|
-
" end"
|
|
198
|
-
end.join("\n")
|
|
199
|
-
|
|
200
|
-
test_content = <<~RUBY
|
|
201
|
-
require_relative "#{relative_spec_helper_path}"
|
|
202
|
-
|
|
203
|
-
describe "Routes for #{branch_name}" do
|
|
204
|
-
#{test_route_definitions}
|
|
205
|
-
end
|
|
206
|
-
RUBY
|
|
207
|
-
File.write(test_filename, test_content)
|
|
208
|
-
puts "Created test file: #{test_filename}"
|
|
209
|
-
end
|
|
210
|
-
end
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
module Views
|
|
2
|
-
class Html
|
|
3
|
-
include HtmlSlice
|
|
4
|
-
|
|
5
|
-
# for more component classes
|
|
6
|
-
attr_reader :foo
|
|
7
|
-
|
|
8
|
-
def initialize(t)
|
|
9
|
-
@t = t
|
|
10
|
-
@foo = Views::Foo::Html.new
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def js_entrypoint_tag(entrypoint)
|
|
14
|
-
if Config.not_production?
|
|
15
|
-
"<script src=\"/public/assets/#{entrypoint}.js\" defer></script>"
|
|
16
|
-
else
|
|
17
|
-
"<script src=\"#{Config.get[:assets][:host]}/#{Config.get[:assets][:manifest]["#{entrypoint}.js"]}\" defer></script>"
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def css_entrypoint_tag(entrypoint)
|
|
22
|
-
if Config.not_production?
|
|
23
|
-
"<link rel=\"stylesheet\" href=\"/public/assets/#{entrypoint}.css\" />"
|
|
24
|
-
else
|
|
25
|
-
"<link rel=\"stylesheet\" href=\"#{Config.get[:assets][:host]}/#{Config.get[:assets][:manifest]["#{entrypoint}.css"]}\" />"
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def navbar
|
|
30
|
-
html_slice do
|
|
31
|
-
div class: "navbar" do
|
|
32
|
-
a "home", href: "/"
|
|
33
|
-
a "foo/bar", href: "/foo/bar"
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
<head>
|
|
3
|
-
<meta charset='utf-8' />
|
|
4
|
-
|
|
5
|
-
<%= html.css_entrypoint_tag(:app) %>
|
|
6
|
-
<%= html.js_entrypoint_tag(:app) %>
|
|
7
|
-
</head>
|
|
8
|
-
<body>
|
|
9
|
-
<img src='/public/images/roda-project.png' />
|
|
10
|
-
<br>
|
|
11
|
-
<%= html.navbar %>
|
|
12
|
-
|
|
13
|
-
<%= yield %>
|
|
14
|
-
</body>
|
|
15
|
-
</html>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/data/lib/roda/{templates → project/templates}/base/scaffold/app/config/locales/foo/pt-br.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/data/lib/roda/{templates → project/templates}/tests/minimal/minitest/spec/spec_helper.rb.erb
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/data/lib/roda/{templates → project/templates}/tests/minitest/spec/app/routes/test_branch_spec.rb
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/data/lib/roda/{templates → project/templates}/tests/rspec/spec/app/routes/test_branch_spec.rb
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|