roda-project 0.1.10 → 0.1.11
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/migration/action_detector.rb +7 -7
- data/lib/roda/project/bin/generators/migration/code_builder.rb +7 -7
- data/lib/roda/project/bin/generators/migration/field_parser.rb +3 -25
- data/lib/roda/project/bin/generators/migration.rb +7 -5
- data/lib/roda/project/bin/generators/model.rb +119 -0
- data/lib/roda/project/bin/generators/routes.rb +6 -12
- data/lib/roda/project/bin/generators.rb +5 -0
- data/lib/roda/project/cli.rb +4 -0
- data/lib/roda/project/generator.rb +10 -1
- data/lib/roda/project/helpers/inflections.rb +12 -4
- data/lib/roda/project/helpers/interactive_input.rb +0 -4
- data/lib/roda/project/helpers/template.rb +7 -0
- data/lib/roda/project/version.rb +1 -1
- data/lib/roda/project.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3fceab0441f37da52ca87b8c028d4fa72573854e2a1adc25f34f76ac6e7b4e2a
|
|
4
|
+
data.tar.gz: 24c9c54923283bee8394d0597206feed0d1a914cbf30caa1368bef696a2ffa3a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7aa0cc8165bd3a515e8e06a625e0621ffd9257fa276431fd1babfd2ba1f3a4fd8336dc595c4a56d41f09c18505a8809870e1369612e46c810204ad65d9511c71
|
|
7
|
+
data.tar.gz: 9cf9d5bda0e6f992d820b20ec16647df888bcf36246500669a828efac54b1c091ddf73d628a54706af50bdd9b466b027076765755e74d00aa4fee6ea05fdf06b
|
|
@@ -19,18 +19,18 @@ class Roda
|
|
|
19
19
|
camel_name = camelize(name)
|
|
20
20
|
|
|
21
21
|
if (m = camel_name.match(/^CreateJoinTable(?<t1>[A-Z][a-zA-Z0-9]*?)(?<t2>[A-Z][a-zA-Z0-9]*)$/)) ||
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
(m = camel_name.match(/JoinTable(?<t1>[A-Z][a-zA-Z0-9]*?)(?<t2>[A-Z][a-zA-Z0-9]*)$/)) ||
|
|
23
|
+
camel_name.start_with?("CreateJoinTable") || camel_name.include?("JoinTable")
|
|
24
24
|
tables = parse_join_tables(m)
|
|
25
|
-
{
|
|
25
|
+
{action: :create_join_table, tables: tables}
|
|
26
26
|
elsif (m = camel_name.match(/^Create(?<table_name>[A-Z0-9].*)$/))
|
|
27
|
-
{
|
|
27
|
+
{action: :create_table, table_name: pluralize(underscore(m[:table_name]))}
|
|
28
28
|
elsif (m = camel_name.match(/^Add.+To(?<table_name>[A-Z0-9].*)$/))
|
|
29
|
-
{
|
|
29
|
+
{action: :add_columns, table_name: pluralize(underscore(m[:table_name]))}
|
|
30
30
|
elsif (m = camel_name.match(/^Remove.+From(?<table_name>[A-Z0-9].*)$/))
|
|
31
|
-
{
|
|
31
|
+
{action: :drop_columns, table_name: pluralize(underscore(m[:table_name]))}
|
|
32
32
|
else
|
|
33
|
-
{
|
|
33
|
+
{action: :generic, table_name: nil}
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
@@ -166,13 +166,13 @@ class Roda
|
|
|
166
166
|
|
|
167
167
|
formatted = opts.map do |k, v|
|
|
168
168
|
val_str = case v
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
169
|
+
when Array
|
|
170
|
+
"[#{v.join(", ")}]"
|
|
171
|
+
when Symbol
|
|
172
|
+
":#{v}"
|
|
173
|
+
else
|
|
174
|
+
v.inspect
|
|
175
|
+
end
|
|
176
176
|
"#{k}: #{val_str}"
|
|
177
177
|
end.join(", ")
|
|
178
178
|
|
|
@@ -6,6 +6,8 @@ class Roda
|
|
|
6
6
|
class Generators
|
|
7
7
|
class Migration
|
|
8
8
|
class FieldParser
|
|
9
|
+
include Roda::Project::Helpers::Inflections
|
|
10
|
+
|
|
9
11
|
TYPE_MAP = {
|
|
10
12
|
"string" => "String",
|
|
11
13
|
"text" => "String",
|
|
@@ -80,7 +82,7 @@ class Roda
|
|
|
80
82
|
if modifier.include?(".")
|
|
81
83
|
prec, scale = modifier.split(".").map(&:to_i)
|
|
82
84
|
options[:size] = [prec, scale]
|
|
83
|
-
elsif
|
|
85
|
+
elsif /^\d+$/.match?(modifier)
|
|
84
86
|
options[:size] = modifier.to_i
|
|
85
87
|
end
|
|
86
88
|
end
|
|
@@ -119,30 +121,6 @@ class Roda
|
|
|
119
121
|
false
|
|
120
122
|
end
|
|
121
123
|
end
|
|
122
|
-
|
|
123
|
-
def singularize(str)
|
|
124
|
-
if str.end_with?("ies")
|
|
125
|
-
"#{str[0..-4]}y"
|
|
126
|
-
elsif str.end_with?("es") && !str.end_with?("ques")
|
|
127
|
-
str[0..-3]
|
|
128
|
-
elsif str.end_with?("s") && !str.end_with?("ss")
|
|
129
|
-
str[0..-2]
|
|
130
|
-
else
|
|
131
|
-
str
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def pluralize(str)
|
|
136
|
-
return str if str.end_with?("s")
|
|
137
|
-
|
|
138
|
-
if str.end_with?("y") && !str.end_with?("ay", "ey", "oy", "uy")
|
|
139
|
-
"#{str[0..-2]}ies"
|
|
140
|
-
elsif str.end_with?("s", "x", "z", "ch", "sh")
|
|
141
|
-
"#{str}es"
|
|
142
|
-
else
|
|
143
|
-
"#{str}s"
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
124
|
end
|
|
147
125
|
end
|
|
148
126
|
end
|
|
@@ -11,6 +11,7 @@ class Roda
|
|
|
11
11
|
exit 1
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
+
puts "* creating migration"
|
|
14
15
|
FileUtils.mkdir_p(migrations_path) unless File.directory?(migrations_path)
|
|
15
16
|
|
|
16
17
|
existing_migrations = Dir.glob(File.join(migrations_path, "*.rb"))
|
|
@@ -27,7 +28,8 @@ class Roda
|
|
|
27
28
|
content = CodeBuilder.new(detection: detection, fields: fields).build
|
|
28
29
|
|
|
29
30
|
File.write(filename, content)
|
|
30
|
-
|
|
31
|
+
|
|
32
|
+
puts_create_message(filename)
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
def migrations_path
|
|
@@ -39,16 +41,16 @@ class Roda
|
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
def field_args
|
|
42
|
-
@field_args ||=
|
|
44
|
+
@field_args ||= @args[1..] || []
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
private
|
|
46
48
|
|
|
47
49
|
def underscore(str)
|
|
48
50
|
str.to_s.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
|
52
|
+
.tr("-", "_")
|
|
53
|
+
.downcase
|
|
52
54
|
end
|
|
53
55
|
end
|
|
54
56
|
end
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
class Roda
|
|
2
|
+
module Project
|
|
3
|
+
module Bin
|
|
4
|
+
class Generators < ::Thor
|
|
5
|
+
class Model < Roda::Project::Bin::Generator
|
|
6
|
+
include Roda::Project::Helpers::Inflections
|
|
7
|
+
|
|
8
|
+
def call
|
|
9
|
+
if model_name.nil? || field_args == []
|
|
10
|
+
puts "Usage: bin/roda g model name field1 field2"
|
|
11
|
+
exit 1
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
puts "* creating model"
|
|
15
|
+
create_model
|
|
16
|
+
create_model_test
|
|
17
|
+
Migration.new(args: [migration_name].concat(field_args)).call
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create_model_test
|
|
21
|
+
ensure_and_get_path("spec/app/models", model_relative_path)
|
|
22
|
+
filename = File.join("spec/app/models", *name_segments[0..-2], "#{model_file_basename}_spec.rb")
|
|
23
|
+
File.write(filename, spec_code)
|
|
24
|
+
|
|
25
|
+
puts_create_message(filename)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def create_model
|
|
29
|
+
ensure_and_get_path("app/models", model_relative_path)
|
|
30
|
+
filename = File.join("app/models", *name_segments[0..-2], "#{model_file_basename}.rb")
|
|
31
|
+
File.write(filename, code)
|
|
32
|
+
|
|
33
|
+
puts_create_message(filename)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def spec_code
|
|
37
|
+
depth = 2 + name_segments.length - 1
|
|
38
|
+
relative_prefix = "../" * depth
|
|
39
|
+
<<~RUBY
|
|
40
|
+
require_relative "#{relative_prefix}spec_helper"
|
|
41
|
+
|
|
42
|
+
describe #{qualified_class_name} do
|
|
43
|
+
end
|
|
44
|
+
RUBY
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def code
|
|
48
|
+
if name_segments.length == 1
|
|
49
|
+
<<~RUBY
|
|
50
|
+
class #{qualified_class_name}
|
|
51
|
+
end
|
|
52
|
+
RUBY
|
|
53
|
+
else
|
|
54
|
+
depth = name_segments.length - 1
|
|
55
|
+
class_indent = " " * depth
|
|
56
|
+
lines = [
|
|
57
|
+
"#{class_indent}class #{camelize(name_segments.last)} < Sequel::Model(:#{table_name})",
|
|
58
|
+
"#{class_indent}end"
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
name_segments[0..-2].map { |s| camelize(s) }.reverse.each_with_index do |mod, idx|
|
|
62
|
+
mod_indent = " " * (depth - 1 - idx)
|
|
63
|
+
lines = ["#{mod_indent}class #{mod}"] + lines + ["#{mod_indent}end"]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
lines.join("\n") + "\n"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def migration_name
|
|
71
|
+
segs = name_segments.map { |s| camelize(s) }
|
|
72
|
+
segs[-1] = pluralize(segs[-1])
|
|
73
|
+
"Create" + segs.join("_")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def name_segments
|
|
77
|
+
@name_segments ||= @args[0].to_s.split("/")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def qualified_class_name
|
|
81
|
+
@qualified_class_name ||= name_segments.map { |s| camelize(s) }.join("::")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def flat_class_name
|
|
85
|
+
@flat_class_name ||= name_segments.map { |s| camelize(s) }.join
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def table_name
|
|
89
|
+
@table_name ||= begin
|
|
90
|
+
segs = name_segments.map { |s| underscore(camelize(s)) }
|
|
91
|
+
segs[-1] = pluralize(segs[-1])
|
|
92
|
+
segs.join("_")
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def model_relative_path
|
|
97
|
+
@model_relative_path ||= if name_segments.length > 1
|
|
98
|
+
File.join(*name_segments[0..-2], model_file_basename)
|
|
99
|
+
else
|
|
100
|
+
model_file_basename
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def model_file_basename
|
|
105
|
+
@model_file_basename ||= underscore(name_segments.last)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def model_name
|
|
109
|
+
@model_name ||= @args[0].nil? ? nil : qualified_class_name
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def field_args
|
|
113
|
+
@field_args ||= @args[1..] || []
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -10,6 +10,7 @@ class Roda
|
|
|
10
10
|
exit 1
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
puts "* creating routes"
|
|
13
14
|
generate_routes
|
|
14
15
|
generate_views
|
|
15
16
|
generate_tests
|
|
@@ -19,7 +20,7 @@ class Roda
|
|
|
19
20
|
private
|
|
20
21
|
|
|
21
22
|
def generate_routes
|
|
22
|
-
filename = File.join(ensure_and_get_path("app/routes"), "#{branch_name}.rb")
|
|
23
|
+
filename = File.join(ensure_and_get_path("app/routes", branch_name), "#{branch_name}.rb")
|
|
23
24
|
route_definitions = routes_list.map do |route_str|
|
|
24
25
|
method, name = parse_route_string(route_str)
|
|
25
26
|
view_line = (method == "get" && must_generate_views?) ? "\n view('#{name}')" : ""
|
|
@@ -44,7 +45,7 @@ class Roda
|
|
|
44
45
|
end
|
|
45
46
|
RUBY
|
|
46
47
|
File.write(filename, content)
|
|
47
|
-
|
|
48
|
+
puts_create_message(filename)
|
|
48
49
|
end
|
|
49
50
|
|
|
50
51
|
def generate_views
|
|
@@ -56,14 +57,14 @@ class Roda
|
|
|
56
57
|
if method == "get"
|
|
57
58
|
view_filename = File.join(branch_views_dir, "#{name}.erb")
|
|
58
59
|
File.write(view_filename, "")
|
|
59
|
-
|
|
60
|
+
puts_create_message(view_filename)
|
|
60
61
|
end
|
|
61
62
|
end
|
|
62
63
|
end
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
def generate_tests
|
|
66
|
-
test_filename = File.join(ensure_and_get_path("spec/app/routes"), "#{branch_name}_spec.rb")
|
|
67
|
+
test_filename = File.join(ensure_and_get_path("spec/app/routes", branch_name), "#{branch_name}_spec.rb")
|
|
67
68
|
nesting_level = branch_name.count("/")
|
|
68
69
|
relative_spec_helper_path = "../" * (2 + nesting_level) + "spec_helper"
|
|
69
70
|
|
|
@@ -83,7 +84,7 @@ class Roda
|
|
|
83
84
|
end
|
|
84
85
|
RUBY
|
|
85
86
|
File.write(test_filename, test_content)
|
|
86
|
-
|
|
87
|
+
puts_create_message(test_filename)
|
|
87
88
|
end
|
|
88
89
|
|
|
89
90
|
def must_generate_views?
|
|
@@ -96,13 +97,6 @@ class Roda
|
|
|
96
97
|
[method, name]
|
|
97
98
|
end
|
|
98
99
|
|
|
99
|
-
def ensure_and_get_path(path)
|
|
100
|
-
full_path_dir = File.join(path, File.dirname(branch_name))
|
|
101
|
-
FileUtils.mkdir_p(full_path_dir) unless File.directory?(full_path_dir)
|
|
102
|
-
|
|
103
|
-
path
|
|
104
|
-
end
|
|
105
|
-
|
|
106
100
|
def routes_list
|
|
107
101
|
@routes_list ||= @args[1..]
|
|
108
102
|
end
|
data/lib/roda/project/cli.rb
CHANGED
|
@@ -97,8 +97,11 @@ class Roda
|
|
|
97
97
|
erb_cp_file("front-end", "esbuild.js")
|
|
98
98
|
erb_cp_file("front-end", "package.json")
|
|
99
99
|
cp_dir("front-end", "app/views")
|
|
100
|
+
puts_create_message("app/views")
|
|
100
101
|
cp_dir("front-end", "public/assets")
|
|
102
|
+
puts_create_message("public/assets")
|
|
101
103
|
cp_dir("front-end", "public/images")
|
|
104
|
+
puts_create_message("public/images")
|
|
102
105
|
end
|
|
103
106
|
end
|
|
104
107
|
|
|
@@ -118,6 +121,7 @@ class Roda
|
|
|
118
121
|
erb_cp_file("rodauth", "db/migrations/001_add_rodauth.rb")
|
|
119
122
|
if @context.fullstack?
|
|
120
123
|
cp_file("rodauth", "app/views/create-account.erb")
|
|
124
|
+
puts_create_message("app/views/create-account.erb")
|
|
121
125
|
end
|
|
122
126
|
end
|
|
123
127
|
end
|
|
@@ -4,16 +4,25 @@ class Roda
|
|
|
4
4
|
include Helpers::Template
|
|
5
5
|
include Helpers::Ids
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
attr_reader :pastel
|
|
8
|
+
|
|
9
|
+
def initialize(context: MainContext.new, args: [], options: {}, dir: nil, pastel: Pastel.new)
|
|
8
10
|
@context = context
|
|
9
11
|
@args = args
|
|
10
12
|
@options = options
|
|
11
13
|
@dir = dir
|
|
14
|
+
@pastel = pastel
|
|
12
15
|
end
|
|
13
16
|
|
|
14
17
|
def call
|
|
15
18
|
false
|
|
16
19
|
end
|
|
20
|
+
|
|
21
|
+
protected
|
|
22
|
+
|
|
23
|
+
def puts_create_message(path)
|
|
24
|
+
puts(pastel.green(" create ") + path)
|
|
25
|
+
end
|
|
17
26
|
end
|
|
18
27
|
end
|
|
19
28
|
end
|
|
@@ -7,16 +7,16 @@ class Roda
|
|
|
7
7
|
module_function
|
|
8
8
|
|
|
9
9
|
def camelize(str)
|
|
10
|
-
return str if
|
|
10
|
+
return str if /[A-Z]/.match?(str)
|
|
11
11
|
|
|
12
12
|
str.split("_").map(&:capitalize).join
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def underscore(str)
|
|
16
16
|
str.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
|
18
|
+
.tr("-", "_")
|
|
19
|
+
.downcase
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def pluralize(str)
|
|
@@ -42,6 +42,14 @@ class Roda
|
|
|
42
42
|
str
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
|
+
|
|
46
|
+
def singular?(str)
|
|
47
|
+
str == singularize(str)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def plural?(str)
|
|
51
|
+
str == pluralize(str)
|
|
52
|
+
end
|
|
45
53
|
end
|
|
46
54
|
end
|
|
47
55
|
end
|
|
@@ -34,6 +34,13 @@ class Roda
|
|
|
34
34
|
)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
def ensure_and_get_path(path, name)
|
|
38
|
+
full_path_dir = File.join(path, File.dirname(name))
|
|
39
|
+
FileUtils.mkdir_p(full_path_dir) unless File.directory?(full_path_dir)
|
|
40
|
+
|
|
41
|
+
path
|
|
42
|
+
end
|
|
43
|
+
|
|
37
44
|
def templates_root
|
|
38
45
|
@templates_root ||= "../templates"
|
|
39
46
|
end
|
data/lib/roda/project/version.rb
CHANGED
data/lib/roda/project.rb
CHANGED
|
@@ -60,13 +60,14 @@ require_relative "project/helpers/inflections"
|
|
|
60
60
|
require_relative "project/main_context"
|
|
61
61
|
require_relative "project/generator"
|
|
62
62
|
require_relative "project/cli"
|
|
63
|
-
# Generators/base
|
|
64
63
|
require_relative "project/bin/generator"
|
|
65
64
|
# Generators/migration
|
|
66
65
|
require_relative "project/bin/generators/migration"
|
|
67
66
|
require_relative "project/bin/generators/migration/action_detector"
|
|
68
67
|
require_relative "project/bin/generators/migration/field_parser"
|
|
69
68
|
require_relative "project/bin/generators/migration/code_builder"
|
|
69
|
+
# Generators/model
|
|
70
|
+
require_relative "project/bin/generators/model"
|
|
70
71
|
# Generators/routes
|
|
71
72
|
require_relative "project/bin/generators/routes"
|
|
72
73
|
# Generators/base
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: roda-project
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Henrique F. Teixeira
|
|
@@ -83,6 +83,7 @@ files:
|
|
|
83
83
|
- lib/roda/project/bin/generators/migration/action_detector.rb
|
|
84
84
|
- lib/roda/project/bin/generators/migration/code_builder.rb
|
|
85
85
|
- lib/roda/project/bin/generators/migration/field_parser.rb
|
|
86
|
+
- lib/roda/project/bin/generators/model.rb
|
|
86
87
|
- lib/roda/project/bin/generators/routes.rb
|
|
87
88
|
- lib/roda/project/cli.rb
|
|
88
89
|
- lib/roda/project/generator.rb
|
|
@@ -163,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
163
164
|
requirements:
|
|
164
165
|
- - ">="
|
|
165
166
|
- !ruby/object:Gem::Version
|
|
166
|
-
version: 3.
|
|
167
|
+
version: 3.0.0
|
|
167
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
169
|
requirements:
|
|
169
170
|
- - ">="
|