js_from_routes 4.0.2 → 4.1.0
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 +9 -0
- data/lib/js_from_routes/generator.rb +68 -7
- data/lib/js_from_routes/version.rb +1 -1
- metadata +24 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3f4bdf584f20e9d501c07a584faaf0d9a592794c0ef0b48b7c687a302fc7b41f
|
|
4
|
+
data.tar.gz: 440fa7063465c567ac001198be8d7024b85bd726bd614c5b5a7f9b6be4320527
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 73b25326be13bf7bd2ad3294a967bcc7f044696ab8870dd601fe3bcb173ffa14f859e5c82488959a2bc25d15f301a775ee0677d727e2a767c10f1e19e2b88bc3
|
|
7
|
+
data.tar.gz: 38115d06a1f4dbc8d6cea476418215b379266d0fbae5a7b14234b916f42d2cb6ec625ac98ed7a02b46a98aebcbb73a1f883eb6a3745a57f2f27d373759c5bffc
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
# [4.1.0](https://github.com/ElMassimo/js_from_routes/compare/js_from_routes@4.0.2...js_from_routes@4.1.0) (2026-08-03)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* support multiple generator instances for sub-app routing ([#70](https://github.com/ElMassimo/js_from_routes/issues/70)) ([49d944b](https://github.com/ElMassimo/js_from_routes/commit/49d944b7fcde885f1e8b26312738450a4a3f9136))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
## [4.0.2](https://github.com/ElMassimo/js_from_routes/compare/js_from_routes@4.0.1...js_from_routes@4.0.2) (2025-01-15)
|
|
2
11
|
|
|
3
12
|
|
|
@@ -164,19 +164,32 @@ module JsFromRoutes
|
|
|
164
164
|
end
|
|
165
165
|
end
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
167
|
+
# Public: A generator instance with its own configuration. Allows generating
|
|
168
|
+
# routes separately for different sub-apps in a Rails monolith.
|
|
169
|
+
#
|
|
170
|
+
# Example:
|
|
171
|
+
# JsFromRoutes.config(:admin) do |config|
|
|
172
|
+
# config.output_folder = Rails.root.join("app/javascript/admin/api")
|
|
173
|
+
# config.export_if = ->(route) { route.defaults[:export] == :admin }
|
|
174
|
+
# end
|
|
175
|
+
#
|
|
176
|
+
# JsFromRoutes.config(:public) do |config|
|
|
177
|
+
# config.output_folder = Rails.root.join("app/javascript/public/api")
|
|
178
|
+
# config.export_if = ->(route) { route.defaults[:export] == :public }
|
|
179
|
+
# end
|
|
180
|
+
class Instance
|
|
181
|
+
attr_reader :name, :config
|
|
182
|
+
|
|
183
|
+
def initialize(name, config)
|
|
184
|
+
@name = name
|
|
185
|
+
@config = config
|
|
173
186
|
end
|
|
174
187
|
|
|
175
188
|
# Public: Generates code for the specified routes with { export: true }.
|
|
176
189
|
def generate!(app_or_routes = Rails.application)
|
|
177
190
|
raise ArgumentError, "A Rails app must be defined, or you must specify a custom `output_folder`" if config.output_folder.to_s.blank?
|
|
178
191
|
rails_routes = app_or_routes.is_a?(::Rails::Engine) ? app_or_routes.routes.routes : app_or_routes
|
|
179
|
-
generate_files
|
|
192
|
+
generate_files(exported_routes_by_controller(rails_routes))
|
|
180
193
|
end
|
|
181
194
|
|
|
182
195
|
private
|
|
@@ -221,4 +234,52 @@ module JsFromRoutes
|
|
|
221
234
|
.group_by { |route| namespace_for_route(route)&.to_s }
|
|
222
235
|
end
|
|
223
236
|
end
|
|
237
|
+
|
|
238
|
+
class << self
|
|
239
|
+
# Public: Configuration of the code generator.
|
|
240
|
+
#
|
|
241
|
+
# Without a name, returns/yields the default global configuration:
|
|
242
|
+
# JsFromRoutes.config do |config|
|
|
243
|
+
# config.file_suffix = "Api.ts"
|
|
244
|
+
# end
|
|
245
|
+
#
|
|
246
|
+
# With a name, defines a named generator instance with its own configuration,
|
|
247
|
+
# allowing separate route generation for different sub-apps:
|
|
248
|
+
# JsFromRoutes.config(:admin) do |config|
|
|
249
|
+
# config.output_folder = Rails.root.join("app/javascript/admin/api")
|
|
250
|
+
# config.export_if = ->(route) { route.defaults[:export] == :admin }
|
|
251
|
+
# end
|
|
252
|
+
def config(name = nil)
|
|
253
|
+
if name
|
|
254
|
+
root = ::Rails.root || Pathname.new(Dir.pwd)
|
|
255
|
+
new_config = Configuration.new(root)
|
|
256
|
+
yield(new_config) if block_given?
|
|
257
|
+
instances[name] = Instance.new(name, new_config)
|
|
258
|
+
else
|
|
259
|
+
@config ||= Configuration.new(::Rails.root || Pathname.new(Dir.pwd))
|
|
260
|
+
if block_given?
|
|
261
|
+
@config_customized = true
|
|
262
|
+
yield(@config)
|
|
263
|
+
end
|
|
264
|
+
@config
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
# Public: Returns all registered named instances.
|
|
269
|
+
def instances
|
|
270
|
+
@instances ||= {}
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
# Public: Generates code for the specified routes with { export: true }.
|
|
274
|
+
#
|
|
275
|
+
# Runs every named instance, plus the default global config whenever it was
|
|
276
|
+
# explicitly configured (or when no named instances exist at all). This keeps
|
|
277
|
+
# mixed usage working: adding a named instance never silently disables the
|
|
278
|
+
# global config that an existing app already relies on.
|
|
279
|
+
def generate!(app_or_routes = Rails.application)
|
|
280
|
+
runnable = instances.values
|
|
281
|
+
runnable.unshift(Instance.new(:default, config)) if @config_customized || runnable.empty?
|
|
282
|
+
runnable.each { |inst| inst.generate!(app_or_routes) }
|
|
283
|
+
end
|
|
284
|
+
end
|
|
224
285
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: js_from_routes
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.0
|
|
4
|
+
version: 4.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Máximo Mussini
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-08-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: railties
|
|
@@ -34,16 +34,22 @@ dependencies:
|
|
|
34
34
|
name: bundler
|
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
|
-
- - "
|
|
37
|
+
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
39
|
version: '2'
|
|
40
|
+
- - "<"
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '5'
|
|
40
43
|
type: :development
|
|
41
44
|
prerelease: false
|
|
42
45
|
version_requirements: !ruby/object:Gem::Requirement
|
|
43
46
|
requirements:
|
|
44
|
-
- - "
|
|
47
|
+
- - ">="
|
|
45
48
|
- !ruby/object:Gem::Version
|
|
46
49
|
version: '2'
|
|
50
|
+
- - "<"
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '5'
|
|
47
53
|
- !ruby/object:Gem::Dependency
|
|
48
54
|
name: listen
|
|
49
55
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -72,6 +78,20 @@ dependencies:
|
|
|
72
78
|
- - "~>"
|
|
73
79
|
- !ruby/object:Gem::Version
|
|
74
80
|
version: '3.9'
|
|
81
|
+
- !ruby/object:Gem::Dependency
|
|
82
|
+
name: readline
|
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0'
|
|
88
|
+
type: :development
|
|
89
|
+
prerelease: false
|
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
91
|
+
requirements:
|
|
92
|
+
- - ">="
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: '0'
|
|
75
95
|
- !ruby/object:Gem::Dependency
|
|
76
96
|
name: rake
|
|
77
97
|
requirement: !ruby/object:Gem::Requirement
|