-
Notifications
You must be signed in to change notification settings - Fork 149
/
js_routes.rb
72 lines (59 loc) · 1.83 KB
/
js_routes.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# typed: strict
if defined?(::Rails)
require 'js_routes/engine'
end
require 'js_routes/version'
require "js_routes/configuration"
require "js_routes/instance"
require "js_routes/types"
require 'active_support/core_ext/string/indent'
module JsRoutes
extend T::Sig
#
# API
#
class << self
include JsRoutes::Types
extend T::Sig
sig { params(block: ConfigurationBlock).void }
def setup(&block)
configuration.setup(&block)
end
sig { returns(JsRoutes::Configuration) }
def configuration
@configuration ||= T.let(Configuration.new, T.nilable(JsRoutes::Configuration))
end
sig { params(opts: T.untyped).returns(String) }
def generate(**opts)
Instance.new(**opts).generate
end
sig { params(file_name: FileName, typed: T::Boolean, opts: T.untyped).void }
def generate!(file_name = configuration.file, typed: false, **opts)
Instance.new(file: file_name, **opts).generate!
definitions!(file_name, **opts) if typed
end
sig { params(file_name: FileName, opts: T.untyped).void }
def remove!(file_name = configuration.file, **opts)
Instance.new(file: file_name, **opts).remove!
end
sig { params(opts: T.untyped).returns(String) }
def definitions(**opts)
generate(**opts, module_type: 'DTS')
end
sig { params(file_name: FileName, opts: T.untyped).void }
def definitions!(file_name = nil, **opts)
file_name ||= configuration.file
file_name = file_name&.sub(%r{(\.d)?\.(j|t)s\Z}, ".d.ts")
generate!(file_name, **opts, module_type: 'DTS')
end
sig { params(value: T.untyped).returns(String) }
def json(value)
ActiveSupport::JSON.encode(value)
end
end
module Generators
end
end
require "js_routes/middleware"
require "js_routes/generators/webpacker"
require "js_routes/generators/middleware"