ruflet_rails 0.0.8 → 0.0.10
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/generators/ruflet/install/install_generator.rb +7 -33
- data/lib/ruflet/rails/install_support.rb +4 -117
- data/lib/ruflet/rails/railtie.rb +14 -9
- data/lib/ruflet/rails.rb +2 -0
- data/lib/ruflet/version.rb +1 -1
- metadata +19 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2ffd81f0143fcba01b93a6d0f773d1d0e4aa983a01c4bf282ed383a631273b13
|
|
4
|
+
data.tar.gz: 8840d1be44c36b8d82789f9a9d8055bd2ab0f8e893bafe1fc2ab6f8f082f90d0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 456e8aaf3966f272a7b5b0945163a8f96955c240577fb5a1f4f5023ec635260eb531872505e03d552199f6d52c5a68839cbb3a2a4115d82d25f3e1c0bcf95765
|
|
7
|
+
data.tar.gz: a63099e903e698ceb130f8b678deaa8a2cb238335266615704fdac47b41f1775fc8e1d677789bab3c6a3961034173d323719325ac159d1b679b4dfd772636a03
|
|
@@ -6,10 +6,8 @@ require "ruflet/rails/install_support"
|
|
|
6
6
|
module Ruflet
|
|
7
7
|
module Generators
|
|
8
8
|
class InstallGenerator < ::Rails::Generators::Base
|
|
9
|
-
class_option :frontend, type: :boolean, default: false, desc: "Install the Rails-hosted Ruflet web client"
|
|
10
|
-
class_option :web, type: :boolean, default: false, desc: "Install the Rails-hosted Ruflet web client"
|
|
11
9
|
class_option :desktop, type: :boolean, default: false, desc: "Download the server-driven desktop Ruflet client"
|
|
12
|
-
class_option :client, type: :string, default: nil, desc: "Download prebuilt client from GitHub releases:
|
|
10
|
+
class_option :client, type: :string, default: nil, desc: "Download prebuilt client from GitHub releases: desktop or none"
|
|
13
11
|
|
|
14
12
|
desc "Install Ruflet into a Rails app."
|
|
15
13
|
|
|
@@ -32,7 +30,8 @@ module Ruflet
|
|
|
32
30
|
return unless File.file?(target)
|
|
33
31
|
|
|
34
32
|
route = Ruflet::Rails::InstallSupport.route_snippet(entrypoint: entrypoint_path)
|
|
35
|
-
|
|
33
|
+
source = File.read(target)
|
|
34
|
+
return if source.include?(route)
|
|
36
35
|
|
|
37
36
|
insert_into_file target, " #{route}\n", after: /Rails\.application\.routes\.draw do\s*\n/
|
|
38
37
|
end
|
|
@@ -46,17 +45,8 @@ module Ruflet
|
|
|
46
45
|
|
|
47
46
|
def download_prebuilt_client
|
|
48
47
|
client = requested_client
|
|
49
|
-
@web_client_published = false
|
|
50
48
|
return if client == "none"
|
|
51
49
|
|
|
52
|
-
if %w[web all].include?(client)
|
|
53
|
-
@web_client_published = Ruflet::Rails::InstallSupport.publish_web_build(destination_root)
|
|
54
|
-
if @web_client_published
|
|
55
|
-
say "Ruflet web build copied from build/web to public/#{Ruflet::Rails::InstallSupport.default_web_public_path}"
|
|
56
|
-
return if client == "web"
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
50
|
require "ruflet/cli"
|
|
61
51
|
exit_code = Dir.chdir(destination_root) do
|
|
62
52
|
Ruflet::CLI.command_update([client])
|
|
@@ -64,17 +54,6 @@ module Ruflet
|
|
|
64
54
|
unless exit_code.to_i.zero?
|
|
65
55
|
@client_download_failed = true
|
|
66
56
|
say_status(:warn, "Ruflet client download failed; install files were generated and build/update steps are printed below", :yellow)
|
|
67
|
-
return
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
return unless %w[web all].include?(client)
|
|
71
|
-
|
|
72
|
-
published = Ruflet::Rails::InstallSupport.publish_prebuilt_web_client(destination_root)
|
|
73
|
-
@web_client_published = published
|
|
74
|
-
if published
|
|
75
|
-
say "Ruflet web client published at /#{Ruflet::Rails::InstallSupport.default_web_public_path}/"
|
|
76
|
-
else
|
|
77
|
-
say_status(:warn, "Ruflet web client downloaded, but no prebuilt web index.html was found to publish", :yellow)
|
|
78
57
|
end
|
|
79
58
|
rescue StandardError => e
|
|
80
59
|
@client_download_failed = true
|
|
@@ -85,8 +64,7 @@ module Ruflet
|
|
|
85
64
|
Ruflet::Rails::InstallSupport.install_next_steps(
|
|
86
65
|
target: install_target,
|
|
87
66
|
entrypoint: entrypoint_path,
|
|
88
|
-
client: requested_client
|
|
89
|
-
web_published: !!@web_client_published
|
|
67
|
+
client: requested_client
|
|
90
68
|
).each { |line| say line }
|
|
91
69
|
end
|
|
92
70
|
|
|
@@ -103,22 +81,18 @@ module Ruflet
|
|
|
103
81
|
def requested_client
|
|
104
82
|
explicit = options[:client].to_s.strip.downcase
|
|
105
83
|
unless explicit.empty?
|
|
106
|
-
raise Thor::Error, "--client must be
|
|
84
|
+
raise Thor::Error, "--client must be desktop or none" unless %w[desktop none].include?(explicit)
|
|
107
85
|
|
|
108
86
|
return explicit
|
|
109
87
|
end
|
|
110
88
|
|
|
111
|
-
|
|
112
|
-
wants_desktop = options[:desktop]
|
|
113
|
-
return "all" if wants_web && wants_desktop
|
|
114
|
-
return "web" if wants_web
|
|
115
|
-
return "desktop" if wants_desktop
|
|
89
|
+
return "desktop" if options[:desktop]
|
|
116
90
|
|
|
117
91
|
"none"
|
|
118
92
|
end
|
|
119
93
|
|
|
120
94
|
def desktop_requested?
|
|
121
|
-
|
|
95
|
+
requested_client == "desktop"
|
|
122
96
|
end
|
|
123
97
|
|
|
124
98
|
def install_target
|
|
@@ -831,9 +831,7 @@ module Ruflet
|
|
|
831
831
|
normalized = normalize_build_platform(platform)
|
|
832
832
|
return [] if normalized.to_s.empty?
|
|
833
833
|
|
|
834
|
-
|
|
835
|
-
args += ["--base-href", web_base_href] if normalized == "web"
|
|
836
|
-
args
|
|
834
|
+
[normalized]
|
|
837
835
|
end
|
|
838
836
|
|
|
839
837
|
def default_entrypoint_path
|
|
@@ -844,128 +842,17 @@ module Ruflet
|
|
|
844
842
|
%(match "#{mount_path}", to: Ruflet::Rails.#{helper}(Rails.root.join("#{entrypoint}")), via: :all)
|
|
845
843
|
end
|
|
846
844
|
|
|
847
|
-
def
|
|
848
|
-
"app"
|
|
849
|
-
end
|
|
850
|
-
|
|
851
|
-
def web_base_href(public_path = default_web_public_path)
|
|
852
|
-
normalized = public_path.to_s.strip.gsub(%r{\A/+|/+\z}, "")
|
|
853
|
-
normalized.empty? ? "/" : "/#{normalized}/"
|
|
854
|
-
end
|
|
855
|
-
|
|
856
|
-
def publish_web_build(root, public_path: default_web_public_path)
|
|
857
|
-
publish_web_client(root, source: File.join(root, "build", "web"), public_path: public_path)
|
|
858
|
-
end
|
|
859
|
-
|
|
860
|
-
def publish_prebuilt_web_client(root, platform: host_desktop_platform, public_path: default_web_public_path)
|
|
861
|
-
source = prebuilt_web_client_path(platform: platform)
|
|
862
|
-
return false unless source
|
|
863
|
-
|
|
864
|
-
publish_web_client(root, source: source, public_path: public_path)
|
|
865
|
-
end
|
|
866
|
-
|
|
867
|
-
def prebuilt_web_client_path(platform: host_desktop_platform)
|
|
868
|
-
return nil if platform.to_s.empty?
|
|
869
|
-
|
|
870
|
-
source = File.join(prebuilt_client_cache_root(platform: platform), "web")
|
|
871
|
-
return nil unless Dir.exist?(source)
|
|
872
|
-
return nil unless File.file?(File.join(source, "index.html"))
|
|
873
|
-
|
|
874
|
-
source
|
|
875
|
-
end
|
|
876
|
-
|
|
877
|
-
def prebuilt_client_cache_root(platform: host_desktop_platform)
|
|
878
|
-
require "ruflet/cli"
|
|
879
|
-
|
|
880
|
-
if Ruflet::CLI.respond_to?(:client_cache_root_for, true)
|
|
881
|
-
Ruflet::CLI.send(:client_cache_root_for, platform)
|
|
882
|
-
else
|
|
883
|
-
File.join(Dir.home, ".ruflet", "client", Ruflet::VERSION, platform.to_s)
|
|
884
|
-
end
|
|
885
|
-
end
|
|
886
|
-
|
|
887
|
-
def publish_web_client(root, source:, public_path: default_web_public_path)
|
|
888
|
-
return false unless Dir.exist?(source)
|
|
889
|
-
return false unless File.file?(File.join(source, "index.html"))
|
|
890
|
-
|
|
891
|
-
target = File.join(root, "public", public_path.to_s.gsub(%r{\A/+|/+\z}, ""))
|
|
892
|
-
FileUtils.rm_rf(target)
|
|
893
|
-
FileUtils.mkdir_p(File.dirname(target))
|
|
894
|
-
FileUtils.cp_r(source, target)
|
|
895
|
-
rewrite_web_base_href(target, public_path: public_path)
|
|
896
|
-
inject_web_client_bootstrap(target)
|
|
897
|
-
true
|
|
898
|
-
end
|
|
899
|
-
|
|
900
|
-
def rewrite_web_base_href(target, public_path:)
|
|
901
|
-
index_path = File.join(target, "index.html")
|
|
902
|
-
return unless File.file?(index_path)
|
|
903
|
-
|
|
904
|
-
content = File.read(index_path)
|
|
905
|
-
base_href = web_base_href(public_path)
|
|
906
|
-
updated =
|
|
907
|
-
if content.match?(%r{<base\s+href=["'][^"']*["']\s*/?>}i)
|
|
908
|
-
content.sub(%r{<base\s+href=["'][^"']*["']\s*/?>}i, %(<base href="#{base_href}">))
|
|
909
|
-
else
|
|
910
|
-
content.sub(%r{<head([^>]*)>}i, %(<head\\1>\n <base href="#{base_href}">))
|
|
911
|
-
end
|
|
912
|
-
File.write(index_path, updated)
|
|
913
|
-
end
|
|
914
|
-
|
|
915
|
-
def inject_web_client_bootstrap(target)
|
|
916
|
-
index_path = File.join(target, "index.html")
|
|
917
|
-
return unless File.file?(index_path)
|
|
918
|
-
|
|
919
|
-
content = File.read(index_path)
|
|
920
|
-
return if content.include?('id="ruflet-rails-bootstrap"')
|
|
921
|
-
|
|
922
|
-
script = <<~HTML
|
|
923
|
-
<script id="ruflet-rails-bootstrap">
|
|
924
|
-
if (window.location.search === "" && window.location.hash === "") {
|
|
925
|
-
const rufletServerUrl = window.location.origin + "/";
|
|
926
|
-
window.history.replaceState(
|
|
927
|
-
null,
|
|
928
|
-
document.title,
|
|
929
|
-
window.location.pathname + "?url=" + encodeURIComponent(rufletServerUrl)
|
|
930
|
-
);
|
|
931
|
-
}
|
|
932
|
-
</script>
|
|
933
|
-
HTML
|
|
934
|
-
|
|
935
|
-
updated =
|
|
936
|
-
if content.include?('<script src="flutter_bootstrap.js"')
|
|
937
|
-
content.sub(%r{<script src="flutter_bootstrap\.js"[^>]*></script>}i) { |match| "#{script} #{match}" }
|
|
938
|
-
else
|
|
939
|
-
content.sub(%r{</body>}i, "#{script}</body>")
|
|
940
|
-
end
|
|
941
|
-
File.write(index_path, updated)
|
|
942
|
-
end
|
|
943
|
-
|
|
944
|
-
def install_next_steps(target:, entrypoint:, client:, web_published:, mount_path: "/ws")
|
|
945
|
-
web_path = default_web_public_path
|
|
845
|
+
def install_next_steps(target:, entrypoint:, client:, mount_path: "/ws")
|
|
946
846
|
lines = [
|
|
947
847
|
"Ruflet Rails installed.",
|
|
948
848
|
"Generated entrypoint: #{entrypoint}",
|
|
949
849
|
"Mounted websocket: #{mount_path}",
|
|
950
850
|
"Next steps:",
|
|
951
851
|
" 1. Start Rails: bin/rails server",
|
|
952
|
-
" 2.
|
|
852
|
+
" 2. Connect your Ruflet app to ws://localhost:3000#{mount_path}"
|
|
953
853
|
]
|
|
954
854
|
|
|
955
|
-
if
|
|
956
|
-
lines << "Web client copied to public/#{web_path}."
|
|
957
|
-
elsif target.to_s == "ruflet" || %w[web all].include?(client.to_s)
|
|
958
|
-
lines += [
|
|
959
|
-
"Web client was not copied because no built/prebuilt web index.html was found.",
|
|
960
|
-
"To download the prebuilt client from GitHub: bin/rails ruflet:update[web]",
|
|
961
|
-
"To build the WASM web client yourself, install the ruflet CLI globally first:",
|
|
962
|
-
" gem install ruflet",
|
|
963
|
-
"Then build and copy build/web into public/#{web_path}:",
|
|
964
|
-
" bin/rails ruflet:build[web]"
|
|
965
|
-
]
|
|
966
|
-
end
|
|
967
|
-
|
|
968
|
-
if %w[desktop all].include?(client.to_s)
|
|
855
|
+
if client.to_s == "desktop"
|
|
969
856
|
lines += [
|
|
970
857
|
"Desktop clients are server-driven and connect to this Rails app.",
|
|
971
858
|
"Plain bin/dev, bin/rails server, and bin/rails s do not launch desktop.",
|
data/lib/ruflet/rails/railtie.rb
CHANGED
|
@@ -15,10 +15,12 @@ module Ruflet
|
|
|
15
15
|
|
|
16
16
|
rake_tasks do
|
|
17
17
|
namespace :ruflet do
|
|
18
|
-
desc "Build Ruflet client for this Rails app. Usage: rake ruflet:build[web]"
|
|
19
|
-
task :build, [:platform] do |_task, args|
|
|
18
|
+
desc "Build Ruflet client for this Rails app. Usage: rake ruflet:build[web,app]"
|
|
19
|
+
task :build, [:platform, :web_path] do |_task, args|
|
|
20
20
|
requested_platform = args[:platform].to_s.strip.downcase
|
|
21
|
-
|
|
21
|
+
web_path = args[:web_path].to_s.strip
|
|
22
|
+
public_path = web_path.empty? ? Ruflet::Rails::InstallSupport.default_web_public_path : web_path
|
|
23
|
+
build_args = Ruflet::Rails::InstallSupport.build_args_for_platform(requested_platform, public_path: public_path)
|
|
22
24
|
platform = build_args.first
|
|
23
25
|
if platform.to_s.empty?
|
|
24
26
|
warn "Usage: rake ruflet:build[apk|android|ios|aab|web|desktop|macos|windows|linux]"
|
|
@@ -32,17 +34,17 @@ module Ruflet
|
|
|
32
34
|
raise SystemExit, exit_code unless exit_code.to_i.zero?
|
|
33
35
|
|
|
34
36
|
if platform == "web"
|
|
35
|
-
published = Ruflet::Rails::InstallSupport.publish_web_build(::Rails.root.to_s)
|
|
37
|
+
published = Ruflet::Rails::InstallSupport.publish_web_build(::Rails.root.to_s, public_path: public_path)
|
|
36
38
|
if published
|
|
37
|
-
puts "Ruflet web client published at
|
|
39
|
+
puts "Ruflet web client published at #{Ruflet::Rails::InstallSupport.web_base_href(public_path)}"
|
|
38
40
|
else
|
|
39
41
|
warn "Ruflet web build completed, but build/web was not found to publish."
|
|
40
42
|
end
|
|
41
43
|
end
|
|
42
44
|
end
|
|
43
45
|
|
|
44
|
-
desc "Download/update prebuilt Ruflet clients from GitHub releases. Usage: rake ruflet:update[web
|
|
45
|
-
task :update, [:target] do |_task, args|
|
|
46
|
+
desc "Download/update prebuilt Ruflet clients from GitHub releases. Usage: rake ruflet:update[web,app]"
|
|
47
|
+
task :update, [:target, :web_path] do |_task, args|
|
|
46
48
|
target = args[:target].to_s.strip
|
|
47
49
|
if target.empty?
|
|
48
50
|
warn "Usage: rake ruflet:update[web|desktop|all]"
|
|
@@ -50,6 +52,8 @@ module Ruflet
|
|
|
50
52
|
end
|
|
51
53
|
normalized_target = target.downcase
|
|
52
54
|
platform = Ruflet::Rails::InstallSupport.host_desktop_platform
|
|
55
|
+
web_path = args[:web_path].to_s.strip
|
|
56
|
+
public_path = web_path.empty? ? Ruflet::Rails::InstallSupport.default_web_public_path : web_path
|
|
53
57
|
|
|
54
58
|
require "ruflet/cli"
|
|
55
59
|
exit_code = Dir.chdir(::Rails.root) do
|
|
@@ -60,10 +64,11 @@ module Ruflet
|
|
|
60
64
|
if %w[web all].include?(normalized_target)
|
|
61
65
|
published = Ruflet::Rails::InstallSupport.publish_prebuilt_web_client(
|
|
62
66
|
::Rails.root.to_s,
|
|
63
|
-
platform: platform
|
|
67
|
+
platform: platform,
|
|
68
|
+
public_path: public_path
|
|
64
69
|
)
|
|
65
70
|
if published
|
|
66
|
-
puts "Ruflet web client published at
|
|
71
|
+
puts "Ruflet web client published at #{Ruflet::Rails::InstallSupport.web_base_href(public_path)}"
|
|
67
72
|
else
|
|
68
73
|
warn "Ruflet web client downloaded, but no prebuilt web index.html was found to publish."
|
|
69
74
|
end
|
data/lib/ruflet/rails.rb
CHANGED
data/lib/ruflet/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruflet_rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
7
|
+
- Adam Moussa Ali
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
@@ -51,10 +51,24 @@ dependencies:
|
|
|
51
51
|
- - ">="
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
53
|
version: 0.0.14
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: ruflet_server
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: 0.0.14
|
|
61
|
+
type: :runtime
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 0.0.14
|
|
68
|
+
description: Build cross-platform mobile and desktop apps with Ruby on Rails using
|
|
69
|
+
Ruflet.
|
|
56
70
|
email:
|
|
57
|
-
-
|
|
71
|
+
- adammusaaly@gmail.com
|
|
58
72
|
executables: []
|
|
59
73
|
extensions: []
|
|
60
74
|
extra_rdoc_files: []
|