roda-project 0.1.17 → 0.1.19
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/generators/routes/inertia_path.rb +45 -0
- data/lib/roda/project/bin/generators/routes/inertia_view_builder.rb +53 -0
- data/lib/roda/project/bin/generators/routes/namespace.rb +23 -0
- data/lib/roda/project/bin/generators/routes/nested_branch_file_builder.rb +38 -0
- data/lib/roda/project/bin/generators/routes/route.rb +38 -0
- data/lib/roda/project/bin/generators/routes/route_spec_builder.rb +50 -0
- data/lib/roda/project/bin/generators/routes/routes_file_builder.rb +64 -0
- data/lib/roda/project/bin/generators/routes.rb +73 -121
- data/lib/roda/project/bin/generators.rb +1 -0
- data/lib/roda/project/cli.rb +25 -12
- data/lib/roda/project/helpers/ids.rb +9 -0
- data/lib/roda/project/helpers/inflections.rb +2 -2
- data/lib/roda/project/main_context.rb +27 -5
- data/lib/roda/project/templates/base/app/app.rb.erb +11 -2
- data/lib/roda/project/templates/{base/scaffold → base-scaffold}/AGENTS.md.erb +14 -7
- data/lib/roda/project/templates/{base/scaffold → base-scaffold}/Gemfile.erb +3 -2
- data/lib/roda/project/templates/front-end-inertia/app/assets/css/app.css +20 -0
- data/lib/roda/project/templates/front-end-inertia/app/assets/js/app.js +11 -0
- data/lib/roda/project/templates/front-end-inertia/app/assets/js/inertia/components/Layout.jsx +11 -0
- data/lib/roda/project/templates/front-end-inertia/app/assets/js/inertia/views/Index.jsx +13 -0
- data/lib/roda/project/templates/front-end-inertia/app/config/locales/en.yml +273 -0
- data/lib/roda/project/templates/front-end-inertia/app/config/locales/foo/en.yml +2 -0
- data/lib/roda/project/templates/front-end-inertia/app/config/locales/foo/pt-br.yml +2 -0
- data/lib/roda/project/templates/front-end-inertia/app/config/locales/pt-br.yml +244 -0
- data/lib/roda/project/templates/front-end-inertia/app/views/foo/bar.erb +1 -0
- data/lib/roda/project/templates/front-end-inertia/app/views/index.erb +1 -0
- data/lib/roda/project/templates/front-end-inertia/app/views/layout.erb +23 -0
- data/lib/roda/project/templates/front-end-inertia/babel.config.js +6 -0
- data/lib/roda/project/templates/front-end-inertia/esbuild.js +53 -0
- data/lib/roda/project/templates/front-end-inertia/jest.config.js +10 -0
- data/lib/roda/project/templates/front-end-inertia/jest.inertia-mock.js +11 -0
- data/lib/roda/project/templates/front-end-inertia/jest.setup.js +1 -0
- data/lib/roda/project/templates/front-end-inertia/package.json +32 -0
- data/lib/roda/project/templates/front-end-inertia/public/assets/app.css +1 -0
- data/lib/roda/project/templates/front-end-inertia/public/images/roda-project.png +0 -0
- data/lib/roda/project/templates/{tests/rspec → tests-rspec}/spec/app/app_spec.rb.erb +1 -1
- data/lib/roda/project/templates/tests-rspec/spec/app/views/html_spec.rb +0 -0
- data/lib/roda/project/version.rb +1 -1
- data/lib/roda/project.rb +10 -0
- metadata +64 -38
- data/lib/roda/project/templates/front-end/app/assets/js/some/foo.js +0 -5
- /data/lib/roda/project/templates/{base/minimal → base-minimal}/AGENTS.md +0 -0
- /data/lib/roda/project/templates/{base/minimal → base-minimal}/Gemfile.erb +0 -0
- /data/lib/roda/project/templates/{base/minimal → base-minimal}/Gemfile.lock +0 -0
- /data/lib/roda/project/templates/{base/minimal → base-minimal}/Guardfile +0 -0
- /data/lib/roda/project/templates/{base/minimal → base-minimal}/README.md +0 -0
- /data/lib/roda/project/templates/{base/minimal → base-minimal}/app.rb +0 -0
- /data/lib/roda/project/templates/{base/minimal → base-minimal}/bin/roda.erb +0 -0
- /data/lib/roda/project/templates/{base/minimal → base-minimal}/boot.rb +0 -0
- /data/lib/roda/project/templates/{base/minimal → base-minimal}/config.ru +0 -0
- /data/lib/roda/project/templates/{base/minimal → base-minimal}/public/exception_page.css +0 -0
- /data/lib/roda/project/templates/{base/scaffold → base-scaffold}/Guardfile +0 -0
- /data/lib/roda/project/templates/{base/scaffold → base-scaffold}/README.md +0 -0
- /data/lib/roda/project/templates/{base/scaffold → base-scaffold}/app/config/config.rb.erb +0 -0
- /data/lib/roda/project/templates/{base/scaffold → base-scaffold}/app/config/providers/logger.rb +0 -0
- /data/lib/roda/project/templates/{base/scaffold → base-scaffold}/app/config/providers/mailer.rb +0 -0
- /data/lib/roda/project/templates/{base/scaffold → base-scaffold}/app/routes/foo.rb.erb +0 -0
- /data/lib/roda/project/templates/{base/scaffold → base-scaffold}/bin/roda.erb +0 -0
- /data/lib/roda/project/templates/{base/scaffold → base-scaffold}/boot.rb.erb +0 -0
- /data/lib/roda/project/templates/{base/scaffold → base-scaffold}/config.ru.erb +0 -0
- /data/lib/roda/project/templates/{base/scaffold → base-scaffold}/public/exception_page.css +0 -0
- /data/lib/roda/project/templates/{tests/minitest/spec/app/views/html_spec.rb → front-end-inertia/public/assets/app.js} +0 -0
- /data/lib/roda/project/templates/{tests/minimal/minitest → tests-minimal-minitest}/spec/app_spec.rb +0 -0
- /data/lib/roda/project/templates/{tests/minimal/minitest → tests-minimal-minitest}/spec/spec_helper.rb.erb +0 -0
- /data/lib/roda/project/templates/{tests/minimal/rspec → tests-minimal-rspec}/spec/app_spec.rb +0 -0
- /data/lib/roda/project/templates/{tests/minimal/rspec → tests-minimal-rspec}/spec/spec_helper.rb +0 -0
- /data/lib/roda/project/templates/{tests/minitest → tests-minitest}/spec/app/app_spec.rb.erb +0 -0
- /data/lib/roda/project/templates/{tests/minitest → tests-minitest}/spec/app/routes/foo_spec.rb.erb +0 -0
- /data/lib/roda/project/templates/{tests/minitest → tests-minitest}/spec/app/routes/test_branch_spec.rb +0 -0
- /data/lib/roda/project/templates/{tests/rspec → tests-minitest}/spec/app/views/html_spec.rb +0 -0
- /data/lib/roda/project/templates/{tests/minitest → tests-minitest}/spec/spec_helper.rb.erb +0 -0
- /data/lib/roda/project/templates/{tests/rspec → tests-rspec}/spec/app/routes/foo_spec.rb.erb +0 -0
- /data/lib/roda/project/templates/{tests/rspec → tests-rspec}/spec/app/routes/test_branch_spec.rb +0 -0
- /data/lib/roda/project/templates/{tests/rspec → tests-rspec}/spec/spec_helper.rb.erb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 84a58b65b141c3d2088c07052ff66b90a020e4eec2318ae616152e0a180faad9
|
|
4
|
+
data.tar.gz: 8d0e6f6081add8077fcdbdadc7a03224073b1b846c685d0cd33238e899f0577f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 395ba486f899a3bae89797950575c5fd814c23c15ebe7764f4dafb8bfaf487c47893b4a97fcfcfb5870ea1eb7d5b8f472b23752831d7392826940e9f5f4f8c07
|
|
7
|
+
data.tar.gz: 0ffaf1e80285e5a95ebeac8a90d5b700a0ce147d80f2d524e08d66aa7699726f37b82e580c8e1622598c2e53ff252580cde5f9fba2f4e942e0af9f626b6e6ed1
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Roda
|
|
4
|
+
module Project
|
|
5
|
+
module Bin
|
|
6
|
+
class Generators
|
|
7
|
+
class Routes
|
|
8
|
+
class InertiaPath
|
|
9
|
+
attr_reader :view_path, :component_name, :display_path, :layout_import_path
|
|
10
|
+
|
|
11
|
+
def initialize(branch_name, name)
|
|
12
|
+
@view_path = build_view_path(branch_name, name)
|
|
13
|
+
@component_name = build_component_name(name)
|
|
14
|
+
@display_path = build_display_path(branch_name, name)
|
|
15
|
+
@layout_import_path = build_layout_import_path
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def build_layout_import_path
|
|
21
|
+
prefix = "../" * (view_path.count("/") + 1)
|
|
22
|
+
"#{prefix}components/Layout"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def build_view_path(branch_name, name)
|
|
26
|
+
segments = branch_name.split("/")
|
|
27
|
+
segments << (name || DEFAULT_VIEW_NAME)
|
|
28
|
+
(segments[0..-2] + [segments.last.capitalize]).join("/")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def build_component_name(name)
|
|
32
|
+
(name || DEFAULT_VIEW_NAME).capitalize
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def build_display_path(branch_name, name)
|
|
36
|
+
segments = branch_name.split("/")
|
|
37
|
+
segments << (name || DEFAULT_VIEW_NAME)
|
|
38
|
+
segments.join("/")
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Roda
|
|
4
|
+
module Project
|
|
5
|
+
module Bin
|
|
6
|
+
class Generators
|
|
7
|
+
class Routes
|
|
8
|
+
class InertiaViewBuilder
|
|
9
|
+
def initialize(path)
|
|
10
|
+
@path = path
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def component_content
|
|
14
|
+
<<~JSX
|
|
15
|
+
import React from 'react'
|
|
16
|
+
import { Link } from '@inertiajs/react'
|
|
17
|
+
import Layout from '#{@path.layout_import_path}'
|
|
18
|
+
|
|
19
|
+
const #{@path.component_name} = props => {
|
|
20
|
+
return (<Layout>
|
|
21
|
+
<div>
|
|
22
|
+
#{@path.display_path}
|
|
23
|
+
</div>
|
|
24
|
+
</Layout>)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default #{@path.component_name}
|
|
28
|
+
JSX
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_content
|
|
32
|
+
<<~JS
|
|
33
|
+
import React from 'react'
|
|
34
|
+
import { render, screen } from '@testing-library/react'
|
|
35
|
+
import #{@path.component_name} from './#{@path.component_name}'
|
|
36
|
+
|
|
37
|
+
describe('#{@path.component_name}', () => {
|
|
38
|
+
it('renders', () => {
|
|
39
|
+
render(<#{@path.component_name} />)
|
|
40
|
+
|
|
41
|
+
expect(
|
|
42
|
+
screen.getByText('#{@path.display_path}')
|
|
43
|
+
).toBeInTheDocument()
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
JS
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Roda
|
|
4
|
+
module Project
|
|
5
|
+
module Bin
|
|
6
|
+
class Generators
|
|
7
|
+
class Routes
|
|
8
|
+
module Namespace
|
|
9
|
+
module_function
|
|
10
|
+
|
|
11
|
+
def for_path(sub_path)
|
|
12
|
+
sub_path.include?("/") ? ":\"#{sub_path}\"" : ":#{sub_path}"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def hash_branches_line(sub_path)
|
|
16
|
+
"r.hash_branches(#{for_path(sub_path)})"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Roda
|
|
4
|
+
module Project
|
|
5
|
+
module Bin
|
|
6
|
+
class Generators
|
|
7
|
+
class Routes
|
|
8
|
+
class NestedBranchFileBuilder
|
|
9
|
+
def initialize(project_name:, prefix:)
|
|
10
|
+
@project_name = project_name
|
|
11
|
+
@prefix = prefix
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def content
|
|
15
|
+
<<~RUBY
|
|
16
|
+
class #{@project_name}
|
|
17
|
+
#{header} # #{@prefix} branch
|
|
18
|
+
r.hash_branches(#{Namespace.for_path(@prefix)}) # #{@prefix}/ +1 routes
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
RUBY
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def header
|
|
27
|
+
return "hash_branch \"#{@prefix}\" do |r|" unless @prefix.include?("/")
|
|
28
|
+
|
|
29
|
+
parts = @prefix.split("/")
|
|
30
|
+
parent_path = parts[0..-2].join("/")
|
|
31
|
+
"hash_branch #{Namespace.for_path(parent_path)}, \"#{parts.last}\" do |r|"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Roda
|
|
4
|
+
module Project
|
|
5
|
+
module Bin
|
|
6
|
+
class Generators
|
|
7
|
+
class Routes
|
|
8
|
+
class Route
|
|
9
|
+
VALID_METHODS = %w[get post delete put patch].freeze
|
|
10
|
+
|
|
11
|
+
attr_reader :method, :name
|
|
12
|
+
|
|
13
|
+
def self.parse(route_str)
|
|
14
|
+
method, name = route_str.split(":", 2)
|
|
15
|
+
|
|
16
|
+
if name && VALID_METHODS.include?(method)
|
|
17
|
+
new(method, name)
|
|
18
|
+
elsif name.nil? && VALID_METHODS.include?(route_str)
|
|
19
|
+
new(route_str, nil)
|
|
20
|
+
else
|
|
21
|
+
new("get", route_str)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def initialize(method, name)
|
|
26
|
+
@method = method
|
|
27
|
+
@name = name
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def get?
|
|
31
|
+
method == "get"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Roda
|
|
4
|
+
module Project
|
|
5
|
+
module Bin
|
|
6
|
+
class Generators
|
|
7
|
+
class Routes
|
|
8
|
+
class RouteSpecBuilder
|
|
9
|
+
def initialize(branch_name:, routes:)
|
|
10
|
+
@branch_name = branch_name
|
|
11
|
+
@routes = routes
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def content
|
|
15
|
+
[
|
|
16
|
+
"require_relative \"#{relative_spec_helper_path}\"",
|
|
17
|
+
"",
|
|
18
|
+
"describe \"Routes for #{@branch_name}\" do",
|
|
19
|
+
test_definitions,
|
|
20
|
+
"end",
|
|
21
|
+
""
|
|
22
|
+
].join("\n")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def test_definitions
|
|
28
|
+
@routes.map { |route| build_test_definition(route) }.join("\n")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def build_test_definition(route)
|
|
32
|
+
test_name = route.name ? " /#{@branch_name}/#{route.name}" : " /#{@branch_name}"
|
|
33
|
+
test_path = route.name ? " \"/#{@branch_name}/#{route.name}\"" : " \"/#{@branch_name}\""
|
|
34
|
+
|
|
35
|
+
" it \"responds to #{route.method.upcase}#{test_name}\" do\n" \
|
|
36
|
+
" #{route.method}#{test_path}\n" \
|
|
37
|
+
" expect(last_response.status).to eq(200)\n" \
|
|
38
|
+
" end"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def relative_spec_helper_path
|
|
42
|
+
prefix = "../" * (2 + @branch_name.count("/"))
|
|
43
|
+
"#{prefix}spec_helper"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Roda
|
|
4
|
+
module Project
|
|
5
|
+
module Bin
|
|
6
|
+
class Generators
|
|
7
|
+
class Routes
|
|
8
|
+
class RoutesFileBuilder
|
|
9
|
+
def initialize(project_name:, branch_name:, routes:, view_mode:)
|
|
10
|
+
@project_name = project_name
|
|
11
|
+
@branch_name = branch_name
|
|
12
|
+
@routes = routes
|
|
13
|
+
@view_mode = view_mode
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def content
|
|
17
|
+
<<~RUBY
|
|
18
|
+
class #{@project_name}
|
|
19
|
+
#{branch_header}
|
|
20
|
+
#{route_definitions}
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
RUBY
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def route_definitions
|
|
29
|
+
@routes.map { |route| build_route_definition(route) }.join("\n\n")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def build_route_definition(route)
|
|
33
|
+
view_line = build_view_line(route)
|
|
34
|
+
route_block(route, view_line)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def build_view_line(route)
|
|
38
|
+
return "" unless route.get? && @view_mode != :none
|
|
39
|
+
|
|
40
|
+
if @view_mode == :inertia
|
|
41
|
+
"\n inertia('#{InertiaPath.new(@branch_name, route.name).view_path}')"
|
|
42
|
+
else
|
|
43
|
+
"\n view('#{route.name || DEFAULT_VIEW_NAME}')"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def route_block(route, view_line)
|
|
48
|
+
route_name = route.name ? " \"#{route.name}\"" : ""
|
|
49
|
+
" r.#{route.method}#{route_name} do#{view_line}\n end"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def branch_header
|
|
53
|
+
return "hash_branch \"#{@branch_name}\" do |r|" unless @branch_name.include?("/")
|
|
54
|
+
|
|
55
|
+
parts = @branch_name.split("/")
|
|
56
|
+
sub_path = parts[0..-2].join("/")
|
|
57
|
+
"hash_branch #{Namespace.for_path(sub_path)}, \"#{parts.last}\" do |r|"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
class Roda
|
|
3
4
|
module Project
|
|
4
5
|
module Bin
|
|
5
6
|
class Generators < ::Thor
|
|
6
7
|
class Routes < Roda::Project::Bin::Generator
|
|
8
|
+
DEFAULT_VIEW_NAME = "index"
|
|
9
|
+
|
|
7
10
|
def call
|
|
8
11
|
if branch_name.nil? || branch_name.empty? || routes_list.nil? || routes_list.empty?
|
|
9
|
-
puts "Usage: bin/roda g routes branch_name route1 route2
|
|
12
|
+
puts "Usage: bin/roda g routes branch_name route1 method:route2"
|
|
10
13
|
exit 1
|
|
11
14
|
end
|
|
12
15
|
|
|
@@ -15,163 +18,112 @@ class Roda
|
|
|
15
18
|
generate_nested_branch_files
|
|
16
19
|
generate_views
|
|
17
20
|
generate_tests
|
|
21
|
+
generate_inertia_view_tests
|
|
18
22
|
end
|
|
19
23
|
|
|
20
24
|
private
|
|
21
25
|
|
|
22
26
|
def generate_routes
|
|
23
27
|
filename = File.join(ensure_and_get_path("app/routes", branch_name), "#{branch_name}.rb")
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
parts = branch_name.split("/")
|
|
39
|
-
sub_path = parts[0..-2].join("/")
|
|
40
|
-
branch_segment = parts.last
|
|
41
|
-
"hash_branch #{namespace_for(sub_path)}, \"#{branch_segment}\" do |r|"
|
|
28
|
+
write_file(filename, routes_file_content)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def generate_nested_branch_files
|
|
32
|
+
return unless branch_name.include?("/")
|
|
33
|
+
|
|
34
|
+
branch_prefixes.each { |prefix| generate_nested_branch_file(prefix) }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def generate_nested_branch_file(prefix)
|
|
38
|
+
filename = File.join("app/routes", "#{prefix}.rb")
|
|
39
|
+
|
|
40
|
+
if File.exist?(filename)
|
|
41
|
+
ensure_hash_branches_line(filename, prefix)
|
|
42
42
|
else
|
|
43
|
-
|
|
43
|
+
FileUtils.mkdir_p(File.dirname(filename))
|
|
44
|
+
write_file(filename, NestedBranchFileBuilder.new(project_name:, prefix:).content)
|
|
44
45
|
end
|
|
45
|
-
|
|
46
|
-
content = <<~RUBY
|
|
47
|
-
class #{@context.const_project_name}
|
|
48
|
-
#{hash_branch_header}
|
|
49
|
-
#{route_definitions}
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
RUBY
|
|
53
|
-
File.write(filename, content)
|
|
54
|
-
action_success_message(filename)
|
|
55
46
|
end
|
|
56
47
|
|
|
57
48
|
def generate_views
|
|
58
|
-
if
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
end
|
|
49
|
+
generate_inertia_views if view_mode == :inertia
|
|
50
|
+
generate_erb_views if view_mode == :erb
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def generate_erb_views
|
|
54
|
+
dir = File.join("app/views", branch_name)
|
|
55
|
+
FileUtils.mkdir_p(dir)
|
|
56
|
+
view_routes.each { |route| write_file(File.join(dir, "#{route.name || DEFAULT_VIEW_NAME}.erb"), "") }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def generate_inertia_views
|
|
60
|
+
write_inertia_files(".jsx", &:component_content)
|
|
71
61
|
end
|
|
72
62
|
|
|
73
63
|
def generate_tests
|
|
74
64
|
test_filename = File.join(ensure_and_get_path("spec/app/routes", branch_name), "#{branch_name}_spec.rb")
|
|
75
|
-
|
|
76
|
-
relative_spec_helper_path = "../" * (2 + nesting_level) + "spec_helper"
|
|
77
|
-
|
|
78
|
-
test_route_definitions = routes_list.map do |route_str|
|
|
79
|
-
method, name = parse_route_string(route_str)
|
|
80
|
-
|
|
81
|
-
if name != nil
|
|
82
|
-
" it \"responds to #{method.upcase} /#{branch_name}/#{name}\" do\n" \
|
|
83
|
-
" #{method} \"/#{branch_name}/#{name}\"\n" \
|
|
84
|
-
" expect(last_response.status).to eq(200)\n" \
|
|
85
|
-
" end"
|
|
86
|
-
else
|
|
87
|
-
" it \"responds to #{method.upcase} /#{branch_name}\" do\n" \
|
|
88
|
-
" #{method} \"/#{branch_name}\"\n" \
|
|
89
|
-
" expect(last_response.status).to eq(200)\n" \
|
|
90
|
-
" end"
|
|
91
|
-
end
|
|
92
|
-
end.join("\n")
|
|
93
|
-
|
|
94
|
-
test_content = <<~RUBY
|
|
95
|
-
require_relative "#{relative_spec_helper_path}"
|
|
96
|
-
|
|
97
|
-
describe "Routes for #{branch_name}" do
|
|
98
|
-
#{test_route_definitions}
|
|
99
|
-
end
|
|
100
|
-
RUBY
|
|
101
|
-
File.write(test_filename, test_content)
|
|
102
|
-
action_success_message(test_filename)
|
|
65
|
+
write_file(test_filename, RouteSpecBuilder.new(branch_name:, routes:).content)
|
|
103
66
|
end
|
|
104
67
|
|
|
105
|
-
def
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
parts = branch_name.split("/")
|
|
109
|
-
parts[0..-2].each_with_index do |_segment, index|
|
|
110
|
-
prefix = parts[0..index].join("/")
|
|
111
|
-
filename = File.join("app/routes", "#{prefix}.rb")
|
|
112
|
-
|
|
113
|
-
if File.exist?(filename)
|
|
114
|
-
ensure_hash_branches_line(filename, namespace_for(prefix))
|
|
115
|
-
next
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
dir = File.dirname(filename)
|
|
119
|
-
FileUtils.mkdir_p(dir) unless File.directory?(dir)
|
|
120
|
-
File.write(filename, nested_branch_file_content(prefix, index))
|
|
121
|
-
action_success_message(filename)
|
|
122
|
-
end
|
|
68
|
+
def generate_inertia_view_tests
|
|
69
|
+
write_inertia_files(".test.js", &:test_content) if view_mode == :inertia
|
|
123
70
|
end
|
|
124
71
|
|
|
125
|
-
def
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
72
|
+
def write_inertia_files(extension)
|
|
73
|
+
views_dir = "app/assets/js/inertia/views"
|
|
74
|
+
FileUtils.mkdir_p(views_dir)
|
|
75
|
+
view_routes.each do |route|
|
|
76
|
+
path = InertiaPath.new(branch_name, route.name)
|
|
77
|
+
filename = File.join(views_dir, "#{path.view_path}#{extension}")
|
|
78
|
+
FileUtils.mkdir_p(File.dirname(filename))
|
|
79
|
+
write_file(filename, yield(InertiaViewBuilder.new(path)))
|
|
133
80
|
end
|
|
81
|
+
end
|
|
134
82
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
#{header} # #{prefix} branch
|
|
138
|
-
r.hash_branches(#{namespace_for(prefix)}) # #{prefix}/ +1 routes
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
RUBY
|
|
83
|
+
def routes_file_content
|
|
84
|
+
RoutesFileBuilder.new(project_name:, branch_name:, routes:, view_mode:).content
|
|
142
85
|
end
|
|
143
86
|
|
|
144
|
-
def ensure_hash_branches_line(filename,
|
|
145
|
-
expected_line =
|
|
87
|
+
def ensure_hash_branches_line(filename, prefix)
|
|
88
|
+
expected_line = Namespace.hash_branches_line(prefix)
|
|
146
89
|
return if File.read(filename).include?(expected_line)
|
|
147
90
|
|
|
148
91
|
puts " warning: #{filename} already exists — please add:"
|
|
149
92
|
puts " #{expected_line}"
|
|
150
93
|
end
|
|
151
94
|
|
|
152
|
-
def
|
|
153
|
-
|
|
95
|
+
def branch_prefixes
|
|
96
|
+
parts = branch_name.split("/")
|
|
97
|
+
(0...parts.length - 1).map { |index| parts[0..index].join("/") }
|
|
154
98
|
end
|
|
155
99
|
|
|
156
|
-
def
|
|
157
|
-
@options[:views] && Dir.exist?("app/views")
|
|
158
|
-
end
|
|
100
|
+
def view_mode = @view_mode ||= compute_view_mode
|
|
159
101
|
|
|
160
|
-
def
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
102
|
+
def compute_view_mode
|
|
103
|
+
return :none unless @options[:views]
|
|
104
|
+
|
|
105
|
+
views_exist = @context.inertia? ? Dir.exist?("app/assets/js/inertia/views") : Dir.exist?("app/views")
|
|
106
|
+
return :none unless views_exist
|
|
164
107
|
|
|
165
|
-
|
|
166
|
-
@routes_list ||= @args[1..]
|
|
108
|
+
@context.inertia? ? :inertia : :erb
|
|
167
109
|
end
|
|
168
110
|
|
|
169
|
-
def
|
|
170
|
-
|
|
111
|
+
def routes = @routes ||= routes_list.map { |route_str| Route.parse(route_str) }
|
|
112
|
+
|
|
113
|
+
def view_routes = @view_routes ||= routes.select(&:get?)
|
|
114
|
+
|
|
115
|
+
def project_name = @context.const_project_name
|
|
116
|
+
|
|
117
|
+
def write_file(filename, content)
|
|
118
|
+
File.write(filename, content)
|
|
119
|
+
action_success_message(filename)
|
|
171
120
|
end
|
|
121
|
+
|
|
122
|
+
def routes_list = @routes_list ||= @args[1..]
|
|
123
|
+
|
|
124
|
+
def branch_name = @branch_name ||= @args[0]
|
|
172
125
|
end
|
|
173
126
|
end
|
|
174
127
|
end
|
|
175
128
|
end
|
|
176
129
|
end
|
|
177
|
-
# rubocop:enable Layout/HeredocIndentation
|
|
@@ -37,6 +37,7 @@ class Roda
|
|
|
37
37
|
@context = Roda::Project::MainContext.new
|
|
38
38
|
@context.project_name = options[:main_context][:project_name]
|
|
39
39
|
@context.base = options[:main_context][:base]
|
|
40
|
+
@context.frontend = options[:main_context][:frontend]
|
|
40
41
|
@context.database = options[:main_context][:database]
|
|
41
42
|
@context.database_type = options[:main_context][:database_type]
|
|
42
43
|
@context.rodauth = options[:main_context][:rodauth]
|
data/lib/roda/project/cli.rb
CHANGED
|
@@ -49,6 +49,10 @@ class Roda
|
|
|
49
49
|
return if jeremy?
|
|
50
50
|
|
|
51
51
|
retry_on_error { @context.base = read_line("(#{fullstack_id}) Fullstack (#{api_id}) API (#{minimal_id}) Minimal › ", fullstack_id).to_i }
|
|
52
|
+
if @context.fullstack?
|
|
53
|
+
retry_on_error { @context.frontend = read_line("(#{erb_id}) Only ERB (#{inertia_id}) Inertia.js › ", erb_id).to_i }
|
|
54
|
+
end
|
|
55
|
+
|
|
52
56
|
retry_on_error { @context.tests = read_line("(#{rspec_id}) RSpec (#{minitest_id}) Minitest › ", rspec_id).to_i }
|
|
53
57
|
|
|
54
58
|
unless @context.minimal?
|
|
@@ -75,7 +79,7 @@ class Roda
|
|
|
75
79
|
puts "* creating base project"
|
|
76
80
|
if @context.minimal?
|
|
77
81
|
TTY::File.copy_directory(
|
|
78
|
-
File.expand_path("templates/base
|
|
82
|
+
File.expand_path("templates/base-minimal", __dir__),
|
|
79
83
|
"#{@dir}#{@context.project_name}",
|
|
80
84
|
context: @context
|
|
81
85
|
)
|
|
@@ -84,7 +88,7 @@ class Roda
|
|
|
84
88
|
end
|
|
85
89
|
|
|
86
90
|
TTY::File.copy_directory(
|
|
87
|
-
File.expand_path("templates/base
|
|
91
|
+
File.expand_path("templates/base-scaffold", __dir__),
|
|
88
92
|
"#{@dir}#{@context.project_name}",
|
|
89
93
|
context: @context
|
|
90
94
|
)
|
|
@@ -101,16 +105,25 @@ class Roda
|
|
|
101
105
|
def add_front_end
|
|
102
106
|
if @context.fullstack?
|
|
103
107
|
puts "* adding front-end"
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
from_template = "front-end"
|
|
109
|
+
from_template = "front-end-inertia" if @context.inertia?
|
|
110
|
+
|
|
111
|
+
erb_cp_dir(from_template, "app/assets")
|
|
112
|
+
erb_cp_file(from_template, "esbuild.js")
|
|
113
|
+
erb_cp_file(from_template, "package.json")
|
|
114
|
+
if @context.inertia?
|
|
115
|
+
erb_cp_file(from_template, "babel.config.js")
|
|
116
|
+
erb_cp_file(from_template, "jest.config.js")
|
|
117
|
+
erb_cp_file(from_template, "jest.setup.js")
|
|
118
|
+
erb_cp_file(from_template, "jest.inertia-mock.js")
|
|
119
|
+
end
|
|
120
|
+
cp_dir(from_template, "app/config/locales")
|
|
108
121
|
action_success_message("app/config/locales")
|
|
109
|
-
cp_dir(
|
|
122
|
+
cp_dir(from_template, "app/views")
|
|
110
123
|
action_success_message("app/views")
|
|
111
|
-
cp_dir(
|
|
124
|
+
cp_dir(from_template, "public/assets")
|
|
112
125
|
action_success_message("public/assets")
|
|
113
|
-
cp_dir(
|
|
126
|
+
cp_dir(from_template, "public/images")
|
|
114
127
|
action_success_message("public/images")
|
|
115
128
|
end
|
|
116
129
|
end
|
|
@@ -138,12 +151,12 @@ class Roda
|
|
|
138
151
|
|
|
139
152
|
def add_test_files
|
|
140
153
|
puts "* adding test files"
|
|
141
|
-
minimal_dir = @context.minimal? ? "minimal
|
|
154
|
+
minimal_dir = @context.minimal? ? "minimal-" : ""
|
|
142
155
|
|
|
143
156
|
if @context.rspec?
|
|
144
|
-
erb_cp_dir("tests
|
|
157
|
+
erb_cp_dir("tests-#{minimal_dir}rspec", "spec")
|
|
145
158
|
else
|
|
146
|
-
erb_cp_dir("tests
|
|
159
|
+
erb_cp_dir("tests-#{minimal_dir}minitest", "spec")
|
|
147
160
|
end
|
|
148
161
|
end
|
|
149
162
|
end
|