jsx_rosetta 0.3.0 → 0.5.1
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/CHANGELOG.md +334 -0
- data/README.md +69 -7
- data/ROADMAP.md +92 -0
- data/lib/jsx_rosetta/ast/inflector.rb +15 -0
- data/lib/jsx_rosetta/ast/node.rb +28 -1
- data/lib/jsx_rosetta/backend/phlex.rb +1018 -0
- data/lib/jsx_rosetta/backend/rails_view.rb +3 -1
- data/lib/jsx_rosetta/backend/view_component/expression_translator.rb +338 -25
- data/lib/jsx_rosetta/backend/view_component.rb +361 -77
- data/lib/jsx_rosetta/backend.rb +1 -0
- data/lib/jsx_rosetta/cli.rb +33 -5
- data/lib/jsx_rosetta/ir/lowering.rb +790 -213
- data/lib/jsx_rosetta/ir/module_shape_classifier.rb +167 -0
- data/lib/jsx_rosetta/ir/types.rb +154 -22
- data/lib/jsx_rosetta/version.rb +1 -1
- data/lib/jsx_rosetta.rb +7 -6
- metadata +4 -1
data/lib/jsx_rosetta/cli.rb
CHANGED
|
@@ -63,16 +63,40 @@ module JsxRosetta
|
|
|
63
63
|
|
|
64
64
|
out_dir = options[:out] || "."
|
|
65
65
|
typescript = options[:tsx] || input_path.end_with?(".tsx")
|
|
66
|
-
backend = options[:as]
|
|
66
|
+
backend = backend_for_as(options[:as])
|
|
67
|
+
backend_options = backend_options_for(backend, options)
|
|
67
68
|
|
|
68
69
|
source = File.read(input_path)
|
|
69
70
|
files = JsxRosetta.translate(
|
|
70
71
|
source,
|
|
71
72
|
backend: backend,
|
|
73
|
+
backend_options: backend_options,
|
|
72
74
|
typescript: typescript,
|
|
73
75
|
source_filename: input_path
|
|
74
76
|
)
|
|
75
77
|
|
|
78
|
+
write_emitted_files(files, out_dir)
|
|
79
|
+
EXIT_OK
|
|
80
|
+
rescue ParseError, IR::Lowering::LoweringError, ArgumentError => e
|
|
81
|
+
@stderr.puts "jsx_rosetta translate: #{e.message}"
|
|
82
|
+
EXIT_FAILURE
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def backend_for_as(value)
|
|
86
|
+
case value
|
|
87
|
+
when "view" then :rails_view
|
|
88
|
+
when "phlex" then :phlex
|
|
89
|
+
else :view_component
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def backend_options_for(backend, options)
|
|
94
|
+
return {} unless backend == :phlex
|
|
95
|
+
|
|
96
|
+
{ suffix: options[:phlex_suffix], namespace: options[:phlex_namespace] }.compact
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def write_emitted_files(files, out_dir)
|
|
76
100
|
FileUtils.mkdir_p(out_dir)
|
|
77
101
|
files.each do |file|
|
|
78
102
|
target = File.join(out_dir, file.path)
|
|
@@ -80,10 +104,6 @@ module JsxRosetta
|
|
|
80
104
|
File.write(target, file.contents)
|
|
81
105
|
@stdout.puts "wrote #{target}"
|
|
82
106
|
end
|
|
83
|
-
EXIT_OK
|
|
84
|
-
rescue ParseError, IR::Lowering::LoweringError => e
|
|
85
|
-
@stderr.puts "jsx_rosetta translate: #{e.message}"
|
|
86
|
-
EXIT_FAILURE
|
|
87
107
|
end
|
|
88
108
|
|
|
89
109
|
def run_routes
|
|
@@ -142,6 +162,10 @@ module JsxRosetta
|
|
|
142
162
|
when "--tsx", "--typescript" then options[:tsx] = true
|
|
143
163
|
when "--as" then options[:as] = @argv.shift
|
|
144
164
|
when /\A--as=(.+)\z/ then options[:as] = ::Regexp.last_match(1)
|
|
165
|
+
when "--phlex-suffix" then options[:phlex_suffix] = @argv.shift
|
|
166
|
+
when /\A--phlex-suffix=(.*)\z/ then options[:phlex_suffix] = ::Regexp.last_match(1)
|
|
167
|
+
when "--phlex-namespace" then options[:phlex_namespace] = @argv.shift
|
|
168
|
+
when /\A--phlex-namespace=(.+)\z/ then options[:phlex_namespace] = ::Regexp.last_match(1)
|
|
145
169
|
else positional << arg
|
|
146
170
|
end
|
|
147
171
|
end
|
|
@@ -166,6 +190,10 @@ module JsxRosetta
|
|
|
166
190
|
Pass --as=view to emit a Rails view template (`<snake>.html.erb`)
|
|
167
191
|
instead of a ViewComponent class + sidecar template — appropriate
|
|
168
192
|
for pages tied to a route.
|
|
193
|
+
Pass --as=phlex to emit a single-file Phlex 2.x view class
|
|
194
|
+
(`<snake>.rb`) instead of a ViewComponent. Configure the class
|
|
195
|
+
name with --phlex-suffix=Component or --phlex-namespace=Components
|
|
196
|
+
(mutually exclusive; default is bare class name).
|
|
169
197
|
routes FILE [-o OUT.rb] Parse <Route path=... element={<X/>} /> patterns from FILE
|
|
170
198
|
and emit a reviewable Ruby script that calls `rails generate
|
|
171
199
|
controller` and prints suggested config/routes.rb additions.
|