@prismicio/adapter-nuxt 0.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.
Files changed (49) hide show
  1. package/dist/constants.d.ts +4 -0
  2. package/dist/constants.js +5 -0
  3. package/dist/constants.js.map +1 -0
  4. package/dist/hooks/project-init.d.ts +3 -0
  5. package/dist/hooks/project-init.js +117 -0
  6. package/dist/hooks/project-init.js.map +1 -0
  7. package/dist/hooks/slice-create.d.ts +3 -0
  8. package/dist/hooks/slice-create.js +68 -0
  9. package/dist/hooks/slice-create.js.map +1 -0
  10. package/dist/index.d.ts +3 -0
  11. package/dist/index.js +5 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/lib/buildSrcPath.d.ts +5 -0
  14. package/dist/lib/buildSrcPath.js +23 -0
  15. package/dist/lib/buildSrcPath.js.map +1 -0
  16. package/dist/lib/checkIsTypeScriptProject.d.ts +8 -0
  17. package/dist/lib/checkIsTypeScriptProject.js +8 -0
  18. package/dist/lib/checkIsTypeScriptProject.js.map +1 -0
  19. package/dist/lib/getJSFileExtension.d.ts +5 -0
  20. package/dist/lib/getJSFileExtension.js +12 -0
  21. package/dist/lib/getJSFileExtension.js.map +1 -0
  22. package/dist/lib/pascalCase.d.ts +8 -0
  23. package/dist/lib/pascalCase.js +8 -0
  24. package/dist/lib/pascalCase.js.map +1 -0
  25. package/dist/lib/rejectIfNecessary.d.ts +1 -0
  26. package/dist/lib/rejectIfNecessary.js +10 -0
  27. package/dist/lib/rejectIfNecessary.js.map +1 -0
  28. package/dist/lib/upsertSliceLibraryIndexFile.d.ts +7 -0
  29. package/dist/lib/upsertSliceLibraryIndexFile.js +74 -0
  30. package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -0
  31. package/dist/package.json.js +5 -0
  32. package/dist/package.json.js.map +1 -0
  33. package/dist/plugin.d.ts +2 -0
  34. package/dist/plugin.js +144 -0
  35. package/dist/plugin.js.map +1 -0
  36. package/dist/types.d.ts +34 -0
  37. package/package.json +79 -0
  38. package/src/constants.ts +5 -0
  39. package/src/hooks/project-init.ts +199 -0
  40. package/src/hooks/slice-create.ts +131 -0
  41. package/src/index.ts +5 -0
  42. package/src/lib/buildSrcPath.ts +30 -0
  43. package/src/lib/checkIsTypeScriptProject.ts +18 -0
  44. package/src/lib/getJSFileExtension.ts +22 -0
  45. package/src/lib/pascalCase.ts +12 -0
  46. package/src/lib/rejectIfNecessary.ts +16 -0
  47. package/src/lib/upsertSliceLibraryIndexFile.ts +110 -0
  48. package/src/plugin.ts +191 -0
  49. package/src/types.ts +38 -0
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Banner text added to files that should not be edited by users.
3
+ */
4
+ export declare const NON_EDITABLE_FILE_BANNER = "// Code generated by Prismic. DO NOT EDIT.";
@@ -0,0 +1,5 @@
1
+ const NON_EDITABLE_FILE_BANNER = "// Code generated by Prismic. DO NOT EDIT.";
2
+ export {
3
+ NON_EDITABLE_FILE_BANNER
4
+ };
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["/**\n * Banner text added to files that should not be edited by users.\n */\nexport const NON_EDITABLE_FILE_BANNER =\n\t\"// Code generated by Prismic. DO NOT EDIT.\";\n"],"names":[],"mappings":"AAGO,MAAM,2BACZ;"}
@@ -0,0 +1,3 @@
1
+ import type { ProjectInitHook } from "@prismicio/plugin-kit";
2
+ import type { PluginOptions } from "../types.js";
3
+ export declare const projectInit: ProjectInitHook<PluginOptions>;
@@ -0,0 +1,117 @@
1
+ import * as path from "node:path";
2
+ import { checkHasProjectFile, readProjectFile, writeProjectFile, deleteProjectFile } from "@prismicio/plugin-kit/fs";
3
+ import { loadFile, builders, writeFile } from "magicast";
4
+ import { buildSrcPath } from "../lib/buildSrcPath.js";
5
+ import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
6
+ const NUXT_PRISMIC = "@nuxtjs/prismic";
7
+ const installDependencies = async ({ installDependencies: installDependencies2 }) => {
8
+ await installDependencies2({
9
+ dependencies: {
10
+ [NUXT_PRISMIC]: "^4.0.0"
11
+ },
12
+ dev: true
13
+ });
14
+ };
15
+ const configurePrismicModule = async ({ helpers }) => {
16
+ let nuxtConfigFilename = "nuxt.config.js";
17
+ if (!await checkHasProjectFile({ filename: nuxtConfigFilename, helpers })) {
18
+ nuxtConfigFilename = "nuxt.config.ts";
19
+ if (!await checkHasProjectFile({ filename: nuxtConfigFilename, helpers })) {
20
+ return;
21
+ }
22
+ }
23
+ const nuxtConfigPath = helpers.joinPathFromRoot(nuxtConfigFilename);
24
+ const mod = await loadFile(nuxtConfigPath);
25
+ const config = mod.exports.default.$type === "function-call" ? mod.exports.default.$args[0] : mod.exports.default;
26
+ let hasInlinedConfiguration = false;
27
+ const hasPrismicModuleRegistered = (config.modules || []).find((registration) => {
28
+ if (typeof registration === "string") {
29
+ return registration === NUXT_PRISMIC;
30
+ } else if (Array.isArray(registration)) {
31
+ hasInlinedConfiguration = !!registration[1];
32
+ return registration[0] === NUXT_PRISMIC;
33
+ }
34
+ return false;
35
+ });
36
+ if (!hasPrismicModuleRegistered) {
37
+ config.modules ||= [];
38
+ config.modules.push(NUXT_PRISMIC);
39
+ }
40
+ if (!hasInlinedConfiguration) {
41
+ mod.imports.$add({
42
+ from: "./prismic.config.json",
43
+ imported: "apiEndpoint"
44
+ });
45
+ mod.imports.$add({
46
+ from: "./prismic.config.json",
47
+ imported: "repositoryName"
48
+ });
49
+ config.prismic ||= {};
50
+ config.prismic.endpoint = builders.raw("apiEndpoint || repositoryName");
51
+ }
52
+ await writeFile(mod, nuxtConfigPath);
53
+ };
54
+ const moveOrDeleteAppVue = async ({ helpers, options }) => {
55
+ const filenameAppVue = await buildSrcPath({ filename: "app.vue", helpers });
56
+ if (!await checkHasProjectFile({ filename: filenameAppVue, helpers })) {
57
+ return;
58
+ }
59
+ const filecontentAppVue = await readProjectFile({
60
+ filename: filenameAppVue,
61
+ helpers,
62
+ encoding: "utf-8"
63
+ });
64
+ if (!filecontentAppVue.includes("<NuxtWelcome")) {
65
+ return;
66
+ }
67
+ const filenameIndexVue = await buildSrcPath({
68
+ filename: path.join("pages/index.vue"),
69
+ helpers
70
+ });
71
+ if (!await checkHasProjectFile({ filename: filenameIndexVue, helpers })) {
72
+ await writeProjectFile({
73
+ filename: filenameIndexVue,
74
+ contents: filecontentAppVue,
75
+ format: options.format,
76
+ helpers
77
+ });
78
+ }
79
+ await deleteProjectFile({
80
+ filename: filenameAppVue,
81
+ helpers
82
+ });
83
+ };
84
+ const modifyPrismicConfig = async ({ helpers, options, actions }) => {
85
+ const hasAppDirectory = await checkHasProjectFile({
86
+ filename: "app",
87
+ helpers
88
+ });
89
+ const hasSrcDirectory = await checkHasProjectFile({
90
+ filename: "src",
91
+ helpers
92
+ });
93
+ const project = await helpers.getProject();
94
+ if ((hasAppDirectory || hasSrcDirectory) && project.config.libraries && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
95
+ const sliceLibrary = await actions.readSliceLibrary({
96
+ libraryID: project.config.libraries[0]
97
+ });
98
+ if (sliceLibrary.sliceIDs.length < 1) {
99
+ project.config.libraries = hasAppDirectory ? ["./app/slices"] : ["./src/slices"];
100
+ }
101
+ }
102
+ await helpers.updatePrismicConfig(project.config, {
103
+ format: options.format
104
+ });
105
+ };
106
+ const projectInit = async ({ installDependencies: _installDependencies }, context) => {
107
+ rejectIfNecessary(await Promise.allSettled([
108
+ installDependencies({ installDependencies: _installDependencies }),
109
+ configurePrismicModule(context),
110
+ moveOrDeleteAppVue(context),
111
+ modifyPrismicConfig(context)
112
+ ]));
113
+ };
114
+ export {
115
+ projectInit
116
+ };
117
+ //# sourceMappingURL=project-init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-init.js","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import * as path from \"node:path\";\n\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tPluginSystemContext,\n} from \"@prismicio/plugin-kit\";\nimport {\n\tcheckHasProjectFile,\n\tdeleteProjectFile,\n\treadProjectFile,\n\twriteProjectFile,\n} from \"@prismicio/plugin-kit/fs\";\nimport { builders, loadFile, writeFile } from \"magicast\";\n\nimport { buildSrcPath } from \"../lib/buildSrcPath\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport type { PluginOptions } from \"../types\";\n\nconst NUXT_PRISMIC = \"@nuxtjs/prismic\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t[NUXT_PRISMIC]: \"^4.0.0\",\n\t\t},\n\t\tdev: true,\n\t});\n};\n\ntype ConfigurePrismicModuleArgs = PluginSystemContext<PluginOptions>;\n\nconst configurePrismicModule = async ({\n\thelpers,\n}: ConfigurePrismicModuleArgs) => {\n\tlet nuxtConfigFilename = \"nuxt.config.js\";\n\n\tif (!(await checkHasProjectFile({ filename: nuxtConfigFilename, helpers }))) {\n\t\tnuxtConfigFilename = \"nuxt.config.ts\";\n\n\t\t// nuxt.config.* not found\n\t\tif (\n\t\t\t!(await checkHasProjectFile({ filename: nuxtConfigFilename, helpers }))\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst nuxtConfigPath = helpers.joinPathFromRoot(nuxtConfigFilename);\n\n\tconst mod = await loadFile(nuxtConfigPath);\n\tconst config =\n\t\tmod.exports.default.$type === \"function-call\"\n\t\t\t? mod.exports.default.$args[0]\n\t\t\t: mod.exports.default;\n\n\t// Register Prismic module\n\tlet hasInlinedConfiguration = false;\n\tconst hasPrismicModuleRegistered = (config.modules || []).find(\n\t\t(registration: string | [string, unknown]) => {\n\t\t\tif (typeof registration === \"string\") {\n\t\t\t\treturn registration === NUXT_PRISMIC;\n\t\t\t} else if (Array.isArray(registration)) {\n\t\t\t\thasInlinedConfiguration = !!registration[1];\n\n\t\t\t\treturn registration[0] === NUXT_PRISMIC;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t},\n\t);\n\n\tif (!hasPrismicModuleRegistered) {\n\t\tconfig.modules ||= [];\n\t\tconfig.modules.push(NUXT_PRISMIC);\n\t}\n\n\t// Append Prismic module configuration\n\tif (!hasInlinedConfiguration) {\n\t\t// Import Prismic configuration\n\t\tmod.imports.$add({\n\t\t\tfrom: \"./prismic.config.json\",\n\t\t\timported: \"apiEndpoint\",\n\t\t});\n\t\tmod.imports.$add({\n\t\t\tfrom: \"./prismic.config.json\",\n\t\t\timported: \"repositoryName\",\n\t\t});\n\n\t\t// Add inline configuration\n\t\tconfig.prismic ||= {};\n\t\tconfig.prismic.endpoint = builders.raw(\"apiEndpoint || repositoryName\");\n\t}\n\n\tawait writeFile(mod, nuxtConfigPath);\n};\n\nconst moveOrDeleteAppVue = async ({\n\thelpers,\n\toptions,\n}: PluginSystemContext<PluginOptions>) => {\n\tconst filenameAppVue = await buildSrcPath({ filename: \"app.vue\", helpers });\n\n\t// If there's no `app.vue`, there's nothing to do.\n\tif (!(await checkHasProjectFile({ filename: filenameAppVue, helpers }))) {\n\t\treturn;\n\t}\n\n\tconst filecontentAppVue = await readProjectFile({\n\t\tfilename: filenameAppVue,\n\t\thelpers,\n\t\tencoding: \"utf-8\",\n\t});\n\n\t// We check for app.vue to contain Nuxt default welcome component to determine\n\t// if we need to consider it as the default one or not.\n\tif (!filecontentAppVue.includes(\"<NuxtWelcome\")) {\n\t\treturn;\n\t}\n\n\tconst filenameIndexVue = await buildSrcPath({\n\t\tfilename: path.join(\"pages/index.vue\"),\n\t\thelpers,\n\t});\n\n\t// If we don't have an `index.vue` we create one with the content of `app.vue`\n\tif (!(await checkHasProjectFile({ filename: filenameIndexVue, helpers }))) {\n\t\tawait writeProjectFile({\n\t\t\tfilename: filenameIndexVue,\n\t\t\tcontents: filecontentAppVue,\n\t\t\tformat: options.format,\n\t\t\thelpers,\n\t\t});\n\t}\n\n\t// Delete `app.vue`\n\tawait deleteProjectFile({\n\t\tfilename: filenameAppVue,\n\t\thelpers,\n\t});\n};\n\nconst modifyPrismicConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: PluginSystemContext<PluginOptions>) => {\n\tconst hasAppDirectory = await checkHasProjectFile({\n\t\tfilename: \"app\",\n\t\thelpers,\n\t});\n\tconst hasSrcDirectory = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers,\n\t});\n\tconst project = await helpers.getProject();\n\n\t// Nest the default Slice Library in the `app` or `src` directory if it\n\t// exists and is empty.\n\tif (\n\t\t(hasAppDirectory || hasSrcDirectory) &&\n\t\tproject.config.libraries &&\n\t\tJSON.stringify(project.config.libraries) === JSON.stringify([\"./slices\"])\n\t) {\n\t\tconst sliceLibrary = await actions.readSliceLibrary({\n\t\t\tlibraryID: project.config.libraries[0],\n\t\t});\n\n\t\tif (sliceLibrary.sliceIDs.length < 1) {\n\t\t\tproject.config.libraries = hasAppDirectory\n\t\t\t\t? [\"./app/slices\"]\n\t\t\t\t: [\"./src/slices\"];\n\t\t}\n\t}\n\n\tawait helpers.updatePrismicConfig(project.config, {\n\t\tformat: options.format,\n\t});\n};\n\nexport const projectInit: ProjectInitHook<PluginOptions> = async (\n\t{ installDependencies: _installDependencies },\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tinstallDependencies({ installDependencies: _installDependencies }),\n\t\t\tconfigurePrismicModule(context),\n\t\t\tmoveOrDeleteAppVue(context),\n\t\t\tmodifyPrismicConfig(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies"],"mappings":";;;;;AAmBA,MAAM,eAAe;AAMrB,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,CAAC,YAAY,GAAG;AAAA,IAAA;AAAA,IAEjB,KAAK;AAAA,EAAA,CACL;AACF;AAIA,MAAM,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AAQ;AAAA,EAAA,CAChB;AACF;AAEO,MAAM,cAA8C,OAC1D,EAAE,qBAAqB,qBAAA,GACvB,YACG;AACH,oBACC,MAAM,QAAQ,WAAW;AAAA,IACxB,oBAAoB,EAAE,qBAAqB,sBAAsB;AAAA,IACjE,uBAAuB,OAAO;AAAA,IAC9B,mBAAmB,OAAO;AAAA,IAC1B,oBAAoB,OAAO;AAAA,EAAA,CAC3B,CAAC;AAEJ;"}
@@ -0,0 +1,3 @@
1
+ import type { SliceCreateHook } from "@prismicio/plugin-kit";
2
+ import type { PluginOptions } from "../types.js";
3
+ export declare const sliceCreate: SliceCreateHook<PluginOptions>;
@@ -0,0 +1,68 @@
1
+ import { writeSliceModel, upsertGlobalTypeScriptTypes, writeSliceFile } from "@prismicio/plugin-kit/fs";
2
+ import { stripIndent } from "common-tags";
3
+ import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
4
+ import { pascalCase } from "../lib/pascalCase.js";
5
+ import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
6
+ import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile.js";
7
+ var __freeze = Object.freeze;
8
+ var __defProp = Object.defineProperty;
9
+ var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
10
+ var _a, _b;
11
+ const createComponentFile = async ({ data, helpers, actions, options }) => {
12
+ const pascalName = pascalCase(data.model.name);
13
+ let contents;
14
+ const isTypeScriptProject = await checkIsTypeScriptProject({
15
+ helpers,
16
+ options
17
+ });
18
+ const placeholderInstructions = `
19
+ <br />
20
+ <strong>You can edit this slice directly in your code editor.</strong>
21
+ <!--
22
+ 💡 Use the Prismic MCP server with your code editor
23
+ 📚 Docs: https://prismic.io/docs/ai#code-with-prismics-mcp-server
24
+ -->`;
25
+ if (data.componentContents) {
26
+ contents = data.componentContents;
27
+ } else if (isTypeScriptProject) {
28
+ contents = stripIndent(_a || (_a = __template(['\n <script setup lang="ts">\n import type { Content } from "@prismicio/client";\n\n // The array passed to `getSliceComponentProps` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps<Content.', 'Slice>(\n ["slice", "index", "slices", "context"]\n ));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for ', " (variation: {{ slice.variation }}) slices.\n ", "\n </section>\n </template>\n "], ['\n <script setup lang="ts">\n import type { Content } from "@prismicio/client";\n\n // The array passed to \\`getSliceComponentProps\\` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps<Content.', 'Slice>(\n ["slice", "index", "slices", "context"]\n ));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for ', " (variation: {{ slice.variation }}) slices.\n ", "\n </section>\n </template>\n "])), pascalName, data.model.id, placeholderInstructions);
29
+ } else {
30
+ contents = stripIndent(_b || (_b = __template(['\n <script setup>\n // The array passed to `getSliceComponentProps` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps(["slice", "index", "slices", "context"]));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for {{ model.id }} (variation: {{ slice.variation }}) slices.\n ', "\n </section>\n </template>\n "], ['\n <script setup>\n // The array passed to \\`getSliceComponentProps\\` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps(["slice", "index", "slices", "context"]));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for {{ model.id }} (variation: {{ slice.variation }}) slices.\n ', "\n </section>\n </template>\n "])), placeholderInstructions);
31
+ }
32
+ await writeSliceFile({
33
+ libraryID: data.libraryID,
34
+ model: data.model,
35
+ filename: "index.vue",
36
+ contents,
37
+ format: options.format,
38
+ actions,
39
+ helpers
40
+ });
41
+ };
42
+ const sliceCreate = async (data, context) => {
43
+ rejectIfNecessary(await Promise.allSettled([
44
+ writeSliceModel({
45
+ libraryID: data.libraryID,
46
+ model: data.model,
47
+ format: context.options.format,
48
+ helpers: context.helpers
49
+ }),
50
+ createComponentFile({ data, ...context })
51
+ ]));
52
+ rejectIfNecessary(await Promise.allSettled([
53
+ upsertSliceLibraryIndexFile({
54
+ libraryID: data.libraryID,
55
+ ...context
56
+ }),
57
+ upsertGlobalTypeScriptTypes({
58
+ filename: context.options.generatedTypesFilePath,
59
+ format: context.options.format,
60
+ helpers: context.helpers,
61
+ actions: context.actions
62
+ })
63
+ ]));
64
+ };
65
+ export {
66
+ sliceCreate
67
+ };
68
+ //# sourceMappingURL=slice-create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slice-create.js","sources":["../../../src/hooks/slice-create.ts"],"sourcesContent":["import type {\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tPluginSystemContext,\n} from \"@prismicio/plugin-kit\";\nimport {\n\tupsertGlobalTypeScriptTypes,\n\twriteSliceFile,\n\twriteSliceModel,\n} from \"@prismicio/plugin-kit/fs\";\nimport { stripIndent } from \"common-tags\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { pascalCase } from \"../lib/pascalCase\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\nimport type { PluginOptions } from \"../types\";\n\ntype CreateComponentFileArgs = {\n\tdata: SliceCreateHookData;\n} & PluginSystemContext<PluginOptions>;\n\nconst createComponentFile = async ({\n\tdata,\n\thelpers,\n\tactions,\n\toptions,\n}: CreateComponentFileArgs) => {\n\tconst pascalName = pascalCase(data.model.name);\n\n\tlet contents: string;\n\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst placeholderInstructions = `\n\t\t<br />\n\t\t<strong>You can edit this slice directly in your code editor.</strong>\n\t\t<!--\n\t\t\t💡 Use the Prismic MCP server with your code editor\n\t\t\t📚 Docs: https://prismic.io/docs/ai#code-with-prismics-mcp-server\n\t\t-->`;\n\n\tif (data.componentContents) {\n\t\tcontents = data.componentContents;\n\t} else if (isTypeScriptProject) {\n\t\tcontents = stripIndent`\n\t\t\t<script setup lang=\"ts\">\n\t\t\timport type { Content } from \"@prismicio/client\";\n\n\t\t\t// The array passed to \\`getSliceComponentProps\\` is purely optional.\n\t\t\t// Consider it as a visual hint for you when templating your slice.\n\t\t\tdefineProps(getSliceComponentProps<Content.${pascalName}Slice>(\n\t\t\t\t[\"slice\", \"index\", \"slices\", \"context\"]\n\t\t\t));\n\t\t\t</script>\n\n\t\t\t<template>\n\t\t\t\t<section\n\t\t\t\t\t:data-slice-type=\"slice.slice_type\"\n\t\t\t\t\t:data-slice-variation=\"slice.variation\"\n\t\t\t\t>\n\t\t\t\t\tPlaceholder component for ${data.model.id} (variation: {{ slice.variation }}) slices.\n\t\t\t\t\t${placeholderInstructions}\n\t\t\t\t</section>\n\t\t\t</template>\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\t<script setup>\n\t\t\t// The array passed to \\`getSliceComponentProps\\` is purely optional.\n\t\t\t// Consider it as a visual hint for you when templating your slice.\n\t\t\tdefineProps(getSliceComponentProps([\"slice\", \"index\", \"slices\", \"context\"]));\n\t\t\t</script>\n\n\t\t\t<template>\n\t\t\t\t<section\n\t\t\t\t\t:data-slice-type=\"slice.slice_type\"\n\t\t\t\t\t:data-slice-variation=\"slice.variation\"\n\t\t\t\t>\n\t\t\t\t\tPlaceholder component for {{ model.id }} (variation: {{ slice.variation }}) slices.\n\t\t\t\t\t${placeholderInstructions}\n\t\t\t\t</section>\n\t\t\t</template>\n\t\t`;\n\t}\n\n\tawait writeSliceFile({\n\t\tlibraryID: data.libraryID,\n\t\tmodel: data.model,\n\t\tfilename: \"index.vue\",\n\t\tcontents,\n\t\tformat: options.format,\n\t\tactions,\n\t\thelpers,\n\t});\n};\n\nexport const sliceCreate: SliceCreateHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\twriteSliceModel({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\tmodel: data.model,\n\t\t\t\tformat: context.options.format,\n\t\t\t\thelpers: context.helpers,\n\t\t\t}),\n\t\t\tcreateComponentFile({ data, ...context }),\n\t\t]),\n\t);\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupsertSliceLibraryIndexFile({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\t...context,\n\t\t\t}),\n\t\t\tupsertGlobalTypeScriptTypes({\n\t\t\t\tfilename: context.options.generatedTypesFilePath,\n\t\t\t\tformat: context.options.format,\n\t\t\t\thelpers: context.helpers,\n\t\t\t\tactions: context.actions,\n\t\t\t}),\n\t\t]),\n\t);\n};\n"],"names":[],"mappings":";;;;;;;;;AAKA,IAAA,IAAA;AAiBA,MAAM,sBAAsB,OAAO,EAClC,MACA,SACA,SACA,cAC6B;AAC7B,QAAM,aAAa,WAAW,KAAK,MAAM,IAAI;AAE7C,MAAI;AAEJ,QAAM,sBAAsB,MAAM,yBAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AAED,QAAM,0BAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQhC,MAAI,KAAK,mBAAmB;AAC3B,eAAW,KAAK;AAAA,EACjB,WAAW,qBAAqB;AAC/B,eAAW,YAAA,OAAA,KAAW,WAAA,CAAA,yRAMkC,8OAUZ,sDAChB,sCAAA,GAjBN,CAAA,6RAMkC,8OAUZ,sDAChB,sCAAA,CAAA,IAXkB,YAUf,KAAK,MAAM,IACrC,uBAAA;AAAA,EAIN,OAAO;AACN,eAAW,YAAA,OAAA,KAAW,WAAA,CAAA,ueAaM,sCAAA,GAbN,CAAA,2eAaM,sCAAA,CAAA,IAAvB,uBAAA;AAAA,EAIN;AAEA,QAAM,eAAe;AAAA,IACpB,WAAW,KAAK;AAAA,IAChB,OAAO,KAAK;AAAA,IACZ,UAAU;AAAA,IACV;AAAA,IACA,QAAQ,QAAQ;AAAA,IAChB;AAAA,IACA;AAAA,EAAA,CACA;AACF;AAEO,MAAM,cAA8C,OAC1D,MACA,YACG;AACH,oBACC,MAAM,QAAQ,WAAW;AAAA,IACxB,gBAAgB;AAAA,MACf,WAAW,KAAK;AAAA,MAChB,OAAO,KAAK;AAAA,MACZ,QAAQ,QAAQ,QAAQ;AAAA,MACxB,SAAS,QAAQ;AAAA,IAAA,CACjB;AAAA,IACD,oBAAoB,EAAE,MAAM,GAAG,SAAS;AAAA,EAAA,CACxC,CAAC;AAGH,oBACC,MAAM,QAAQ,WAAW;AAAA,IACxB,4BAA4B;AAAA,MAC3B,WAAW,KAAK;AAAA,MAChB,GAAG;AAAA,IAAA,CACH;AAAA,IACD,4BAA4B;AAAA,MAC3B,UAAU,QAAQ,QAAQ;AAAA,MAC1B,QAAQ,QAAQ,QAAQ;AAAA,MACxB,SAAS,QAAQ;AAAA,MACjB,SAAS,QAAQ;AAAA,IAAA,CACjB;AAAA,EAAA,CACD,CAAC;AAEJ;"}
@@ -0,0 +1,3 @@
1
+ import { plugin } from "./plugin.js";
2
+ export default plugin;
3
+ export type { PluginOptions } from "./types.js";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { plugin } from "./plugin.js";
2
+ export {
3
+ plugin as default
4
+ };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,5 @@
1
+ import { PluginSystemHelpers } from "@prismicio/plugin-kit";
2
+ export declare function buildSrcPath(args: {
3
+ filename: string;
4
+ helpers: PluginSystemHelpers;
5
+ }): Promise<string>;
@@ -0,0 +1,23 @@
1
+ import * as path from "node:path";
2
+ import { checkHasProjectFile } from "@prismicio/plugin-kit/fs";
3
+ async function buildSrcPath(args) {
4
+ const hasAppDirectory = await checkHasProjectFile({
5
+ filename: "app",
6
+ helpers: args.helpers
7
+ });
8
+ if (hasAppDirectory) {
9
+ return path.join("app", args.filename);
10
+ }
11
+ const hasSrcDirectory = await checkHasProjectFile({
12
+ filename: "src",
13
+ helpers: args.helpers
14
+ });
15
+ if (hasSrcDirectory) {
16
+ return path.join("src", args.filename);
17
+ }
18
+ return args.filename;
19
+ }
20
+ export {
21
+ buildSrcPath
22
+ };
23
+ //# sourceMappingURL=buildSrcPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildSrcPath.js","sources":["../../../src/lib/buildSrcPath.ts"],"sourcesContent":["// TODO: If Nuxt provides a way to read `nuxt.config.js`'s `srcDir` value, we\n// can use the exact value given. The current implementation does not support\n// custom values different than \"app\" or \"src\".\nimport * as path from \"node:path\";\n\nimport { PluginSystemHelpers } from \"@prismicio/plugin-kit\";\nimport { checkHasProjectFile } from \"@prismicio/plugin-kit/fs\";\n\nexport async function buildSrcPath(args: {\n\tfilename: string;\n\thelpers: PluginSystemHelpers;\n}): Promise<string> {\n\tconst hasAppDirectory = await checkHasProjectFile({\n\t\tfilename: \"app\",\n\t\thelpers: args.helpers,\n\t});\n\tif (hasAppDirectory) {\n\t\treturn path.join(\"app\", args.filename);\n\t}\n\n\tconst hasSrcDirectory = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers: args.helpers,\n\t});\n\tif (hasSrcDirectory) {\n\t\treturn path.join(\"src\", args.filename);\n\t}\n\n\treturn args.filename;\n}\n"],"names":[],"mappings":";;AAQA,eAAsB,aAAa,MAGlC;AACA,QAAM,kBAAkB,MAAM,oBAAoB;AAAA,IACjD,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AACD,MAAI,iBAAiB;AACpB,WAAO,KAAK,KAAK,OAAO,KAAK,QAAQ;AAAA,EACtC;AAEA,QAAM,kBAAkB,MAAM,oBAAoB;AAAA,IACjD,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AACD,MAAI,iBAAiB;AACpB,WAAO,KAAK,KAAK,OAAO,KAAK,QAAQ;AAAA,EACtC;AAEA,SAAO,KAAK;AACb;"}
@@ -0,0 +1,8 @@
1
+ import { PluginSystemContext } from "@prismicio/plugin-kit";
2
+ import { PluginOptions } from "../types.js";
3
+ type CheckIsTypeScriptProjectArgs = {
4
+ helpers: PluginSystemContext<PluginOptions>["helpers"];
5
+ options: PluginSystemContext<PluginOptions>["options"];
6
+ };
7
+ export declare const checkIsTypeScriptProject: (args: CheckIsTypeScriptProjectArgs) => Promise<boolean>;
8
+ export {};
@@ -0,0 +1,8 @@
1
+ import { checkIsTypeScriptProject as checkIsTypeScriptProject$1 } from "@prismicio/plugin-kit/fs";
2
+ const checkIsTypeScriptProject = async (args) => {
3
+ return args.options.typescript ?? checkIsTypeScriptProject$1({ helpers: args.helpers });
4
+ };
5
+ export {
6
+ checkIsTypeScriptProject
7
+ };
8
+ //# sourceMappingURL=checkIsTypeScriptProject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkIsTypeScriptProject.js","sources":["../../../src/lib/checkIsTypeScriptProject.ts"],"sourcesContent":["import { PluginSystemContext } from \"@prismicio/plugin-kit\";\nimport { checkIsTypeScriptProject as baseCheckIsTypeScriptProject } from \"@prismicio/plugin-kit/fs\";\n\nimport { PluginOptions } from \"../types\";\n\ntype CheckIsTypeScriptProjectArgs = {\n\thelpers: PluginSystemContext<PluginOptions>[\"helpers\"];\n\toptions: PluginSystemContext<PluginOptions>[\"options\"];\n};\n\nexport const checkIsTypeScriptProject = async (\n\targs: CheckIsTypeScriptProjectArgs,\n): Promise<boolean> => {\n\treturn (\n\t\targs.options.typescript ??\n\t\tbaseCheckIsTypeScriptProject({ helpers: args.helpers })\n\t);\n};\n"],"names":["baseCheckIsTypeScriptProject"],"mappings":";AAUO,MAAM,2BAA2B,OACvC,SACqB;AACrB,SACC,KAAK,QAAQ,cACbA,2BAA6B,EAAE,SAAS,KAAK,SAAS;AAExD;"}
@@ -0,0 +1,5 @@
1
+ import { PluginSystemContext } from "@prismicio/plugin-kit";
2
+ import { PluginOptions } from "../types.js";
3
+ type GetJSFileExtensionArgs = Pick<PluginSystemContext<PluginOptions>, "helpers" | "options">;
4
+ export declare const getJSFileExtension: ({ helpers, options, }: GetJSFileExtensionArgs) => Promise<string>;
5
+ export {};
@@ -0,0 +1,12 @@
1
+ import { checkIsTypeScriptProject } from "./checkIsTypeScriptProject.js";
2
+ const getJSFileExtension = async ({ helpers, options }) => {
3
+ const isTypeScriptProject = await checkIsTypeScriptProject({
4
+ helpers,
5
+ options
6
+ });
7
+ return isTypeScriptProject ? "ts" : "js";
8
+ };
9
+ export {
10
+ getJSFileExtension
11
+ };
12
+ //# sourceMappingURL=getJSFileExtension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getJSFileExtension.js","sources":["../../../src/lib/getJSFileExtension.ts"],"sourcesContent":["import { PluginSystemContext } from \"@prismicio/plugin-kit\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { checkIsTypeScriptProject } from \"./checkIsTypeScriptProject\";\n\ntype GetJSFileExtensionArgs = Pick<\n\tPluginSystemContext<PluginOptions>,\n\t\"helpers\" | \"options\"\n>;\n\nexport const getJSFileExtension = async ({\n\thelpers,\n\toptions,\n}: GetJSFileExtensionArgs): Promise<string> => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\treturn isTypeScriptProject ? \"ts\" : \"js\";\n};\n"],"names":[],"mappings":";AAWO,MAAM,qBAAqB,OAAO,EACxC,SACA,cAC6C;AAC7C,QAAM,sBAAsB,MAAM,yBAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AAED,SAAO,sBAAsB,OAAO;AACrC;"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Converts a string to a Pascal cased string.
3
+ *
4
+ * @param input - String to convert into a Pascal cased string.
5
+ *
6
+ * @returns Pascal cased string version of `input`.
7
+ */
8
+ export declare const pascalCase: (...input: (string | undefined)[]) => string;
@@ -0,0 +1,8 @@
1
+ import { pascalCase as pascalCase$1 } from "pascal-case";
2
+ const pascalCase = (...input) => {
3
+ return pascalCase$1(input.filter(Boolean).join(" "));
4
+ };
5
+ export {
6
+ pascalCase
7
+ };
8
+ //# sourceMappingURL=pascalCase.js.map
@@ -0,0 +1 @@
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":";AASO,MAAM,aAAa,IAAI,UAAyC;AACtE,SAAOA,aAAe,MAAM,OAAO,OAAO,EAAE,KAAK,GAAG,CAAC;AACtD;"}
@@ -0,0 +1 @@
1
+ export declare const rejectIfNecessary: <TPromiseSettledResults extends readonly PromiseSettledResult<any>[]>(promiseSettledResults: TPromiseSettledResults) => void;
@@ -0,0 +1,10 @@
1
+ const rejectIfNecessary = (promiseSettledResults) => {
2
+ const rejectedReasons = promiseSettledResults.filter((result) => result.status === "rejected").map((result) => result.reason);
3
+ if (rejectedReasons.length > 0) {
4
+ throw rejectedReasons[0];
5
+ }
6
+ };
7
+ export {
8
+ rejectIfNecessary
9
+ };
10
+ //# sourceMappingURL=rejectIfNecessary.js.map
@@ -0,0 +1 @@
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":"AAAO,MAAM,oBAAoB,CAIhC,0BACS;AACT,QAAM,kBAAkB,sBACtB,OACA,CAAC,WAA4C,OAAO,WAAW,UAAU,EAEzE,IAAI,CAAC,WAAW,OAAO,MAAM;AAE/B,MAAI,gBAAgB,SAAS,GAAG;AAC/B,UAAM,gBAAgB,CAAC;AAAA,EACxB;AACD;"}
@@ -0,0 +1,7 @@
1
+ import { PluginSystemContext } from "@prismicio/plugin-kit";
2
+ import { PluginOptions } from "../types.js";
3
+ type UpsertSliceLibraryIndexFileArgs = {
4
+ libraryID: string;
5
+ } & PluginSystemContext<PluginOptions>;
6
+ export declare const upsertSliceLibraryIndexFile: (args: UpsertSliceLibraryIndexFileArgs) => Promise<void>;
7
+ export {};
@@ -0,0 +1,74 @@
1
+ import * as path from "node:path";
2
+ import { buildSliceDirectoryPath, buildSliceLibraryDirectoryPath, writeProjectFile } from "@prismicio/plugin-kit/fs";
3
+ import { stripIndent } from "common-tags";
4
+ import { NON_EDITABLE_FILE_BANNER } from "../constants.js";
5
+ import { getJSFileExtension } from "./getJSFileExtension.js";
6
+ import { pascalCase } from "./pascalCase.js";
7
+ const upsertSliceLibraryIndexFile = async (args) => {
8
+ const slices = await args.actions.readAllSliceModelsForLibrary({
9
+ libraryID: args.libraryID
10
+ });
11
+ let contents;
12
+ if (args.options.lazyLoadSlices) {
13
+ contents = stripIndent`
14
+ ${NON_EDITABLE_FILE_BANNER}
15
+
16
+ import { defineAsyncComponent } from "vue";
17
+ import { defineSliceZoneComponents } from "@prismicio/vue";
18
+
19
+ export const components = defineSliceZoneComponents({
20
+ ${(await Promise.all(slices.map(async (slice) => {
21
+ const id = slice.model.id;
22
+ const dirName = path.basename(await buildSliceDirectoryPath({
23
+ model: slice.model,
24
+ helpers: args.helpers,
25
+ libraryID: args.libraryID
26
+ }));
27
+ return `${id}: defineAsyncComponent(() => import("./${dirName}/index.vue"))`;
28
+ }))).join(",\n")}
29
+ });
30
+ `;
31
+ } else {
32
+ contents = stripIndent`
33
+ ${NON_EDITABLE_FILE_BANNER}
34
+
35
+ import { defineSliceZoneComponents } from "@prismicio/vue";
36
+
37
+ ${(await Promise.all(slices.map(async (slice) => {
38
+ const dirName = path.basename(await buildSliceDirectoryPath({
39
+ model: slice.model,
40
+ helpers: args.helpers,
41
+ libraryID: args.libraryID
42
+ }));
43
+ const componentName = pascalCase(slice.model.name);
44
+ return `import ${componentName} from "./${dirName}/index.vue";`;
45
+ }))).join("\n")}
46
+
47
+ export const components = defineSliceZoneComponents({
48
+ ${slices.map((slice) => {
49
+ const id = slice.model.id;
50
+ const componentName = pascalCase(slice.model.name);
51
+ return `${id}: ${componentName}`;
52
+ }).join(",\n")}
53
+ });
54
+ `;
55
+ }
56
+ const extension = await getJSFileExtension({
57
+ helpers: args.helpers,
58
+ options: args.options
59
+ });
60
+ const filePath = path.join(buildSliceLibraryDirectoryPath({
61
+ libraryID: args.libraryID,
62
+ helpers: args.helpers
63
+ }), `index.${extension}`);
64
+ await writeProjectFile({
65
+ filename: filePath,
66
+ contents,
67
+ format: args.options.format,
68
+ helpers: args.helpers
69
+ });
70
+ };
71
+ export {
72
+ upsertSliceLibraryIndexFile
73
+ };
74
+ //# sourceMappingURL=upsertSliceLibraryIndexFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upsertSliceLibraryIndexFile.js","sources":["../../../src/lib/upsertSliceLibraryIndexFile.ts"],"sourcesContent":["import * as path from \"node:path\";\n\nimport { PluginSystemContext } from \"@prismicio/plugin-kit\";\nimport {\n\tbuildSliceDirectoryPath,\n\tbuildSliceLibraryDirectoryPath,\n\twriteProjectFile,\n} from \"@prismicio/plugin-kit/fs\";\nimport { stripIndent } from \"common-tags\";\n\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\nimport { PluginOptions } from \"../types\";\n\nimport { getJSFileExtension } from \"./getJSFileExtension\";\nimport { pascalCase } from \"./pascalCase\";\n\ntype UpsertSliceLibraryIndexFileArgs = {\n\tlibraryID: string;\n} & PluginSystemContext<PluginOptions>;\n\nexport const upsertSliceLibraryIndexFile = async (\n\targs: UpsertSliceLibraryIndexFileArgs,\n): Promise<void> => {\n\tconst slices = await args.actions.readAllSliceModelsForLibrary({\n\t\tlibraryID: args.libraryID,\n\t});\n\n\tlet contents: string;\n\n\tif (args.options.lazyLoadSlices) {\n\t\tcontents = stripIndent`\n\t\t\t${NON_EDITABLE_FILE_BANNER}\n\n\t\t\timport { defineAsyncComponent } from \"vue\";\n\t\t\timport { defineSliceZoneComponents } from \"@prismicio/vue\";\n\n\t\t\texport const components = defineSliceZoneComponents({\n\t\t\t\t${(\n\t\t\t\t\tawait Promise.all(\n\t\t\t\t\t\tslices.map(async (slice) => {\n\t\t\t\t\t\t\tconst id = slice.model.id;\n\t\t\t\t\t\t\tconst dirName = path.basename(\n\t\t\t\t\t\t\t\tawait buildSliceDirectoryPath({\n\t\t\t\t\t\t\t\t\tmodel: slice.model,\n\t\t\t\t\t\t\t\t\thelpers: args.helpers,\n\t\t\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\treturn `${id}: defineAsyncComponent(() => import(\"./${dirName}/index.vue\"))`;\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t).join(\",\\n\")}\n\t\t\t});\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\t${NON_EDITABLE_FILE_BANNER}\n\n\t\t\timport { defineSliceZoneComponents } from \"@prismicio/vue\";\n\n\t\t\t${(\n\t\t\t\tawait Promise.all(\n\t\t\t\t\tslices.map(async (slice) => {\n\t\t\t\t\t\tconst dirName = path.basename(\n\t\t\t\t\t\t\tawait buildSliceDirectoryPath({\n\t\t\t\t\t\t\t\tmodel: slice.model,\n\t\t\t\t\t\t\t\thelpers: args.helpers,\n\t\t\t\t\t\t\t\tlibraryID: args.libraryID,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst componentName = pascalCase(slice.model.name);\n\n\t\t\t\t\t\treturn `import ${componentName} from \"./${dirName}/index.vue\";`;\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t).join(\"\\n\")}\n\n\t\t\texport const components = defineSliceZoneComponents({\n\t\t\t\t${slices\n\t\t\t\t\t.map((slice) => {\n\t\t\t\t\t\tconst id = slice.model.id;\n\t\t\t\t\t\tconst componentName = pascalCase(slice.model.name);\n\n\t\t\t\t\t\treturn `${id}: ${componentName}`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\",\\n\")}\n\t\t\t});\n\t\t`;\n\t}\n\n\tconst extension = await getJSFileExtension({\n\t\thelpers: args.helpers,\n\t\toptions: args.options,\n\t});\n\tconst filePath = path.join(\n\t\tbuildSliceLibraryDirectoryPath({\n\t\t\tlibraryID: args.libraryID,\n\t\t\thelpers: args.helpers,\n\t\t}),\n\t\t`index.${extension}`,\n\t);\n\n\tawait writeProjectFile({\n\t\tfilename: filePath,\n\t\tcontents,\n\t\tformat: args.options.format,\n\t\thelpers: args.helpers,\n\t});\n};\n"],"names":[],"mappings":";;;;;;AAoBO,MAAM,8BAA8B,OAC1C,SACkB;AAClB,QAAM,SAAS,MAAM,KAAK,QAAQ,6BAA6B;AAAA,IAC9D,WAAW,KAAK;AAAA,EAAA,CAChB;AAED,MAAI;AAEJ,MAAI,KAAK,QAAQ,gBAAgB;AAChC,eAAW;AAAA,KACR,wBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAOxB,MAAM,QAAQ,IACb,OAAO,IAAI,OAAO,UAAS;AAC1B,YAAM,KAAK,MAAM,MAAM;AACvB,YAAM,UAAU,KAAK,SACpB,MAAM,w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3
+ name
4
+ };
5
+ //# sourceMappingURL=package.json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,2 @@
1
+ import { PluginOptions } from "./types.js";
2
+ export declare const plugin: import("@prismicio/plugin-kit").Plugin<PluginOptions>;