@tolki/ts 0.2.0 → 1.0.1
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.
- package/README.md +4752 -56
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +112 -112
- package/dist/vite-plugin.d.ts +5 -3
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +55 -51
- package/package.json +20 -3
package/dist/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,4BAA4B,EAC5B,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,EACpB,MAAM,cAAc,CAAC;AAYtB,YAAY,EACR,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,4BAA4B,EAC5B,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,GACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,KAAK,CAC7C,QAAQ,SAAS,SAAS,MAAM,EAAE,EAClC,KAAK,SAAS,SAAS,YAAY,EAAE,EACrC,UAAU,SAAS,kBAAkB,GAAG,SAAS,EACjD,kBAAkB,EAClB,uBAAuB,EAEvB,KAAK,EAAE,iBAAiB,CACpB,QAAQ,EACR,KAAK,EACL,UAAU,EACV,kBAAkB,EAClB,uBAAuB,CAC1B,KACA,iBAAiB,CAClB,QAAQ,EACR,KAAK,EACL,UAAU,EACV,UAAU,EACV,uBAAuB,CAC1B,CA8BA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,CAAC,eAAe,KAAK,CACvD,QAAQ,SAAS,SAAS,MAAM,EAAE,EAClC,KAAK,SAAS,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wBAAgB,gBAAgB,CAC5B,QAAQ,EACF,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GACzC,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,GACxD,IAAI,CAEN;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC3B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GACjC,IAAI,CAMN;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAE5E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AA8YD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC3B,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,iBAAiB,GAC5B,iBAAiB,CAWnB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,CACvB,KAAK,CAAC,QAAQ,SAAS,SAAS,MAAM,EAAE,EACxC,KAAK,CAAC,KAAK,SAAS,SAAS,YAAY,EAAE,GAAG,SAAS,EAAE,EACzD,KAAK,CAAC,UAAU,SAAS,kBAAkB,GAAG,SAAS,GAAG,SAAS,EAEnE,QAAQ,EAAE,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,UAAU,CAAC,GACrD,iBAAiB,CAAC,QAAQ,EAAE,KAAK,EAAE,UAAU,CAAC,CAkGhD"}
|
package/dist/routes.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { isString as U, isFunction as
|
|
2
|
-
function
|
|
1
|
+
import { isString as U, isFunction as E, isUndefined as $, isNull as j, isObject as g, isArray as q, isNumber as K, isBoolean as Q } from "@tolki/utils";
|
|
2
|
+
function F() {
|
|
3
3
|
return function(e) {
|
|
4
4
|
return e;
|
|
5
5
|
};
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function I() {
|
|
8
8
|
return function(e) {
|
|
9
9
|
return e;
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
-
const
|
|
13
|
-
let y =
|
|
12
|
+
const C = () => ({});
|
|
13
|
+
let y = C;
|
|
14
14
|
function T(e) {
|
|
15
|
-
y =
|
|
15
|
+
y = E(e) ? e : () => ({ ...e });
|
|
16
16
|
}
|
|
17
17
|
function V(e, n) {
|
|
18
|
-
const
|
|
18
|
+
const t = y;
|
|
19
19
|
y = () => ({
|
|
20
|
-
...
|
|
20
|
+
...t(),
|
|
21
21
|
[e]: n
|
|
22
22
|
});
|
|
23
23
|
}
|
|
@@ -25,20 +25,20 @@ function v() {
|
|
|
25
25
|
return { ...y() };
|
|
26
26
|
}
|
|
27
27
|
function L() {
|
|
28
|
-
y =
|
|
28
|
+
y = C;
|
|
29
29
|
}
|
|
30
30
|
function O(e, n) {
|
|
31
31
|
if ($(e) || j(e))
|
|
32
32
|
return "";
|
|
33
|
-
if (
|
|
33
|
+
if (g(e)) {
|
|
34
34
|
if (n?._routeKey) {
|
|
35
|
-
const
|
|
36
|
-
if (
|
|
37
|
-
return String(e[
|
|
35
|
+
const t = n._routeKey;
|
|
36
|
+
if (t in e)
|
|
37
|
+
return String(e[t]);
|
|
38
38
|
if ("id" in e)
|
|
39
39
|
return String(e.id);
|
|
40
40
|
throw new Error(
|
|
41
|
-
`Route error: object passed as '${n.name}' parameter is missing route model binding key '${
|
|
41
|
+
`Route error: object passed as '${n.name}' parameter is missing route model binding key '${t}'.`
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
44
|
if (n?._enumValues) {
|
|
@@ -55,137 +55,137 @@ function O(e, n) {
|
|
|
55
55
|
function S(e, n) {
|
|
56
56
|
if (j(n) || $(n))
|
|
57
57
|
return [];
|
|
58
|
-
if (
|
|
58
|
+
if (Q(n))
|
|
59
59
|
return [`${encodeURIComponent(e)}=${n ? "1" : "0"}`];
|
|
60
60
|
if (q(n)) {
|
|
61
|
-
const
|
|
61
|
+
const t = [];
|
|
62
62
|
for (let r = 0; r < n.length; r++)
|
|
63
|
-
|
|
63
|
+
t.push(
|
|
64
64
|
...S(`${e}[${r}]`, n[r])
|
|
65
65
|
);
|
|
66
|
-
return
|
|
66
|
+
return t;
|
|
67
67
|
}
|
|
68
|
-
if (
|
|
69
|
-
const
|
|
68
|
+
if (g(n)) {
|
|
69
|
+
const t = [];
|
|
70
70
|
for (const [r, h] of Object.entries(n))
|
|
71
|
-
|
|
71
|
+
t.push(
|
|
72
72
|
...S(`${e}[${r}]`, h)
|
|
73
73
|
);
|
|
74
|
-
return
|
|
74
|
+
return t;
|
|
75
75
|
}
|
|
76
76
|
return [`${encodeURIComponent(e)}=${encodeURIComponent(String(n))}`];
|
|
77
77
|
}
|
|
78
|
-
function
|
|
78
|
+
function x(e) {
|
|
79
79
|
const n = [];
|
|
80
|
-
for (const [
|
|
81
|
-
n.push(...S(
|
|
80
|
+
for (const [t, r] of Object.entries(e))
|
|
81
|
+
n.push(...S(t, r));
|
|
82
82
|
return n.length === 0 ? "" : `?${n.join("&")}`;
|
|
83
83
|
}
|
|
84
84
|
function R(e, n) {
|
|
85
85
|
if (e.length === 0)
|
|
86
86
|
return [{}, void 0];
|
|
87
|
-
const
|
|
87
|
+
const t = n;
|
|
88
88
|
let r;
|
|
89
|
-
if (
|
|
90
|
-
return e.length === 1 &&
|
|
91
|
-
const h = new Set(
|
|
89
|
+
if (t.length === 0)
|
|
90
|
+
return e.length === 1 && g(e[0]) ? [{}, e[0]] : [{}, void 0];
|
|
91
|
+
const h = new Set(t.map((s) => s.name));
|
|
92
92
|
if (e.length >= 2) {
|
|
93
93
|
const s = e[e.length - 1];
|
|
94
|
-
|
|
95
|
-
(
|
|
96
|
-
) && e.length >
|
|
94
|
+
g(s) && !Object.keys(s).some(
|
|
95
|
+
(c) => h.has(c)
|
|
96
|
+
) && e.length > t.length && (r = s, e = e.slice(0, -1));
|
|
97
97
|
}
|
|
98
98
|
if (e.length === 1 && q(e[0])) {
|
|
99
99
|
const s = e[0], m = {};
|
|
100
|
-
for (let
|
|
101
|
-
m[
|
|
100
|
+
for (let c = 0; c < s.length && c < t.length; c++)
|
|
101
|
+
m[t[c].name] = s[c];
|
|
102
102
|
return [m, r];
|
|
103
103
|
}
|
|
104
|
-
if (e.length === 1 &&
|
|
104
|
+
if (e.length === 1 && g(e[0])) {
|
|
105
105
|
const s = e[0];
|
|
106
|
-
if (Object.keys(s).some((
|
|
107
|
-
const
|
|
108
|
-
for (const [
|
|
109
|
-
h.has(
|
|
106
|
+
if (Object.keys(s).some((c) => h.has(c))) {
|
|
107
|
+
const c = {}, i = {};
|
|
108
|
+
for (const [u, f] of Object.entries(s))
|
|
109
|
+
h.has(u) ? c[u] = f : u === "_query" ? r = {
|
|
110
110
|
...r,
|
|
111
|
-
_query:
|
|
112
|
-
} : u
|
|
113
|
-
return Object.keys(
|
|
114
|
-
|
|
111
|
+
_query: f
|
|
112
|
+
} : i[u] = f;
|
|
113
|
+
return Object.keys(i).length > 0 && (r = { ...r, ...i }), [
|
|
114
|
+
c,
|
|
115
115
|
Object.keys(r ?? {}).length > 0 ? r : void 0
|
|
116
116
|
];
|
|
117
117
|
}
|
|
118
|
-
if (
|
|
119
|
-
const
|
|
120
|
-
if (
|
|
121
|
-
return [{ [
|
|
118
|
+
if (t.length === 1) {
|
|
119
|
+
const c = t[0], i = c.name, u = c._routeKey;
|
|
120
|
+
if (u && u in s || "id" in s || "_routeKey" in s)
|
|
121
|
+
return [{ [i]: s }, r];
|
|
122
122
|
}
|
|
123
123
|
return [{}, { ...r, ...s }];
|
|
124
124
|
}
|
|
125
|
-
if (e.length >= 1 && e.every((s) => U(s) ||
|
|
125
|
+
if (e.length >= 1 && e.every((s) => U(s) || K(s) || g(s))) {
|
|
126
126
|
const s = {};
|
|
127
|
-
for (let m = 0; m < e.length && m <
|
|
128
|
-
s[
|
|
127
|
+
for (let m = 0; m < e.length && m < t.length; m++)
|
|
128
|
+
s[t[m].name] = e[m];
|
|
129
129
|
return [s, r];
|
|
130
130
|
}
|
|
131
131
|
return [{}, r];
|
|
132
132
|
}
|
|
133
|
-
function d(e, n,
|
|
133
|
+
function d(e, n, t, r) {
|
|
134
134
|
let h = e;
|
|
135
135
|
!h.startsWith("/") && !h.startsWith("//") && !h.includes("://") && (h = `//${h}`);
|
|
136
|
-
const s = new Map(
|
|
137
|
-
for (const
|
|
138
|
-
|
|
139
|
-
for (const [
|
|
140
|
-
|
|
141
|
-
for (const
|
|
142
|
-
if (
|
|
143
|
-
const
|
|
144
|
-
if (
|
|
136
|
+
const s = new Map(t.map((o) => [o.name, o])), m = y(), c = {};
|
|
137
|
+
for (const o of t)
|
|
138
|
+
o.name in m && !(o.name in n) && (c[o.name] = m[o.name]);
|
|
139
|
+
for (const [o, l] of Object.entries(n))
|
|
140
|
+
c[o] = l;
|
|
141
|
+
for (const o of t)
|
|
142
|
+
if (o.where && o.name in c) {
|
|
143
|
+
const l = O(c[o.name], o);
|
|
144
|
+
if (l !== "") {
|
|
145
145
|
let p;
|
|
146
146
|
try {
|
|
147
|
-
p = new RegExp(`^${
|
|
147
|
+
p = new RegExp(`^${o.where}$`);
|
|
148
148
|
} catch {
|
|
149
149
|
throw new Error(
|
|
150
|
-
`Route error: '${
|
|
150
|
+
`Route error: '${o.name}' has invalid 'where' constraint pattern '${o.where}'.`
|
|
151
151
|
);
|
|
152
152
|
}
|
|
153
|
-
if (!p.test(
|
|
153
|
+
if (!p.test(l))
|
|
154
154
|
throw new Error(
|
|
155
|
-
`Route error: '${
|
|
155
|
+
`Route error: '${o.name}' parameter '${l}' does not match required format '${o.where}'.`
|
|
156
156
|
);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
const
|
|
159
|
+
const u = h.replace(
|
|
160
160
|
/{([^{}?]+)(\??)}/g,
|
|
161
|
-
(
|
|
162
|
-
const b =
|
|
161
|
+
(o, l, p) => {
|
|
162
|
+
const b = c[l], P = s.get(l);
|
|
163
163
|
if (!p && ($(b) || j(b)))
|
|
164
164
|
throw new Error(
|
|
165
|
-
`Route error: '${
|
|
165
|
+
`Route error: '${l}' parameter is required.`
|
|
166
166
|
);
|
|
167
|
-
const
|
|
168
|
-
return encodeURI(
|
|
167
|
+
const D = O(b, P);
|
|
168
|
+
return encodeURI(D).replace(/%7C/g, "|").replace(/%25/g, "%").replace(/\$/g, "%24");
|
|
169
169
|
}
|
|
170
|
-
).replace(/([^:])\/{2,}/g, "$1/").replace(/\/+$/, "") || "/",
|
|
170
|
+
).replace(/([^:])\/{2,}/g, "$1/").replace(/\/+$/, "") || "/", f = {};
|
|
171
171
|
if (r) {
|
|
172
172
|
if (r.mergeQuery) {
|
|
173
|
-
const
|
|
174
|
-
for (const [
|
|
175
|
-
l
|
|
176
|
-
for (const [
|
|
177
|
-
j(p) || $(p) ? delete l
|
|
173
|
+
const o = $(globalThis.window) ? new URLSearchParams() : new URLSearchParams(globalThis.window.location.search);
|
|
174
|
+
for (const [l, p] of o.entries())
|
|
175
|
+
f[l] = p;
|
|
176
|
+
for (const [l, p] of Object.entries(r.mergeQuery))
|
|
177
|
+
j(p) || $(p) ? delete f[l] : f[l] = p;
|
|
178
178
|
}
|
|
179
|
-
for (const [
|
|
180
|
-
if (
|
|
179
|
+
for (const [o, l] of Object.entries(r))
|
|
180
|
+
if (o === "_query" && g(l))
|
|
181
181
|
for (const [p, b] of Object.entries(
|
|
182
|
-
|
|
182
|
+
l
|
|
183
183
|
))
|
|
184
|
-
|
|
185
|
-
else
|
|
184
|
+
f[p] = b;
|
|
185
|
+
else o !== "_query" && o !== "mergeQuery" && (f[o] = l);
|
|
186
186
|
}
|
|
187
|
-
const
|
|
188
|
-
return
|
|
187
|
+
const a = x(f);
|
|
188
|
+
return u + a;
|
|
189
189
|
}
|
|
190
190
|
function k(e, n) {
|
|
191
191
|
return {
|
|
@@ -205,68 +205,68 @@ function _(e, n) {
|
|
|
205
205
|
}
|
|
206
206
|
};
|
|
207
207
|
}
|
|
208
|
-
function
|
|
209
|
-
const
|
|
208
|
+
function w(e, n) {
|
|
209
|
+
const t = n?.mergeQuery ? "mergeQuery" : "_query", r = n?.[t] ?? {};
|
|
210
210
|
return {
|
|
211
211
|
...n,
|
|
212
|
-
[
|
|
212
|
+
[t]: {
|
|
213
213
|
...r,
|
|
214
214
|
_method: e.toUpperCase()
|
|
215
215
|
}
|
|
216
216
|
};
|
|
217
217
|
}
|
|
218
218
|
function W(e) {
|
|
219
|
-
const n = e.args ?? [],
|
|
220
|
-
const [u,
|
|
221
|
-
return k(
|
|
219
|
+
const n = e.args ?? [], t = e.methods[0] ?? "get", r = (...i) => {
|
|
220
|
+
const [u, f] = R(i, n), a = d(e.url, u, n, f);
|
|
221
|
+
return k(a, t);
|
|
222
222
|
}, s = Object.assign(r, {
|
|
223
|
-
url: (...
|
|
224
|
-
const [u,
|
|
225
|
-
return d(e.url, u, n,
|
|
223
|
+
url: (...i) => {
|
|
224
|
+
const [u, f] = R(i, n);
|
|
225
|
+
return d(e.url, u, n, f);
|
|
226
226
|
},
|
|
227
227
|
definition: e,
|
|
228
228
|
toString() {
|
|
229
229
|
return d(e.url, {}, n);
|
|
230
230
|
}
|
|
231
231
|
});
|
|
232
|
-
for (const
|
|
232
|
+
for (const i of e.methods)
|
|
233
233
|
Object.assign(s, {
|
|
234
|
-
[
|
|
235
|
-
const [
|
|
236
|
-
return k(
|
|
234
|
+
[i]: (...u) => {
|
|
235
|
+
const [f, a] = R(u, n), o = d(e.url, f, n, a);
|
|
236
|
+
return k(o, i);
|
|
237
237
|
}
|
|
238
238
|
});
|
|
239
|
-
const m = (...
|
|
240
|
-
const [u,
|
|
241
|
-
return _(
|
|
239
|
+
const m = t !== "get" && t !== "post", c = (...i) => {
|
|
240
|
+
const [u, f] = R(i, n), a = m ? w(t, f) : f, o = d(e.url, u, n, a);
|
|
241
|
+
return _(o, t);
|
|
242
242
|
};
|
|
243
|
-
for (const
|
|
244
|
-
const u =
|
|
245
|
-
Object.assign(
|
|
246
|
-
[
|
|
247
|
-
const [
|
|
248
|
-
return _(
|
|
243
|
+
for (const i of e.methods) {
|
|
244
|
+
const u = i !== "get" && i !== "post";
|
|
245
|
+
Object.assign(c, {
|
|
246
|
+
[i]: (...f) => {
|
|
247
|
+
const [a, o] = R(f, n), l = u ? w(i, o) : o, p = d(e.url, a, n, l);
|
|
248
|
+
return _(p, i);
|
|
249
249
|
}
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
|
-
if (Object.assign(s, { form:
|
|
252
|
+
if (Object.assign(s, { form: c }), e.component !== void 0)
|
|
253
253
|
if (Object.assign(s, { component: e.component }), U(e.component)) {
|
|
254
|
-
const
|
|
254
|
+
const i = e.component;
|
|
255
255
|
Object.assign(s, {
|
|
256
|
-
withComponent: (...u) => ({ ...r(...u), component:
|
|
256
|
+
withComponent: (...u) => ({ ...r(...u), component: i })
|
|
257
257
|
});
|
|
258
258
|
} else
|
|
259
259
|
Object.assign(s, {
|
|
260
|
-
withComponent: (
|
|
260
|
+
withComponent: (i, ...u) => ({ ...r(...u), component: i })
|
|
261
261
|
});
|
|
262
262
|
return s;
|
|
263
263
|
}
|
|
264
264
|
export {
|
|
265
265
|
V as addRouteDefault,
|
|
266
|
-
|
|
267
|
-
|
|
266
|
+
F as annotatePageProps,
|
|
267
|
+
I as annotateRequestPayload,
|
|
268
268
|
W as defineRoute,
|
|
269
|
-
|
|
269
|
+
w as formSafeOptions,
|
|
270
270
|
v as getRouteDefaults,
|
|
271
271
|
L as resetRouteDefaults,
|
|
272
272
|
T as setRouteDefaults
|
package/dist/vite-plugin.d.ts
CHANGED
|
@@ -101,9 +101,11 @@ export interface LaravelTsPublishOptions {
|
|
|
101
101
|
/**
|
|
102
102
|
* Whether to append `--quiet` to every artisan command the plugin runs.
|
|
103
103
|
*
|
|
104
|
-
* The plugin
|
|
105
|
-
*
|
|
106
|
-
*
|
|
104
|
+
* The plugin determines success or failure from the exit code, so
|
|
105
|
+
* passing `--quiet` suppresses normal console output and Laravel
|
|
106
|
+
* Prompts rendering, which speeds up execution. When the command
|
|
107
|
+
* fails, its captured error output is still surfaced in the plugin's
|
|
108
|
+
* failure message.
|
|
107
109
|
*
|
|
108
110
|
* @default true
|
|
109
111
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,KAAK,MAAM,EAGd,MAAM,MAAM,CAAC;AAId;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUpD;AAED,MAAM,WAAW,uBAAuB;IACpC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;;;;;;;;;OAeG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC/B;;;;;;;;;;OAUG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC
|
|
1
|
+
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,KAAK,MAAM,EAGd,MAAM,MAAM,CAAC;AAId;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUpD;AAED,MAAM,WAAW,uBAAuB;IACpC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;;;;;;;;;OAeG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC/B;;;;;;;;;;OAUG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;;;;;;;;OAUG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAgB,gBAAgB,CAC5B,OAAO,GAAE,uBAA4B,GACtC,MAAM,CAuPR"}
|
package/dist/vite-plugin.js
CHANGED
|
@@ -1,77 +1,81 @@
|
|
|
1
|
-
import { exec as
|
|
2
|
-
import { readFile as
|
|
3
|
-
import
|
|
4
|
-
import { promisify as
|
|
1
|
+
import { exec as R } from "node:child_process";
|
|
2
|
+
import { readFile as W } from "node:fs/promises";
|
|
3
|
+
import q from "node:path";
|
|
4
|
+
import { promisify as k } from "node:util";
|
|
5
5
|
import { normalizePath as p } from "vite";
|
|
6
|
-
const
|
|
7
|
-
function
|
|
8
|
-
return
|
|
6
|
+
const B = k(R);
|
|
7
|
+
function H(a) {
|
|
8
|
+
return a === "" ? "''" : /^[\w@%+=:,./-]+$/.test(a) ? a : "'" + a.replace(/'/g, "'\\''") + "'";
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function G(a = {}) {
|
|
11
11
|
const {
|
|
12
12
|
command: l = "php artisan ts:publish",
|
|
13
|
-
filename:
|
|
14
|
-
directory:
|
|
15
|
-
runOnDevStart:
|
|
16
|
-
runOnBuildStart:
|
|
17
|
-
reload:
|
|
13
|
+
filename: z = "laravel-ts-collected-files.json",
|
|
14
|
+
directory: F = "resources/js/types/data/",
|
|
15
|
+
runOnDevStart: P = !1,
|
|
16
|
+
runOnBuildStart: T = !0,
|
|
17
|
+
reload: x = !0,
|
|
18
18
|
failOnError: h,
|
|
19
19
|
sourceCommand: w,
|
|
20
|
-
onBuildOnlyFunctional:
|
|
20
|
+
onBuildOnlyFunctional: M = !0,
|
|
21
21
|
quiet: y = !0
|
|
22
|
-
} =
|
|
23
|
-
let
|
|
24
|
-
const
|
|
22
|
+
} = a, $ = w === !1 ? !1 : w ?? `${l} --source={file}`;
|
|
23
|
+
let t, c;
|
|
24
|
+
const r = /* @__PURE__ */ new Map();
|
|
25
25
|
let u = "", g = !1;
|
|
26
26
|
const d = [], n = "[laravel-ts-publish]", b = async () => {
|
|
27
|
-
|
|
27
|
+
r.clear();
|
|
28
28
|
try {
|
|
29
|
-
const e = await
|
|
29
|
+
const e = await W(u, "utf-8"), o = JSON.parse(e);
|
|
30
30
|
for (const f of o) {
|
|
31
|
-
const
|
|
32
|
-
|
|
31
|
+
const s = p(q.resolve(t.root, f));
|
|
32
|
+
r.set(s, f);
|
|
33
33
|
}
|
|
34
34
|
} catch (e) {
|
|
35
35
|
if (e instanceof Error && e.code === "ENOENT") {
|
|
36
|
-
|
|
36
|
+
t.logger.warn(
|
|
37
37
|
`${n} Manifest not found: ${u}`
|
|
38
38
|
);
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
t.logger.error(
|
|
42
42
|
`${n} Failed to read manifest: ${e instanceof Error ? e.message : String(e)}`
|
|
43
43
|
);
|
|
44
44
|
}
|
|
45
45
|
}, v = () => {
|
|
46
46
|
if (c)
|
|
47
|
-
for (const e of
|
|
47
|
+
for (const e of r.keys())
|
|
48
48
|
c.watcher.add(e);
|
|
49
|
-
},
|
|
49
|
+
}, j = () => h !== void 0 ? h : t.command === "build", m = async (e = null, o) => {
|
|
50
50
|
if (g) {
|
|
51
51
|
d.includes(e) || d.push(e);
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
g = !0;
|
|
55
|
-
let
|
|
55
|
+
let s = e && $ ? $.replaceAll(
|
|
56
56
|
"{file}",
|
|
57
|
-
|
|
57
|
+
H(e)
|
|
58
58
|
) : o ?? l;
|
|
59
|
-
y && !
|
|
59
|
+
y && !s.includes("--quiet") && (s += " --quiet");
|
|
60
60
|
try {
|
|
61
|
-
|
|
61
|
+
t.logger.info(`${n} Running: ${s}`, {
|
|
62
62
|
timestamp: !0
|
|
63
|
-
}), await
|
|
63
|
+
}), await B(s, { cwd: t.root }), t.logger.info(`${n} Types published successfully`, {
|
|
64
64
|
timestamp: !0
|
|
65
|
-
}),
|
|
66
|
-
} catch (
|
|
67
|
-
const C =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
}), x && c && c.ws.send({ type: "full-reload" });
|
|
66
|
+
} catch (i) {
|
|
67
|
+
const C = i instanceof Error ? i.message : String(i), { stdout: A, stderr: N } = i, O = [N?.trim(), A?.trim()].filter(
|
|
68
|
+
(E) => !!E && !C.includes(E)
|
|
69
|
+
).join(`
|
|
70
|
+
`), S = `${n} Command failed: ${C}${O ? `
|
|
71
|
+
${O}` : ""}`;
|
|
72
|
+
if (j())
|
|
73
|
+
throw new Error(S, { cause: i });
|
|
74
|
+
t.logger.error(S);
|
|
71
75
|
} finally {
|
|
72
76
|
if (g = !1, d.length > 0) {
|
|
73
|
-
const
|
|
74
|
-
await m(
|
|
77
|
+
const i = d.shift();
|
|
78
|
+
await m(i);
|
|
75
79
|
}
|
|
76
80
|
}
|
|
77
81
|
};
|
|
@@ -79,41 +83,41 @@ function D(i = {}) {
|
|
|
79
83
|
name: "@tolki/vite-plugin-laravel-ts-publish",
|
|
80
84
|
enforce: "pre",
|
|
81
85
|
configResolved(e) {
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
t = e, u = p(
|
|
87
|
+
q.resolve(t.root, F, z)
|
|
84
88
|
);
|
|
85
89
|
},
|
|
86
90
|
configureServer(e) {
|
|
87
91
|
c = e;
|
|
88
92
|
},
|
|
89
93
|
async buildStart() {
|
|
90
|
-
if (
|
|
91
|
-
if (
|
|
92
|
-
let e =
|
|
94
|
+
if (t.command === "build") {
|
|
95
|
+
if (T) {
|
|
96
|
+
let e = M && !l.includes("--only-functional") ? `${l} --only-functional` : l;
|
|
93
97
|
y && !e.includes("--quiet") && (e += " --quiet"), await m(null, e);
|
|
94
98
|
}
|
|
95
99
|
return;
|
|
96
100
|
}
|
|
97
|
-
await b(), v(),
|
|
98
|
-
`${n} Watching ${
|
|
101
|
+
await b(), v(), r.size > 0 && t.logger.info(
|
|
102
|
+
`${n} Watching ${r.size} PHP file${r.size === 1 ? "" : "s"} for changes`,
|
|
99
103
|
{ timestamp: !0 }
|
|
100
|
-
),
|
|
104
|
+
), P && await m();
|
|
101
105
|
},
|
|
102
106
|
async handleHotUpdate({ file: e }) {
|
|
103
107
|
const o = p(e);
|
|
104
108
|
if (o === u)
|
|
105
|
-
return
|
|
109
|
+
return t.logger.info(
|
|
106
110
|
`${n} Manifest changed, reloading watched files`,
|
|
107
111
|
{ timestamp: !0 }
|
|
108
112
|
), await b(), v(), [];
|
|
109
|
-
if (
|
|
110
|
-
const f =
|
|
113
|
+
if (r.has(o)) {
|
|
114
|
+
const f = r.get(o) ?? null;
|
|
111
115
|
return await m(f), [];
|
|
112
116
|
}
|
|
113
117
|
}
|
|
114
118
|
};
|
|
115
119
|
}
|
|
116
120
|
export {
|
|
117
|
-
|
|
118
|
-
|
|
121
|
+
H as escapeShellArg,
|
|
122
|
+
G as laravelTsPublish
|
|
119
123
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tolki/ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A set of TypeScript utilities for the Laravel TypeScript Publish PHP package.",
|
|
5
5
|
"author": "Abraham Arango <https://github.com/abetwothree>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -74,8 +74,25 @@
|
|
|
74
74
|
"tolki": {
|
|
75
75
|
"docs": [
|
|
76
76
|
"ts/index.md",
|
|
77
|
-
"ts/
|
|
78
|
-
"ts/
|
|
77
|
+
"ts/enums.md",
|
|
78
|
+
"ts/models.md",
|
|
79
|
+
"ts/api-resources.md",
|
|
80
|
+
"ts/broadcast-channels.md",
|
|
81
|
+
"ts/broadcast-events.md",
|
|
82
|
+
"ts/casing-configuration.md",
|
|
83
|
+
"ts/enum-api-resource.md",
|
|
84
|
+
"ts/excluding-content.md",
|
|
85
|
+
"ts/extending-interfaces.md",
|
|
86
|
+
"ts/form-requests.md",
|
|
87
|
+
"ts/generating-cache.md",
|
|
88
|
+
"ts/inertia.md",
|
|
89
|
+
"ts/modular-publishing.md",
|
|
90
|
+
"ts/pre-command-hook.md",
|
|
91
|
+
"ts/routing.md",
|
|
92
|
+
"ts/vite-env.md",
|
|
93
|
+
"ts/vite-plugin.md",
|
|
94
|
+
"ts/customizing-the-pipeline.md",
|
|
95
|
+
"ts/configuration-reference.md"
|
|
79
96
|
]
|
|
80
97
|
},
|
|
81
98
|
"scripts": {
|