enroute 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +7 -7
- data/.rubocop.yml +6 -0
- data/.tool-versions +2 -1
- data/README.md +5 -5
- data/gemfiles/rails_7_1.gemfile +6 -0
- data/jest.config.js +2 -1
- data/lib/enroute/export.rb +24 -8
- data/lib/enroute/routes.rb +2 -2
- data/lib/enroute/template.ts.erb +25 -1
- data/lib/enroute/version.rb +1 -1
- data/package.json +3 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e448075c7d87f3b0a6c937069a8d97aabafc703eb1a32de10ed724c7360eb09a
|
4
|
+
data.tar.gz: 0440e5b70267913d65ed6876884a0bde6eb3d76d9b9ab7432d248706cbc5585b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 630f02374224590f3f51283d6b2735cabafc52454139e295be371cf5381a99c5d27f15d3d6fee4b46a7e09462cb6b6d5f20919e0956c94667beca4933743a9be
|
7
|
+
data.tar.gz: 485794ae75c343f3d198c206a0e9e89ba8d512d8a931f6414ef77a9b96a8d552b3a9bc1b428abb5b550ba3f621c5c7ff7684d24afbb9f66279f5d34edab4dfaa
|
data/.github/workflows/tests.yml
CHANGED
@@ -19,16 +19,16 @@ jobs:
|
|
19
19
|
strategy:
|
20
20
|
fail-fast: false
|
21
21
|
matrix:
|
22
|
-
ruby: ["
|
23
|
-
node: ["
|
22
|
+
ruby: ["3.1", "3.2", "3.3"]
|
23
|
+
node: ["18", "20"]
|
24
24
|
gemfile:
|
25
|
+
- gemfiles/rails_7_1.gemfile
|
25
26
|
- gemfiles/rails_7_0.gemfile
|
26
|
-
- gemfiles/rails_6_1.gemfile
|
27
27
|
|
28
28
|
steps:
|
29
|
-
- uses: actions/checkout@
|
29
|
+
- uses: actions/checkout@v4
|
30
30
|
|
31
|
-
- uses: actions/cache@
|
31
|
+
- uses: actions/cache@v3
|
32
32
|
with:
|
33
33
|
path: vendor/bundle
|
34
34
|
key: >
|
@@ -36,7 +36,7 @@ jobs:
|
|
36
36
|
hashFiles('package.json') }}
|
37
37
|
|
38
38
|
- name: Set up Node
|
39
|
-
uses: actions/setup-node@
|
39
|
+
uses: actions/setup-node@v4
|
40
40
|
with:
|
41
41
|
node-version: ${{ matrix.node }}
|
42
42
|
|
@@ -44,7 +44,7 @@ jobs:
|
|
44
44
|
run: |
|
45
45
|
yarn install
|
46
46
|
|
47
|
-
- uses: actions/cache@
|
47
|
+
- uses: actions/cache@v3
|
48
48
|
with:
|
49
49
|
path: vendor/bundle
|
50
50
|
key: >
|
data/.rubocop.yml
CHANGED
data/.tool-versions
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
nodejs
|
1
|
+
nodejs 21.6.1
|
2
|
+
ruby 3.3.0
|
data/README.md
CHANGED
@@ -83,10 +83,10 @@ You can then import any route that's been exported. Parameters are positional.
|
|
83
83
|
```typescript
|
84
84
|
import { userUrl } from "./routes";
|
85
85
|
|
86
|
-
userUrl(1234);
|
86
|
+
userUrl({ id: 1234 });
|
87
87
|
//=> "/users/1234"
|
88
88
|
|
89
|
-
userUrl(1234, "json");
|
89
|
+
userUrl({ id: 1234, format: "json" });
|
90
90
|
//=> "/users/1234.json"
|
91
91
|
```
|
92
92
|
|
@@ -100,7 +100,7 @@ import { editSettingsUrl } from "./routes";
|
|
100
100
|
editSettingsUrl();
|
101
101
|
//=> "/settings/edit"
|
102
102
|
|
103
|
-
editSettingsUrl("security");
|
103
|
+
editSettingsUrl({ section: "security" });
|
104
104
|
//=> "/settings/edit/security"
|
105
105
|
```
|
106
106
|
|
@@ -139,6 +139,6 @@ found at https://github.com/fnando/enroute/blob/main/LICENSE.md.
|
|
139
139
|
|
140
140
|
## Code of Conduct
|
141
141
|
|
142
|
-
Everyone interacting in the enroute project's codebases, issue
|
143
|
-
|
142
|
+
Everyone interacting in the enroute project's codebases, issue trackers, chat
|
143
|
+
rooms and mailing lists is expected to follow the
|
144
144
|
[code of conduct](https://github.com/fnando/enroute/blob/main/CODE_OF_CONDUCT.md).
|
data/jest.config.js
CHANGED
data/lib/enroute/export.rb
CHANGED
@@ -54,14 +54,21 @@ module Enroute
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def build_ts_args_definition(route)
|
57
|
-
route[:segments].
|
57
|
+
args = route[:segments].each_with_object([]) do |segment, buffer|
|
58
58
|
type = route.dig(:typings, segment)&.chomp ||
|
59
59
|
config.dig(:typings, :_default, segment)&.chomp ||
|
60
60
|
"any"
|
61
61
|
|
62
62
|
optional = route[:requiredSegments].include?(segment) ? "" : "?"
|
63
|
-
|
64
|
-
|
63
|
+
|
64
|
+
buffer << "#{segment.camelize(:lower)}#{optional}: #{type}"
|
65
|
+
end
|
66
|
+
|
67
|
+
args << "params?: Record<string, unknown>"
|
68
|
+
|
69
|
+
"args?: {#{args.join('; ')}}"
|
70
|
+
|
71
|
+
# (args + ["params: Record<string, unknown> = {}"]).join(", ")
|
65
72
|
end
|
66
73
|
|
67
74
|
def build_ts_handler_function(route)
|
@@ -71,12 +78,21 @@ module Enroute
|
|
71
78
|
|
72
79
|
def build_ts_route_function(route)
|
73
80
|
args = build_ts_args_definition(route)
|
74
|
-
segments = route[:segments].map {|segment| segment.camelize(:lower) }
|
75
81
|
|
76
|
-
[
|
77
|
-
|
78
|
-
|
79
|
-
|
82
|
+
segments = route[:segments].map {|segment| segment.camelize(:lower) }
|
83
|
+
destruct = [segments.join(", "), "params"].reject(&:blank?).join(", ")
|
84
|
+
|
85
|
+
<<~TYPESCRIPT
|
86
|
+
export function #{route[:name]}Url(#{args}): string {
|
87
|
+
const {#{destruct}} = args ?? {};
|
88
|
+
return buildUrl(#{route[:name]}Handler(#{segments.join(', ')}), params ?? {}).url;
|
89
|
+
}
|
90
|
+
|
91
|
+
export function #{route[:name]}Path(#{args}): string {
|
92
|
+
const {#{destruct}} = args ?? {};
|
93
|
+
return buildUrl(#{route[:name]}Handler(#{segments.join(', ')}), params ?? {}).path;
|
94
|
+
}
|
95
|
+
TYPESCRIPT
|
80
96
|
end
|
81
97
|
end
|
82
98
|
end
|
data/lib/enroute/routes.rb
CHANGED
@@ -42,7 +42,7 @@ module Enroute
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def reduce_methods(routes)
|
45
|
-
routes.map(&:verb).flatten.map(&:downcase).uniq
|
45
|
+
routes.map(&:verb).flatten.map(&:downcase).uniq.reject(&:empty?)
|
46
46
|
end
|
47
47
|
|
48
48
|
def camelize_map(list)
|
@@ -72,7 +72,7 @@ module Enroute
|
|
72
72
|
# on `:ignore`.
|
73
73
|
selected_routes.reject do |route|
|
74
74
|
route.name.nil? ||
|
75
|
-
route.name.match?(/rails|script/) ||
|
75
|
+
route.name.match?(/rails|script|turbo/) ||
|
76
76
|
config.fetch(:ignore, []).include?(route.name)
|
77
77
|
end
|
78
78
|
end
|
data/lib/enroute/template.ts.erb
CHANGED
@@ -2,7 +2,13 @@
|
|
2
2
|
// This file has been automatically generated.
|
3
3
|
// Don't edit it manually. Use `enroute export` instead.
|
4
4
|
|
5
|
-
|
5
|
+
function zipObject(keys: string[], values: unknown[]): Record<string, unknown> {
|
6
|
+
return keys.reduce((buffer, key, index) =>
|
7
|
+
Object.assign(
|
8
|
+
buffer,
|
9
|
+
{[key]: values[index]}
|
10
|
+
), {} as Record<string, unknown>)
|
11
|
+
}
|
6
12
|
|
7
13
|
function camelize(text: string): string {
|
8
14
|
return text.replace(
|
@@ -110,6 +116,24 @@ export type RouteHandler = RouteHelper & {
|
|
110
116
|
underscore: RouteHelper;
|
111
117
|
};
|
112
118
|
|
119
|
+
const baseUrl = location.protocol + "//" + location.host;
|
120
|
+
|
121
|
+
const buildUrl = (
|
122
|
+
path: string,
|
123
|
+
params: Record<string, unknown>
|
124
|
+
): {path: string; url: string} => {
|
125
|
+
const url = new URL(baseUrl + path);
|
126
|
+
|
127
|
+
Object.keys(params).forEach((key) => {
|
128
|
+
url.searchParams.set(key, String(params[key]));
|
129
|
+
});
|
130
|
+
|
131
|
+
return {
|
132
|
+
path: url.pathname + url.search,
|
133
|
+
url: url.toString(),
|
134
|
+
};
|
135
|
+
}
|
136
|
+
|
113
137
|
<%= handler_functions %>
|
114
138
|
|
115
139
|
<%= route_functions %>
|
data/lib/enroute/version.rb
CHANGED
data/package.json
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enroute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -166,6 +166,7 @@ files:
|
|
166
166
|
- exe/enroute
|
167
167
|
- gemfiles/rails_6_1.gemfile
|
168
168
|
- gemfiles/rails_7_0.gemfile
|
169
|
+
- gemfiles/rails_7_1.gemfile
|
169
170
|
- jest.config.js
|
170
171
|
- lib/enroute.rb
|
171
172
|
- lib/enroute/cli.rb
|
@@ -198,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
199
|
- !ruby/object:Gem::Version
|
199
200
|
version: '0'
|
200
201
|
requirements: []
|
201
|
-
rubygems_version: 3.
|
202
|
+
rubygems_version: 3.5.5
|
202
203
|
signing_key:
|
203
204
|
specification_version: 4
|
204
205
|
summary: Export Rails routes to TypeScript definitions
|