anycable-rails-core 1.6.2 → 1.6.3
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/CHANGELOG.md +17 -0
- data/MIT-LICENSE +1 -1
- data/README.md +12 -0
- data/lib/anycable/rails/channel/presence.rb +1 -1
- data/lib/anycable/rails/version.rb +1 -1
- data/lib/generators/anycable/bin/USAGE +3 -1
- data/lib/generators/anycable/bin/bin_generator.rb +7 -6
- data/lib/generators/anycable/bin/templates/bin/anycable-go.tt +4 -3
- data/lib/generators/anycable/download/download_generator.rb +2 -11
- data/lib/generators/anycable/setup/USAGE +8 -0
- data/lib/generators/anycable/setup/setup_generator.rb +104 -68
- data/lib/generators/anycable/setup/templates/Procfile.dev.tt +1 -1
- data/lib/generators/anycable/with_release_helpers.rb +69 -0
- data/lib/puma/plugin/anycable.rb +171 -0
- data/skills/anycable-rails/SKILL.md +82 -0
- data/skills/anycable-rails/references/deployment.md +187 -0
- data/skills/anycable-rails/references/hotwire.md +269 -0
- data/skills/anycable-rails/references/installation.md +292 -0
- data/skills/anycable-rails/references/live-checks.md +129 -0
- data/skills/anycable-rails/references/personalization.md +114 -0
- data/skills/anycable-rails/references/presence.md +240 -0
- data/skills/anycable-rails/references/realtime-features.md +231 -0
- data/skills/anycable-rails/references/testing.md +145 -0
- data/skills/anycable-rails/references/troubleshooting.md +128 -0
- data/skills/anycable-rails/scenarios/channel.yml +51 -0
- data/skills/anycable-rails/scenarios/signed-stream.yml +38 -0
- metadata +18 -3
- data/lib/generators/anycable/setup/templates/bin/anycable-go.tt +0 -27
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b2e99737d795373a6efe6acdd6340a8208521a1a6d1a1c13b52b8407ebdaf62b
|
|
4
|
+
data.tar.gz: 43f00dc736d3d0f794f9161e4bcf2c4c129c372c6042622f0625bb744fd45114
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1eead9eb29039b654158e54024cc1edea844cc20c88ebe836a2118f3e2d8a45883328cf2e5c4125fb5c7c3222b2aa115b58d4cdf93a3def8375ff61f4ebf8df7
|
|
7
|
+
data.tar.gz: 45737a8fb57db5537c123351ab0906d37b7d658823e24566af03f6561b73e72ae1a8c68df7e7e306af9fd7b11096c4512e31d9dfb0f6ae587406872acb2f3a2e
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
## main
|
|
4
4
|
|
|
5
|
+
## 1.6.3 (2026-11-29)
|
|
6
|
+
|
|
7
|
+
- Fix and improve generators. ([@palkan][])
|
|
8
|
+
|
|
9
|
+
- Add Puma plugin to run AnyCable server in development. ([@palkan][])
|
|
10
|
+
|
|
11
|
+
Add `plugin :anycable if ENV["ANYCABLE_IN_PUMA"]` to `config/puma.rb`. The plugin starts `bin/anycable-go` after Puma boots, keeps it running during Puma restarts, and stops it with Puma. Use `anycable_command`, `anycable_log` and `anycable_pidfile` to change the defaults.
|
|
12
|
+
|
|
13
|
+
- Add an agent skill (`skills/anycable-rails`) for coding agents. ([@palkan][])
|
|
14
|
+
|
|
15
|
+
The skill covers installation and configuration, deployment, troubleshooting (with `wsdirector` scenarios for live checks), and best practices for real-time features. It is shipped with `anycable-rails-core` and installed by [Rails Hyperdrive](https://github.com/rails-hyperdrive/rails-hyperdrive).
|
|
16
|
+
|
|
17
|
+
- Cast the presence ID to a string on leave, matching join. ([@ashwin47][])
|
|
18
|
+
|
|
19
|
+
`#join_presence` already casts the ID via `#to_s`, but `#leave_presence` passed it through untouched, so a non-string `user_presence_id` (e.g. a numeric record id) raised `Invalid argument for string field 'id'` when building the presence response.
|
|
20
|
+
|
|
5
21
|
## 1.6.2 (2026-04-02)
|
|
6
22
|
|
|
7
23
|
- Upgrade setup generator. ([@palkan][])
|
|
@@ -306,3 +322,4 @@ See [Changelog](https://github.com/anycable/anycable-rails/blob/0-6-stable/CHANG
|
|
|
306
322
|
[@sponomarev]: https://github.com/sponomarev
|
|
307
323
|
[@bibendi]: https://github.com/bibendi
|
|
308
324
|
[@lHydra]: http://github.com/lHydra
|
|
325
|
+
[@ashwin47]: https://github.com/ashwin47
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -28,6 +28,18 @@ bundle exec rails g anycable:setup
|
|
|
28
28
|
|
|
29
29
|
Learn more [here](https://docs.anycable.io/rails/getting_started).
|
|
30
30
|
|
|
31
|
+
## Agent skills
|
|
32
|
+
|
|
33
|
+
The gem ships a skill for coding agents in `skills/anycable-rails`. The skill helps agents install and configure AnyCable, troubleshoot connections and broadcasts, and build real-time features. It follows the [skills.sh](https://www.skills.sh) layout, so it works with any agent that reads `SKILL.md`.
|
|
34
|
+
|
|
35
|
+
With [Rails Hyperdrive](https://github.com/rails-hyperdrive/rails-hyperdrive), the skill installs automatically: run `bin/rails hyperdrive:init` the first time, then `bundle install` or `bin/rails hyperdrive:sync` puts it into `.claude/skills/anycable-rails`.
|
|
36
|
+
|
|
37
|
+
Without Rails Hyperdrive, install it from the repository with the [skills.sh](https://www.skills.sh) CLI, or copy `skills/anycable-rails` into your agent's skills directory:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
npx skills add anycable/anycable-rails
|
|
41
|
+
```
|
|
42
|
+
|
|
31
43
|
## Contributing
|
|
32
44
|
|
|
33
45
|
Bug reports and pull requests are welcome on GitHub at [https://github.com/anycable/anycable-rails](https://github.com/anycable/anycable-rails).
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "generators/anycable/
|
|
3
|
+
require "generators/anycable/with_release_helpers"
|
|
4
4
|
|
|
5
5
|
module AnyCableRailsGenerators
|
|
6
6
|
# Generates bin/anycable-go binstub
|
|
7
7
|
class BinGenerator < ::Rails::Generators::Base
|
|
8
8
|
namespace "anycable:bin"
|
|
9
9
|
|
|
10
|
+
include WithReleaseHelpers
|
|
11
|
+
|
|
10
12
|
source_root File.expand_path("templates", __dir__)
|
|
11
13
|
|
|
12
14
|
class_option :version,
|
|
13
15
|
type: :string,
|
|
14
16
|
desc: "Specify AnyCable server version (defaults to latest release)",
|
|
15
|
-
|
|
17
|
+
default: "latest"
|
|
16
18
|
|
|
17
19
|
def generate_bin
|
|
18
20
|
inside("bin") do
|
|
@@ -43,10 +45,9 @@ module AnyCableRailsGenerators
|
|
|
43
45
|
return unless version
|
|
44
46
|
return if version.chomp == "latest"
|
|
45
47
|
|
|
46
|
-
# We need a full version for bin/anycable-go script
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
segments.join(".")
|
|
48
|
+
# We need a full version for bin/anycable-go script:
|
|
49
|
+
# a partial one (e.g., "1.6") resolves to the latest patch release
|
|
50
|
+
resolve_version(version)
|
|
50
51
|
end
|
|
51
52
|
end
|
|
52
53
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
|
|
3
|
-
cd $(dirname $0)/..
|
|
3
|
+
cd "$(dirname "$0")/.."
|
|
4
4
|
|
|
5
5
|
# It's recommended to use the exact version of AnyCable here
|
|
6
6
|
version="<%= anycable_go_version %>"
|
|
@@ -10,7 +10,7 @@ if [ ! -f ./bin/dist/anycable-go ]; then
|
|
|
10
10
|
./bin/rails g anycable:download --version=$version --bin-path=./bin/dist
|
|
11
11
|
fi
|
|
12
12
|
|
|
13
|
-
if [ -x ./bin/dist/anycable-go ]; then
|
|
13
|
+
if [ ! -x ./bin/dist/anycable-go ]; then
|
|
14
14
|
echo "Setting execution permission for AnyCable server"
|
|
15
15
|
chmod +x ./bin/dist/anycable-go
|
|
16
16
|
fi
|
|
@@ -24,4 +24,5 @@ if [[ "$version" != "latest" ]]; then
|
|
|
24
24
|
fi
|
|
25
25
|
fi
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
# Replace the shell process, so that signals reach the server
|
|
28
|
+
exec ./bin/dist/anycable-go "$@"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "generators/anycable/with_os_helpers"
|
|
4
|
+
require "generators/anycable/with_release_helpers"
|
|
4
5
|
|
|
5
6
|
module AnyCableRailsGenerators
|
|
6
7
|
# Downloads anycable-go binary
|
|
@@ -8,6 +9,7 @@ module AnyCableRailsGenerators
|
|
|
8
9
|
namespace "anycable:download"
|
|
9
10
|
|
|
10
11
|
include WithOSHelpers
|
|
12
|
+
include WithReleaseHelpers
|
|
11
13
|
|
|
12
14
|
VERSION = "latest"
|
|
13
15
|
|
|
@@ -43,17 +45,6 @@ module AnyCableRailsGenerators
|
|
|
43
45
|
end
|
|
44
46
|
end
|
|
45
47
|
|
|
46
|
-
def repository_name(version)
|
|
47
|
-
return "anycable/anycable" if version == "latest"
|
|
48
|
-
|
|
49
|
-
major, minor, = Gem::Version.new(version).segments
|
|
50
|
-
if (major >= 1 && minor >= 6) || (major > 1)
|
|
51
|
-
"anycable/anycable"
|
|
52
|
-
else
|
|
53
|
-
"anycable/anycable-go"
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
48
|
def legacy_release_url(version)
|
|
58
49
|
"https://github.com/#{repository_name(version)}/releases/download/v#{version}/" \
|
|
59
50
|
"anycable-go-v#{version}-#{os_name}-#{cpu_name}"
|
|
@@ -3,3 +3,11 @@ Description:
|
|
|
3
3
|
|
|
4
4
|
Example:
|
|
5
5
|
rails generate anycable:setup
|
|
6
|
+
|
|
7
|
+
rails generate anycable:setup --rpc=none --development=puma --version=1.6
|
|
8
|
+
|
|
9
|
+
Development options:
|
|
10
|
+
bin — run bin/anycable-go via Procfile.dev (bin/dev)
|
|
11
|
+
puma — run bin/anycable-go via Puma plugin (ANYCABLE_IN_PUMA=1)
|
|
12
|
+
docker — print a Docker Compose snippet
|
|
13
|
+
skip — do not configure AnyCable server for development
|
|
@@ -9,7 +9,7 @@ module AnyCableRailsGenerators
|
|
|
9
9
|
source_root File.expand_path("templates", __dir__)
|
|
10
10
|
|
|
11
11
|
DOCS_ROOT = "https://docs.anycable.io"
|
|
12
|
-
DEVELOPMENT_METHODS = %w[skip bin docker].freeze
|
|
12
|
+
DEVELOPMENT_METHODS = %w[skip bin puma docker].freeze
|
|
13
13
|
DEPLOYMENT_METHODS = %w[skip thruster fly heroku anycable_plus].freeze
|
|
14
14
|
RPC_IMPL = %w[none grpc http].freeze
|
|
15
15
|
|
|
@@ -86,7 +86,7 @@ module AnyCableRailsGenerators
|
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
# Fast-track for local development
|
|
89
|
-
if file_exists?("bin/dev") && file_exists?("Procfile.dev")
|
|
89
|
+
if !@development && file_exists?("bin/dev") && file_exists?("Procfile.dev")
|
|
90
90
|
@development = "bin"
|
|
91
91
|
end
|
|
92
92
|
|
|
@@ -96,15 +96,22 @@ module AnyCableRailsGenerators
|
|
|
96
96
|
You can run AnyCable server locally (recommended for most cases) or as a Docker container (in case you develop in a containerized environment).
|
|
97
97
|
|
|
98
98
|
For a local installation, we provide a convenient binstub (`bin/anycable-go`) which automatically
|
|
99
|
-
installs AnyCable server for the current platform.
|
|
99
|
+
installs AnyCable server for the current platform. You can run it:
|
|
100
|
+
- via Procfile.dev (bin) — together with other processes using foreman or overmind;
|
|
101
|
+
- via Puma plugin (puma) — AnyCable server starts and stops with your Rails server.
|
|
100
102
|
MSG
|
|
101
103
|
say ""
|
|
102
104
|
|
|
103
|
-
answer = ask "Which way to run AnyCable server locally would you prefer?", limited_to: %w[bin docker skip], default:
|
|
105
|
+
answer = ask "Which way to run AnyCable server locally would you prefer?", limited_to: %w[bin puma docker skip], default: default_development_method
|
|
104
106
|
|
|
105
107
|
@development = answer
|
|
106
108
|
end
|
|
107
109
|
|
|
110
|
+
if @development == "puma" && grpc?
|
|
111
|
+
say_status :warn, "Puma plugin doesn't run the gRPC server. Using Procfile.dev instead", :yellow
|
|
112
|
+
@development = "bin"
|
|
113
|
+
end
|
|
114
|
+
|
|
108
115
|
case @development
|
|
109
116
|
when "skip"
|
|
110
117
|
@todos << "Install AnyCable server for local development: #{DOCS_ROOT}/anycable-go/getting_started"
|
|
@@ -127,7 +134,7 @@ module AnyCableRailsGenerators
|
|
|
127
134
|
return unless rubocop?
|
|
128
135
|
|
|
129
136
|
say_status :info, "🤖 Running static compatibility checks with RuboCop"
|
|
130
|
-
res = run "bundle exec rubocop -r 'anycable/rails/compatibility/rubocop' --only AnyCable/InstanceVars,AnyCable/PeriodicalTimers,AnyCable/
|
|
137
|
+
res = run "bundle exec rubocop -r 'anycable/rails/compatibility/rubocop' --only AnyCable/InstanceVars,AnyCable/PeriodicalTimers,AnyCable/StreamFrom"
|
|
131
138
|
|
|
132
139
|
unless res
|
|
133
140
|
say_status :help, "⚠️ Please, take a look at the incompatibilities above and fix them"
|
|
@@ -200,6 +207,10 @@ module AnyCableRailsGenerators
|
|
|
200
207
|
// Prevent frequent resubscriptions during morphing or navigation
|
|
201
208
|
start(cable, { delayedUnsubscribe: true })
|
|
202
209
|
JS
|
|
210
|
+
|
|
211
|
+
@todos << "⚠️ `@hotwired/turbo-rails` has been replaced with `@hotwired/turbo` in app/javascript/application.js.\n" \
|
|
212
|
+
" Links and forms with `data-turbo-method` (e.g., `delete`) now send real PATCH/PUT/DELETE requests (no `_method` param),\n" \
|
|
213
|
+
" and a 302 redirect after them is followed with the same method. Make sure these actions redirect with `status: :see_other`"
|
|
203
214
|
return
|
|
204
215
|
end
|
|
205
216
|
|
|
@@ -238,6 +249,13 @@ module AnyCableRailsGenerators
|
|
|
238
249
|
|
|
239
250
|
private
|
|
240
251
|
|
|
252
|
+
def default_development_method
|
|
253
|
+
return "bin" if grpc? || file_exists?("Procfile.dev")
|
|
254
|
+
return "puma" if file_exists?("config/puma.rb")
|
|
255
|
+
|
|
256
|
+
"bin"
|
|
257
|
+
end
|
|
258
|
+
|
|
241
259
|
def redis?
|
|
242
260
|
!!gemfile_lock&.match?(/^\s+redis\b/)
|
|
243
261
|
end
|
|
@@ -324,77 +342,88 @@ module AnyCableRailsGenerators
|
|
|
324
342
|
|
|
325
343
|
say "Here is an example snippet for Docker Compose:"
|
|
326
344
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
345
|
+
# The server reads settings from the anycable.toml file (mounted into the container);
|
|
346
|
+
# environment variables override the values that are different in Docker
|
|
347
|
+
ws_environment = ["ANYCABLE_HOST: \"0.0.0.0\""]
|
|
348
|
+
ws_environment << "ANYCABLE_RPC_HOST: http://rails:3000/_anycable" if http_rpc?
|
|
349
|
+
ws_environment << "ANYCABLE_RPC_HOST: anycable:50051" if grpc?
|
|
350
|
+
|
|
351
|
+
snippet = <<~YML
|
|
352
|
+
# Your Rails application service
|
|
353
|
+
rails: &rails
|
|
354
|
+
# ...
|
|
355
|
+
ports:
|
|
356
|
+
- '3000:3000'
|
|
357
|
+
environment: &rails_environment
|
|
332
358
|
# ...
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
ANYCABLE_RPC_HOST: anycable:50051
|
|
352
|
-
ANYCABLE_DEBUG: ${ANYCABLE_DEBUG:-true}
|
|
353
|
-
ANYCABLE_SECRET: "anycable-local-secret"
|
|
359
|
+
ANYCABLE_HTTP_BROADCAST_URL: http://ws:8080/_broadcast
|
|
360
|
+
depends_on: &rails_depends_on
|
|
361
|
+
# ...
|
|
362
|
+
ws:
|
|
363
|
+
condition: service_started
|
|
364
|
+
|
|
365
|
+
ws:
|
|
366
|
+
image: anycable/anycable-go:1.6
|
|
367
|
+
ports:
|
|
368
|
+
- '8080:8080'
|
|
369
|
+
volumes:
|
|
370
|
+
- ./anycable.toml:/etc/anycable/anycable.toml:ro
|
|
371
|
+
environment:
|
|
372
|
+
#{ws_environment.join("\n ")}
|
|
373
|
+
YML
|
|
374
|
+
|
|
375
|
+
if grpc?
|
|
376
|
+
snippet += <<~YML
|
|
354
377
|
|
|
355
378
|
anycable:
|
|
356
379
|
<<: *rails
|
|
357
380
|
command: bundle exec anycable
|
|
381
|
+
ports:
|
|
382
|
+
- '50051'
|
|
358
383
|
environment:
|
|
359
384
|
<<: *rails_environment
|
|
360
385
|
ANYCABLE_RPC_HOST: 0.0.0.0:50051
|
|
361
|
-
ports:
|
|
362
|
-
- '50051'
|
|
363
386
|
depends_on:
|
|
364
387
|
<<: *rails_depends_on
|
|
365
|
-
ws:
|
|
366
|
-
condition: service_started
|
|
367
|
-
─────────────────────────────────────────
|
|
368
|
-
YML
|
|
369
|
-
else
|
|
370
|
-
say <<~YML
|
|
371
|
-
─────────────────────────────────────────
|
|
372
|
-
# Your Rails application service
|
|
373
|
-
rails: &rails
|
|
374
|
-
# ...
|
|
375
|
-
ports:
|
|
376
|
-
- '3000:3000'
|
|
377
|
-
environment: &rails_environment
|
|
378
|
-
# ...
|
|
379
|
-
ANYCABLE_HTTP_BROADCAST_URL: http://ws:8090/_broadcast
|
|
380
|
-
depends_on: &rails_depends_on
|
|
381
|
-
#...
|
|
382
|
-
anycable:
|
|
383
|
-
condition: service_started
|
|
384
|
-
|
|
385
|
-
ws:
|
|
386
|
-
image: anycable/anycable-go:1.5
|
|
387
|
-
ports:
|
|
388
|
-
- '8080:8080'
|
|
389
|
-
environment:
|
|
390
|
-
ANYCABLE_HOST: "0.0.0.0"
|
|
391
|
-
ANYCABLE_BROADCAST_ADAPTER: http
|
|
392
|
-
ANYCABLE_RPC_HOST: http://rails:3000/_anycable
|
|
393
|
-
ANYCABLE_DEBUG: ${ANYCABLE_DEBUG:-true}
|
|
394
|
-
ANYCABLE_SECRET: "anycable-local-secret"
|
|
395
|
-
─────────────────────────────────────────
|
|
396
388
|
YML
|
|
397
389
|
end
|
|
390
|
+
|
|
391
|
+
say "─────────────────────────────────────────"
|
|
392
|
+
say snippet
|
|
393
|
+
say "─────────────────────────────────────────"
|
|
394
|
+
|
|
395
|
+
@todos << "Add the AnyCable services to your Docker Compose file (see the snippet above)"
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
def install_for_puma
|
|
399
|
+
unless file_exists?("bin/anycable-go")
|
|
400
|
+
generate "anycable:bin", "--version #{options[:version]}"
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
unless file_exists?("config/puma.rb")
|
|
404
|
+
@todos << "⚠️ Add `plugin :anycable if ENV[\"ANYCABLE_IN_PUMA\"]` to your Puma configuration file"
|
|
405
|
+
return
|
|
406
|
+
end
|
|
407
|
+
|
|
408
|
+
in_root do
|
|
409
|
+
contents = File.read("config/puma.rb")
|
|
410
|
+
next if contents.match?(/^\s*plugin\s+:anycable\b/)
|
|
411
|
+
|
|
412
|
+
plugin = <<~RUBY
|
|
413
|
+
# Run AnyCable server together with Puma (set ANYCABLE_IN_PUMA=1 to enable)
|
|
414
|
+
plugin :anycable if ENV["ANYCABLE_IN_PUMA"]
|
|
415
|
+
RUBY
|
|
416
|
+
|
|
417
|
+
# Put the plugin before Solid Queue: Puma runs the stop hooks in the order of plugins,
|
|
418
|
+
# and the Solid Queue hook may fail and prevent the following ones from running
|
|
419
|
+
if contents.match?(/^\s*plugin\s+:solid_queue\b/)
|
|
420
|
+
inject_into_file "config/puma.rb", "#{plugin}\n", before: /^\s*plugin\s+:solid_queue\b.*$/
|
|
421
|
+
else
|
|
422
|
+
append_file "config/puma.rb", "\n#{plugin}"
|
|
423
|
+
end
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
@todos << "Run your Rails server with ANYCABLE_IN_PUMA=1 to start AnyCable server via Puma plugin (e.g., `ANYCABLE_IN_PUMA=1 bin/rails s`)"
|
|
398
427
|
end
|
|
399
428
|
|
|
400
429
|
def install_for_bin
|
|
@@ -449,7 +478,7 @@ module AnyCableRailsGenerators
|
|
|
449
478
|
if file_exists?(file_name)
|
|
450
479
|
update_procfile(file_name)
|
|
451
480
|
else
|
|
452
|
-
return if options[:
|
|
481
|
+
return if options[:skip_procfile]
|
|
453
482
|
|
|
454
483
|
template file_name
|
|
455
484
|
end
|
|
@@ -459,13 +488,15 @@ module AnyCableRailsGenerators
|
|
|
459
488
|
in_root do
|
|
460
489
|
contents = File.read(file_name)
|
|
461
490
|
|
|
491
|
+
append_file file_name, "\n", force: true unless contents.empty? || contents.end_with?("\n")
|
|
492
|
+
|
|
462
493
|
if grpc?
|
|
463
494
|
unless contents.match?(/^anycable:\s/)
|
|
464
495
|
append_file file_name, "anycable: bundle exec anycable\n", force: true
|
|
465
496
|
end
|
|
466
497
|
end
|
|
467
498
|
unless contents.match?(/^ws:\s/)
|
|
468
|
-
append_file file_name, "ws: bin/anycable-go --port 8080", force: true
|
|
499
|
+
append_file file_name, "ws: bin/anycable-go --port 8080\n", force: true
|
|
469
500
|
end
|
|
470
501
|
end
|
|
471
502
|
end
|
|
@@ -500,7 +531,10 @@ module AnyCableRailsGenerators
|
|
|
500
531
|
end
|
|
501
532
|
|
|
502
533
|
def inform_jwt_identifiers(path)
|
|
503
|
-
|
|
534
|
+
unless file_exists?("app/channels/application_cable/connection.rb")
|
|
535
|
+
@todos << "To identify users (e.g., for presence or channels), pass identifiers to the #action_cable_with_jwt_meta_tag in #{path} (e.g., `action_cable_with_jwt_meta_tag(user: current_user)`). Read more: 👉 #{DOCS_ROOT}/rails/authentication?id=jwt-authentication"
|
|
536
|
+
return
|
|
537
|
+
end
|
|
504
538
|
|
|
505
539
|
in_root do
|
|
506
540
|
contents = File.read("app/channels/application_cable/connection.rb")
|
|
@@ -514,9 +548,11 @@ module AnyCableRailsGenerators
|
|
|
514
548
|
def install_js_packages
|
|
515
549
|
if file_exists?("config/importmap.rb") && file_exists?("bin/importmap")
|
|
516
550
|
run "bin/importmap pin @hotwired/turbo @anycable/web @anycable/turbo-stream"
|
|
551
|
+
# @hotwired/turbo-rails is no longer used by the application.js
|
|
552
|
+
gsub_file "config/importmap.rb", /^pin "@hotwired\/turbo-rails".*\n/, ""
|
|
517
553
|
elsif file_exists?("yarn.lock")
|
|
518
554
|
run "yarn add @anycable/web @anycable/turbo-stream"
|
|
519
|
-
elsif file_exists?("package-json
|
|
555
|
+
elsif file_exists?("package-lock.json")
|
|
520
556
|
run "npm install @anycable/web @anycable/turbo-stream"
|
|
521
557
|
else
|
|
522
558
|
false
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AnyCableRailsGenerators
|
|
4
|
+
# Helpers to work with AnyCable server releases on GitHub
|
|
5
|
+
module WithReleaseHelpers
|
|
6
|
+
# The version to use when we cannot get the list of releases from GitHub
|
|
7
|
+
FALLBACK_VERSION = "1.6.22"
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def repository_name(version)
|
|
12
|
+
return "anycable/anycable" if version == "latest"
|
|
13
|
+
|
|
14
|
+
major, minor, = Gem::Version.new(version).segments
|
|
15
|
+
if (major >= 1 && minor.to_i >= 6) || (major > 1)
|
|
16
|
+
"anycable/anycable"
|
|
17
|
+
else
|
|
18
|
+
"anycable/anycable-go"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Returns the full version for a partial one (e.g., "1.6" -> "1.6.22").
|
|
23
|
+
# Returns the version itself if it's already full.
|
|
24
|
+
def resolve_version(version)
|
|
25
|
+
segments = Gem::Version.new(version).segments
|
|
26
|
+
return version if segments.size >= 3
|
|
27
|
+
|
|
28
|
+
latest = latest_release_version(segments)
|
|
29
|
+
return latest if latest
|
|
30
|
+
|
|
31
|
+
fallback =
|
|
32
|
+
if FALLBACK_VERSION.start_with?("#{segments.join(".")}.")
|
|
33
|
+
FALLBACK_VERSION
|
|
34
|
+
else
|
|
35
|
+
(segments + [0] * (3 - segments.size)).join(".")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
say_status :warn, "Failed to find the latest AnyCable server release for #{version}. Using #{fallback}", :yellow
|
|
39
|
+
fallback
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def latest_release_version(segments)
|
|
43
|
+
prefix = segments.join(".")
|
|
44
|
+
|
|
45
|
+
versions = fetch_release_tags(repository_name(prefix)).filter_map do |tag|
|
|
46
|
+
version = tag.delete_prefix("v")
|
|
47
|
+
next unless version.match?(/\A\d+\.\d+\.\d+\z/)
|
|
48
|
+
next unless version.start_with?("#{prefix}.")
|
|
49
|
+
|
|
50
|
+
Gem::Version.new(version)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
versions.max&.to_s
|
|
54
|
+
rescue => _e
|
|
55
|
+
nil
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# We use Git instead of GitHub API to avoid rate limits
|
|
59
|
+
def fetch_release_tags(repo)
|
|
60
|
+
output = IO.popen(
|
|
61
|
+
["git", "ls-remote", "--tags", "--refs", "https://github.com/#{repo}"],
|
|
62
|
+
err: File::NULL, &:read
|
|
63
|
+
)
|
|
64
|
+
return [] unless $?.success?
|
|
65
|
+
|
|
66
|
+
output.lines.map { _1.split("refs/tags/").last.strip }
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|