ruby_wasm_ui 0.9.0 → 0.9.2
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 +30 -27
- 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/README.md +20 -0
- 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 +7 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e90874b5e8d1349f9db40911bc81c1f5ca825b0409f6af9fc00f975ece476ff0
|
|
4
|
+
data.tar.gz: 6bf1c289444c30d04298f22fdb16385bcfb5e9e3b77e2547d86bde168fbd6ad1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1e783adc1baf70d4f49b5aa1d6982dbb40c5fcb6cd6aaeb2904b001c1725367bf6cf181506e5e3a20f04a00ae92c94ae8af1f6b967950acaffcff6fd19d18dd2
|
|
7
|
+
data.tar.gz: 6799bad94c0b2ef86ef188e29707fe3988cb5676302f65c31ad2bb0a4ef315b8ec2d4c9dbeda3e47a7001b4d32e8cd517875fdfcc14390f7227dc1bec719918a
|
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.2"></script>
|
|
25
25
|
<script defer type="text/ruby" src="app.rb"></script>
|
|
26
26
|
</head>
|
|
27
27
|
<body>
|
|
@@ -112,7 +112,7 @@ bundle install
|
|
|
112
112
|
|
|
113
113
|
### Building Your Application
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
Set up your project (first time only):
|
|
116
116
|
|
|
117
117
|
```bash
|
|
118
118
|
bundle exec ruby-wasm-ui setup
|
|
@@ -124,28 +124,24 @@ This command will:
|
|
|
124
124
|
- Update `.gitignore`
|
|
125
125
|
- Create initial `src/index.html` and `src/index.rb` files
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
The setup command will configure your project structure as follows:
|
|
128
128
|
|
|
129
|
-
```
|
|
130
|
-
|
|
129
|
+
```
|
|
130
|
+
my-app/
|
|
131
|
+
├── Gemfile
|
|
132
|
+
└── src/
|
|
133
|
+
├── index.rb
|
|
134
|
+
└── index.html
|
|
131
135
|
```
|
|
132
136
|
|
|
133
|
-
This command packs your Ruby files from the `./src` directory into the WASM file.
|
|
134
137
|
|
|
135
|
-
|
|
138
|
+
### Develop Your Application
|
|
136
139
|
|
|
137
140
|
- **Development server**: Start a development server with file watching and auto-build:
|
|
138
141
|
```bash
|
|
139
142
|
bundle exec ruby-wasm-ui dev
|
|
140
143
|
```
|
|
141
144
|
|
|
142
|
-
- **Rebuild Ruby WASM**: Rebuild the Ruby WASM file when you add new gems:
|
|
143
|
-
```bash
|
|
144
|
-
bundle exec ruby-wasm-ui rebuild
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### Creating Your HTML File
|
|
148
|
-
|
|
149
145
|
Create an HTML file in the `src` directory that loads the WASM file:
|
|
150
146
|
|
|
151
147
|
```html
|
|
@@ -161,7 +157,7 @@ Create an HTML file in the `src` directory that loads the WASM file:
|
|
|
161
157
|
const { vm } = await DefaultRubyVM(module);
|
|
162
158
|
vm.evalAsync(`
|
|
163
159
|
require "ruby_wasm_ui"
|
|
164
|
-
require_relative './src/
|
|
160
|
+
require_relative './src/index.rb'
|
|
165
161
|
`);
|
|
166
162
|
</script>
|
|
167
163
|
</head>
|
|
@@ -171,18 +167,7 @@ Create an HTML file in the `src` directory that loads the WASM file:
|
|
|
171
167
|
</html>
|
|
172
168
|
```
|
|
173
169
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
```
|
|
177
|
-
my-app/
|
|
178
|
-
├── Gemfile
|
|
179
|
-
├── src.wasm
|
|
180
|
-
└── src/
|
|
181
|
-
├── app.rb
|
|
182
|
-
└── index.html
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
Your `src/app.rb` file can use `ruby_wasm_ui` just like in the Quick Start example:
|
|
170
|
+
Your `src/index.rb` file can use `ruby_wasm_ui` just like in the Quick Start example:
|
|
186
171
|
|
|
187
172
|
```ruby
|
|
188
173
|
CounterComponent = RubyWasmUi.define_component(
|
|
@@ -211,6 +196,24 @@ app.mount(app_element)
|
|
|
211
196
|
|
|
212
197
|
See the [examples](examples) directory for a complete working example.
|
|
213
198
|
|
|
199
|
+
|
|
200
|
+
**Additional Commands:**
|
|
201
|
+
|
|
202
|
+
- **Rebuild Ruby WASM**: Rebuild the Ruby WASM file when you add new gems:
|
|
203
|
+
```bash
|
|
204
|
+
bundle exec ruby-wasm-ui rebuild
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Deployment
|
|
208
|
+
|
|
209
|
+
Pack your application files for deployment:
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
bundle exec ruby-wasm-ui pack
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
This command packs your Ruby files from the `./src` directory into the WASM file and outputs to the `dist` directory for deployment.
|
|
216
|
+
|
|
214
217
|
## Documentation
|
|
215
218
|
|
|
216
219
|
- [Conditional Rendering with r-if](docs/conditional-rendering.md)
|
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.2",
|
|
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.2",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"workspaces": [
|
|
12
12
|
"packages/*"
|
data/package.json
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# ruby-wasm-ui
|
|
2
2
|
|
|
3
|
+
> ⚠️ **This package has been renamed to `ruwi`**
|
|
4
|
+
>
|
|
5
|
+
> Starting from v0.10.0, this library has been renamed from `ruby-wasm-ui` to `ruwi`.
|
|
6
|
+
>
|
|
7
|
+
> **Please migrate to the new package:**
|
|
8
|
+
>
|
|
9
|
+
> - **New npm package**: [ruwi](https://www.npmjs.com/package/ruwi)
|
|
10
|
+
>
|
|
11
|
+
> ```html
|
|
12
|
+
> <!-- Old -->
|
|
13
|
+
> <script src="https://unpkg.com/ruby-wasm-ui@0.9.2"></script>
|
|
14
|
+
>
|
|
15
|
+
> <!-- New -->
|
|
16
|
+
> <script src="https://unpkg.com/ruwi@0.10.0"></script>
|
|
17
|
+
> ```
|
|
18
|
+
>
|
|
19
|
+
> For migration details, please see the [v0.10.0 release notes](https://github.com/t0yohei/ruby-wasm-ui/releases/tag/v0.10.0).
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
3
23
|
A modern web frontend framework for Ruby using [ruby.wasm](https://github.com/ruby/ruby.wasm). Write reactive web applications using familiar Ruby syntax and patterns.
|
|
4
24
|
|
|
5
25
|
Please refer to the [GitHub README](https://github.com/t0yohei/ruby-wasm-ui#readme) for full documentation.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ruby-wasm-ui",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
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.2",
|
|
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
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby_wasm_ui
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.
|
|
4
|
+
version: 0.9.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- t0yohei
|
|
@@ -79,7 +79,10 @@ dependencies:
|
|
|
79
79
|
- - "~>"
|
|
80
80
|
- !ruby/object:Gem::Version
|
|
81
81
|
version: '6.0'
|
|
82
|
-
description: Write reactive web applications using familiar Ruby syntax and patterns
|
|
82
|
+
description: 'Write reactive web applications using familiar Ruby syntax and patterns.
|
|
83
|
+
⚠️ WARNING: This gem has been renamed to ''ruwi'' starting from v0.10.0. Please
|
|
84
|
+
migrate to the ''ruwi'' gem. See https://github.com/t0yohei/ruby-wasm-ui/releases/tag/v0.10.0
|
|
85
|
+
for migration details.'
|
|
83
86
|
email:
|
|
84
87
|
- k.t0yohei@gmail.com
|
|
85
88
|
executables:
|
|
@@ -225,5 +228,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
225
228
|
requirements: []
|
|
226
229
|
rubygems_version: 3.7.2
|
|
227
230
|
specification_version: 4
|
|
228
|
-
summary: A modern web frontend framework for Ruby using ruby.wasm
|
|
231
|
+
summary: A modern web frontend framework for Ruby using ruby.wasm (⚠️ This gem has
|
|
232
|
+
been renamed to 'ruwi' starting from v0.10.0)
|
|
229
233
|
test_files: []
|