roda-project 0.1.5 → 0.1.7

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