svelte-on-rails 0.0.18 → 0.0.20
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/README.md +5 -5
- data/lib/svelte-on-rails.rb +1 -0
- data/lib/svelte_on_rails/configuration.rb +2 -2
- data/lib/svelte_on_rails/installer_utils.rb +170 -0
- data/lib/svelte_on_rails/render_server_side.rb +34 -13
- data/lib/svelte_on_rails/view_helpers.rb +9 -9
- data/lib/tasks/svelte_on_rails_tasks.rake +18 -172
- 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: 06d39c6909bc770f4cef89091d1ac17566715996aa7425afe29e847072691ee0
|
4
|
+
data.tar.gz: ca26182656cd9e27bd3a4f9f6d6e58e5e283b625d06a6133b9fd196c369c4306
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ac18b72caf1f4b64c960423690d4d62dbb9a456edca7337ceb49044b5efa920d5ea728886721dd10818fc2d0be7019af3bc9005ff8e9609017655f21a9e004c
|
7
|
+
data.tar.gz: 7e355580850438267e99bc8eef9077968860813e55f3de90f2b1d451c59ddb68fd1ca99381dec3e44b84232ac8d488f5628a01ab6248ac158e02a33b3936de1b
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Svelte
|
1
|
+
# Svelte. On rails! Awesome.
|
2
2
|
|
3
3
|
Seamless and robust Svelte in Rails integration.
|
4
4
|
|
@@ -92,7 +92,7 @@ On [@csedl/svelte-on-rails](https://www.npmjs.com/package/@csedl/svelte-on-rails
|
|
92
92
|
are details how the frontend part is working.
|
93
93
|
|
94
94
|
Without the npm package installed,
|
95
|
-
or by passing `
|
95
|
+
or by passing `ssr: true` and `hydrate: false` to the view helper,
|
96
96
|
you would see the same html, and the styled button,
|
97
97
|
but the increment button would not work.
|
98
98
|
|
@@ -112,13 +112,13 @@ Among others there are
|
|
112
112
|
- `import { someFunction } from '../customJavascript.js';`
|
113
113
|
- `import Child from './Child.svelte';`
|
114
114
|
|
115
|
-
## Option `
|
115
|
+
## Option `ssr: :auto`
|
116
116
|
|
117
|
-
`
|
117
|
+
`ssr: :auto` is the default option, as set on config file and can be overridden on the view helper.
|
118
118
|
|
119
119
|
Works with `hotwired/turbo` only
|
120
120
|
|
121
|
-
By passing the `
|
121
|
+
By passing the `ssr: :auto` option to the view helper,
|
122
122
|
it checks if the request is an initial request (request header `X-Turbo-Request-ID` is present):
|
123
123
|
|
124
124
|
On Initial-Request, it adds the attribute `data-svelte-on-rails-initialize-action="hydrate"` and
|
data/lib/svelte-on-rails.rb
CHANGED
@@ -0,0 +1,170 @@
|
|
1
|
+
module SvelteOnRails
|
2
|
+
|
3
|
+
module InstallerUtils
|
4
|
+
def self.install_npm_package
|
5
|
+
package_name = "@csedl/svelte-on-rails@latest"
|
6
|
+
puts "Installing #{package_name} via npm..."
|
7
|
+
|
8
|
+
if system("npm install #{package_name}")
|
9
|
+
puts "#{package_name} successfully installed."
|
10
|
+
else
|
11
|
+
abort "Failed to install #{package_name}. Please ensure npm is installed and try running 'npm install #{package_name}' manually."
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.install_turbo
|
16
|
+
|
17
|
+
pkg_js = Rails.root.join("package.json")
|
18
|
+
package_name = "@hotwired/turbo-rails"
|
19
|
+
file_content = File.exist?(pkg_js) ? File.read(pkg_js) : ""
|
20
|
+
|
21
|
+
if file_content.match?(/#{package_name}/)
|
22
|
+
puts "#{package_name} is already present in package.json, assuming that it is set up well and working."
|
23
|
+
else
|
24
|
+
puts "Installing #{package_name} via npm..."
|
25
|
+
if system("npm install #{package_name}")
|
26
|
+
puts "#{package_name} successfully installed."
|
27
|
+
add_line_to_file(Rails.root.join("app", "frontend", "entrypoints", "application.js"), "import '#{package_name}';")
|
28
|
+
else
|
29
|
+
abort "Failed to install #{package_name}. Please ensure npm is installed and try running 'npm install #{package_name}' manually."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.create_folder(folder)
|
36
|
+
if Dir.exist?(folder)
|
37
|
+
puts "Folder already exists: #{folder}"
|
38
|
+
else
|
39
|
+
FileUtils.mkdir_p(folder)
|
40
|
+
puts "Created folder: #{folder}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.create_configuration_file
|
45
|
+
config_path = Rails.root.join("config", "svelte_on_rails.yml")
|
46
|
+
if File.exist?(config_path)
|
47
|
+
puts "Configuration file already exists at file://#{config_path}"
|
48
|
+
else
|
49
|
+
File.write(config_path, <<~YAML)
|
50
|
+
|
51
|
+
frontend_folder: "app/frontend"
|
52
|
+
# the entrypoint that is your web root, example for vite: where @ points to
|
53
|
+
# relative to Rails.root
|
54
|
+
|
55
|
+
components_folder: "javascript/components"
|
56
|
+
# relative to frontend_folder
|
57
|
+
# where your svelte components are located
|
58
|
+
|
59
|
+
ssr: :auto
|
60
|
+
# options: true, false, :auto
|
61
|
+
# :auto: render server side if request is initial request (works only with turbo, because it checks for the X-Turbo-Request-ID header)
|
62
|
+
# when not server-side rendered the components must be built as custom elements, see node-package @csedl/svelte-on-rails
|
63
|
+
|
64
|
+
development:
|
65
|
+
watch_changes: true
|
66
|
+
# Check on every request if any file within the svelte components folder have changed, for recompiling
|
67
|
+
# Case sensitive path checking, even the file system is case insensitive
|
68
|
+
# Make sure this ist set to tue for development and test, but not for production
|
69
|
+
|
70
|
+
test:
|
71
|
+
watch_changes: true
|
72
|
+
|
73
|
+
production:
|
74
|
+
YAML
|
75
|
+
puts "Created configuration file at file://#{config_path}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.add_line_to_file(file_path, line)
|
80
|
+
file_content = File.exist?(file_path) ? File.read(file_path) : ""
|
81
|
+
|
82
|
+
if file_content.match?(/#{line}/)
|
83
|
+
puts "#{line} already present in #{file_path}, nothing changed here."
|
84
|
+
return
|
85
|
+
end
|
86
|
+
|
87
|
+
File.open(file_path, 'a') do |file|
|
88
|
+
file.puts(line)
|
89
|
+
end
|
90
|
+
puts "added #{line} to #{file_path}."
|
91
|
+
rescue StandardError => e
|
92
|
+
puts "Error: #{e.message}"
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.create_file(file_path)
|
96
|
+
|
97
|
+
unless File.exist?(file_path)
|
98
|
+
FileUtils.touch(file_path)
|
99
|
+
puts "Created empty file at file://#{file_path}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
def self.create_javascript_initializer
|
105
|
+
config_path = Rails.root.join("app", "frontend", "initializers", "svelte.js")
|
106
|
+
if File.exist?(config_path)
|
107
|
+
puts "Initializer already exists: file://#{config_path}"
|
108
|
+
else
|
109
|
+
File.write(config_path, <<~JAVASCRIPT)
|
110
|
+
|
111
|
+
import { initializeSvelteComponents, cleanupSvelteComponents } from '@csedl/svelte-on-rails';
|
112
|
+
|
113
|
+
const components = import.meta.glob('/javascript/components/**/*.svelte', { eager: true });
|
114
|
+
const componentsRoot = '/javascript/components';
|
115
|
+
|
116
|
+
// Initialize Svelte components
|
117
|
+
initializeSvelteComponents(componentsRoot, components, true);
|
118
|
+
|
119
|
+
// Turbo event listener for page load
|
120
|
+
document.addEventListener('turbo:load', () => {
|
121
|
+
initializeSvelteComponents(componentsRoot, components, true);
|
122
|
+
});
|
123
|
+
|
124
|
+
// Turbo event listener for cleanup before page cache
|
125
|
+
document.addEventListener('turbo:before-cache', () => {
|
126
|
+
cleanupSvelteComponents(false);
|
127
|
+
});
|
128
|
+
JAVASCRIPT
|
129
|
+
puts "Created initializer file at file://#{config_path}"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.create_svelte_hello_world
|
134
|
+
file_path = Rails.root.join("app", "frontend", "javascript", "components", "HelloWorld.svelte")
|
135
|
+
if File.exist?(file_path)
|
136
|
+
puts "Hello World file already exists: file://#{file_path}"
|
137
|
+
else
|
138
|
+
File.write(file_path, <<~HTML)
|
139
|
+
<script>
|
140
|
+
export let items
|
141
|
+
let count = 0;
|
142
|
+
|
143
|
+
function increment() {
|
144
|
+
count += 1;
|
145
|
+
}
|
146
|
+
</script>
|
147
|
+
|
148
|
+
<h1>Greetings from svelte</h1>
|
149
|
+
|
150
|
+
<button on:click={increment}>Increment: {count}</button>
|
151
|
+
<ul>
|
152
|
+
{#each items as item}
|
153
|
+
<li>{item}</li>
|
154
|
+
{/each}
|
155
|
+
</ul>
|
156
|
+
|
157
|
+
<style>
|
158
|
+
button {
|
159
|
+
background-color: darkred;
|
160
|
+
color: white;
|
161
|
+
padding: 10px;
|
162
|
+
border: none;
|
163
|
+
}
|
164
|
+
</style>
|
165
|
+
HTML
|
166
|
+
puts "Hello World file at file://#{file_path}"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -3,11 +3,14 @@ module SvelteOnRails
|
|
3
3
|
|
4
4
|
require 'open3'
|
5
5
|
|
6
|
-
def initialize(filename)
|
6
|
+
def initialize(filename, base_path: SvelteOnRails::Configuration.instance.components_folder_full)
|
7
7
|
|
8
|
-
|
8
|
+
fn = (filename.match(/\.svelte$/) ? filename[0..-8] : filename)
|
9
|
+
@svelte_file = base_path + filename
|
9
10
|
@svelte_filename = filename
|
10
|
-
|
11
|
+
cnf = SvelteOnRails::Configuration.instance
|
12
|
+
cf = cnf.dist_folder + cnf.components_folder + fn
|
13
|
+
@compiled_file = cf.to_s
|
11
14
|
|
12
15
|
end
|
13
16
|
|
@@ -62,7 +65,7 @@ module SvelteOnRails
|
|
62
65
|
|
63
66
|
stdout, stderr, status = Open3.capture3(cmd, chdir: self.class.gem_app_dir)
|
64
67
|
unless status.to_s.match(/^pid [0-9]+ exit 0$/)
|
65
|
-
raise "Render Svelte Server-side:\n" + stderr
|
68
|
+
raise "Render Svelte Server-side:\nrender.js => #{compiled_js_file}\n" + stderr
|
66
69
|
end
|
67
70
|
|
68
71
|
begin
|
@@ -88,13 +91,15 @@ module SvelteOnRails
|
|
88
91
|
|
89
92
|
start_time = Time.now
|
90
93
|
|
91
|
-
|
94
|
+
cnf = SvelteOnRails::Configuration.instance
|
92
95
|
subs = @svelte_filename.split('/')[0..-2].join('/')
|
96
|
+
dist = cnf.dist_folder + cnf.components_folder + subs
|
97
|
+
|
93
98
|
cmd = [
|
94
99
|
'node',
|
95
100
|
self.class.gem_app_dir + 'compile.js',
|
96
101
|
@svelte_file,
|
97
|
-
dist
|
102
|
+
dist,
|
98
103
|
self.class.gem_app_dir
|
99
104
|
].join(' ')
|
100
105
|
|
@@ -112,6 +117,17 @@ module SvelteOnRails
|
|
112
117
|
File.expand_path('../svelte_on_rails', __dir__) + '/'
|
113
118
|
end
|
114
119
|
|
120
|
+
def self.file_exist_case_sensitive?(containing_dir, filename)
|
121
|
+
# Combine the directory path and filename
|
122
|
+
full_path = File.join(containing_dir, filename)
|
123
|
+
|
124
|
+
# Check if the file exists and the path matches case-sensitively
|
125
|
+
File.exist?(full_path) && Dir[File.join(containing_dir, "**/*")].any? do |f|
|
126
|
+
f == full_path
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# assets:precompile
|
115
131
|
def self.reset_dist
|
116
132
|
unless Dir.exist?(SvelteOnRails::Configuration.instance.dist_folder)
|
117
133
|
FileUtils.mkdir_p(SvelteOnRails::Configuration.instance.dist_folder)
|
@@ -120,16 +136,21 @@ module SvelteOnRails
|
|
120
136
|
FileUtils.touch SvelteOnRails::Configuration.instance.dist_folder.join('reset_timestamp')
|
121
137
|
end
|
122
138
|
|
123
|
-
def self.
|
124
|
-
|
125
|
-
|
139
|
+
def self.reset_and_compile_all
|
140
|
+
SvelteOnRails::RenderServerSide.reset_dist
|
141
|
+
cnf = SvelteOnRails::Configuration.instance
|
142
|
+
frontend_folder = cnf.frontend_folder_full
|
143
|
+
sveltes = Dir.glob(cnf.frontend_folder_full.join('**/*.svelte'))
|
144
|
+
sveltes.each_with_index do |file, ind|
|
145
|
+
comp_name = file.to_s[(cnf.frontend_folder_full.to_s.length + 1)..-1]
|
146
|
+
|
147
|
+
n = SvelteOnRails::RenderServerSide.new(comp_name, base_path: frontend_folder)
|
148
|
+
n.compile
|
149
|
+
|
150
|
+
puts "compiled #{ind + 1}/#{sveltes.length}: #{comp_name}"
|
126
151
|
|
127
|
-
# Check if the file exists and the path matches case-sensitively
|
128
|
-
File.exist?(full_path) && Dir[File.join(containing_dir, "**/*")].any? do |f|
|
129
|
-
f == full_path
|
130
152
|
end
|
131
153
|
end
|
132
154
|
|
133
|
-
|
134
155
|
end
|
135
156
|
end
|
@@ -18,15 +18,15 @@ module SvelteOnRails
|
|
18
18
|
|
19
19
|
# check what to do
|
20
20
|
|
21
|
-
rss = if props.key?(:
|
22
|
-
props.delete(:
|
21
|
+
rss = if props.key?(:ssr)
|
22
|
+
props.delete(:ssr)
|
23
23
|
else
|
24
|
-
conf.
|
24
|
+
conf.ssr
|
25
25
|
end
|
26
26
|
unless [true, false, :auto].include?(rss)
|
27
|
-
raise "Only true, false or auto are allowed for the argument #
|
27
|
+
raise "Only true, false or auto are allowed for the argument #ssr"
|
28
28
|
end
|
29
|
-
|
29
|
+
ssr = (rss == :auto && request.headers['X-Turbo-Request-ID'].blank? || rss)
|
30
30
|
|
31
31
|
hydrate = if props.key?(:hydrate)
|
32
32
|
props[:hydrate]
|
@@ -37,7 +37,7 @@ module SvelteOnRails
|
|
37
37
|
# separate hashes
|
38
38
|
|
39
39
|
props.delete(:hydrate)
|
40
|
-
props.delete(:
|
40
|
+
props.delete(:ssr)
|
41
41
|
options = props.slice(:class, :id, :style)
|
42
42
|
props.delete(:class)
|
43
43
|
props.delete(:id)
|
@@ -45,13 +45,13 @@ module SvelteOnRails
|
|
45
45
|
|
46
46
|
# set up html
|
47
47
|
|
48
|
-
options[:class] = options[:class].to_s
|
49
|
-
options[:class] += '
|
48
|
+
options[:class] = options[:class].to_s + ' svelte-component'
|
49
|
+
options[:class] += ' please-hydrate-me-svelte-on-rails' if hydrate
|
50
50
|
options[:data] ||= {}
|
51
51
|
options[:data][:props] = props.to_json
|
52
52
|
options[:data][:svelte_component] = filename
|
53
53
|
|
54
|
-
if
|
54
|
+
if ssr
|
55
55
|
|
56
56
|
# render server side
|
57
57
|
|
@@ -1,8 +1,10 @@
|
|
1
1
|
Rake::Task["assets:precompile"].enhance do
|
2
|
-
SvelteOnRails::RenderServerSide.
|
3
|
-
puts "Mount Svelte: Reset dist
|
2
|
+
SvelteOnRails::RenderServerSide.reset_and_compile_all
|
3
|
+
puts "Mount Svelte: Reset dist and compile-all executed"
|
4
4
|
end
|
5
5
|
|
6
|
+
require 'svelte_on_rails/installer_utils'
|
7
|
+
|
6
8
|
namespace :svelte_on_rails do
|
7
9
|
desc "Installs SvelteOnRails YAML configuration into your Rails application"
|
8
10
|
task :install do
|
@@ -14,17 +16,20 @@ namespace :svelte_on_rails do
|
|
14
16
|
desc "Installs SvelteOnRails for usage together with vite_rails and @hotwired/turbo-rails"
|
15
17
|
task :install_for_vite_and_turbo do
|
16
18
|
|
17
|
-
|
19
|
+
iu = SvelteOnRails::InstallerUtils
|
20
|
+
|
21
|
+
iu.create_configuration_file
|
22
|
+
|
18
23
|
|
19
|
-
install_npm_package
|
20
|
-
install_turbo
|
24
|
+
iu.install_npm_package
|
25
|
+
iu.install_turbo
|
21
26
|
|
22
|
-
create_folder(Rails.root.join("app", "frontend", "initializers"))
|
23
|
-
create_folder(Rails.root.join("app", "frontend", "javascript", "components"))
|
24
|
-
add_line_to_file(Rails.root.join("app", "frontend", "entrypoints", "application.js"), "import '../initializers/svelte.js';")
|
27
|
+
iu.create_folder(Rails.root.join("app", "frontend", "initializers"))
|
28
|
+
iu.create_folder(Rails.root.join("app", "frontend", "javascript", "components"))
|
29
|
+
iu.add_line_to_file(Rails.root.join("app", "frontend", "entrypoints", "application.js"), "import '../initializers/svelte.js';")
|
25
30
|
|
26
|
-
create_javascript_initializer
|
27
|
-
create_svelte_hello_world
|
31
|
+
iu.create_javascript_initializer
|
32
|
+
iu.create_svelte_hello_world
|
28
33
|
|
29
34
|
puts ''
|
30
35
|
puts 'SvelteOnRails installed successfully for using together with vite_rails and @hotwired/turbo-rails.'
|
@@ -33,168 +38,9 @@ namespace :svelte_on_rails do
|
|
33
38
|
|
34
39
|
end
|
35
40
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
if system("npm install #{package_name}")
|
41
|
-
puts "#{package_name} successfully installed."
|
42
|
-
else
|
43
|
-
abort "Failed to install #{package_name}. Please ensure npm is installed and try running 'npm install #{package_name}' manually."
|
44
|
-
end
|
41
|
+
desc "Compile all Svelte components"
|
42
|
+
task :reset_and_compile_all do
|
43
|
+
SvelteOnRails::RenderServerSide.reset_and_compile_all
|
45
44
|
end
|
46
45
|
|
47
|
-
def install_turbo
|
48
|
-
|
49
|
-
pkg_js = Rails.root.join("package.json")
|
50
|
-
package_name = "@hotwired/turbo-rails"
|
51
|
-
file_content = File.exist?(pkg_js) ? File.read(pkg_js) : ""
|
52
|
-
|
53
|
-
if file_content.match?(/#{package_name}/)
|
54
|
-
puts "#{package_name} is already present in package.json, assuming that it is set up well and working."
|
55
|
-
else
|
56
|
-
puts "Installing #{package_name} via npm..."
|
57
|
-
if system("npm install #{package_name}")
|
58
|
-
puts "#{package_name} successfully installed."
|
59
|
-
add_line_to_file(Rails.root.join("app", "frontend", "entrypoints", "application.js"), "import '#{package_name}';")
|
60
|
-
else
|
61
|
-
abort "Failed to install #{package_name}. Please ensure npm is installed and try running 'npm install #{package_name}' manually."
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
def create_javascript_initializer
|
68
|
-
config_path = Rails.root.join("app", "frontend", "initializers", "svelte.js")
|
69
|
-
if File.exist?(config_path)
|
70
|
-
puts "Initializer already exists: file://#{config_path}"
|
71
|
-
else
|
72
|
-
File.write(config_path, <<~JAVASCRIPT)
|
73
|
-
|
74
|
-
import { initializeSvelteComponents, cleanupSvelteComponents } from '@csedl/svelte-on-rails';
|
75
|
-
|
76
|
-
const components = import.meta.glob('/javascript/components/**/*.svelte', { eager: true });
|
77
|
-
const componentsRoot = '/javascript/components';
|
78
|
-
|
79
|
-
// Initialize Svelte components
|
80
|
-
initializeSvelteComponents(componentsRoot, components, true);
|
81
|
-
|
82
|
-
// Turbo event listener for page load
|
83
|
-
document.addEventListener('turbo:load', () => {
|
84
|
-
initializeSvelteComponents(componentsRoot, components, true);
|
85
|
-
});
|
86
|
-
|
87
|
-
// Turbo event listener for cleanup before page cache
|
88
|
-
document.addEventListener('turbo:before-cache', () => {
|
89
|
-
cleanupSvelteComponents(false);
|
90
|
-
});
|
91
|
-
JAVASCRIPT
|
92
|
-
puts "Created initializer file at file://#{config_path}"
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def create_svelte_hello_world
|
97
|
-
file_path = Rails.root.join("app", "frontend", "javascript", "components", "HelloWorld.svelte")
|
98
|
-
if File.exist?(file_path)
|
99
|
-
puts "Hello World file already exists: file://#{file_path}"
|
100
|
-
else
|
101
|
-
File.write(file_path, <<~HTML)
|
102
|
-
<script>
|
103
|
-
export let items
|
104
|
-
let count = 0;
|
105
|
-
|
106
|
-
function increment() {
|
107
|
-
count += 1;
|
108
|
-
}
|
109
|
-
</script>
|
110
|
-
|
111
|
-
<h1>Greetings from svelte</h1>
|
112
|
-
|
113
|
-
<button on:click={increment}>Increment: {count}</button>
|
114
|
-
<ul>
|
115
|
-
{#each items as item}
|
116
|
-
<li>{item}</li>
|
117
|
-
{/each}
|
118
|
-
</ul>
|
119
|
-
|
120
|
-
<style>
|
121
|
-
button {
|
122
|
-
background-color: darkred;
|
123
|
-
color: white;
|
124
|
-
padding: 10px;
|
125
|
-
border: none;
|
126
|
-
}
|
127
|
-
</style>
|
128
|
-
HTML
|
129
|
-
puts "Hello World file at file://#{file_path}"
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
def create_file(file_path)
|
134
|
-
|
135
|
-
unless File.exist?(file_path)
|
136
|
-
FileUtils.touch(file_path)
|
137
|
-
puts "Created empty file at file://#{file_path}"
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def add_line_to_file(file_path, line)
|
142
|
-
file_content = File.exist?(file_path) ? File.read(file_path) : ""
|
143
|
-
|
144
|
-
if file_content.match?(/#{line}/)
|
145
|
-
puts "#{line} already present in #{file_path}, nothing changed here."
|
146
|
-
return
|
147
|
-
end
|
148
|
-
|
149
|
-
File.open(file_path, 'a') do |file|
|
150
|
-
file.puts(line)
|
151
|
-
end
|
152
|
-
puts "added #{line} to #{file_path}."
|
153
|
-
rescue StandardError => e
|
154
|
-
puts "Error: #{e.message}"
|
155
|
-
end
|
156
|
-
|
157
|
-
def create_folder(folder)
|
158
|
-
if Dir.exist?(folder)
|
159
|
-
puts "Folder already exists: #{folder}"
|
160
|
-
else
|
161
|
-
FileUtils.mkdir_p(folder)
|
162
|
-
puts "Created folder: #{folder}"
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def create_configuration_file
|
167
|
-
config_path = Rails.root.join("config", "svelte_on_rails.yml")
|
168
|
-
if File.exist?(config_path)
|
169
|
-
puts "Configuration file already exists at file://#{config_path}"
|
170
|
-
else
|
171
|
-
File.write(config_path, <<~YAML)
|
172
|
-
|
173
|
-
frontend_folder: "app/frontend"
|
174
|
-
# the entrypoint that is your web root, example for vite: where @ points to
|
175
|
-
# relative to Rails.root
|
176
|
-
|
177
|
-
components_folder: "javascript/components"
|
178
|
-
# relative to frontend_folder
|
179
|
-
# where your svelte components are located
|
180
|
-
|
181
|
-
render_server_side: :auto
|
182
|
-
# options: true, false, :auto
|
183
|
-
# :auto: render server side if request is initial request (works only with turbo, because it checks for the X-Turbo-Request-ID header)
|
184
|
-
# when not server-side rendered the components must be built as custom elements, see node-package @csedl/svelte-on-rails
|
185
|
-
|
186
|
-
development:
|
187
|
-
watch_changes: true
|
188
|
-
# Check on every request if any file within the svelte components folder have changed, for recompiling
|
189
|
-
# Case sensitive path checking, even the file system is case insensitive
|
190
|
-
# Make sure this ist set to tue for development and test, but not for production
|
191
|
-
|
192
|
-
test:
|
193
|
-
watch_changes: true
|
194
|
-
|
195
|
-
production:
|
196
|
-
YAML
|
197
|
-
puts "Created configuration file at file://#{config_path}"
|
198
|
-
end
|
199
|
-
end
|
200
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svelte-on-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Sedlmair
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-04-
|
11
|
+
date: 2025-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/svelte-on-rails.rb
|
35
35
|
- lib/svelte_on_rails/compile.js
|
36
36
|
- lib/svelte_on_rails/configuration.rb
|
37
|
+
- lib/svelte_on_rails/installer_utils.rb
|
37
38
|
- lib/svelte_on_rails/node_modules/@ampproject/remapping/LICENSE
|
38
39
|
- lib/svelte_on_rails/node_modules/@ampproject/remapping/README.md
|
39
40
|
- lib/svelte_on_rails/node_modules/@ampproject/remapping/dist/remapping.mjs
|