@slicemachine/adapter-next 0.0.2 → 0.0.4
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/SliceSimulator.cjs +14 -41
- package/dist/SliceSimulator.cjs.map +1 -1
- package/dist/SliceSimulator.d.ts +2 -2
- package/dist/SliceSimulator.js +11 -36
- package/dist/SliceSimulator.js.map +1 -1
- package/dist/_virtual/_commonjsHelpers.cjs +5 -0
- package/dist/_virtual/_commonjsHelpers.cjs.map +1 -0
- package/dist/_virtual/_commonjsHelpers.js +5 -0
- package/dist/_virtual/_commonjsHelpers.js.map +1 -0
- package/dist/_virtual/ponyfill.es2018.cjs +5 -0
- package/dist/_virtual/ponyfill.es2018.cjs.map +1 -0
- package/dist/_virtual/ponyfill.es2018.js +5 -0
- package/dist/_virtual/ponyfill.es2018.js.map +1 -0
- package/dist/constants.cjs +5 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/hooks/customType-asset-delete.cjs +3 -5
- package/dist/hooks/customType-asset-delete.cjs.map +1 -1
- package/dist/hooks/customType-asset-delete.js.map +1 -1
- package/dist/hooks/customType-asset-read.cjs +3 -5
- package/dist/hooks/customType-asset-read.cjs.map +1 -1
- package/dist/hooks/customType-asset-read.js.map +1 -1
- package/dist/hooks/customType-asset-update.cjs +4 -6
- package/dist/hooks/customType-asset-update.cjs.map +1 -1
- package/dist/hooks/customType-asset-update.js.map +1 -1
- package/dist/hooks/customType-create.cjs +4 -6
- package/dist/hooks/customType-create.cjs.map +1 -1
- package/dist/hooks/customType-create.js.map +1 -1
- package/dist/hooks/customType-delete.cjs +3 -5
- package/dist/hooks/customType-delete.cjs.map +1 -1
- package/dist/hooks/customType-delete.js.map +1 -1
- package/dist/hooks/customType-read.cjs +1 -1
- package/dist/hooks/customType-read.cjs.map +1 -1
- package/dist/hooks/customType-read.js.map +1 -1
- package/dist/hooks/customType-rename.cjs +6 -0
- package/dist/hooks/customType-rename.cjs.map +1 -0
- package/dist/hooks/customType-rename.d.ts +1 -0
- package/dist/hooks/customType-rename.js +6 -0
- package/dist/hooks/customType-rename.js.map +1 -0
- package/dist/hooks/customType-update.cjs +1 -1
- package/dist/hooks/customType-update.cjs.map +1 -1
- package/dist/hooks/customType-update.js.map +1 -1
- package/dist/hooks/customTypeLibrary-read.cjs +16 -10
- package/dist/hooks/customTypeLibrary-read.cjs.map +1 -1
- package/dist/hooks/customTypeLibrary-read.js +12 -4
- package/dist/hooks/customTypeLibrary-read.js.map +1 -1
- package/dist/hooks/slice-asset-delete.cjs +3 -5
- package/dist/hooks/slice-asset-delete.cjs.map +1 -1
- package/dist/hooks/slice-asset-delete.js.map +1 -1
- package/dist/hooks/slice-asset-read.cjs +3 -5
- package/dist/hooks/slice-asset-read.cjs.map +1 -1
- package/dist/hooks/slice-asset-read.js.map +1 -1
- package/dist/hooks/slice-asset-update.cjs +4 -6
- package/dist/hooks/slice-asset-update.cjs.map +1 -1
- package/dist/hooks/slice-asset-update.js.map +1 -1
- package/dist/hooks/slice-create.cjs +18 -30
- package/dist/hooks/slice-create.cjs.map +1 -1
- package/dist/hooks/slice-create.js +14 -24
- package/dist/hooks/slice-create.js.map +1 -1
- package/dist/hooks/slice-delete.cjs +6 -18
- package/dist/hooks/slice-delete.cjs.map +1 -1
- package/dist/hooks/slice-delete.js +3 -13
- package/dist/hooks/slice-delete.js.map +1 -1
- package/dist/hooks/slice-read.cjs +41 -7
- package/dist/hooks/slice-read.cjs.map +1 -1
- package/dist/hooks/slice-read.js +22 -6
- package/dist/hooks/slice-read.js.map +1 -1
- package/dist/hooks/slice-rename.cjs +43 -0
- package/dist/hooks/slice-rename.cjs.map +1 -0
- package/dist/hooks/slice-rename.d.ts +3 -0
- package/dist/hooks/slice-rename.js +26 -0
- package/dist/hooks/slice-rename.js.map +1 -0
- package/dist/hooks/slice-update.cjs +7 -34
- package/dist/hooks/slice-update.cjs.map +1 -1
- package/dist/hooks/slice-update.js +6 -13
- package/dist/hooks/slice-update.js.map +1 -1
- package/dist/hooks/sliceLibrary-read.cjs +16 -20
- package/dist/hooks/sliceLibrary-read.cjs.map +1 -1
- package/dist/hooks/sliceLibrary-read.js +12 -13
- package/dist/hooks/sliceLibrary-read.js.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.cjs +31 -94
- package/dist/hooks/sliceSimulator-setup-read.cjs.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.js +31 -75
- package/dist/hooks/sliceSimulator-setup-read.js.map +1 -1
- package/dist/hooks/snippet-read.cjs +33 -18
- package/dist/hooks/snippet-read.cjs.map +1 -1
- package/dist/hooks/snippet-read.js +30 -13
- package/dist/hooks/snippet-read.js.map +1 -1
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/getJSOrTSXFileExtension.cjs +1 -1
- package/dist/lib/getJSOrTSXFileExtension.cjs.map +1 -1
- package/dist/lib/getJSOrTSXFileExtension.js.map +1 -1
- package/dist/lib/isSharedSliceModel.cjs +25 -0
- package/dist/lib/isSharedSliceModel.cjs.map +1 -0
- package/dist/lib/isSharedSliceModel.d.ts +2 -0
- package/dist/lib/isSharedSliceModel.js +8 -0
- package/dist/lib/isSharedSliceModel.js.map +1 -0
- package/dist/lib/pascalCase.cjs +1 -1
- package/dist/lib/pascalCase.cjs.map +1 -1
- package/dist/lib/pascalCase.js.map +1 -1
- package/dist/lib/readJSONFile.cjs +3 -5
- package/dist/lib/readJSONFile.cjs.map +1 -1
- package/dist/lib/readJSONFile.js.map +1 -1
- package/dist/lib/rejectIfNecessary.cjs +1 -1
- package/dist/lib/rejectIfNecessary.cjs.map +1 -1
- package/dist/lib/rejectIfNecessary.js.map +1 -1
- package/dist/lib/updateSliceModelFile.cjs +31 -0
- package/dist/lib/updateSliceModelFile.cjs.map +1 -0
- package/dist/lib/updateSliceModelFile.d.ts +9 -0
- package/dist/lib/updateSliceModelFile.js +14 -0
- package/dist/lib/updateSliceModelFile.js.map +1 -0
- package/dist/lib/upsertGlobalContentTypes.cjs +8 -6
- package/dist/lib/upsertGlobalContentTypes.cjs.map +1 -1
- package/dist/lib/upsertGlobalContentTypes.d.ts +1 -1
- package/dist/lib/upsertGlobalContentTypes.js +4 -0
- package/dist/lib/upsertGlobalContentTypes.js.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.cjs +48 -0
- package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -0
- package/dist/lib/upsertSliceLibraryIndexFile.d.ts +7 -0
- package/dist/lib/upsertSliceLibraryIndexFile.js +31 -0
- package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.cjs +41 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.cjs.map +1 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.js +41 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.js.map +1 -0
- package/dist/node_modules/fetch-blob/file.cjs +55 -0
- package/dist/node_modules/fetch-blob/file.cjs.map +1 -0
- package/dist/node_modules/fetch-blob/file.js +55 -0
- package/dist/node_modules/fetch-blob/file.js.map +1 -0
- package/dist/node_modules/fetch-blob/index.cjs +176 -0
- package/dist/node_modules/fetch-blob/index.cjs.map +1 -0
- package/dist/node_modules/fetch-blob/index.js +176 -0
- package/dist/node_modules/fetch-blob/index.js.map +1 -0
- package/dist/node_modules/fetch-blob/streams.cjs +43 -0
- package/dist/node_modules/fetch-blob/streams.cjs.map +1 -0
- package/dist/node_modules/fetch-blob/streams.js +42 -0
- package/dist/node_modules/fetch-blob/streams.js.map +1 -0
- package/dist/node_modules/formdata-polyfill/esm.min.cjs +115 -0
- package/dist/node_modules/formdata-polyfill/esm.min.cjs.map +1 -0
- package/dist/node_modules/formdata-polyfill/esm.min.js +115 -0
- package/dist/node_modules/formdata-polyfill/esm.min.js.map +1 -0
- package/dist/node_modules/node-domexception/index.cjs +10 -0
- package/dist/node_modules/node-domexception/index.cjs.map +1 -0
- package/dist/node_modules/node-domexception/index.js +9 -0
- package/dist/node_modules/node-domexception/index.js.map +1 -0
- package/dist/node_modules/node-fetch/src/body.cjs +237 -0
- package/dist/node_modules/node-fetch/src/body.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/body.js +237 -0
- package/dist/node_modules/node-fetch/src/body.js.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.cjs +10 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.js +10 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.js.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/base.cjs +17 -0
- package/dist/node_modules/node-fetch/src/errors/base.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/base.js +17 -0
- package/dist/node_modules/node-fetch/src/errors/base.js.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs +14 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.js +14 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.js.map +1 -0
- package/dist/node_modules/node-fetch/src/headers.cjs +173 -0
- package/dist/node_modules/node-fetch/src/headers.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/headers.js +173 -0
- package/dist/node_modules/node-fetch/src/headers.js.map +1 -0
- package/dist/node_modules/node-fetch/src/index.cjs +292 -0
- package/dist/node_modules/node-fetch/src/index.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/index.js +298 -0
- package/dist/node_modules/node-fetch/src/index.js.map +1 -0
- package/dist/node_modules/node-fetch/src/request.cjs +193 -0
- package/dist/node_modules/node-fetch/src/request.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/request.js +193 -0
- package/dist/node_modules/node-fetch/src/request.js.map +1 -0
- package/dist/node_modules/node-fetch/src/response.cjs +110 -0
- package/dist/node_modules/node-fetch/src/response.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/response.js +110 -0
- package/dist/node_modules/node-fetch/src/response.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.cjs +12 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.js +12 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.cjs +8 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.js +8 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is.cjs +28 -0
- package/dist/node_modules/node-fetch/src/utils/is.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is.js +28 -0
- package/dist/node_modules/node-fetch/src/utils/is.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs +350 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.js +350 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.cjs +149 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.js +149 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.js.map +1 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs +3599 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs.map +1 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js +3599 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js.map +1 -0
- package/dist/package.json.cjs +5 -0
- package/dist/package.json.cjs.map +1 -0
- package/dist/{package.js → package.json.js} +1 -1
- package/dist/package.json.js.map +1 -0
- package/dist/plugin.cjs +6 -2
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +5 -1
- package/dist/plugin.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +32 -15
- package/src/constants.ts +5 -0
- package/src/hooks/customType-rename.ts +3 -0
- package/src/hooks/customTypeLibrary-read.ts +13 -4
- package/src/hooks/slice-create.ts +14 -32
- package/src/hooks/slice-delete.ts +3 -21
- package/src/hooks/slice-read.ts +37 -11
- package/src/hooks/slice-rename.ts +44 -0
- package/src/hooks/slice-update.ts +7 -31
- package/src/hooks/sliceLibrary-read.ts +13 -23
- package/src/hooks/sliceSimulator-setup-read.ts +37 -76
- package/src/hooks/snippet-read.ts +42 -22
- package/src/index.ts +0 -6
- package/src/lib/isSharedSliceModel.ts +14 -0
- package/src/lib/updateSliceModelFile.ts +32 -0
- package/src/lib/upsertGlobalContentTypes.ts +3 -0
- package/src/lib/{buildSliceLibraryIndexFileContents.ts → upsertSliceLibraryIndexFile.ts} +19 -9
- package/src/plugin.ts +4 -0
- package/dist/lib/buildSliceLibraryIndexFileContents.cjs +0 -23
- package/dist/lib/buildSliceLibraryIndexFileContents.cjs.map +0 -1
- package/dist/lib/buildSliceLibraryIndexFileContents.d.ts +0 -10
- package/dist/lib/buildSliceLibraryIndexFileContents.js +0 -23
- package/dist/lib/buildSliceLibraryIndexFileContents.js.map +0 -1
- package/dist/package.cjs +0 -5
- package/dist/package.cjs.map +0 -1
- package/dist/package.js.map +0 -1
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
import * as prismicT from "@prismicio/types";
|
|
2
2
|
import { stripIndent } from "common-tags";
|
|
3
|
-
const prettierOptions = { parser: "typescript" };
|
|
4
3
|
const dotPath = (segments) => {
|
|
5
4
|
return segments.join(".");
|
|
6
5
|
};
|
|
6
|
+
const format = async (input, helpers) => {
|
|
7
|
+
const formattedInput = await helpers.format(input, void 0, {
|
|
8
|
+
includeNewlineAtEnd: false,
|
|
9
|
+
prettier: {
|
|
10
|
+
parser: "typescript"
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
return formattedInput.endsWith(";") ? formattedInput.substring(0, formattedInput.length - 1) : formattedInput;
|
|
14
|
+
};
|
|
7
15
|
const snippetRead = async (data, { helpers }) => {
|
|
8
16
|
const { fieldPath } = data;
|
|
9
17
|
const label = "React";
|
|
10
18
|
switch (data.model.type) {
|
|
19
|
+
case prismicT.CustomTypeModelFieldType.StructuredText: {
|
|
20
|
+
return {
|
|
21
|
+
label,
|
|
22
|
+
language: "tsx",
|
|
23
|
+
code: await format(stripIndent`
|
|
24
|
+
<PrismicRichText field={${dotPath(fieldPath)}} />
|
|
25
|
+
`, helpers)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
11
28
|
case prismicT.CustomTypeModelFieldType.Link: {
|
|
12
29
|
return {
|
|
13
30
|
label,
|
|
14
31
|
language: "tsx",
|
|
15
|
-
code: await
|
|
32
|
+
code: await format(stripIndent`
|
|
16
33
|
<PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
|
|
17
|
-
`,
|
|
34
|
+
`, helpers)
|
|
18
35
|
};
|
|
19
36
|
}
|
|
20
37
|
case prismicT.CustomTypeModelFieldType.Image: {
|
|
@@ -22,25 +39,25 @@ const snippetRead = async (data, { helpers }) => {
|
|
|
22
39
|
{
|
|
23
40
|
label: `${label} (next/image)`,
|
|
24
41
|
language: "tsx",
|
|
25
|
-
code: await
|
|
42
|
+
code: await format(stripIndent`
|
|
26
43
|
<PrismicNextImage field={${dotPath(fieldPath)}} />
|
|
27
|
-
`,
|
|
44
|
+
`, helpers)
|
|
28
45
|
},
|
|
29
46
|
{
|
|
30
47
|
label,
|
|
31
48
|
language: "tsx",
|
|
32
|
-
code: await
|
|
49
|
+
code: await format(stripIndent`
|
|
33
50
|
<PrismicImage field={${dotPath(fieldPath)}} />
|
|
34
|
-
`,
|
|
51
|
+
`, helpers)
|
|
35
52
|
}
|
|
36
53
|
];
|
|
37
54
|
}
|
|
38
55
|
case prismicT.CustomTypeModelFieldType.Group: {
|
|
39
|
-
const code = await
|
|
56
|
+
const code = await format(stripIndent`
|
|
40
57
|
<>{${dotPath(fieldPath)}.map(item => (
|
|
41
58
|
<>{/* Render content for item */}</>
|
|
42
59
|
))}</>
|
|
43
|
-
`,
|
|
60
|
+
`, helpers);
|
|
44
61
|
return {
|
|
45
62
|
label,
|
|
46
63
|
language: "tsx",
|
|
@@ -48,12 +65,12 @@ const snippetRead = async (data, { helpers }) => {
|
|
|
48
65
|
};
|
|
49
66
|
}
|
|
50
67
|
case prismicT.CustomTypeModelFieldType.Slices: {
|
|
51
|
-
const code = await
|
|
68
|
+
const code = await format(stripIndent`
|
|
52
69
|
<SliceZone
|
|
53
70
|
slices={${dotPath(fieldPath)}}
|
|
54
71
|
components={components}
|
|
55
72
|
/>
|
|
56
|
-
`,
|
|
73
|
+
`, helpers);
|
|
57
74
|
return {
|
|
58
75
|
label,
|
|
59
76
|
language: "tsx",
|
|
@@ -64,9 +81,9 @@ const snippetRead = async (data, { helpers }) => {
|
|
|
64
81
|
return {
|
|
65
82
|
label,
|
|
66
83
|
language: "tsx",
|
|
67
|
-
code: await
|
|
84
|
+
code: await format(stripIndent`
|
|
68
85
|
<>{${dotPath(fieldPath)}}</>
|
|
69
|
-
`,
|
|
86
|
+
`, helpers)
|
|
70
87
|
};
|
|
71
88
|
}
|
|
72
89
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snippet-read.js","sources":["
|
|
1
|
+
{"version":3,"file":"snippet-read.js","sources":["../../../src/hooks/snippet-read.ts"],"sourcesContent":["import type {\n\tSliceMachineHelpers,\n\tSnippetReadHook,\n} from \"@slicemachine/plugin-kit\";\nimport * as prismicT from \"@prismicio/types\";\nimport { stripIndent } from \"common-tags\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst dotPath = (segments: string[]): string => {\n\treturn segments.join(\".\");\n};\n\nconst format = async (input: string, helpers: SliceMachineHelpers) => {\n\tconst formattedInput = await helpers.format(input, undefined, {\n\t\tincludeNewlineAtEnd: false,\n\t\tprettier: {\n\t\t\tparser: \"typescript\",\n\t\t},\n\t});\n\n\treturn formattedInput.endsWith(\";\")\n\t\t? formattedInput.substring(0, formattedInput.length - 1)\n\t\t: formattedInput;\n};\n\nexport const snippetRead: SnippetReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst { fieldPath } = data;\n\n\tconst label = \"React\";\n\n\tswitch (data.model.type) {\n\t\tcase prismicT.CustomTypeModelFieldType.StructuredText: {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicRichText field={${dotPath(fieldPath)}} />\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase prismicT.CustomTypeModelFieldType.Link: {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase prismicT.CustomTypeModelFieldType.Image: {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tlabel: `${label} (next/image)`,\n\t\t\t\t\tlanguage: \"tsx\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicNextImage field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tlabel,\n\t\t\t\t\tlanguage: \"tsx\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicImage field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tcase prismicT.CustomTypeModelFieldType.Group: {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<>{${dotPath(fieldPath)}.map(item => (\n\t\t\t\t\t <>{/* Render content for item */}</>\n\t\t\t\t\t))}</>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tcase prismicT.CustomTypeModelFieldType.Slices: {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<SliceZone\n\t\t\t\t\t slices={${dotPath(fieldPath)}}\n\t\t\t\t\t components={components}\n\t\t\t\t\t/>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<>{${dotPath(fieldPath)}}</>\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\t}\n};\n"],"names":[],"mappings":";;AASA,MAAM,UAAU,CAAC,aAA8B;AACvC,SAAA,SAAS,KAAK,GAAG;AACzB;AAEA,MAAM,SAAS,OAAO,OAAe,YAAgC;AACpE,QAAM,iBAAiB,MAAM,QAAQ,OAAO,OAAO,QAAW;AAAA,IAC7D,qBAAqB;AAAA,IACrB,UAAU;AAAA,MACT,QAAQ;AAAA,IACR;AAAA,EAAA,CACD;AAEM,SAAA,eAAe,SAAS,GAAG,IAC/B,eAAe,UAAU,GAAG,eAAe,SAAS,CAAC,IACrD;AACJ;AAEO,MAAM,cAA8C,OAC1D,MACA,EAAE,cACC;AACG,QAAA,EAAE,UAAc,IAAA;AAEtB,QAAM,QAAQ;AAEN,UAAA,KAAK,MAAM,MAAM;AAAA,IACxB,KAAK,SAAS,yBAAyB,gBAAgB;AAC/C,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,gCAC2B,QAAQ,SAAS;AAAA,QAE5C,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,IAED,KAAK,SAAS,yBAAyB,MAAM;AACrC,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,4BACuB,QAAQ,SAAS;AAAA,QAExC,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,IAED,KAAK,SAAS,yBAAyB,OAAO;AACtC,aAAA;AAAA,QACN;AAAA,UACC,OAAO,GAAG;AAAA,UACV,UAAU;AAAA,UACV,MAAM,MAAM,OACX;AAAA,kCAC4B,QAAQ,SAAS;AAAA,SAE7C,OAAO;AAAA,QAER;AAAA,QACD;AAAA,UACC;AAAA,UACA,UAAU;AAAA,UACV,MAAM,MAAM,OACX;AAAA,8BACwB,QAAQ,SAAS;AAAA,SAEzC,OAAO;AAAA,QAER;AAAA,MAAA;AAAA,IAEF;AAAA,IAED,KAAK,SAAS,yBAAyB,OAAO;AACvC,YAAA,OAAO,MAAM,OAClB;AAAA,UACM,QAAQ,SAAS;AAAA;AAAA;AAAA,OAIvB,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,KAAK,SAAS,yBAAyB,QAAQ;AACxC,YAAA,OAAO,MAAM,OAClB;AAAA;AAAA,iBAEa,QAAQ,SAAS;AAAA;AAAA;AAAA,OAI9B,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,SAAS;AACD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,WACM,QAAQ,SAAS;AAAA,QAEvB,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,EACD;AACF;"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
3
|
const plugin = require("./plugin.cjs");
|
|
4
|
-
const SliceSimulator = require("./SliceSimulator.cjs");
|
|
5
4
|
exports.default = plugin.plugin;
|
|
6
|
-
exports.SliceSimulator = SliceSimulator.SliceSimulator;
|
|
7
5
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const getJSOrTSXFileExtension = (pluginOptions) => {
|
|
4
4
|
if (pluginOptions.typescript) {
|
|
5
5
|
return "tsx";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getJSOrTSXFileExtension.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"getJSOrTSXFileExtension.cjs","sources":["../../../src/lib/getJSOrTSXFileExtension.ts"],"sourcesContent":["import type { PluginOptions } from \"../types\";\n\nexport const getJSOrTSXFileExtension = (\n\tpluginOptions: PluginOptions,\n): string => {\n\tif (pluginOptions.typescript) {\n\t\treturn \"tsx\";\n\t} else if (pluginOptions.jsxExtension) {\n\t\treturn \"jsx\";\n\t} else {\n\t\treturn \"js\";\n\t}\n};\n"],"names":[],"mappings":";;AAEa,MAAA,0BAA0B,CACtC,kBACW;AACX,MAAI,cAAc,YAAY;AACtB,WAAA;AAAA,EAAA,WACG,cAAc,cAAc;AAC/B,WAAA;AAAA,EAAA,OACD;AACC,WAAA;AAAA,EACP;AACF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getJSOrTSXFileExtension.js","sources":["
|
|
1
|
+
{"version":3,"file":"getJSOrTSXFileExtension.js","sources":["../../../src/lib/getJSOrTSXFileExtension.ts"],"sourcesContent":["import type { PluginOptions } from \"../types\";\n\nexport const getJSOrTSXFileExtension = (\n\tpluginOptions: PluginOptions,\n): string => {\n\tif (pluginOptions.typescript) {\n\t\treturn \"tsx\";\n\t} else if (pluginOptions.jsxExtension) {\n\t\treturn \"jsx\";\n\t} else {\n\t\treturn \"js\";\n\t}\n};\n"],"names":[],"mappings":"AAEa,MAAA,0BAA0B,CACtC,kBACW;AACX,MAAI,cAAc,YAAY;AACtB,WAAA;AAAA,EAAA,WACG,cAAc,cAAc;AAC/B,WAAA;AAAA,EAAA,OACD;AACC,WAAA;AAAA,EACP;AACF;"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const prismicT = require("@prismicio/types");
|
|
4
|
+
function _interopNamespaceDefault(e) {
|
|
5
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
6
|
+
if (e) {
|
|
7
|
+
for (const k in e) {
|
|
8
|
+
if (k !== "default") {
|
|
9
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
10
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: () => e[k]
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
n.default = e;
|
|
18
|
+
return Object.freeze(n);
|
|
19
|
+
}
|
|
20
|
+
const prismicT__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismicT);
|
|
21
|
+
const isSharedSliceModel = (input) => {
|
|
22
|
+
return typeof input === "object" && input !== null && "type" in input && input.type === prismicT__namespace.CustomTypeModelSliceType.SharedSlice && typeof input.id === "string";
|
|
23
|
+
};
|
|
24
|
+
exports.isSharedSliceModel = isSharedSliceModel;
|
|
25
|
+
//# sourceMappingURL=isSharedSliceModel.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isSharedSliceModel.cjs","sources":["../../../src/lib/isSharedSliceModel.ts"],"sourcesContent":["import * as prismicT from \"@prismicio/types\";\n\nexport const isSharedSliceModel = (\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n\tinput: any,\n): input is prismicT.SharedSliceModel => {\n\treturn (\n\t\ttypeof input === \"object\" &&\n\t\tinput !== null &&\n\t\t\"type\" in input &&\n\t\tinput.type === prismicT.CustomTypeModelSliceType.SharedSlice &&\n\t\ttypeof input.id === \"string\"\n\t);\n};\n"],"names":["prismicT"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEa,MAAA,qBAAqB,CAEjC,UACuC;AACvC,SACC,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAASA,oBAAS,yBAAyB,eACjD,OAAO,MAAM,OAAO;AAEtB;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import * as prismicT from "@prismicio/types";
|
|
2
|
+
export declare const isSharedSliceModel: (input: any) => input is prismicT.SharedSliceModel<string, prismicT.SharedSliceModelVariation<string, Record<string, prismicT.CustomTypeModelFieldForGroup>, Record<string, prismicT.CustomTypeModelFieldForGroup>>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as prismicT from "@prismicio/types";
|
|
2
|
+
const isSharedSliceModel = (input) => {
|
|
3
|
+
return typeof input === "object" && input !== null && "type" in input && input.type === prismicT.CustomTypeModelSliceType.SharedSlice && typeof input.id === "string";
|
|
4
|
+
};
|
|
5
|
+
export {
|
|
6
|
+
isSharedSliceModel
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=isSharedSliceModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isSharedSliceModel.js","sources":["../../../src/lib/isSharedSliceModel.ts"],"sourcesContent":["import * as prismicT from \"@prismicio/types\";\n\nexport const isSharedSliceModel = (\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n\tinput: any,\n): input is prismicT.SharedSliceModel => {\n\treturn (\n\t\ttypeof input === \"object\" &&\n\t\tinput !== null &&\n\t\t\"type\" in input &&\n\t\tinput.type === prismicT.CustomTypeModelSliceType.SharedSlice &&\n\t\ttypeof input.id === \"string\"\n\t);\n};\n"],"names":[],"mappings":";AAEa,MAAA,qBAAqB,CAEjC,UACuC;AACvC,SACC,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS,SAAS,yBAAyB,eACjD,OAAO,MAAM,OAAO;AAEtB;"}
|
package/dist/lib/pascalCase.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const pascalCase$1 = require("pascal-case");
|
|
4
4
|
const pascalCase = (...input) => {
|
|
5
5
|
return pascalCase$1.pascalCase(input.filter(Boolean).join(" "));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pascalCase.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"pascalCase.cjs","sources":["../../../src/lib/pascalCase.ts"],"sourcesContent":["import { pascalCase as basePascalCase } from \"pascal-case\";\n\n/**\n * Converts a string to a Pascal cased string.\n *\n * @param input - String to convert into a Pascal cased string.\n *\n * @returns Pascal cased string version of `input`.\n */\nexport const pascalCase = (...input: (string | undefined)[]): string => {\n\treturn basePascalCase(input.filter(Boolean).join(\" \"));\n};\n"],"names":["basePascalCase"],"mappings":";;;AASa,MAAA,aAAa,IAAI,UAAyC;AACtE,SAAOA,aAAAA,WAAe,MAAM,OAAO,OAAO,EAAE,KAAK,GAAG,CAAC;AACtD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pascalCase.js","sources":["
|
|
1
|
+
{"version":3,"file":"pascalCase.js","sources":["../../../src/lib/pascalCase.ts"],"sourcesContent":["import { pascalCase as basePascalCase } from \"pascal-case\";\n\n/**\n * Converts a string to a Pascal cased string.\n *\n * @param input - String to convert into a Pascal cased string.\n *\n * @returns Pascal cased string version of `input`.\n */\nexport const pascalCase = (...input: (string | undefined)[]): string => {\n\treturn basePascalCase(input.filter(Boolean).join(\" \"));\n};\n"],"names":["basePascalCase"],"mappings":";AASa,MAAA,aAAa,IAAI,UAAyC;AACtE,SAAOA,aAAe,MAAM,OAAO,OAAO,EAAE,KAAK,GAAG,CAAC;AACtD;"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const fs = require("node:fs/promises");
|
|
4
|
-
function
|
|
5
|
-
if (e && e.__esModule)
|
|
6
|
-
return e;
|
|
4
|
+
function _interopNamespaceDefault(e) {
|
|
7
5
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
6
|
if (e) {
|
|
9
7
|
for (const k in e) {
|
|
@@ -19,7 +17,7 @@ function _interopNamespace(e) {
|
|
|
19
17
|
n.default = e;
|
|
20
18
|
return Object.freeze(n);
|
|
21
19
|
}
|
|
22
|
-
const fs__namespace = /* @__PURE__ */
|
|
20
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
23
21
|
const readJSONFile = async (path) => {
|
|
24
22
|
const contents = await fs__namespace.readFile(path, "utf8");
|
|
25
23
|
return JSON.parse(contents);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readJSONFile.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"readJSONFile.cjs","sources":["../../../src/lib/readJSONFile.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\n\nexport const readJSONFile = async <T = unknown>(path: string): Promise<T> => {\n\tconst contents = await fs.readFile(path, \"utf8\");\n\n\treturn JSON.parse(contents);\n};\n"],"names":["fs"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEa,MAAA,eAAe,OAAoB,SAA4B;AAC3E,QAAM,WAAW,MAAMA,cAAG,SAAS,MAAM,MAAM;AAExC,SAAA,KAAK,MAAM,QAAQ;AAC3B;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readJSONFile.js","sources":["
|
|
1
|
+
{"version":3,"file":"readJSONFile.js","sources":["../../../src/lib/readJSONFile.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\n\nexport const readJSONFile = async <T = unknown>(path: string): Promise<T> => {\n\tconst contents = await fs.readFile(path, \"utf8\");\n\n\treturn JSON.parse(contents);\n};\n"],"names":[],"mappings":";AAEa,MAAA,eAAe,OAAoB,SAA4B;AAC3E,QAAM,WAAW,MAAM,GAAG,SAAS,MAAM,MAAM;AAExC,SAAA,KAAK,MAAM,QAAQ;AAC3B;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const rejectIfNecessary = (promiseSettledResults) => {
|
|
4
4
|
const rejectedReasons = promiseSettledResults.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
5
5
|
if (rejectedReasons.length > 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rejectIfNecessary.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"rejectIfNecessary.cjs","sources":["../../../src/lib/rejectIfNecessary.ts"],"sourcesContent":["export const rejectIfNecessary = <\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTPromiseSettledResults extends readonly PromiseSettledResult<any>[],\n>(\n\tpromiseSettledResults: TPromiseSettledResults,\n): void => {\n\tconst rejectedReasons = promiseSettledResults\n\t\t.filter(\n\t\t\t(result): result is PromiseRejectedResult => result.status === \"rejected\",\n\t\t)\n\t\t.map((result) => result.reason);\n\n\tif (rejectedReasons.length > 0) {\n\t\tthrow rejectedReasons[0];\n\t}\n};\n"],"names":[],"mappings":";;AAAa,MAAA,oBAAoB,CAIhC,0BACS;AACT,QAAM,kBAAkB,sBACtB,OACA,CAAC,WAA4C,OAAO,WAAW,UAAU,EAEzE,IAAI,CAAC,WAAW,OAAO,MAAM;AAE3B,MAAA,gBAAgB,SAAS,GAAG;AAC/B,UAAM,gBAAgB;AAAA,EACtB;AACF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rejectIfNecessary.js","sources":["
|
|
1
|
+
{"version":3,"file":"rejectIfNecessary.js","sources":["../../../src/lib/rejectIfNecessary.ts"],"sourcesContent":["export const rejectIfNecessary = <\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTPromiseSettledResults extends readonly PromiseSettledResult<any>[],\n>(\n\tpromiseSettledResults: TPromiseSettledResults,\n): void => {\n\tconst rejectedReasons = promiseSettledResults\n\t\t.filter(\n\t\t\t(result): result is PromiseRejectedResult => result.status === \"rejected\",\n\t\t)\n\t\t.map((result) => result.reason);\n\n\tif (rejectedReasons.length > 0) {\n\t\tthrow rejectedReasons[0];\n\t}\n};\n"],"names":[],"mappings":"AAAa,MAAA,oBAAoB,CAIhC,0BACS;AACT,QAAM,kBAAkB,sBACtB,OACA,CAAC,WAA4C,OAAO,WAAW,UAAU,EAEzE,IAAI,CAAC,WAAW,OAAO,MAAM;AAE3B,MAAA,gBAAgB,SAAS,GAAG;AAC/B,UAAM,gBAAgB;AAAA,EACtB;AACF;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const fs = require("node:fs/promises");
|
|
4
|
+
const pascalCase = require("./pascalCase.cjs");
|
|
5
|
+
function _interopNamespaceDefault(e) {
|
|
6
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
7
|
+
if (e) {
|
|
8
|
+
for (const k in e) {
|
|
9
|
+
if (k !== "default") {
|
|
10
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: () => e[k]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
n.default = e;
|
|
19
|
+
return Object.freeze(n);
|
|
20
|
+
}
|
|
21
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
22
|
+
const updateSliceModelFile = async ({ libraryID, model, helpers, options }) => {
|
|
23
|
+
const filePath = helpers.joinPathFromRoot(libraryID, pascalCase.pascalCase(model.name), "model.json");
|
|
24
|
+
let contents = JSON.stringify(model);
|
|
25
|
+
if (options.format) {
|
|
26
|
+
contents = await helpers.format(contents, filePath);
|
|
27
|
+
}
|
|
28
|
+
await fs__namespace.writeFile(filePath, contents);
|
|
29
|
+
};
|
|
30
|
+
exports.updateSliceModelFile = updateSliceModelFile;
|
|
31
|
+
//# sourceMappingURL=updateSliceModelFile.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateSliceModelFile.cjs","sources":["../../../src/lib/updateSliceModelFile.ts"],"sourcesContent":["import { SharedSliceModel } from \"@prismicio/types\";\nimport { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\n\nimport type { PluginOptions } from \"../types\";\nimport { pascalCase } from \"./pascalCase\";\n\ntype UpdateSliceModelFileArgs = {\n\tlibraryID: string;\n\tmodel: SharedSliceModel;\n} & SliceMachineContext<PluginOptions>;\n\nexport const updateSliceModelFile = async ({\n\tlibraryID,\n\tmodel,\n\thelpers,\n\toptions,\n}: UpdateSliceModelFileArgs): Promise<void> => {\n\tconst filePath = helpers.joinPathFromRoot(\n\t\tlibraryID,\n\t\tpascalCase(model.name),\n\t\t\"model.json\",\n\t);\n\n\tlet contents = JSON.stringify(model);\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":["pascalCase","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAYO,MAAM,uBAAuB,OAAO,EAC1C,WACA,OACA,SACA,cAC6C;AACvC,QAAA,WAAW,QAAQ,iBACxB,WACAA,sBAAW,MAAM,IAAI,GACrB,YAAY;AAGT,MAAA,WAAW,KAAK,UAAU,KAAK;AAEnC,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAAC,cAAG,UAAU,UAAU,QAAQ;AACtC;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SharedSliceModel } from "@prismicio/types";
|
|
2
|
+
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
3
|
+
import type { PluginOptions } from "../types";
|
|
4
|
+
type UpdateSliceModelFileArgs = {
|
|
5
|
+
libraryID: string;
|
|
6
|
+
model: SharedSliceModel;
|
|
7
|
+
} & SliceMachineContext<PluginOptions>;
|
|
8
|
+
export declare const updateSliceModelFile: ({ libraryID, model, helpers, options, }: UpdateSliceModelFileArgs) => Promise<void>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import { pascalCase } from "./pascalCase.js";
|
|
3
|
+
const updateSliceModelFile = async ({ libraryID, model, helpers, options }) => {
|
|
4
|
+
const filePath = helpers.joinPathFromRoot(libraryID, pascalCase(model.name), "model.json");
|
|
5
|
+
let contents = JSON.stringify(model);
|
|
6
|
+
if (options.format) {
|
|
7
|
+
contents = await helpers.format(contents, filePath);
|
|
8
|
+
}
|
|
9
|
+
await fs.writeFile(filePath, contents);
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
updateSliceModelFile
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=updateSliceModelFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateSliceModelFile.js","sources":["../../../src/lib/updateSliceModelFile.ts"],"sourcesContent":["import { SharedSliceModel } from \"@prismicio/types\";\nimport { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\n\nimport type { PluginOptions } from \"../types\";\nimport { pascalCase } from \"./pascalCase\";\n\ntype UpdateSliceModelFileArgs = {\n\tlibraryID: string;\n\tmodel: SharedSliceModel;\n} & SliceMachineContext<PluginOptions>;\n\nexport const updateSliceModelFile = async ({\n\tlibraryID,\n\tmodel,\n\thelpers,\n\toptions,\n}: UpdateSliceModelFileArgs): Promise<void> => {\n\tconst filePath = helpers.joinPathFromRoot(\n\t\tlibraryID,\n\t\tpascalCase(model.name),\n\t\t\"model.json\",\n\t);\n\n\tlet contents = JSON.stringify(model);\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":[],"mappings":";;AAYO,MAAM,uBAAuB,OAAO,EAC1C,WACA,OACA,SACA,cAC6C;AACvC,QAAA,WAAW,QAAQ,iBACxB,WACA,WAAW,MAAM,IAAI,GACrB,YAAY;AAGT,MAAA,WAAW,KAAK,UAAU,KAAK;AAEnC,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const prismicTsCodegen = require("prismic-ts-codegen");
|
|
4
4
|
const fs = require("node:fs/promises");
|
|
5
5
|
const path = require("node:path");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return e;
|
|
6
|
+
const constants = require("../constants.cjs");
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
9
8
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
9
|
if (e) {
|
|
11
10
|
for (const k in e) {
|
|
@@ -21,8 +20,8 @@ function _interopNamespace(e) {
|
|
|
21
20
|
n.default = e;
|
|
22
21
|
return Object.freeze(n);
|
|
23
22
|
}
|
|
24
|
-
const fs__namespace = /* @__PURE__ */
|
|
25
|
-
const path__namespace = /* @__PURE__ */
|
|
23
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
24
|
+
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
26
25
|
const upsertGlobalContentTypes = async ({ actions, helpers, options }) => {
|
|
27
26
|
const filePath = helpers.joinPathFromRoot(".slicemachine", "prismicio.d.ts");
|
|
28
27
|
const [customTypeModelDescriptors, sharedSliceModelDescriptors] = await Promise.all([
|
|
@@ -43,6 +42,9 @@ const upsertGlobalContentTypes = async ({ actions, helpers, options }) => {
|
|
|
43
42
|
includeContentNamespace: true
|
|
44
43
|
}
|
|
45
44
|
});
|
|
45
|
+
contents = `${constants.NON_EDITABLE_FILE_BANNER}
|
|
46
|
+
|
|
47
|
+
${contents}`;
|
|
46
48
|
if (options.format) {
|
|
47
49
|
contents = await helpers.format(contents, filePath);
|
|
48
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upsertGlobalContentTypes.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"upsertGlobalContentTypes.cjs","sources":["../../../src/lib/upsertGlobalContentTypes.ts"],"sourcesContent":["import type { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { generateTypes } from \"prismic-ts-codegen\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\n/**\n * Arguments for `upsertGlobalContentTypes()`.\n */\ntype UpsertGlobalTypesArgs = Pick<\n\tSliceMachineContext<PluginOptions>,\n\t\"actions\" | \"helpers\" | \"options\"\n>;\n\n/**\n * Creates a globally accessible TypeScript file containing types representing\n * the Prismic repository's content.\n */\nexport const upsertGlobalContentTypes = async ({\n\tactions,\n\thelpers,\n\toptions,\n}: UpsertGlobalTypesArgs): Promise<void> => {\n\tconst filePath = helpers.joinPathFromRoot(\".slicemachine\", \"prismicio.d.ts\");\n\n\tconst [customTypeModelDescriptors, sharedSliceModelDescriptors] =\n\t\tawait Promise.all([\n\t\t\tactions.readAllCustomTypeModels(),\n\t\t\tactions.readAllSliceModels(),\n\t\t]);\n\n\tconst customTypeModels = customTypeModelDescriptors.map(\n\t\t(customTypeModelDescriptors) => {\n\t\t\treturn customTypeModelDescriptors.model;\n\t\t},\n\t);\n\tconst sharedSliceModels = sharedSliceModelDescriptors.map(\n\t\t(sharedSliceModelDescriptors) => {\n\t\t\treturn sharedSliceModelDescriptors.model;\n\t\t},\n\t);\n\n\tlet contents = generateTypes({\n\t\tcustomTypeModels,\n\t\tsharedSliceModels,\n\t\tclientIntegration: {\n\t\t\tincludeCreateClientInterface: true,\n\t\t\tincludeContentNamespace: true,\n\t\t},\n\t});\n\n\tcontents = `${NON_EDITABLE_FILE_BANNER}\\n\\n${contents}`;\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":["customTypeModelDescriptors","sharedSliceModelDescriptors","generateTypes","NON_EDITABLE_FILE_BANNER","fs","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoBO,MAAM,2BAA2B,OAAO,EAC9C,SACA,SACA,cAC0C;AAC1C,QAAM,WAAW,QAAQ,iBAAiB,iBAAiB,gBAAgB;AAE3E,QAAM,CAAC,4BAA4B,2BAA2B,IAC7D,MAAM,QAAQ,IAAI;AAAA,IACjB,QAAQ,wBAAyB;AAAA,IACjC,QAAQ,mBAAoB;AAAA,EAAA,CAC5B;AAEF,QAAM,mBAAmB,2BAA2B,IACnD,CAACA,gCAA8B;AAC9B,WAAOA,4BAA2B;AAAA,EAAA,CAClC;AAEF,QAAM,oBAAoB,4BAA4B,IACrD,CAACC,iCAA+B;AAC/B,WAAOA,6BAA4B;AAAA,EAAA,CACnC;AAGF,MAAI,WAAWC,iBAAAA,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,MAClB,8BAA8B;AAAA,MAC9B,yBAAyB;AAAA,IACzB;AAAA,EAAA,CACD;AAED,aAAW,GAAGC;;EAA+B;AAE7C,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAAC,cAAG,MAAMC,gBAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAA,CAAM;AACpD,QAAAD,cAAG,UAAU,UAAU,QAAQ;AACtC;;"}
|
|
@@ -3,7 +3,7 @@ import type { PluginOptions } from "../types";
|
|
|
3
3
|
/**
|
|
4
4
|
* Arguments for `upsertGlobalContentTypes()`.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
type UpsertGlobalTypesArgs = Pick<SliceMachineContext<PluginOptions>, "actions" | "helpers" | "options">;
|
|
7
7
|
/**
|
|
8
8
|
* Creates a globally accessible TypeScript file containing types representing
|
|
9
9
|
* the Prismic repository's content.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { generateTypes } from "prismic-ts-codegen";
|
|
2
2
|
import * as fs from "node:fs/promises";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
+
import { NON_EDITABLE_FILE_BANNER } from "../constants.js";
|
|
4
5
|
const upsertGlobalContentTypes = async ({ actions, helpers, options }) => {
|
|
5
6
|
const filePath = helpers.joinPathFromRoot(".slicemachine", "prismicio.d.ts");
|
|
6
7
|
const [customTypeModelDescriptors, sharedSliceModelDescriptors] = await Promise.all([
|
|
@@ -21,6 +22,9 @@ const upsertGlobalContentTypes = async ({ actions, helpers, options }) => {
|
|
|
21
22
|
includeContentNamespace: true
|
|
22
23
|
}
|
|
23
24
|
});
|
|
25
|
+
contents = `${NON_EDITABLE_FILE_BANNER}
|
|
26
|
+
|
|
27
|
+
${contents}`;
|
|
24
28
|
if (options.format) {
|
|
25
29
|
contents = await helpers.format(contents, filePath);
|
|
26
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upsertGlobalContentTypes.js","sources":["
|
|
1
|
+
{"version":3,"file":"upsertGlobalContentTypes.js","sources":["../../../src/lib/upsertGlobalContentTypes.ts"],"sourcesContent":["import type { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { generateTypes } from \"prismic-ts-codegen\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\n/**\n * Arguments for `upsertGlobalContentTypes()`.\n */\ntype UpsertGlobalTypesArgs = Pick<\n\tSliceMachineContext<PluginOptions>,\n\t\"actions\" | \"helpers\" | \"options\"\n>;\n\n/**\n * Creates a globally accessible TypeScript file containing types representing\n * the Prismic repository's content.\n */\nexport const upsertGlobalContentTypes = async ({\n\tactions,\n\thelpers,\n\toptions,\n}: UpsertGlobalTypesArgs): Promise<void> => {\n\tconst filePath = helpers.joinPathFromRoot(\".slicemachine\", \"prismicio.d.ts\");\n\n\tconst [customTypeModelDescriptors, sharedSliceModelDescriptors] =\n\t\tawait Promise.all([\n\t\t\tactions.readAllCustomTypeModels(),\n\t\t\tactions.readAllSliceModels(),\n\t\t]);\n\n\tconst customTypeModels = customTypeModelDescriptors.map(\n\t\t(customTypeModelDescriptors) => {\n\t\t\treturn customTypeModelDescriptors.model;\n\t\t},\n\t);\n\tconst sharedSliceModels = sharedSliceModelDescriptors.map(\n\t\t(sharedSliceModelDescriptors) => {\n\t\t\treturn sharedSliceModelDescriptors.model;\n\t\t},\n\t);\n\n\tlet contents = generateTypes({\n\t\tcustomTypeModels,\n\t\tsharedSliceModels,\n\t\tclientIntegration: {\n\t\t\tincludeCreateClientInterface: true,\n\t\t\tincludeContentNamespace: true,\n\t\t},\n\t});\n\n\tcontents = `${NON_EDITABLE_FILE_BANNER}\\n\\n${contents}`;\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":["customTypeModelDescriptors","sharedSliceModelDescriptors"],"mappings":";;;;AAoBO,MAAM,2BAA2B,OAAO,EAC9C,SACA,SACA,cAC0C;AAC1C,QAAM,WAAW,QAAQ,iBAAiB,iBAAiB,gBAAgB;AAE3E,QAAM,CAAC,4BAA4B,2BAA2B,IAC7D,MAAM,QAAQ,IAAI;AAAA,IACjB,QAAQ,wBAAyB;AAAA,IACjC,QAAQ,mBAAoB;AAAA,EAAA,CAC5B;AAEF,QAAM,mBAAmB,2BAA2B,IACnD,CAACA,gCAA8B;AAC9B,WAAOA,4BAA2B;AAAA,EAAA,CAClC;AAEF,QAAM,oBAAoB,4BAA4B,IACrD,CAACC,iCAA+B;AAC/B,WAAOA,6BAA4B;AAAA,EAAA,CACnC;AAGF,MAAI,WAAW,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,MAClB,8BAA8B;AAAA,MAC9B,yBAAyB;AAAA,IACzB;AAAA,EAAA,CACD;AAED,aAAW,GAAG;AAAA;AAAA,EAA+B;AAE7C,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAA,GAAG,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAA,CAAM;AACpD,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const commonTags = require("common-tags");
|
|
4
|
+
const fs = require("node:fs/promises");
|
|
5
|
+
const constants = require("../constants.cjs");
|
|
6
|
+
const pascalCase = require("./pascalCase.cjs");
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
8
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
9
|
+
if (e) {
|
|
10
|
+
for (const k in e) {
|
|
11
|
+
if (k !== "default") {
|
|
12
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: () => e[k]
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
24
|
+
const upsertSliceLibraryIndexFile = async (args) => {
|
|
25
|
+
const filePath = args.helpers.joinPathFromRoot(args.libraryID, args.options.typescript ? "index.ts" : "index.js");
|
|
26
|
+
const slices = await args.actions.readAllSliceModelsForLibrary({
|
|
27
|
+
libraryID: args.libraryID
|
|
28
|
+
});
|
|
29
|
+
let contents = commonTags.stripIndent`
|
|
30
|
+
${constants.NON_EDITABLE_FILE_BANNER}
|
|
31
|
+
|
|
32
|
+
import dynamic from 'next/dynamic'
|
|
33
|
+
|
|
34
|
+
export const components = {
|
|
35
|
+
${slices.map((slice) => {
|
|
36
|
+
const id = slice.model.id;
|
|
37
|
+
const dirName = pascalCase.pascalCase(slice.model.name);
|
|
38
|
+
return `${id}: dynamic(() => import('./${dirName}'))`;
|
|
39
|
+
}).join(",\n")}
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
if (args.options.format) {
|
|
43
|
+
contents = await args.helpers.format(contents, filePath);
|
|
44
|
+
}
|
|
45
|
+
await fs__namespace.writeFile(filePath, contents);
|
|
46
|
+
};
|
|
47
|
+
exports.upsertSliceLibraryIndexFile = upsertSliceLibraryIndexFile;
|
|
48
|
+
//# sourceMappingURL=upsertSliceLibraryIndexFile.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upsertSliceLibraryIndexFile.cjs","sources":["../../../src/lib/upsertSliceLibraryIndexFile.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport * as fs from \"node:fs/promises\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { pascalCase } from \"./pascalCase\";\n\ntype UpsertSliceLibraryIndexFileArgs = {\n\tlibraryID: string;\n} & SliceMachineContext<PluginOptions>;\n\nexport const upsertSliceLibraryIndexFile = async (\n\targs: UpsertSliceLibraryIndexFileArgs,\n): Promise<void> => {\n\tconst filePath = args.helpers.joinPathFromRoot(\n\t\targs.libraryID,\n\t\targs.options.typescript ? \"index.ts\" : \"index.js\",\n\t);\n\n\tconst slices = await args.actions.readAllSliceModelsForLibrary({\n\t\tlibraryID: args.libraryID,\n\t});\n\n\tlet contents = stripIndent`\n\t\t${NON_EDITABLE_FILE_BANNER}\n\n\t\timport dynamic from 'next/dynamic'\n\n\t\texport const components = {\n\t\t\t${slices\n\t\t\t\t.map((slice) => {\n\t\t\t\t\tconst id = slice.model.id;\n\t\t\t\t\tconst dirName = pascalCase(slice.model.name);\n\n\t\t\t\t\treturn `${id}: dynamic(() => import('./${dirName}'))`;\n\t\t\t\t})\n\t\t\t\t.join(\",\\n\")}\n\t\t}\n\t`;\n\n\tif (args.options.format) {\n\t\tcontents = await args.helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":["stripIndent","NON_EDITABLE_FILE_BANNER","pascalCase","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAaa,MAAA,8BAA8B,OAC1C,SACkB;AACZ,QAAA,WAAW,KAAK,QAAQ,iBAC7B,KAAK,WACL,KAAK,QAAQ,aAAa,aAAa,UAAU;AAGlD,QAAM,SAAS,MAAM,KAAK,QAAQ,6BAA6B;AAAA,IAC9D,WAAW,KAAK;AAAA,EAAA,CAChB;AAED,MAAI,WAAWA,WAAAA;AAAAA,IACZC;;;;;KAKC,OACA,IAAI,CAAC,UAAS;AACR,UAAA,KAAK,MAAM,MAAM;AACvB,UAAM,UAAUC,WAAA,WAAW,MAAM,MAAM,IAAI;AAE3C,WAAO,GAAG,+BAA+B;AAAA,EAAA,CACzC,EACA,KAAK,KAAK;AAAA;AAAA;AAIV,MAAA,KAAK,QAAQ,QAAQ;AACxB,eAAW,MAAM,KAAK,QAAQ,OAAO,UAAU,QAAQ;AAAA,EACvD;AAEK,QAAAC,cAAG,UAAU,UAAU,QAAQ;AACtC;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
+
import { PluginOptions } from "../types";
|
|
3
|
+
type UpsertSliceLibraryIndexFileArgs = {
|
|
4
|
+
libraryID: string;
|
|
5
|
+
} & SliceMachineContext<PluginOptions>;
|
|
6
|
+
export declare const upsertSliceLibraryIndexFile: (args: UpsertSliceLibraryIndexFileArgs) => Promise<void>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { stripIndent } from "common-tags";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import { NON_EDITABLE_FILE_BANNER } from "../constants.js";
|
|
4
|
+
import { pascalCase } from "./pascalCase.js";
|
|
5
|
+
const upsertSliceLibraryIndexFile = async (args) => {
|
|
6
|
+
const filePath = args.helpers.joinPathFromRoot(args.libraryID, args.options.typescript ? "index.ts" : "index.js");
|
|
7
|
+
const slices = await args.actions.readAllSliceModelsForLibrary({
|
|
8
|
+
libraryID: args.libraryID
|
|
9
|
+
});
|
|
10
|
+
let contents = stripIndent`
|
|
11
|
+
${NON_EDITABLE_FILE_BANNER}
|
|
12
|
+
|
|
13
|
+
import dynamic from 'next/dynamic'
|
|
14
|
+
|
|
15
|
+
export const components = {
|
|
16
|
+
${slices.map((slice) => {
|
|
17
|
+
const id = slice.model.id;
|
|
18
|
+
const dirName = pascalCase(slice.model.name);
|
|
19
|
+
return `${id}: dynamic(() => import('./${dirName}'))`;
|
|
20
|
+
}).join(",\n")}
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
if (args.options.format) {
|
|
24
|
+
contents = await args.helpers.format(contents, filePath);
|
|
25
|
+
}
|
|
26
|
+
await fs.writeFile(filePath, contents);
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
upsertSliceLibraryIndexFile
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=upsertSliceLibraryIndexFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upsertSliceLibraryIndexFile.js","sources":["../../../src/lib/upsertSliceLibraryIndexFile.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport * as fs from \"node:fs/promises\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { pascalCase } from \"./pascalCase\";\n\ntype UpsertSliceLibraryIndexFileArgs = {\n\tlibraryID: string;\n} & SliceMachineContext<PluginOptions>;\n\nexport const upsertSliceLibraryIndexFile = async (\n\targs: UpsertSliceLibraryIndexFileArgs,\n): Promise<void> => {\n\tconst filePath = args.helpers.joinPathFromRoot(\n\t\targs.libraryID,\n\t\targs.options.typescript ? \"index.ts\" : \"index.js\",\n\t);\n\n\tconst slices = await args.actions.readAllSliceModelsForLibrary({\n\t\tlibraryID: args.libraryID,\n\t});\n\n\tlet contents = stripIndent`\n\t\t${NON_EDITABLE_FILE_BANNER}\n\n\t\timport dynamic from 'next/dynamic'\n\n\t\texport const components = {\n\t\t\t${slices\n\t\t\t\t.map((slice) => {\n\t\t\t\t\tconst id = slice.model.id;\n\t\t\t\t\tconst dirName = pascalCase(slice.model.name);\n\n\t\t\t\t\treturn `${id}: dynamic(() => import('./${dirName}'))`;\n\t\t\t\t})\n\t\t\t\t.join(\",\\n\")}\n\t\t}\n\t`;\n\n\tif (args.options.format) {\n\t\tcontents = await args.helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":[],"mappings":";;;;AAaa,MAAA,8BAA8B,OAC1C,SACkB;AACZ,QAAA,WAAW,KAAK,QAAQ,iBAC7B,KAAK,WACL,KAAK,QAAQ,aAAa,aAAa,UAAU;AAGlD,QAAM,SAAS,MAAM,KAAK,QAAQ,6BAA6B;AAAA,IAC9D,WAAW,KAAK;AAAA,EAAA,CAChB;AAED,MAAI,WAAW;AAAA,IACZ;AAAA;AAAA;AAAA;AAAA;AAAA,KAKC,OACA,IAAI,CAAC,UAAS;AACR,UAAA,KAAK,MAAM,MAAM;AACvB,UAAM,UAAU,WAAW,MAAM,MAAM,IAAI;AAE3C,WAAO,GAAG,+BAA+B;AAAA,EAAA,CACzC,EACA,KAAK,KAAK;AAAA;AAAA;AAIV,MAAA,KAAK,QAAQ,QAAQ;AACxB,eAAW,MAAM,KAAK,QAAQ,OAAO,UAAU,QAAQ;AAAA,EACvD;AAEK,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;"}
|