reactive_views 0.1.0
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 +7 -0
- data/CHANGELOG.md +49 -0
- data/LICENSE.txt +22 -0
- data/README.md +134 -0
- data/app/controllers/reactive_views/bundles_controller.rb +47 -0
- data/app/frontend/reactive_views/boot.ts +215 -0
- data/config/routes.rb +10 -0
- data/lib/generators/reactive_views/install/install_generator.rb +645 -0
- data/lib/generators/reactive_views/install/templates/application.html.erb.tt +19 -0
- data/lib/generators/reactive_views/install/templates/application.js.tt +9 -0
- data/lib/generators/reactive_views/install/templates/boot.ts.tt +225 -0
- data/lib/generators/reactive_views/install/templates/example_component.tsx.tt +4 -0
- data/lib/generators/reactive_views/install/templates/initializer.rb.tt +7 -0
- data/lib/generators/reactive_views/install/templates/vite.config.mts.tt +78 -0
- data/lib/generators/reactive_views/install/templates/vite.json.tt +22 -0
- data/lib/reactive_views/cache_store.rb +269 -0
- data/lib/reactive_views/component_resolver.rb +243 -0
- data/lib/reactive_views/configuration.rb +71 -0
- data/lib/reactive_views/controller_props.rb +43 -0
- data/lib/reactive_views/css_strategy.rb +179 -0
- data/lib/reactive_views/engine.rb +14 -0
- data/lib/reactive_views/error_overlay.rb +1390 -0
- data/lib/reactive_views/full_page_renderer.rb +158 -0
- data/lib/reactive_views/helpers.rb +209 -0
- data/lib/reactive_views/props_builder.rb +42 -0
- data/lib/reactive_views/props_inference.rb +89 -0
- data/lib/reactive_views/railtie.rb +93 -0
- data/lib/reactive_views/renderer.rb +484 -0
- data/lib/reactive_views/resolver.rb +66 -0
- data/lib/reactive_views/ssr_process.rb +274 -0
- data/lib/reactive_views/tag_transformer.rb +523 -0
- data/lib/reactive_views/temp_file_manager.rb +81 -0
- data/lib/reactive_views/template_handler.rb +52 -0
- data/lib/reactive_views/version.rb +5 -0
- data/lib/reactive_views.rb +58 -0
- data/lib/tasks/reactive_views.rake +104 -0
- data/node/ssr/server.mjs +965 -0
- data/package-lock.json +516 -0
- data/package.json +14 -0
- metadata +322 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "reactive_views/version"
|
|
4
|
+
require_relative "reactive_views/cache_store"
|
|
5
|
+
require_relative "reactive_views/configuration"
|
|
6
|
+
require_relative "reactive_views/component_resolver"
|
|
7
|
+
require_relative "reactive_views/renderer"
|
|
8
|
+
require_relative "reactive_views/full_page_renderer"
|
|
9
|
+
require_relative "reactive_views/error_overlay"
|
|
10
|
+
require_relative "reactive_views/tag_transformer"
|
|
11
|
+
require_relative "reactive_views/helpers"
|
|
12
|
+
require_relative "reactive_views/props_inference"
|
|
13
|
+
require_relative "reactive_views/temp_file_manager"
|
|
14
|
+
require_relative "reactive_views/props_builder"
|
|
15
|
+
require_relative "reactive_views/template_handler"
|
|
16
|
+
require_relative "reactive_views/resolver"
|
|
17
|
+
require_relative "reactive_views/css_strategy"
|
|
18
|
+
require_relative "reactive_views/ssr_process"
|
|
19
|
+
|
|
20
|
+
if defined?(Rails)
|
|
21
|
+
require_relative "reactive_views/engine"
|
|
22
|
+
require_relative "reactive_views/railtie"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
module ReactiveViews
|
|
26
|
+
# Base error class for all ReactiveViews errors
|
|
27
|
+
class Error < StandardError; end
|
|
28
|
+
|
|
29
|
+
# Raised when the Vite manifest file cannot be found in production
|
|
30
|
+
class AssetManifestNotFoundError < Error; end
|
|
31
|
+
|
|
32
|
+
# Raised when an expected entry is not found in the Vite manifest
|
|
33
|
+
class AssetEntryNotFoundError < Error; end
|
|
34
|
+
|
|
35
|
+
# Raised when the SSR server is unavailable
|
|
36
|
+
class SSRConnectionError < Error; end
|
|
37
|
+
|
|
38
|
+
# Raised when SSR rendering times out
|
|
39
|
+
class SSRTimeoutError < Error; end
|
|
40
|
+
|
|
41
|
+
# Raised when a component cannot be found
|
|
42
|
+
class ComponentNotFoundError < Error; end
|
|
43
|
+
|
|
44
|
+
# Raised when props inference fails
|
|
45
|
+
class PropsInferenceError < Error; end
|
|
46
|
+
|
|
47
|
+
class << self
|
|
48
|
+
attr_accessor :config
|
|
49
|
+
|
|
50
|
+
def configure
|
|
51
|
+
self.config ||= Configuration.new
|
|
52
|
+
yield(config) if block_given?
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Initialize with default configuration
|
|
57
|
+
configure
|
|
58
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
namespace :reactive_views do
|
|
4
|
+
desc "Build production assets with Vite"
|
|
5
|
+
task :build do
|
|
6
|
+
puts "[ReactiveViews] Building production assets..."
|
|
7
|
+
|
|
8
|
+
# Check if vite is available
|
|
9
|
+
unless system("which npx > /dev/null 2>&1") || system("which yarn > /dev/null 2>&1")
|
|
10
|
+
puts "[ReactiveViews] Warning: npx/yarn not found, skipping Vite build"
|
|
11
|
+
next
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Check if vite.config exists
|
|
15
|
+
vite_config = %w[vite.config.mts vite.config.ts vite.config.js].find { |f| File.exist?(f) }
|
|
16
|
+
unless vite_config
|
|
17
|
+
puts "[ReactiveViews] Warning: No vite.config found, skipping Vite build"
|
|
18
|
+
next
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Set production environment
|
|
22
|
+
ENV["NODE_ENV"] ||= "production"
|
|
23
|
+
|
|
24
|
+
# Run Vite build
|
|
25
|
+
build_cmd = if File.exist?("node_modules/.bin/vite")
|
|
26
|
+
"node_modules/.bin/vite build"
|
|
27
|
+
elsif system("which npx > /dev/null 2>&1")
|
|
28
|
+
"npx vite build"
|
|
29
|
+
else
|
|
30
|
+
"yarn vite build"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
puts "[ReactiveViews] Running: #{build_cmd}"
|
|
34
|
+
|
|
35
|
+
success = system(build_cmd)
|
|
36
|
+
|
|
37
|
+
if success
|
|
38
|
+
puts "[ReactiveViews] ✓ Production assets built successfully"
|
|
39
|
+
|
|
40
|
+
# Verify manifest exists
|
|
41
|
+
manifest_path = "public/vite/.vite/manifest.json"
|
|
42
|
+
alt_manifest_path = "public/vite/manifest.json"
|
|
43
|
+
|
|
44
|
+
if File.exist?(manifest_path) || File.exist?(alt_manifest_path)
|
|
45
|
+
puts "[ReactiveViews] ✓ Vite manifest generated"
|
|
46
|
+
else
|
|
47
|
+
puts "[ReactiveViews] Warning: Vite manifest not found at expected location"
|
|
48
|
+
end
|
|
49
|
+
else
|
|
50
|
+
puts "[ReactiveViews] ✗ Vite build failed"
|
|
51
|
+
exit 1
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
desc "Start the ReactiveViews SSR server (for development)"
|
|
56
|
+
task :ssr do
|
|
57
|
+
gem_root = if defined?(Bundler)
|
|
58
|
+
spec = Bundler.load.specs.find { |s| s.name == "reactive_views" }
|
|
59
|
+
spec&.gem_dir
|
|
60
|
+
end
|
|
61
|
+
gem_root ||= Gem.loaded_specs["reactive_views"]&.gem_dir
|
|
62
|
+
|
|
63
|
+
if gem_root.nil?
|
|
64
|
+
puts "Error: Could not find reactive_views gem directory"
|
|
65
|
+
exit 1
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
ssr_script = File.join(gem_root, "node", "ssr", "server.mjs")
|
|
69
|
+
|
|
70
|
+
unless File.exist?(ssr_script)
|
|
71
|
+
puts "Error: SSR server script not found at: #{ssr_script}"
|
|
72
|
+
exit 1
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Find node executable
|
|
76
|
+
node_path = `which node 2>/dev/null`.strip
|
|
77
|
+
if node_path.empty?
|
|
78
|
+
# Check common locations
|
|
79
|
+
candidates = [
|
|
80
|
+
File.expand_path("~/.asdf/shims/node"),
|
|
81
|
+
File.expand_path("~/.nvm/current/bin/node"),
|
|
82
|
+
"/opt/homebrew/bin/node",
|
|
83
|
+
"/usr/local/bin/node",
|
|
84
|
+
"/usr/bin/node",
|
|
85
|
+
File.expand_path("~/.volta/bin/node")
|
|
86
|
+
]
|
|
87
|
+
node_path = candidates.find { |p| File.executable?(p) }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
if node_path.nil? || node_path.empty?
|
|
91
|
+
puts "Error: Could not find node executable"
|
|
92
|
+
puts "Make sure Node.js is installed and available in your PATH"
|
|
93
|
+
exit 1
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
puts "[ReactiveViews] Starting SSR server..."
|
|
97
|
+
exec(node_path, ssr_script)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Hook into assets:precompile if Rails is available and the task exists
|
|
102
|
+
if defined?(Rails) && Rake::Task.task_defined?("assets:precompile")
|
|
103
|
+
Rake::Task["assets:precompile"].enhance([ "reactive_views:build" ])
|
|
104
|
+
end
|