@slicemachine/adapter-sveltekit 0.3.78-alpha.dependabot-npm-and-yarn-nuxt-3-16-0.1 → 0.3.78-alpha.lh-svelte5.2
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/dist/AlternateGrid/javascript.svelte +2 -2
- package/dist/AlternateGrid/javascript.with-let-props.svelte +227 -0
- package/dist/AlternateGrid/typescript.svelte +5 -1
- package/dist/AlternateGrid/typescript.with-let-props.svelte +224 -0
- package/dist/CallToAction/javascript.svelte +3 -3
- package/dist/CallToAction/javascript.with-let-props.svelte +127 -0
- package/dist/CallToAction/typescript.svelte +6 -2
- package/dist/CallToAction/typescript.with-let-props.svelte +124 -0
- package/dist/CustomerLogos/javascript.svelte +2 -2
- package/dist/CustomerLogos/javascript.with-let-props.svelte +124 -0
- package/dist/CustomerLogos/typescript.svelte +5 -1
- package/dist/CustomerLogos/typescript.with-let-props.svelte +121 -0
- package/dist/Hero/javascript.svelte +2 -2
- package/dist/Hero/javascript.with-let-props.svelte +190 -0
- package/dist/Hero/typescript.svelte +5 -1
- package/dist/Hero/typescript.with-let-props.svelte +187 -0
- package/dist/hooks/documentation-read.cjs +9 -2
- package/dist/hooks/documentation-read.cjs.map +1 -1
- package/dist/hooks/documentation-read.js +9 -2
- package/dist/hooks/documentation-read.js.map +1 -1
- package/dist/hooks/project-init.cjs.map +1 -1
- package/dist/hooks/project-init.js.map +1 -1
- package/dist/hooks/slice-create.cjs +22 -7
- package/dist/hooks/slice-create.cjs.map +1 -1
- package/dist/hooks/slice-create.js +22 -7
- package/dist/hooks/slice-create.js.map +1 -1
- package/dist/lib/checkIsSvelte5.cjs +31 -0
- package/dist/lib/checkIsSvelte5.cjs.map +1 -0
- package/dist/lib/checkIsSvelte5.d.ts +7 -0
- package/dist/lib/checkIsSvelte5.js +31 -0
- package/dist/lib/checkIsSvelte5.js.map +1 -0
- package/dist/plugin.cjs +4 -2
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +4 -2
- package/dist/plugin.js.map +1 -1
- package/package.json +5 -3
- package/src/hooks/documentation-read.ts +28 -8
- package/src/hooks/project-init.ts +2 -0
- package/src/hooks/slice-create.ts +55 -22
- package/src/lib/checkIsSvelte5.ts +49 -0
- package/src/plugin.ts +9 -2
@@ -11,6 +11,7 @@ import {
|
|
11
11
|
import { source } from "common-tags";
|
12
12
|
|
13
13
|
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
|
14
|
+
import { checkIsSvelte5 } from "../lib/checkIsSvelte5";
|
14
15
|
import { pascalCase } from "../lib/pascalCase";
|
15
16
|
import { rejectIfNecessary } from "../lib/rejectIfNecessary";
|
16
17
|
import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile";
|
@@ -35,6 +36,7 @@ const createComponentFile = async ({
|
|
35
36
|
helpers,
|
36
37
|
options,
|
37
38
|
});
|
39
|
+
const isSvelte5 = await checkIsSvelte5({ helpers });
|
38
40
|
|
39
41
|
const placeholder = `
|
40
42
|
Placeholder component for {slice.slice_type} (variation: {slice.variation}) slices.
|
@@ -68,29 +70,60 @@ const createComponentFile = async ({
|
|
68
70
|
|
69
71
|
if (data.componentContents) {
|
70
72
|
contents = data.componentContents;
|
71
|
-
} else if (
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
73
|
+
} else if (isSvelte5) {
|
74
|
+
if (isTypeScriptProject) {
|
75
|
+
contents = source`
|
76
|
+
<script lang="ts">
|
77
|
+
import type { Content } from '@prismicio/client';
|
78
|
+
|
79
|
+
interface Props {
|
80
|
+
slice: Content.${pascalName}Slice;
|
81
|
+
}
|
82
|
+
|
83
|
+
let { slice }: Props = $props();
|
84
|
+
</script>
|
85
|
+
|
86
|
+
<section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>
|
87
|
+
${placeholder}
|
88
|
+
</section>
|
89
|
+
`;
|
90
|
+
} else {
|
91
|
+
contents = source`
|
92
|
+
<script>
|
93
|
+
/** @type {{ slice: import("@prismicio/client").Content.${pascalName}Slice }} */
|
94
|
+
let { slice } = $props();
|
95
|
+
</script>
|
96
|
+
|
97
|
+
<section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>
|
98
|
+
${placeholder}
|
99
|
+
</section>
|
100
|
+
`;
|
101
|
+
}
|
83
102
|
} else {
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
103
|
+
if (isTypeScriptProject) {
|
104
|
+
contents = source`
|
105
|
+
<script lang="ts">
|
106
|
+
import type { Content } from '@prismicio/client';
|
107
|
+
|
108
|
+
export let slice: Content.${pascalName}Slice;
|
109
|
+
</script>
|
110
|
+
|
111
|
+
<section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>
|
112
|
+
${placeholder}
|
113
|
+
</section>
|
114
|
+
`;
|
115
|
+
} else {
|
116
|
+
contents = source`
|
117
|
+
<script>
|
118
|
+
/** @type {import("@prismicio/client").Content.${pascalName}Slice} */
|
119
|
+
export let slice;
|
120
|
+
</script>
|
121
|
+
|
122
|
+
<section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>
|
123
|
+
${placeholder}
|
124
|
+
</section>
|
125
|
+
`;
|
126
|
+
}
|
94
127
|
}
|
95
128
|
|
96
129
|
await writeSliceFile({
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
2
|
+
import { readProjectFile } from "@slicemachine/plugin-kit/fs";
|
3
|
+
import semver from "semver";
|
4
|
+
|
5
|
+
import { PluginOptions } from "../types";
|
6
|
+
|
7
|
+
export const checkIsSvelte5 = (args: CheckIsSvelteNArgs): Promise<boolean> => {
|
8
|
+
return checkIsSvelteN(5, args);
|
9
|
+
};
|
10
|
+
|
11
|
+
type CheckIsSvelteNArgs = {
|
12
|
+
helpers: SliceMachineContext<PluginOptions>["helpers"];
|
13
|
+
};
|
14
|
+
|
15
|
+
const checkIsSvelteN = async (
|
16
|
+
version: number,
|
17
|
+
args: CheckIsSvelteNArgs,
|
18
|
+
): Promise<boolean> => {
|
19
|
+
try {
|
20
|
+
const packageJsonContent = await readProjectFile({
|
21
|
+
filename: "package.json",
|
22
|
+
encoding: "utf8",
|
23
|
+
helpers: args.helpers,
|
24
|
+
});
|
25
|
+
|
26
|
+
const packageJson = JSON.parse(packageJsonContent);
|
27
|
+
const allDependencies: Record<string, string> = {
|
28
|
+
...packageJson.dependencies,
|
29
|
+
...packageJson.devDependencies,
|
30
|
+
};
|
31
|
+
const svelteVersion = allDependencies.svelte;
|
32
|
+
|
33
|
+
// Assume version doesn't match when no version is found or on special cases.
|
34
|
+
if (
|
35
|
+
!svelteVersion ||
|
36
|
+
["latest", "next", "beta", "alpha", "dev", "*"].includes(svelteVersion)
|
37
|
+
) {
|
38
|
+
return false;
|
39
|
+
}
|
40
|
+
|
41
|
+
// Try to get the minimum version.
|
42
|
+
const minVersion = semver.minVersion(svelteVersion) ?? svelteVersion;
|
43
|
+
|
44
|
+
// Check if the version is a match.
|
45
|
+
return semver.major(minVersion) === version;
|
46
|
+
} catch (error) {
|
47
|
+
return false;
|
48
|
+
}
|
49
|
+
};
|
package/src/plugin.ts
CHANGED
@@ -44,6 +44,7 @@ import * as Hero from "./sliceTemplates/Hero";
|
|
44
44
|
import * as CallToAction from "./sliceTemplates/CallToAction";
|
45
45
|
import * as AlternateGrid from "./sliceTemplates/AlternateGrid";
|
46
46
|
import * as CustomerLogos from "./sliceTemplates/CustomerLogos";
|
47
|
+
import { checkIsSvelte5 } from "./lib/checkIsSvelte5";
|
47
48
|
|
48
49
|
export const plugin = defineSliceMachinePlugin<PluginOptions>({
|
49
50
|
meta: {
|
@@ -200,14 +201,20 @@ export const plugin = defineSliceMachinePlugin<PluginOptions>({
|
|
200
201
|
////////////////////////////////////////////////////////////////
|
201
202
|
|
202
203
|
hook("slice-template-library:read", async (data, context) => {
|
204
|
+
const isSvelte5 = await checkIsSvelte5({ helpers: context.helpers });
|
205
|
+
|
203
206
|
return await readSliceTemplateLibrary({
|
204
207
|
...data,
|
205
208
|
...context,
|
206
209
|
dirName: path.dirname(fileURLToPath(new URL(import.meta.url))),
|
207
210
|
templates: [Hero, CustomerLogos, AlternateGrid, CallToAction],
|
208
211
|
componentFileNames: {
|
209
|
-
js:
|
210
|
-
|
212
|
+
js: isSvelte5
|
213
|
+
? "javascript.svelte"
|
214
|
+
: "javascript.with-let-props.svelte",
|
215
|
+
ts: isSvelte5
|
216
|
+
? "typescript.svelte"
|
217
|
+
: "typescript.with-let-props.svelte",
|
211
218
|
},
|
212
219
|
});
|
213
220
|
});
|