@tolki/enum 0.0.4 → 0.0.5
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 +19 -1
- package/dist/enums.d.ts +5 -4
- package/dist/enums.d.ts.map +1 -1
- package/dist/enums.js +5 -5
- package/dist/vite-plugin.d.ts +22 -0
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +68 -62
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -146,9 +146,10 @@ By default, the plugin will work in the following way:
|
|
|
146
146
|
2. It will look for the list of transformed PHP files here: `resources/js/types/laravel-ts-collected-files.json`.
|
|
147
147
|
3. If that manifest file changes, it will reload the watched file list without calling the publish command again.
|
|
148
148
|
4. It will reload the page after a successful publish triggered by a watched PHP file change.
|
|
149
|
-
5. It will call the publish command on `vite build` before bundling.
|
|
149
|
+
5. It will call the publish command on `vite build` before bundling, with `--only-enums` appended by default (since model interfaces are type-only and erased at compile time).
|
|
150
150
|
6. It will throw an error if the publish command fails on `vite build`.
|
|
151
151
|
7. When a single PHP file changes during `vite dev`, it will use `--source` to republish only that file instead of running a full publish.
|
|
152
|
+
8. It will append `--quiet` to every command by default, suppressing all console output since the plugin only needs the exit code.
|
|
152
153
|
|
|
153
154
|
#### Single-File Republishing
|
|
154
155
|
|
|
@@ -250,6 +251,23 @@ export default defineConfig({
|
|
|
250
251
|
* Set to `false` to always run the full command.
|
|
251
252
|
*/
|
|
252
253
|
sourceCommand: 'php artisan ts:publish --source="{file}"',
|
|
254
|
+
/**
|
|
255
|
+
* Whether to append `--only-enums` to the command during `vite build`.
|
|
256
|
+
*
|
|
257
|
+
* Model interfaces are type-only and erased at compile time, so
|
|
258
|
+
* generating them during production builds is unnecessary.
|
|
259
|
+
*
|
|
260
|
+
* Has no effect during `vite dev`.
|
|
261
|
+
*/
|
|
262
|
+
onBuildOnlyEnums: true,
|
|
263
|
+
/**
|
|
264
|
+
* Whether to append `--quiet` to every artisan command the plugin runs.
|
|
265
|
+
*
|
|
266
|
+
* The plugin only needs the exit code to determine success or failure;
|
|
267
|
+
* all stdout is ignored. Passing `--quiet` suppresses console output
|
|
268
|
+
* and Laravel Prompts rendering, which speeds up execution.
|
|
269
|
+
*/
|
|
270
|
+
quiet: true,
|
|
253
271
|
}),
|
|
254
272
|
],
|
|
255
273
|
});
|
package/dist/enums.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { CaseValue, DefineEnumResult, EnumConst,
|
|
1
|
+
import { AsEnum, CaseValue, DefineEnumResult, EnumConst, FromResult } from '../../types/src/index.ts';
|
|
2
|
+
export type { AsEnum, CaseValue, DefineEnumResult, EnumConst, FromResult };
|
|
2
3
|
/**
|
|
3
4
|
* Creates an enum instance from a case value similar to PHP's `BackedEnum::from()`
|
|
4
5
|
*
|
|
@@ -16,7 +17,7 @@ import { CaseValue, DefineEnumResult, EnumConst, ToEnumResult } from '../../type
|
|
|
16
17
|
* @returns The resolved enum case with its associated methods and properties for the value provided.
|
|
17
18
|
* @throws If the value does not match any case in the enum, an error is thrown.
|
|
18
19
|
*/
|
|
19
|
-
export declare function from<TEnum extends EnumConst, const TValue extends CaseValue<TEnum>>(enumObj: TEnum, value: TValue):
|
|
20
|
+
export declare function from<TEnum extends EnumConst, const TValue extends CaseValue<TEnum>>(enumObj: TEnum, value: TValue): FromResult<TEnum, TValue>;
|
|
20
21
|
/**
|
|
21
22
|
* Similar to the {@linkcode from | from} function but returns null instead of throwing an error for invalid values.
|
|
22
23
|
*
|
|
@@ -28,7 +29,7 @@ export declare function from<TEnum extends EnumConst, const TValue extends CaseV
|
|
|
28
29
|
* @param value - The case value to resolve.
|
|
29
30
|
* @returns The resolved enum case, or null if the value does not match any case.
|
|
30
31
|
*/
|
|
31
|
-
export declare function tryFrom<TEnum extends EnumConst, const TValue extends CaseValue<TEnum>>(enumObj: TEnum, value: TValue):
|
|
32
|
+
export declare function tryFrom<TEnum extends EnumConst, const TValue extends CaseValue<TEnum>>(enumObj: TEnum, value: TValue): FromResult<TEnum, TValue> | null;
|
|
32
33
|
/**
|
|
33
34
|
* Returns all enum cases as resolved instances by running each case value through the {@linkcode from | from} function.
|
|
34
35
|
*
|
|
@@ -39,7 +40,7 @@ export declare function tryFrom<TEnum extends EnumConst, const TValue extends Ca
|
|
|
39
40
|
* @param enumObj - The enum const object to resolve all cases from.
|
|
40
41
|
* @returns An array of resolved enum instances, one for each case.
|
|
41
42
|
*/
|
|
42
|
-
export declare function cases<TEnum extends EnumConst>(enumObj: TEnum): Array<
|
|
43
|
+
export declare function cases<TEnum extends EnumConst>(enumObj: TEnum): Array<FromResult<TEnum, CaseValue<TEnum>>>;
|
|
43
44
|
/**
|
|
44
45
|
* Factory function that creates an enriched enum object
|
|
45
46
|
*
|
package/dist/enums.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,
|
|
1
|
+
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,MAAM,EACN,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,UAAU,EACb,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AAE3E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,IAAI,CAChB,KAAK,SAAS,SAAS,EACvB,KAAK,CAAC,MAAM,SAAS,SAAS,CAAC,KAAK,CAAC,EACvC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CA8C1D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CACnB,KAAK,SAAS,SAAS,EACvB,KAAK,CAAC,MAAM,SAAS,SAAS,CAAC,KAAK,CAAC,EACvC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,CAMjE;AAED;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,KAAK,SAAS,SAAS,EACzC,OAAO,EAAE,KAAK,GACf,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAI5C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,KAAK,CAAC,KAAK,SAAS,SAAS,EACpD,OAAO,EAAE,KAAK,GACf,gBAAgB,CAAC,KAAK,CAAC,CA2BzB"}
|
package/dist/enums.js
CHANGED
|
@@ -7,12 +7,12 @@ function a(e, t) {
|
|
|
7
7
|
break;
|
|
8
8
|
}
|
|
9
9
|
if (!r) {
|
|
10
|
-
const s = Array.from(n).map((
|
|
10
|
+
const s = Array.from(n).map((c) => e[c]);
|
|
11
11
|
throw new Error(
|
|
12
12
|
`Value "${String(t)}" does not match any case in the enum. Values: ${s.join(", ")}, Cases: ${[...n].join(", ")}`
|
|
13
13
|
);
|
|
14
14
|
}
|
|
15
|
-
const
|
|
15
|
+
const o = { value: t }, h = new Set(e._methods ?? []), i = e._helpers, f = new Set(
|
|
16
16
|
Array.isArray(i) ? i : []
|
|
17
17
|
), l = /* @__PURE__ */ new Set([
|
|
18
18
|
"_cases",
|
|
@@ -20,9 +20,9 @@ function a(e, t) {
|
|
|
20
20
|
"_helpers",
|
|
21
21
|
"_static"
|
|
22
22
|
]);
|
|
23
|
-
for (const [s,
|
|
24
|
-
l.has(s) || n.has(s) || f.has(s) || (h.has(s) ?
|
|
25
|
-
return
|
|
23
|
+
for (const [s, c] of Object.entries(e))
|
|
24
|
+
l.has(s) || n.has(s) || f.has(s) || (h.has(s) ? o[s] = c[r] : o[s] = c);
|
|
25
|
+
return o.name = r, o;
|
|
26
26
|
}
|
|
27
27
|
function y(e, t) {
|
|
28
28
|
try {
|
package/dist/vite-plugin.d.ts
CHANGED
|
@@ -75,6 +75,28 @@ export interface LaravelTsPublishOptions {
|
|
|
75
75
|
* @default Derived from the `command` option: 'php artisan ts:publish --source="{file}"'
|
|
76
76
|
*/
|
|
77
77
|
sourceCommand?: string | false;
|
|
78
|
+
/**
|
|
79
|
+
* Whether to append `--only-enums` to the command during `vite build`.
|
|
80
|
+
*
|
|
81
|
+
* Model interfaces are type-only and erased at compile time, so generating
|
|
82
|
+
* them during production builds is unnecessary. When `true`, the build
|
|
83
|
+
* command becomes e.g. `php artisan ts:publish --only-enums`.
|
|
84
|
+
*
|
|
85
|
+
* Has no effect during `vite dev`.
|
|
86
|
+
*
|
|
87
|
+
* @default true
|
|
88
|
+
*/
|
|
89
|
+
onBuildOnlyEnums?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Whether to append `--quiet` to every artisan command the plugin runs.
|
|
92
|
+
*
|
|
93
|
+
* The plugin only needs the exit code to determine success or failure;
|
|
94
|
+
* all stdout is ignored. Passing `--quiet` suppresses console output
|
|
95
|
+
* and Laravel Prompts rendering, which speeds up execution.
|
|
96
|
+
*
|
|
97
|
+
* @default true
|
|
98
|
+
*/
|
|
99
|
+
quiet?: boolean;
|
|
78
100
|
}
|
|
79
101
|
/**
|
|
80
102
|
* Vite plugin that watches PHP source files listed in the Laravel TypeScript
|
|
@@ -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,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;IACn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|
-
import { exec as
|
|
2
|
-
import { readFile as
|
|
3
|
-
import
|
|
4
|
-
import { promisify as
|
|
5
|
-
import { normalizePath as
|
|
6
|
-
const
|
|
7
|
-
function
|
|
1
|
+
import { exec as F } from "node:child_process";
|
|
2
|
+
import { readFile as M } from "node:fs/promises";
|
|
3
|
+
import C from "node:path";
|
|
4
|
+
import { promisify as N } from "node:util";
|
|
5
|
+
import { normalizePath as g } from "vite";
|
|
6
|
+
const R = N(F);
|
|
7
|
+
function H(E = {}) {
|
|
8
8
|
const {
|
|
9
|
-
command:
|
|
10
|
-
filename:
|
|
11
|
-
directory:
|
|
12
|
-
runOnDevStart:
|
|
13
|
-
runOnBuildStart:
|
|
14
|
-
reload:
|
|
15
|
-
failOnError:
|
|
16
|
-
sourceCommand:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let
|
|
21
|
-
const
|
|
22
|
-
|
|
9
|
+
command: s = "php artisan ts:publish",
|
|
10
|
+
filename: O = "laravel-ts-collected-files.json",
|
|
11
|
+
directory: S = "resources/js/types/",
|
|
12
|
+
runOnDevStart: q = !1,
|
|
13
|
+
runOnBuildStart: z = !0,
|
|
14
|
+
reload: P = !0,
|
|
15
|
+
failOnError: p,
|
|
16
|
+
sourceCommand: h,
|
|
17
|
+
onBuildOnlyEnums: T = !0,
|
|
18
|
+
quiet: w = !0
|
|
19
|
+
} = E, y = h === !1 ? !1 : h ?? `${s} --source="{file}"`;
|
|
20
|
+
let r, l;
|
|
21
|
+
const t = /* @__PURE__ */ new Map();
|
|
22
|
+
let u = "", m = !1;
|
|
23
|
+
const f = [], n = "[laravel-ts-publish]", v = async () => {
|
|
24
|
+
t.clear();
|
|
23
25
|
try {
|
|
24
|
-
const e = await
|
|
25
|
-
for (const
|
|
26
|
-
const
|
|
27
|
-
|
|
26
|
+
const e = await M(u, "utf-8"), o = JSON.parse(e);
|
|
27
|
+
for (const c of o) {
|
|
28
|
+
const i = g(C.resolve(r.root, c));
|
|
29
|
+
t.set(i, c);
|
|
28
30
|
}
|
|
29
31
|
} catch (e) {
|
|
30
32
|
if (e instanceof Error && e.code === "ENOENT") {
|
|
31
33
|
r.logger.warn(
|
|
32
|
-
`${
|
|
34
|
+
`${n} Manifest not found: ${u}`
|
|
33
35
|
);
|
|
34
36
|
return;
|
|
35
37
|
}
|
|
36
38
|
r.logger.error(
|
|
37
|
-
`${
|
|
39
|
+
`${n} Failed to read manifest: ${e instanceof Error ? e.message : String(e)}`
|
|
38
40
|
);
|
|
39
41
|
}
|
|
40
|
-
},
|
|
41
|
-
if (
|
|
42
|
-
for (const e of
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
if (
|
|
46
|
-
|
|
42
|
+
}, $ = () => {
|
|
43
|
+
if (l)
|
|
44
|
+
for (const e of t.keys())
|
|
45
|
+
l.watcher.add(e);
|
|
46
|
+
}, x = () => p !== void 0 ? p : r.command === "build", d = async (e = null, o) => {
|
|
47
|
+
if (m) {
|
|
48
|
+
f.includes(e) || f.push(e);
|
|
47
49
|
return;
|
|
48
50
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
m = !0;
|
|
52
|
+
let i = e && y ? y.replaceAll("{file}", e) : o ?? s;
|
|
53
|
+
w && !i.includes("--quiet") && (i += " --quiet");
|
|
51
54
|
try {
|
|
52
|
-
r.logger.info(`${
|
|
55
|
+
r.logger.info(`${n} Running: ${i}`, {
|
|
53
56
|
timestamp: !0
|
|
54
|
-
}), await
|
|
57
|
+
}), await R(i, { cwd: r.root }), r.logger.info(`${n} Types published successfully`, {
|
|
55
58
|
timestamp: !0
|
|
56
|
-
}),
|
|
57
|
-
} catch (
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
-
throw new Error(
|
|
61
|
-
r.logger.error(
|
|
59
|
+
}), P && l && l.ws.send({ type: "full-reload" });
|
|
60
|
+
} catch (a) {
|
|
61
|
+
const b = `${n} Command failed: ${a instanceof Error ? a.message : String(a)}`;
|
|
62
|
+
if (x())
|
|
63
|
+
throw new Error(b, { cause: a });
|
|
64
|
+
r.logger.error(b);
|
|
62
65
|
} finally {
|
|
63
|
-
if (
|
|
64
|
-
const
|
|
65
|
-
await
|
|
66
|
+
if (m = !1, f.length > 0) {
|
|
67
|
+
const a = f.shift();
|
|
68
|
+
await d(a);
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
71
|
};
|
|
@@ -70,37 +73,40 @@ function k($ = {}) {
|
|
|
70
73
|
name: "@tolki/vite-plugin-laravel-ts-publish",
|
|
71
74
|
enforce: "pre",
|
|
72
75
|
configResolved(e) {
|
|
73
|
-
r = e,
|
|
74
|
-
|
|
76
|
+
r = e, u = g(
|
|
77
|
+
C.resolve(r.root, S, O)
|
|
75
78
|
);
|
|
76
79
|
},
|
|
77
80
|
configureServer(e) {
|
|
78
|
-
|
|
81
|
+
l = e;
|
|
79
82
|
},
|
|
80
83
|
async buildStart() {
|
|
81
84
|
if (r.command === "build") {
|
|
82
|
-
|
|
85
|
+
if (z) {
|
|
86
|
+
let e = T && !s.includes("--only-enums") ? `${s} --only-enums` : s;
|
|
87
|
+
w && !e.includes("--quiet") && (e += " --quiet"), await d(null, e);
|
|
88
|
+
}
|
|
83
89
|
return;
|
|
84
90
|
}
|
|
85
|
-
await
|
|
86
|
-
`${
|
|
91
|
+
await v(), $(), t.size > 0 && r.logger.info(
|
|
92
|
+
`${n} Watching ${t.size} PHP file${t.size === 1 ? "" : "s"} for changes`,
|
|
87
93
|
{ timestamp: !0 }
|
|
88
|
-
),
|
|
94
|
+
), q && await d();
|
|
89
95
|
},
|
|
90
96
|
async handleHotUpdate({ file: e }) {
|
|
91
|
-
const
|
|
92
|
-
if (
|
|
97
|
+
const o = g(e);
|
|
98
|
+
if (o === u)
|
|
93
99
|
return r.logger.info(
|
|
94
|
-
`${
|
|
100
|
+
`${n} Manifest changed, reloading watched files`,
|
|
95
101
|
{ timestamp: !0 }
|
|
96
|
-
), await
|
|
97
|
-
if (
|
|
98
|
-
const
|
|
99
|
-
return await c
|
|
102
|
+
), await v(), $(), [];
|
|
103
|
+
if (t.has(o)) {
|
|
104
|
+
const c = t.get(o) ?? null;
|
|
105
|
+
return await d(c), [];
|
|
100
106
|
}
|
|
101
107
|
}
|
|
102
108
|
};
|
|
103
109
|
}
|
|
104
110
|
export {
|
|
105
|
-
|
|
111
|
+
H as laravelTsPublish
|
|
106
112
|
};
|