storyloco 1.5.2 → 1.6.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AUTO-GENERATED FILE. DO NOT EDIT.
|
|
3
|
-
* Generated by vite-storyblok-schema plugin on 2025-08-
|
|
3
|
+
* Generated by vite-storyblok-schema plugin on 2025-08-14T09:30:49.613Z.
|
|
4
4
|
* Any changes will be overwritten.
|
|
5
5
|
*/
|
|
6
6
|
import type { SbBlokData } from "@storyblok/svelte";
|
|
@@ -4,6 +4,10 @@ interface Options {
|
|
|
4
4
|
storyblok_space_id?: string;
|
|
5
5
|
output_path?: string;
|
|
6
6
|
interval_ms?: number;
|
|
7
|
+
filenames?: {
|
|
8
|
+
json?: string;
|
|
9
|
+
ts?: string;
|
|
10
|
+
};
|
|
7
11
|
}
|
|
8
12
|
/**
|
|
9
13
|
* @remarks
|
|
@@ -14,6 +18,10 @@ interface Options {
|
|
|
14
18
|
* @param [options.storyblok_space_id] - The space ID for the Storyblok space. Defaults to the `STORYBLOK_SPACE_ID` environment variable.
|
|
15
19
|
* @param [options.output_path] - The path to output the generated files to. Defaults to 'src/lib'.
|
|
16
20
|
* @param [options.interval_ms] - The interval in milliseconds to regenerate the component types. Defaults to 60000 (1 minute).
|
|
21
|
+
* @param [options.filenames] - Custom filenames for the generated files.
|
|
22
|
+
* @param [options.filenames.json] - The filename for the JSON schema file. Defaults to 'components.schema.json'.
|
|
23
|
+
* @param [options.filenames.ts] - The filename for the TypeScript definitions file. Defaults to 'components.schema.ts'.
|
|
24
|
+
*
|
|
17
25
|
*
|
|
18
26
|
* @example Default configuration
|
|
19
27
|
* ```ts title=vite.config.ts
|
|
@@ -35,6 +43,20 @@ interface Options {
|
|
|
35
43
|
* })]
|
|
36
44
|
* })
|
|
37
45
|
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example Custom filenames
|
|
48
|
+
* ```ts title=vite.config.ts
|
|
49
|
+
* import { storyblok_schema } from 'kitto/vite'
|
|
50
|
+
*
|
|
51
|
+
* export default defineConfig({
|
|
52
|
+
* plugins: [storyblok_schema({
|
|
53
|
+
* filenames: {
|
|
54
|
+
* json: 'storyblok-components.json',
|
|
55
|
+
* ts: 'storyblok-types.ts'
|
|
56
|
+
* }
|
|
57
|
+
* })]
|
|
58
|
+
* })
|
|
59
|
+
* ```
|
|
38
60
|
*/
|
|
39
|
-
export default function storyblok_schema({ output_path, interval_ms, storyblok_personal_access_token, storyblok_space_id, }?: Options): Plugin;
|
|
61
|
+
export default function storyblok_schema({ output_path, interval_ms, storyblok_personal_access_token, storyblok_space_id, filenames, }?: Options): Plugin;
|
|
40
62
|
export {};
|
|
@@ -19,6 +19,10 @@ const logger = ora({
|
|
|
19
19
|
* @param [options.storyblok_space_id] - The space ID for the Storyblok space. Defaults to the `STORYBLOK_SPACE_ID` environment variable.
|
|
20
20
|
* @param [options.output_path] - The path to output the generated files to. Defaults to 'src/lib'.
|
|
21
21
|
* @param [options.interval_ms] - The interval in milliseconds to regenerate the component types. Defaults to 60000 (1 minute).
|
|
22
|
+
* @param [options.filenames] - Custom filenames for the generated files.
|
|
23
|
+
* @param [options.filenames.json] - The filename for the JSON schema file. Defaults to 'components.schema.json'.
|
|
24
|
+
* @param [options.filenames.ts] - The filename for the TypeScript definitions file. Defaults to 'components.schema.ts'.
|
|
25
|
+
*
|
|
22
26
|
*
|
|
23
27
|
* @example Default configuration
|
|
24
28
|
* ```ts title=vite.config.ts
|
|
@@ -40,8 +44,22 @@ const logger = ora({
|
|
|
40
44
|
* })]
|
|
41
45
|
* })
|
|
42
46
|
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example Custom filenames
|
|
49
|
+
* ```ts title=vite.config.ts
|
|
50
|
+
* import { storyblok_schema } from 'kitto/vite'
|
|
51
|
+
*
|
|
52
|
+
* export default defineConfig({
|
|
53
|
+
* plugins: [storyblok_schema({
|
|
54
|
+
* filenames: {
|
|
55
|
+
* json: 'storyblok-components.json',
|
|
56
|
+
* ts: 'storyblok-types.ts'
|
|
57
|
+
* }
|
|
58
|
+
* })]
|
|
59
|
+
* })
|
|
60
|
+
* ```
|
|
43
61
|
*/
|
|
44
|
-
export default function storyblok_schema({ output_path, interval_ms, storyblok_personal_access_token, storyblok_space_id, } = {}) {
|
|
62
|
+
export default function storyblok_schema({ output_path, interval_ms, storyblok_personal_access_token, storyblok_space_id, filenames, } = {}) {
|
|
45
63
|
let interval = null;
|
|
46
64
|
return {
|
|
47
65
|
name,
|
|
@@ -54,8 +72,8 @@ export default function storyblok_schema({ output_path, interval_ms, storyblok_p
|
|
|
54
72
|
storyblok_personal_access_token =
|
|
55
73
|
storyblok_personal_access_token ?? env.STORYBLOK_PERSONAL_ACCESS_TOKEN;
|
|
56
74
|
storyblok_space_id = storyblok_space_id ?? env.STORYBLOK_SPACE_ID;
|
|
57
|
-
const components_file = path.join(output_path, "components.schema.json");
|
|
58
|
-
const schema_ts_file = path.join(output_path, "components.schema.ts");
|
|
75
|
+
const components_file = path.join(output_path, filenames?.json ?? "components.schema.json");
|
|
76
|
+
const schema_ts_file = path.join(output_path, filenames?.ts ?? "components.schema.ts");
|
|
59
77
|
const seconds = interval_ms / 1000;
|
|
60
78
|
logger.succeed(`Regenerating Storyblok component types every ${seconds} ${seconds === 1 ? "second" : "seconds"}`);
|
|
61
79
|
generate();
|
|
@@ -80,13 +98,14 @@ export default function storyblok_schema({ output_path, interval_ms, storyblok_p
|
|
|
80
98
|
const headers = new Headers({ Authorization: storyblok_personal_access_token });
|
|
81
99
|
const response = await fetch(url, { headers });
|
|
82
100
|
const new_components = await response.json();
|
|
83
|
-
//
|
|
101
|
+
// Make the file writable
|
|
84
102
|
await $ `chmod u+w ${components_file}`.quiet().nothrow();
|
|
85
|
-
// Write the data to the components file
|
|
86
|
-
await writeFile(components_file, JSON.stringify(new_components, null, 2));
|
|
87
103
|
// Compare existing and new components
|
|
88
|
-
if (existing_components
|
|
104
|
+
if (existing_components &&
|
|
105
|
+
JSON.stringify(JSON.parse(existing_components)) === JSON.stringify(new_components))
|
|
89
106
|
return;
|
|
107
|
+
// Write the data to the components file
|
|
108
|
+
await writeFile(components_file, JSON.stringify(new_components, null, 2));
|
|
90
109
|
// Generate types
|
|
91
110
|
logger.start("Generating TypeScript definitions...");
|
|
92
111
|
await $ `chmod u+w ${schema_ts_file}`.quiet().nothrow();
|