ruby_wasm_ui 0.9.0 → 0.9.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/Makefile +3 -0
- data/README.md +11 -9
- data/examples/.gitignore +2 -1
- data/examples/Gemfile.lock +1 -1
- data/examples/src/index.html +1 -1
- data/lib/ruby_wasm_ui/cli/command/base.rb +47 -29
- data/lib/ruby_wasm_ui/cli/command/dev.rb +10 -9
- data/lib/ruby_wasm_ui/cli/command/pack.rb +5 -5
- data/lib/ruby_wasm_ui/cli/command/setup.rb +31 -2
- data/lib/ruby_wasm_ui/version.rb +1 -1
- data/package-lock.json +2 -2
- data/package.json +1 -1
- data/packages/npm-packages/runtime/package-lock.json +2 -2
- data/packages/npm-packages/runtime/package.json +1 -1
- data/spec/ruby_wasm_ui/cli/command/base_spec.rb +202 -57
- data/spec/ruby_wasm_ui/cli/command/dev_spec.rb +46 -16
- data/spec/ruby_wasm_ui/cli/command/pack_spec.rb +8 -4
- data/spec/ruby_wasm_ui/cli/command/setup_spec.rb +71 -6
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bd9d0a33dc10a59959527fb70eb2080fb612f5c1d07cea603eb23ca5c957f342
|
|
4
|
+
data.tar.gz: c5dad3fabee2912ea43fe45d0fdbc899357323e127edd572b5572d4cc474a3cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7cd4c88f0f24adb3521448e94eae17a69836b517bf916e752e8dcb69793d8ec22930eda80a5492f4f5118fabeb546112e6bf142854beee415574ba55474f7b9c
|
|
7
|
+
data.tar.gz: 316e8854f16c214e0f0ce488584d5c3c0ace723fe7b5cd47f45e3961367c29cb72073772519944c71e6d1e8d50db3020e25844c3f6f2224c2dda4412fe414ccf
|
data/Makefile
CHANGED
|
@@ -30,6 +30,9 @@ bump:
|
|
|
30
30
|
@# Update lib/ruby_wasm_ui/version.rb
|
|
31
31
|
@sed -i '' 's/VERSION = ".*"/VERSION = "$(VERSION)"/' lib/ruby_wasm_ui/version.rb
|
|
32
32
|
@echo "✓ Updated lib/ruby_wasm_ui/version.rb"
|
|
33
|
+
@# Update Gemfile.lock
|
|
34
|
+
@bundle install
|
|
35
|
+
@echo "✓ Updated Gemfile.lock"
|
|
33
36
|
@# Update root package.json
|
|
34
37
|
@sed -i '' 's/"version": ".*"/"version": "$(VERSION)"/' package.json
|
|
35
38
|
@echo "✓ Updated package.json"
|
data/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Create an HTML file:
|
|
|
21
21
|
<!DOCTYPE html>
|
|
22
22
|
<html>
|
|
23
23
|
<head>
|
|
24
|
-
<script src="https://unpkg.com/ruby-wasm-ui@0.9.
|
|
24
|
+
<script src="https://unpkg.com/ruby-wasm-ui@0.9.1"></script>
|
|
25
25
|
<script defer type="text/ruby" src="app.rb"></script>
|
|
26
26
|
</head>
|
|
27
27
|
<body>
|
|
@@ -124,14 +124,6 @@ This command will:
|
|
|
124
124
|
- Update `.gitignore`
|
|
125
125
|
- Create initial `src/index.html` and `src/index.rb` files
|
|
126
126
|
|
|
127
|
-
2. Pack your application files:
|
|
128
|
-
|
|
129
|
-
```bash
|
|
130
|
-
bundle exec ruby-wasm-ui pack
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
This command packs your Ruby files from the `./src` directory into the WASM file.
|
|
134
|
-
|
|
135
127
|
**Additional Commands:**
|
|
136
128
|
|
|
137
129
|
- **Development server**: Start a development server with file watching and auto-build:
|
|
@@ -144,6 +136,16 @@ This command packs your Ruby files from the `./src` directory into the WASM file
|
|
|
144
136
|
bundle exec ruby-wasm-ui rebuild
|
|
145
137
|
```
|
|
146
138
|
|
|
139
|
+
### Deployment
|
|
140
|
+
|
|
141
|
+
Pack your application files for deployment:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
bundle exec ruby-wasm-ui pack
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
This command packs your Ruby files from the `./src` directory into the WASM file and outputs to the `dist` directory for deployment.
|
|
148
|
+
|
|
147
149
|
### Creating Your HTML File
|
|
148
150
|
|
|
149
151
|
Create an HTML file in the `src` directory that loads the WASM file:
|
data/examples/.gitignore
CHANGED
data/examples/Gemfile.lock
CHANGED
data/examples/src/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<title>My App</title>
|
|
6
6
|
<script type="module">
|
|
7
7
|
import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.7.2/dist/browser/+esm";
|
|
8
|
-
const response = await fetch("
|
|
8
|
+
const response = await fetch("./src.wasm");
|
|
9
9
|
const module = await WebAssembly.compileStreaming(response);
|
|
10
10
|
const { vm } = await DefaultRubyVM(module);
|
|
11
11
|
vm.evalAsync(`
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "fileutils"
|
|
3
4
|
require "open3"
|
|
4
5
|
require "bundler/setup"
|
|
5
6
|
require "ruby_wasm"
|
|
@@ -74,35 +75,6 @@ module RubyWasmUi
|
|
|
74
75
|
end
|
|
75
76
|
end
|
|
76
77
|
|
|
77
|
-
def update_gitignore(entries_to_add)
|
|
78
|
-
gitignore_path = ".gitignore"
|
|
79
|
-
|
|
80
|
-
# Read existing .gitignore or create new content
|
|
81
|
-
if File.exist?(gitignore_path)
|
|
82
|
-
content = File.read(gitignore_path)
|
|
83
|
-
lines = content.lines.map(&:chomp)
|
|
84
|
-
else
|
|
85
|
-
lines = []
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
# Add entries that don't already exist
|
|
89
|
-
added_entries = []
|
|
90
|
-
entries_to_add.each do |entry|
|
|
91
|
-
unless lines.include?(entry)
|
|
92
|
-
lines << entry
|
|
93
|
-
added_entries << entry
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
# Write back to .gitignore
|
|
98
|
-
File.write(gitignore_path, lines.join("\n") + "\n")
|
|
99
|
-
if added_entries.any?
|
|
100
|
-
log_info("Added to .gitignore: #{added_entries.join(', ')}")
|
|
101
|
-
else
|
|
102
|
-
log_info("No new entries added to .gitignore (all entries already exist)")
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
|
|
106
78
|
protected
|
|
107
79
|
|
|
108
80
|
def log_info(message)
|
|
@@ -168,6 +140,52 @@ module RubyWasmUi
|
|
|
168
140
|
cli = RubyWasm::CLI.new(stdout: $stdout, stderr: $stderr)
|
|
169
141
|
cli.run(command)
|
|
170
142
|
end
|
|
143
|
+
|
|
144
|
+
def ensure_dist_directory
|
|
145
|
+
unless Dir.exist?("dist")
|
|
146
|
+
Dir.mkdir("dist")
|
|
147
|
+
log_info("Created dist directory")
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def copy_non_ruby_files
|
|
152
|
+
log_info("Copying non-Ruby files from src to dist...")
|
|
153
|
+
|
|
154
|
+
copied_files = []
|
|
155
|
+
Dir.glob("src/**/*").each do |src_path|
|
|
156
|
+
next if File.directory?(src_path)
|
|
157
|
+
next if src_path.end_with?(".rb")
|
|
158
|
+
|
|
159
|
+
# Get relative path from src directory
|
|
160
|
+
relative_path = src_path.sub(/^src\//, "")
|
|
161
|
+
dest_path = File.join("dist", relative_path)
|
|
162
|
+
|
|
163
|
+
# Create destination directory if needed
|
|
164
|
+
dest_dir = File.dirname(dest_path)
|
|
165
|
+
FileUtils.mkdir_p(dest_dir) unless Dir.exist?(dest_dir)
|
|
166
|
+
|
|
167
|
+
# Copy file
|
|
168
|
+
FileUtils.cp(src_path, dest_path)
|
|
169
|
+
copied_files << relative_path
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
if copied_files.any?
|
|
173
|
+
log_success("✓ Copied #{copied_files.size} file(s): #{copied_files.join(', ')}")
|
|
174
|
+
else
|
|
175
|
+
log_info("No non-Ruby files to copy")
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def pack_wasm(exit_on_error: true, log_prefix: "Packing")
|
|
180
|
+
command = "bundle exec rbwasm pack ruby.wasm --dir ./src::./src -o dist/src.wasm"
|
|
181
|
+
log_info("#{log_prefix}: #{command}")
|
|
182
|
+
|
|
183
|
+
success = run_command(command, exit_on_error: exit_on_error)
|
|
184
|
+
if success
|
|
185
|
+
log_success("✓ Pack completed")
|
|
186
|
+
end
|
|
187
|
+
success
|
|
188
|
+
end
|
|
171
189
|
end
|
|
172
190
|
end
|
|
173
191
|
end
|
|
@@ -19,6 +19,7 @@ module RubyWasmUi
|
|
|
19
19
|
puts ""
|
|
20
20
|
|
|
21
21
|
ensure_src_directory
|
|
22
|
+
ensure_ruby_wasm
|
|
22
23
|
|
|
23
24
|
# Initial build
|
|
24
25
|
log_info("Performing initial build...")
|
|
@@ -76,11 +77,11 @@ module RubyWasmUi
|
|
|
76
77
|
end
|
|
77
78
|
|
|
78
79
|
def build
|
|
79
|
-
|
|
80
|
-
log_info("Building: #{command}")
|
|
80
|
+
ensure_dist_directory
|
|
81
81
|
|
|
82
|
-
success =
|
|
82
|
+
success = pack_wasm(exit_on_error: false, log_prefix: "Building")
|
|
83
83
|
if success
|
|
84
|
+
copy_non_ruby_files
|
|
84
85
|
log_success("✓ Build completed")
|
|
85
86
|
else
|
|
86
87
|
log_error("Build failed")
|
|
@@ -132,11 +133,11 @@ module RubyWasmUi
|
|
|
132
133
|
# Static file server application
|
|
133
134
|
static_app = lambda do |env|
|
|
134
135
|
path = env["PATH_INFO"]
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
# Remove leading slash and handle root path
|
|
137
|
+
relative_path = path == "/" ? "index.html" : path.sub(/^\//, "")
|
|
138
|
+
|
|
139
|
+
# Serve files from dist directory
|
|
140
|
+
file_path = File.join(Dir.pwd, "dist", relative_path)
|
|
140
141
|
|
|
141
142
|
if File.exist?(file_path) && File.file?(file_path)
|
|
142
143
|
content_type = Rack::Mime.mime_type(File.extname(file_path), "text/html")
|
|
@@ -187,7 +188,7 @@ module RubyWasmUi
|
|
|
187
188
|
# Open browser after a short delay to ensure server is ready
|
|
188
189
|
Thread.new do
|
|
189
190
|
sleep 1
|
|
190
|
-
open_browser("http://localhost:#{port}/
|
|
191
|
+
open_browser("http://localhost:#{port}/index.html")
|
|
191
192
|
end
|
|
192
193
|
|
|
193
194
|
Rack::Handler::Puma.run(app, Port: port, Host: "0.0.0.0")
|
|
@@ -16,19 +16,19 @@ module RubyWasmUi
|
|
|
16
16
|
|
|
17
17
|
ensure_src_directory
|
|
18
18
|
ensure_ruby_wasm
|
|
19
|
+
ensure_dist_directory
|
|
19
20
|
|
|
20
21
|
# Pack WASM file
|
|
21
22
|
pack
|
|
23
|
+
|
|
24
|
+
# Copy non-Ruby files from src to dist
|
|
25
|
+
copy_non_ruby_files
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
private
|
|
25
29
|
|
|
26
30
|
def pack
|
|
27
|
-
|
|
28
|
-
log_info("Packing: #{command}")
|
|
29
|
-
|
|
30
|
-
run_command(command)
|
|
31
|
-
log_success("✓ Pack completed")
|
|
31
|
+
pack_wasm(exit_on_error: true, log_prefix: 'Packing')
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
end
|
|
@@ -32,7 +32,7 @@ module RubyWasmUi
|
|
|
32
32
|
# Update .gitignore
|
|
33
33
|
puts ""
|
|
34
34
|
log_info("Step 3/4: Updating .gitignore...")
|
|
35
|
-
update_gitignore(["
|
|
35
|
+
update_gitignore(["ruby.wasm", "/rubies", "/build", "/dist"])
|
|
36
36
|
log_success("✓ .gitignore updated")
|
|
37
37
|
|
|
38
38
|
# Create initial files
|
|
@@ -46,6 +46,35 @@ module RubyWasmUi
|
|
|
46
46
|
|
|
47
47
|
private
|
|
48
48
|
|
|
49
|
+
def update_gitignore(entries_to_add)
|
|
50
|
+
gitignore_path = ".gitignore"
|
|
51
|
+
|
|
52
|
+
# Read existing .gitignore or create new content
|
|
53
|
+
if File.exist?(gitignore_path)
|
|
54
|
+
content = File.read(gitignore_path)
|
|
55
|
+
lines = content.lines.map(&:chomp)
|
|
56
|
+
else
|
|
57
|
+
lines = []
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Add entries that don't already exist
|
|
61
|
+
added_entries = []
|
|
62
|
+
entries_to_add.each do |entry|
|
|
63
|
+
unless lines.include?(entry)
|
|
64
|
+
lines << entry
|
|
65
|
+
added_entries << entry
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Write back to .gitignore
|
|
70
|
+
File.write(gitignore_path, lines.join("\n") + "\n")
|
|
71
|
+
if added_entries.any?
|
|
72
|
+
log_info("Added to .gitignore: #{added_entries.join(', ')}")
|
|
73
|
+
else
|
|
74
|
+
log_info("No new entries added to .gitignore (all entries already exist)")
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
49
78
|
def create_initial_files
|
|
50
79
|
# Skip if src directory exists
|
|
51
80
|
if Dir.exist?("src")
|
|
@@ -76,7 +105,7 @@ module RubyWasmUi
|
|
|
76
105
|
<title>My App</title>
|
|
77
106
|
<script type="module">
|
|
78
107
|
import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.7.2/dist/browser/+esm";
|
|
79
|
-
const response = await fetch("
|
|
108
|
+
const response = await fetch("./src.wasm");
|
|
80
109
|
const module = await WebAssembly.compileStreaming(response);
|
|
81
110
|
const { vm } = await DefaultRubyVM(module);
|
|
82
111
|
vm.evalAsync(`
|
data/lib/ruby_wasm_ui/version.rb
CHANGED
data/package-lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ruby-wasm-ui-project",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "ruby-wasm-ui-project",
|
|
9
|
-
"version": "0.9.
|
|
9
|
+
"version": "0.9.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"workspaces": [
|
|
12
12
|
"packages/*"
|
data/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ruby-wasm-ui",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "ruby-wasm-ui",
|
|
9
|
-
"version": "0.9.
|
|
9
|
+
"version": "0.9.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@rollup/plugin-replace": "^6.0.2",
|
|
@@ -13,63 +13,6 @@ RSpec.describe RubyWasmUi::Cli::Command::Base do
|
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
describe '#update_gitignore' do
|
|
17
|
-
let(:temp_dir) { Dir.mktmpdir }
|
|
18
|
-
let(:original_dir) { Dir.pwd }
|
|
19
|
-
|
|
20
|
-
around do |example|
|
|
21
|
-
Dir.chdir(temp_dir) do
|
|
22
|
-
example.run
|
|
23
|
-
end
|
|
24
|
-
ensure
|
|
25
|
-
FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context 'when .gitignore does not exist' do
|
|
29
|
-
it 'creates .gitignore with new entries' do
|
|
30
|
-
base_instance.send(:update_gitignore, ['*.wasm', '/rubies'])
|
|
31
|
-
content = File.read('.gitignore')
|
|
32
|
-
expect(content).to include('*.wasm')
|
|
33
|
-
expect(content).to include('/rubies')
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context 'when .gitignore exists' do
|
|
38
|
-
before do
|
|
39
|
-
File.write('.gitignore', "node_modules/\n*.log\n")
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it 'adds new entries to existing .gitignore' do
|
|
43
|
-
base_instance.send(:update_gitignore, ['*.wasm', '/rubies'])
|
|
44
|
-
content = File.read('.gitignore')
|
|
45
|
-
expect(content).to include('node_modules/')
|
|
46
|
-
expect(content).to include('*.log')
|
|
47
|
-
expect(content).to include('*.wasm')
|
|
48
|
-
expect(content).to include('/rubies')
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it 'does not add duplicate entries' do
|
|
52
|
-
File.write('.gitignore', "*.wasm\n")
|
|
53
|
-
base_instance.send(:update_gitignore, ['*.wasm', '/rubies'])
|
|
54
|
-
content = File.read('.gitignore')
|
|
55
|
-
expect(content.scan(/^\*\.wasm$/).count).to eq(1)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'outputs message when entries are added' do
|
|
59
|
-
expect { base_instance.send(:update_gitignore, ['*.wasm']) }.to output(
|
|
60
|
-
/Added to .gitignore: \*\.wasm/
|
|
61
|
-
).to_stdout
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it 'outputs message when no entries are added' do
|
|
65
|
-
File.write('.gitignore', "*.wasm\n")
|
|
66
|
-
expect { base_instance.send(:update_gitignore, ['*.wasm']) }.to output(
|
|
67
|
-
/No new entries added to .gitignore/
|
|
68
|
-
).to_stdout
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
16
|
describe '#run_command' do
|
|
74
17
|
context 'when command succeeds' do
|
|
75
18
|
it 'executes the command and outputs stdout' do
|
|
@@ -355,4 +298,206 @@ RSpec.describe RubyWasmUi::Cli::Command::Base do
|
|
|
355
298
|
base_instance.send(:build_ruby_wasm, '3.4')
|
|
356
299
|
end
|
|
357
300
|
end
|
|
301
|
+
|
|
302
|
+
describe '#ensure_dist_directory' do
|
|
303
|
+
let(:temp_dir) { Dir.mktmpdir }
|
|
304
|
+
let(:original_dir) { Dir.pwd }
|
|
305
|
+
|
|
306
|
+
around do |example|
|
|
307
|
+
Dir.chdir(temp_dir) do
|
|
308
|
+
example.run
|
|
309
|
+
end
|
|
310
|
+
ensure
|
|
311
|
+
FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir)
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
context 'when dist directory does not exist' do
|
|
315
|
+
it 'creates dist directory' do
|
|
316
|
+
expect(Dir.exist?('dist')).to be false
|
|
317
|
+
base_instance.send(:ensure_dist_directory)
|
|
318
|
+
expect(Dir.exist?('dist')).to be true
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
it 'outputs creation message' do
|
|
322
|
+
expect { base_instance.send(:ensure_dist_directory) }.to output(
|
|
323
|
+
/Created dist directory/
|
|
324
|
+
).to_stdout
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
context 'when dist directory already exists' do
|
|
329
|
+
before do
|
|
330
|
+
FileUtils.mkdir_p('dist')
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
it 'does not create dist directory again' do
|
|
334
|
+
expect(Dir).not_to receive(:mkdir)
|
|
335
|
+
base_instance.send(:ensure_dist_directory)
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
it 'does not output creation message' do
|
|
339
|
+
expect { base_instance.send(:ensure_dist_directory) }.not_to output(
|
|
340
|
+
/Created dist directory/
|
|
341
|
+
).to_stdout
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
describe '#copy_non_ruby_files' do
|
|
347
|
+
let(:temp_dir) { Dir.mktmpdir }
|
|
348
|
+
let(:original_dir) { Dir.pwd }
|
|
349
|
+
|
|
350
|
+
around do |example|
|
|
351
|
+
Dir.chdir(temp_dir) do
|
|
352
|
+
example.run
|
|
353
|
+
end
|
|
354
|
+
ensure
|
|
355
|
+
FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir)
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
context 'when non-Ruby files exist' do
|
|
359
|
+
before do
|
|
360
|
+
FileUtils.mkdir_p('src')
|
|
361
|
+
File.write('src/index.html', '<html></html>')
|
|
362
|
+
File.write('src/style.css', 'body {}')
|
|
363
|
+
File.write('src/app.rb', 'puts "hello"')
|
|
364
|
+
FileUtils.mkdir_p('src/subdir')
|
|
365
|
+
File.write('src/subdir/script.js', 'console.log("test")')
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
it 'copies HTML files to dist' do
|
|
369
|
+
base_instance.send(:copy_non_ruby_files)
|
|
370
|
+
expect(File.exist?('dist/index.html')).to be true
|
|
371
|
+
expect(File.read('dist/index.html')).to eq('<html></html>')
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
it 'copies CSS files to dist' do
|
|
375
|
+
base_instance.send(:copy_non_ruby_files)
|
|
376
|
+
expect(File.exist?('dist/style.css')).to be true
|
|
377
|
+
expect(File.read('dist/style.css')).to eq('body {}')
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
it 'does not copy Ruby files' do
|
|
381
|
+
base_instance.send(:copy_non_ruby_files)
|
|
382
|
+
expect(File.exist?('dist/app.rb')).to be false
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
it 'preserves directory structure' do
|
|
386
|
+
base_instance.send(:copy_non_ruby_files)
|
|
387
|
+
expect(File.exist?('dist/subdir/script.js')).to be true
|
|
388
|
+
expect(File.read('dist/subdir/script.js')).to eq('console.log("test")')
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
it 'outputs success message with copied files' do
|
|
392
|
+
expect { base_instance.send(:copy_non_ruby_files) }.to output(
|
|
393
|
+
/Copied.*file\(s\)/
|
|
394
|
+
).to_stdout
|
|
395
|
+
end
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
context 'when no non-Ruby files exist' do
|
|
399
|
+
before do
|
|
400
|
+
FileUtils.mkdir_p('src')
|
|
401
|
+
File.write('src/app.rb', 'puts "hello"')
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
it 'outputs no files message' do
|
|
405
|
+
expect { base_instance.send(:copy_non_ruby_files) }.to output(
|
|
406
|
+
/No non-Ruby files to copy/
|
|
407
|
+
).to_stdout
|
|
408
|
+
end
|
|
409
|
+
end
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
describe '#pack_wasm' do
|
|
413
|
+
let(:temp_dir) { Dir.mktmpdir }
|
|
414
|
+
let(:original_dir) { Dir.pwd }
|
|
415
|
+
|
|
416
|
+
around do |example|
|
|
417
|
+
Dir.chdir(temp_dir) do
|
|
418
|
+
example.run
|
|
419
|
+
end
|
|
420
|
+
ensure
|
|
421
|
+
FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir)
|
|
422
|
+
end
|
|
423
|
+
|
|
424
|
+
before do
|
|
425
|
+
FileUtils.mkdir_p('src')
|
|
426
|
+
FileUtils.touch('ruby.wasm')
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
context 'when command succeeds' do
|
|
430
|
+
before do
|
|
431
|
+
allow(base_instance).to receive(:run_command).and_return(true)
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
it 'executes rbwasm pack command via run_command' do
|
|
435
|
+
expect(base_instance).to receive(:run_command).with(
|
|
436
|
+
'bundle exec rbwasm pack ruby.wasm --dir ./src::./src -o dist/src.wasm',
|
|
437
|
+
exit_on_error: true
|
|
438
|
+
)
|
|
439
|
+
base_instance.send(:pack_wasm)
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
it 'outputs pack message with default prefix' do
|
|
443
|
+
expect { base_instance.send(:pack_wasm) }.to output(
|
|
444
|
+
/Packing: bundle exec rbwasm pack/
|
|
445
|
+
).to_stdout
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
it 'outputs pack message with custom prefix' do
|
|
449
|
+
expect { base_instance.send(:pack_wasm, log_prefix: 'Building') }.to output(
|
|
450
|
+
/Building: bundle exec rbwasm pack/
|
|
451
|
+
).to_stdout
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
it 'outputs success message' do
|
|
455
|
+
expect { base_instance.send(:pack_wasm) }.to output(
|
|
456
|
+
/Pack completed/
|
|
457
|
+
).to_stdout
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
it 'returns true' do
|
|
461
|
+
result = base_instance.send(:pack_wasm)
|
|
462
|
+
expect(result).to be true
|
|
463
|
+
end
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
context 'when command fails' do
|
|
467
|
+
before do
|
|
468
|
+
allow(base_instance).to receive(:run_command).and_raise(SystemExit.new(1))
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
it 'outputs error message and exits by default' do
|
|
472
|
+
expect { base_instance.send(:pack_wasm) }.to raise_error(SystemExit)
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
it 'exits with status 1' do
|
|
476
|
+
expect { base_instance.send(:pack_wasm) }.to raise_error(SystemExit) do |error|
|
|
477
|
+
expect(error.status).to eq(1)
|
|
478
|
+
end
|
|
479
|
+
end
|
|
480
|
+
|
|
481
|
+
context 'when exit_on_error is false' do
|
|
482
|
+
before do
|
|
483
|
+
allow(base_instance).to receive(:run_command).and_return(false)
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
it 'does not raise error' do
|
|
487
|
+
expect { base_instance.send(:pack_wasm, exit_on_error: false) }.not_to raise_error
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
it 'returns false' do
|
|
491
|
+
result = base_instance.send(:pack_wasm, exit_on_error: false)
|
|
492
|
+
expect(result).to be false
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
it 'does not output success message when command fails' do
|
|
496
|
+
expect { base_instance.send(:pack_wasm, exit_on_error: false) }.not_to output(
|
|
497
|
+
/Pack completed/
|
|
498
|
+
).to_stdout
|
|
499
|
+
end
|
|
500
|
+
end
|
|
501
|
+
end
|
|
502
|
+
end
|
|
358
503
|
end
|
|
@@ -55,9 +55,28 @@ RSpec.describe RubyWasmUi::Cli::Command::Dev do
|
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
+
context 'when src directory exists but ruby.wasm does not exist' do
|
|
59
|
+
before do
|
|
60
|
+
FileUtils.mkdir_p('src')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'outputs error message and exits' do
|
|
64
|
+
expect { dev_instance.run([]) }.to output(
|
|
65
|
+
/ruby.wasm not found. Please run 'ruby-wasm-ui setup' first./
|
|
66
|
+
).to_stdout.and raise_error(SystemExit)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'exits with status 1' do
|
|
70
|
+
expect { dev_instance.run([]) }.to raise_error(SystemExit) do |error|
|
|
71
|
+
expect(error.status).to eq(1)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
58
76
|
context 'when src directory exists' do
|
|
59
77
|
before do
|
|
60
78
|
FileUtils.mkdir_p('src')
|
|
79
|
+
FileUtils.touch('ruby.wasm')
|
|
61
80
|
end
|
|
62
81
|
|
|
63
82
|
it 'outputs starting message' do
|
|
@@ -116,6 +135,7 @@ RSpec.describe RubyWasmUi::Cli::Command::Dev do
|
|
|
116
135
|
describe '#build' do
|
|
117
136
|
before do
|
|
118
137
|
FileUtils.mkdir_p('src')
|
|
138
|
+
FileUtils.touch('ruby.wasm')
|
|
119
139
|
end
|
|
120
140
|
|
|
121
141
|
context 'when command succeeds' do
|
|
@@ -123,11 +143,9 @@ RSpec.describe RubyWasmUi::Cli::Command::Dev do
|
|
|
123
143
|
allow(dev_instance).to receive(:run_command).and_return(true)
|
|
124
144
|
end
|
|
125
145
|
|
|
126
|
-
it '
|
|
127
|
-
expect(dev_instance).to receive(:
|
|
128
|
-
|
|
129
|
-
exit_on_error: false
|
|
130
|
-
)
|
|
146
|
+
it 'calls pack_wasm with Building log_prefix' do
|
|
147
|
+
expect(dev_instance).to receive(:pack_wasm).with(exit_on_error: false, log_prefix: 'Building').and_return(true)
|
|
148
|
+
allow(dev_instance).to receive(:copy_non_ruby_files)
|
|
131
149
|
dev_instance.send(:build)
|
|
132
150
|
end
|
|
133
151
|
|
|
@@ -137,6 +155,12 @@ RSpec.describe RubyWasmUi::Cli::Command::Dev do
|
|
|
137
155
|
).to_stdout
|
|
138
156
|
end
|
|
139
157
|
|
|
158
|
+
it 'calls copy_non_ruby_files when build succeeds' do
|
|
159
|
+
allow(dev_instance).to receive(:pack_wasm).and_return(true)
|
|
160
|
+
expect(dev_instance).to receive(:copy_non_ruby_files)
|
|
161
|
+
dev_instance.send(:build)
|
|
162
|
+
end
|
|
163
|
+
|
|
140
164
|
it 'outputs success message' do
|
|
141
165
|
expect { dev_instance.send(:build) }.to output(
|
|
142
166
|
/Build completed/
|
|
@@ -154,6 +178,12 @@ RSpec.describe RubyWasmUi::Cli::Command::Dev do
|
|
|
154
178
|
allow(dev_instance).to receive(:run_command).and_return(false)
|
|
155
179
|
end
|
|
156
180
|
|
|
181
|
+
it 'does not call copy_non_ruby_files when build fails' do
|
|
182
|
+
allow(dev_instance).to receive(:pack_wasm).and_return(false)
|
|
183
|
+
expect(dev_instance).not_to receive(:copy_non_ruby_files)
|
|
184
|
+
dev_instance.send(:build)
|
|
185
|
+
end
|
|
186
|
+
|
|
157
187
|
it 'outputs error message' do
|
|
158
188
|
expect { dev_instance.send(:build) }.to output(
|
|
159
189
|
/Build failed/
|
|
@@ -306,7 +336,7 @@ RSpec.describe RubyWasmUi::Cli::Command::Dev do
|
|
|
306
336
|
instance_double(Thread)
|
|
307
337
|
end
|
|
308
338
|
|
|
309
|
-
expect(dev_instance).to receive(:open_browser).with('http://localhost:8080/
|
|
339
|
+
expect(dev_instance).to receive(:open_browser).with('http://localhost:8080/index.html').and_return(nil)
|
|
310
340
|
|
|
311
341
|
dev_instance.send(:start_server)
|
|
312
342
|
|
|
@@ -358,8 +388,8 @@ RSpec.describe RubyWasmUi::Cli::Command::Dev do
|
|
|
358
388
|
end
|
|
359
389
|
|
|
360
390
|
it 'calls open command' do
|
|
361
|
-
expect(dev_instance).to receive(:system).with('open', 'http://localhost:8080/
|
|
362
|
-
dev_instance.send(:open_browser, 'http://localhost:8080/
|
|
391
|
+
expect(dev_instance).to receive(:system).with('open', 'http://localhost:8080/index.html').and_return(true)
|
|
392
|
+
dev_instance.send(:open_browser, 'http://localhost:8080/index.html')
|
|
363
393
|
end
|
|
364
394
|
|
|
365
395
|
context 'when system call fails' do
|
|
@@ -368,8 +398,8 @@ RSpec.describe RubyWasmUi::Cli::Command::Dev do
|
|
|
368
398
|
end
|
|
369
399
|
|
|
370
400
|
it 'outputs fallback message' do
|
|
371
|
-
expect { dev_instance.send(:open_browser, 'http://localhost:8080/
|
|
372
|
-
/Please open http:\/\/localhost:8080\/
|
|
401
|
+
expect { dev_instance.send(:open_browser, 'http://localhost:8080/index.html') }.to output(
|
|
402
|
+
/Please open http:\/\/localhost:8080\/index.html in your browser/
|
|
373
403
|
).to_stdout
|
|
374
404
|
end
|
|
375
405
|
end
|
|
@@ -381,8 +411,8 @@ RSpec.describe RubyWasmUi::Cli::Command::Dev do
|
|
|
381
411
|
end
|
|
382
412
|
|
|
383
413
|
it 'calls xdg-open command' do
|
|
384
|
-
expect(dev_instance).to receive(:system).with('xdg-open', 'http://localhost:8080/
|
|
385
|
-
dev_instance.send(:open_browser, 'http://localhost:8080/
|
|
414
|
+
expect(dev_instance).to receive(:system).with('xdg-open', 'http://localhost:8080/index.html').and_return(true)
|
|
415
|
+
dev_instance.send(:open_browser, 'http://localhost:8080/index.html')
|
|
386
416
|
end
|
|
387
417
|
end
|
|
388
418
|
|
|
@@ -392,8 +422,8 @@ RSpec.describe RubyWasmUi::Cli::Command::Dev do
|
|
|
392
422
|
end
|
|
393
423
|
|
|
394
424
|
it 'calls start command' do
|
|
395
|
-
expect(dev_instance).to receive(:system).with('start', 'http://localhost:8080/
|
|
396
|
-
dev_instance.send(:open_browser, 'http://localhost:8080/
|
|
425
|
+
expect(dev_instance).to receive(:system).with('start', 'http://localhost:8080/index.html').and_return(true)
|
|
426
|
+
dev_instance.send(:open_browser, 'http://localhost:8080/index.html')
|
|
397
427
|
end
|
|
398
428
|
end
|
|
399
429
|
|
|
@@ -403,8 +433,8 @@ RSpec.describe RubyWasmUi::Cli::Command::Dev do
|
|
|
403
433
|
end
|
|
404
434
|
|
|
405
435
|
it 'outputs manual instruction' do
|
|
406
|
-
expect { dev_instance.send(:open_browser, 'http://localhost:8080/
|
|
407
|
-
/Please open http:\/\/localhost:8080\/
|
|
436
|
+
expect { dev_instance.send(:open_browser, 'http://localhost:8080/index.html') }.to output(
|
|
437
|
+
/Please open http:\/\/localhost:8080\/index.html in your browser/
|
|
408
438
|
).to_stdout
|
|
409
439
|
end
|
|
410
440
|
end
|
|
@@ -62,6 +62,7 @@ RSpec.describe RubyWasmUi::Cli::Command::Pack do
|
|
|
62
62
|
FileUtils.mkdir_p('src')
|
|
63
63
|
FileUtils.touch('ruby.wasm')
|
|
64
64
|
allow(pack_instance).to receive(:pack)
|
|
65
|
+
allow(pack_instance).to receive(:copy_non_ruby_files)
|
|
65
66
|
end
|
|
66
67
|
|
|
67
68
|
it 'outputs packing message' do
|
|
@@ -74,6 +75,11 @@ RSpec.describe RubyWasmUi::Cli::Command::Pack do
|
|
|
74
75
|
expect(pack_instance).to receive(:pack)
|
|
75
76
|
pack_instance.run([])
|
|
76
77
|
end
|
|
78
|
+
|
|
79
|
+
it 'calls copy_non_ruby_files method' do
|
|
80
|
+
expect(pack_instance).to receive(:copy_non_ruby_files)
|
|
81
|
+
pack_instance.run([])
|
|
82
|
+
end
|
|
77
83
|
end
|
|
78
84
|
end
|
|
79
85
|
|
|
@@ -88,10 +94,8 @@ RSpec.describe RubyWasmUi::Cli::Command::Pack do
|
|
|
88
94
|
allow(pack_instance).to receive(:run_command).and_return(true)
|
|
89
95
|
end
|
|
90
96
|
|
|
91
|
-
it '
|
|
92
|
-
expect(pack_instance).to receive(:
|
|
93
|
-
'bundle exec rbwasm pack ruby.wasm --dir ./src::./src -o src.wasm'
|
|
94
|
-
)
|
|
97
|
+
it 'calls pack_wasm with default parameters' do
|
|
98
|
+
expect(pack_instance).to receive(:pack_wasm).with(exit_on_error: true, log_prefix: 'Packing').and_return(true)
|
|
95
99
|
pack_instance.send(:pack)
|
|
96
100
|
end
|
|
97
101
|
|
|
@@ -13,11 +13,20 @@ RSpec.describe RubyWasmUi::Cli::Command::Setup do
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
describe '#run' do
|
|
16
|
+
let(:temp_dir) { Dir.mktmpdir }
|
|
17
|
+
|
|
18
|
+
around do |example|
|
|
19
|
+
Dir.chdir(temp_dir) do
|
|
20
|
+
example.run
|
|
21
|
+
end
|
|
22
|
+
ensure
|
|
23
|
+
FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir)
|
|
24
|
+
end
|
|
25
|
+
|
|
16
26
|
before do
|
|
17
27
|
allow(setup_instance).to receive(:check_ruby_version).and_return(RUBY_VERSION.split('.')[0..1].join('.'))
|
|
18
28
|
allow(setup_instance).to receive(:configure_excluded_gems)
|
|
19
29
|
allow(setup_instance).to receive(:build_ruby_wasm)
|
|
20
|
-
allow(setup_instance).to receive(:update_gitignore)
|
|
21
30
|
allow(setup_instance).to receive(:create_initial_files)
|
|
22
31
|
end
|
|
23
32
|
|
|
@@ -44,10 +53,12 @@ RSpec.describe RubyWasmUi::Cli::Command::Setup do
|
|
|
44
53
|
end
|
|
45
54
|
|
|
46
55
|
it 'updates .gitignore with required entries' do
|
|
47
|
-
expect(setup_instance).to receive(:update_gitignore).with(
|
|
48
|
-
['*.wasm', '/rubies', '/build']
|
|
49
|
-
)
|
|
50
56
|
setup_instance.run([])
|
|
57
|
+
content = File.read('.gitignore')
|
|
58
|
+
expect(content).to include('ruby.wasm')
|
|
59
|
+
expect(content).to include('/rubies')
|
|
60
|
+
expect(content).to include('/build')
|
|
61
|
+
expect(content).to include('/dist')
|
|
51
62
|
end
|
|
52
63
|
|
|
53
64
|
it 'outputs completion message' do
|
|
@@ -85,7 +96,6 @@ RSpec.describe RubyWasmUi::Cli::Command::Setup do
|
|
|
85
96
|
it 'does not execute subsequent steps' do
|
|
86
97
|
expect(setup_instance).not_to receive(:configure_excluded_gems)
|
|
87
98
|
expect(setup_instance).not_to receive(:build_ruby_wasm)
|
|
88
|
-
expect(setup_instance).not_to receive(:update_gitignore)
|
|
89
99
|
expect(setup_instance).not_to receive(:create_initial_files)
|
|
90
100
|
expect { setup_instance.run([]) }.to raise_error(SystemExit)
|
|
91
101
|
end
|
|
@@ -97,7 +107,6 @@ RSpec.describe RubyWasmUi::Cli::Command::Setup do
|
|
|
97
107
|
allow(setup_instance).to receive(:check_ruby_version).and_return('3.2')
|
|
98
108
|
allow(setup_instance).to receive(:configure_excluded_gems)
|
|
99
109
|
allow(setup_instance).to receive(:build_ruby_wasm)
|
|
100
|
-
allow(setup_instance).to receive(:update_gitignore)
|
|
101
110
|
allow(setup_instance).to receive(:create_initial_files)
|
|
102
111
|
end
|
|
103
112
|
|
|
@@ -183,4 +192,60 @@ RSpec.describe RubyWasmUi::Cli::Command::Setup do
|
|
|
183
192
|
end
|
|
184
193
|
end
|
|
185
194
|
end
|
|
195
|
+
|
|
196
|
+
describe '#update_gitignore' do
|
|
197
|
+
let(:temp_dir) { Dir.mktmpdir }
|
|
198
|
+
|
|
199
|
+
around do |example|
|
|
200
|
+
Dir.chdir(temp_dir) do
|
|
201
|
+
example.run
|
|
202
|
+
end
|
|
203
|
+
ensure
|
|
204
|
+
FileUtils.rm_rf(temp_dir) if Dir.exist?(temp_dir)
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
context 'when .gitignore does not exist' do
|
|
208
|
+
it 'creates .gitignore with new entries' do
|
|
209
|
+
setup_instance.send(:update_gitignore, ['*.wasm', '/rubies'])
|
|
210
|
+
content = File.read('.gitignore')
|
|
211
|
+
expect(content).to include('*.wasm')
|
|
212
|
+
expect(content).to include('/rubies')
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
context 'when .gitignore exists' do
|
|
217
|
+
before do
|
|
218
|
+
File.write('.gitignore', "node_modules/\n*.log\n")
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
it 'adds new entries to existing .gitignore' do
|
|
222
|
+
setup_instance.send(:update_gitignore, ['*.wasm', '/rubies'])
|
|
223
|
+
content = File.read('.gitignore')
|
|
224
|
+
expect(content).to include('node_modules/')
|
|
225
|
+
expect(content).to include('*.log')
|
|
226
|
+
expect(content).to include('*.wasm')
|
|
227
|
+
expect(content).to include('/rubies')
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
it 'does not add duplicate entries' do
|
|
231
|
+
File.write('.gitignore', "*.wasm\n")
|
|
232
|
+
setup_instance.send(:update_gitignore, ['*.wasm', '/rubies'])
|
|
233
|
+
content = File.read('.gitignore')
|
|
234
|
+
expect(content.scan(/^\*\.wasm$/).count).to eq(1)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
it 'outputs message when entries are added' do
|
|
238
|
+
expect { setup_instance.send(:update_gitignore, ['*.wasm']) }.to output(
|
|
239
|
+
/Added to .gitignore: \*\.wasm/
|
|
240
|
+
).to_stdout
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
it 'outputs message when no entries are added' do
|
|
244
|
+
File.write('.gitignore', "*.wasm\n")
|
|
245
|
+
expect { setup_instance.send(:update_gitignore, ['*.wasm']) }.to output(
|
|
246
|
+
/No new entries added to .gitignore/
|
|
247
|
+
).to_stdout
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
end
|
|
186
251
|
end
|