@slicemachine/adapter-next 0.3.43-alpha.lg-nested-group-snippets.2 → 0.3.43-beta.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.
- package/dist/hooks/project-init.cjs +29 -42
- package/dist/hooks/project-init.cjs.map +1 -1
- package/dist/hooks/project-init.js +29 -25
- package/dist/hooks/project-init.js.map +1 -1
- package/dist/hooks/snippet-read.cjs +3 -3
- package/dist/hooks/snippet-read.cjs.map +1 -1
- package/dist/hooks/snippet-read.js +3 -3
- package/dist/hooks/snippet-read.js.map +1 -1
- package/dist/lib/buildSrcPath.cjs +30 -0
- package/dist/lib/buildSrcPath.cjs.map +1 -0
- package/dist/lib/buildSrcPath.d.ts +5 -0
- package/dist/lib/buildSrcPath.js +13 -0
- package/dist/lib/buildSrcPath.js.map +1 -0
- package/dist/lib/checkHasAppRouter.cjs +6 -21
- package/dist/lib/checkHasAppRouter.cjs.map +1 -1
- package/dist/lib/checkHasAppRouter.js +6 -4
- package/dist/lib/checkHasAppRouter.js.map +1 -1
- package/package.json +4 -4
- package/src/hooks/project-init.ts +35 -52
- package/src/hooks/snippet-read.ts +3 -3
- package/src/lib/buildSrcPath.ts +16 -0
- package/src/lib/checkHasAppRouter.ts +7 -4
- package/dist/lib/checkHasSrcDirectory.cjs +0 -11
- package/dist/lib/checkHasSrcDirectory.cjs.map +0 -1
- package/dist/lib/checkHasSrcDirectory.d.ts +0 -5
- package/dist/lib/checkHasSrcDirectory.js +0 -11
- package/dist/lib/checkHasSrcDirectory.js.map +0 -1
- package/src/lib/checkHasSrcDirectory.ts +0 -18
|
@@ -1,31 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const path = require("node:path");
|
|
4
3
|
const fs = require("@slicemachine/plugin-kit/fs");
|
|
5
4
|
const commonTags = require("common-tags");
|
|
5
|
+
const buildSrcPath = require("../lib/buildSrcPath.cjs");
|
|
6
6
|
const checkHasAppRouter = require("../lib/checkHasAppRouter.cjs");
|
|
7
|
-
const checkHasSrcDirectory = require("../lib/checkHasSrcDirectory.cjs");
|
|
8
7
|
const checkIsTypeScriptProject = require("../lib/checkIsTypeScriptProject.cjs");
|
|
9
8
|
const getJSFileExtension = require("../lib/getJSFileExtension.cjs");
|
|
10
9
|
const rejectIfNecessary = require("../lib/rejectIfNecessary.cjs");
|
|
11
10
|
const constants = require("../constants.cjs");
|
|
12
|
-
function _interopNamespaceDefault(e) {
|
|
13
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
14
|
-
if (e) {
|
|
15
|
-
for (const k in e) {
|
|
16
|
-
if (k !== "default") {
|
|
17
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: () => e[k]
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
n.default = e;
|
|
26
|
-
return Object.freeze(n);
|
|
27
|
-
}
|
|
28
|
-
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
29
11
|
const installDependencies = async ({ installDependencies: installDependencies2 }) => {
|
|
30
12
|
await installDependencies2({
|
|
31
13
|
dependencies: {
|
|
@@ -40,10 +22,16 @@ const createPrismicIOFile = async ({ helpers, options }) => {
|
|
|
40
22
|
helpers,
|
|
41
23
|
options
|
|
42
24
|
});
|
|
43
|
-
const hasSrcDirectory = await
|
|
25
|
+
const hasSrcDirectory = await fs.checkHasProjectFile({
|
|
26
|
+
filename: "src",
|
|
27
|
+
helpers
|
|
28
|
+
});
|
|
44
29
|
const hasAppRouter = await checkHasAppRouter.checkHasAppRouter({ helpers });
|
|
45
30
|
const extension = await getJSFileExtension.getJSFileExtension({ helpers, options });
|
|
46
|
-
const filename =
|
|
31
|
+
const filename = await buildSrcPath.buildSrcPath({
|
|
32
|
+
filename: `prismicio.${extension}`,
|
|
33
|
+
helpers
|
|
34
|
+
});
|
|
47
35
|
if (await fs.checkHasProjectFile({ filename, helpers })) {
|
|
48
36
|
return;
|
|
49
37
|
}
|
|
@@ -233,13 +221,12 @@ const createSliceSimulatorPage = async ({ helpers, options }) => {
|
|
|
233
221
|
helpers,
|
|
234
222
|
options
|
|
235
223
|
});
|
|
236
|
-
const hasSrcDirectory = await checkHasSrcDirectory.checkHasSrcDirectory({ helpers });
|
|
237
224
|
const hasAppRouter = await checkHasAppRouter.checkHasAppRouter({ helpers });
|
|
238
225
|
const extension = await getJSFileExtension.getJSFileExtension({ helpers, options, jsx: true });
|
|
239
|
-
const filename =
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
226
|
+
const filename = await buildSrcPath.buildSrcPath({
|
|
227
|
+
filename: hasAppRouter ? `app/slice-simulator/page.${extension}` : `pages/slice-simulator.${extension}`,
|
|
228
|
+
helpers
|
|
229
|
+
});
|
|
243
230
|
if (await fs.checkHasProjectFile({ filename, helpers })) {
|
|
244
231
|
return;
|
|
245
232
|
}
|
|
@@ -313,17 +300,16 @@ const createSliceSimulatorPage = async ({ helpers, options }) => {
|
|
|
313
300
|
});
|
|
314
301
|
};
|
|
315
302
|
const createPreviewRoute = async ({ helpers, options }) => {
|
|
316
|
-
const hasSrcDirectory = await checkHasSrcDirectory.checkHasSrcDirectory({ helpers });
|
|
317
303
|
const hasAppRouter = await checkHasAppRouter.checkHasAppRouter({ helpers });
|
|
318
304
|
const isTypeScriptProject = await checkIsTypeScriptProject.checkIsTypeScriptProject({
|
|
319
305
|
helpers,
|
|
320
306
|
options
|
|
321
307
|
});
|
|
322
308
|
const extension = await getJSFileExtension.getJSFileExtension({ helpers, options });
|
|
323
|
-
const filename =
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
309
|
+
const filename = await buildSrcPath.buildSrcPath({
|
|
310
|
+
filename: hasAppRouter ? `app/api/preview/route.${extension}` : `pages/api/preview.${extension}`,
|
|
311
|
+
helpers
|
|
312
|
+
});
|
|
327
313
|
if (await fs.checkHasProjectFile({ filename, helpers })) {
|
|
328
314
|
return;
|
|
329
315
|
}
|
|
@@ -395,17 +381,16 @@ const createPreviewRoute = async ({ helpers, options }) => {
|
|
|
395
381
|
});
|
|
396
382
|
};
|
|
397
383
|
const createExitPreviewRoute = async ({ helpers, options }) => {
|
|
398
|
-
const hasSrcDirectory = await checkHasSrcDirectory.checkHasSrcDirectory({ helpers });
|
|
399
384
|
const hasAppRouter = await checkHasAppRouter.checkHasAppRouter({ helpers });
|
|
400
385
|
const isTypeScriptProject = await checkIsTypeScriptProject.checkIsTypeScriptProject({
|
|
401
386
|
helpers,
|
|
402
387
|
options
|
|
403
388
|
});
|
|
404
389
|
const extension = await getJSFileExtension.getJSFileExtension({ helpers, options });
|
|
405
|
-
const filename =
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
390
|
+
const filename = await buildSrcPath.buildSrcPath({
|
|
391
|
+
filename: hasAppRouter ? `app/api/exit-preview/route.${extension}` : `pages/api/exit-preview.${extension}`,
|
|
392
|
+
helpers
|
|
393
|
+
});
|
|
409
394
|
if (await fs.checkHasProjectFile({ filename, helpers })) {
|
|
410
395
|
return;
|
|
411
396
|
}
|
|
@@ -447,7 +432,10 @@ const createExitPreviewRoute = async ({ helpers, options }) => {
|
|
|
447
432
|
};
|
|
448
433
|
const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
|
|
449
434
|
var _a;
|
|
450
|
-
const hasSrcDirectory = await
|
|
435
|
+
const hasSrcDirectory = await fs.checkHasProjectFile({
|
|
436
|
+
filename: "src",
|
|
437
|
+
helpers
|
|
438
|
+
});
|
|
451
439
|
const project = await helpers.getProject();
|
|
452
440
|
(_a = project.config).localSliceSimulatorURL || (_a.localSliceSimulatorURL = "http://localhost:3000/slice-simulator");
|
|
453
441
|
if (hasSrcDirectory && project.config.libraries && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
|
|
@@ -467,12 +455,11 @@ const createRevalidateRoute = async ({ helpers, options }) => {
|
|
|
467
455
|
if (!hasAppRouter) {
|
|
468
456
|
return;
|
|
469
457
|
}
|
|
470
|
-
const hasSrcDirectory = await checkHasSrcDirectory.checkHasSrcDirectory({ helpers });
|
|
471
458
|
const extension = await getJSFileExtension.getJSFileExtension({ helpers, options });
|
|
472
|
-
const filename =
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
459
|
+
const filename = await buildSrcPath.buildSrcPath({
|
|
460
|
+
filename: `app/api/revalidate/route.${extension}`,
|
|
461
|
+
helpers
|
|
462
|
+
});
|
|
476
463
|
if (await fs.checkHasProjectFile({ filename, helpers })) {
|
|
477
464
|
return;
|
|
478
465
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-init.cjs","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport {\n\tcheckHasProjectFile,\n\twriteProjectFile,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { source } from \"common-tags\";\n\nimport { checkHasAppRouter } from \"../lib/checkHasAppRouter\";\nimport { checkHasSrcDirectory } from \"../lib/checkHasSrcDirectory\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSFileExtension } from \"../lib/getJSFileExtension\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\n\nimport type { PluginOptions } from \"../types\";\nimport { PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME } from \"../constants\";\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\"@prismicio/client\": \"latest\",\n\t\t\t\"@prismicio/react\": \"latest\",\n\t\t\t\"@prismicio/next\": \"latest\",\n\t\t},\n\t});\n};\n\ntype CreatePrismicIOFileArgs = SliceMachineContext<PluginOptions>;\n\nconst createPrismicIOFile = async ({\n\thelpers,\n\toptions,\n}: CreatePrismicIOFileArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(\n\t\t...[hasSrcDirectory ? \"src\" : undefined, `prismicio.${extension}`].filter(\n\t\t\t(segment): segment is NonNullable<typeof segment> => Boolean(segment),\n\t\t),\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet createClientContents: string;\n\n\tif (hasAppRouter) {\n\t\tif (isTypeScriptProject) {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config: prismicNext.CreateClientConfig = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\tfetchOptions:\n\t\t\t\t\t\t\tprocess.env.NODE_ENV === 'production'\n\t\t\t\t\t\t\t\t? { next: { tags: ['prismic'] }, cache: 'force-cache' }\n\t\t\t\t\t\t\t\t: { next: { revalidate: 5 } },\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t} else {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\tfetchOptions:\n\t\t\t\t\t\t\tprocess.env.NODE_ENV === 'production'\n\t\t\t\t\t\t\t\t? { next: { tags: ['prismic'] }, cache: 'force-cache' }\n\t\t\t\t\t\t\t\t: { next: { revalidate: 5 } },\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t}\n\t} else {\n\t\tif (isTypeScriptProject) {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config: prismicNext.CreateClientConfig = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t} else {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t}\n\t}\n\n\tlet contents: string;\n\n\tif (isTypeScriptProject) {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\n\t\t\timport config from \"${hasSrcDirectory ? \"..\" : \".\"}/slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName =\n\t\t\t\tprocess.env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes: prismic.ClientConfig[\"routes\"] = [\n\t\t\t\t// Examples:\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"homepage\",\n\t\t\t\t// \tpath: \"/\",\n\t\t\t\t// },\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"page\",\n\t\t\t\t// \tpath: \"/:uid\",\n\t\t\t\t// },\n\t\t\t];\n\n\t\t\t${createClientContents}\n\t\t`;\n\t} else {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\n\t\t\timport config from \"${hasSrcDirectory ? \"..\" : \".\"}/slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName =\n\t\t\t\tprocess.env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t *\n\t\t\t * @type {prismic.ClientConfig[\"routes\"]}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes = [\n\t\t\t\t// Examples:\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"homepage\",\n\t\t\t\t// \tpath: \"/\",\n\t\t\t\t// },\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"page\",\n\t\t\t\t// \tpath: \"/:uid\",\n\t\t\t\t// },\n\t\t\t];\n\n\t\t\t${createClientContents}\n\t\t`;\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\n\tconst extension = await getJSFileExtension({ helpers, options, jsx: true });\n\tconst filename = path.join(\n\t\t...[\n\t\t\thasSrcDirectory ? \"src\" : undefined,\n\t\t\thasAppRouter\n\t\t\t\t? `app/slice-simulator/page.${extension}`\n\t\t\t\t: `pages/slice-simulator.${extension}`,\n\t\t].filter((segment): segment is NonNullable<typeof segment> =>\n\t\t\tBoolean(segment),\n\t\t),\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet contents;\n\n\tif (hasAppRouter) {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport {\n\t\t\t\t\tSliceSimulator,\n\t\t\t\t\tSliceSimulatorParams,\n\t\t\t\t\tgetSlices,\n\t\t\t\t} from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage({\n\t\t\t\t\tsearchParams,\n\t\t\t\t}: SliceSimulatorParams) {\n\t\t\t\t\tconst slices = getSlices(searchParams.state);\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator>\n\t\t\t\t\t\t\t<SliceZone slices={slices} components={components} />\n\t\t\t\t\t\t</SliceSimulator>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport {\n\t\t\t\t\tSliceSimulator,\n\t\t\t\t\tgetSlices,\n\t\t\t\t} from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage({ searchParams }) {\n\t\t\t\t\tconst slices = getSlices(searchParams.state);\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator>\n\t\t\t\t\t\t\t<SliceZone slices={slices} components={components} />\n\t\t\t\t\t\t</SliceSimulator>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\t} else {\n\t\tcontents = source`\n\t\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\timport { components } from \"../slices\";\n\n\t\t\texport default function SliceSimulatorPage() {\n\t\t\t\treturn (\n\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t`;\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createPreviewRoute = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(\n\t\t...[\n\t\t\thasSrcDirectory ? \"src\" : undefined,\n\t\t\thasAppRouter\n\t\t\t\t? `app/api/preview/route.${extension}`\n\t\t\t\t: `pages/api/preview.${extension}`,\n\t\t].filter((segment): segment is NonNullable<typeof segment> =>\n\t\t\tBoolean(segment),\n\t\t),\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet contents: string;\n\n\tif (hasAppRouter) {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport { NextRequest } from \"next/server\";\n\t\t\t\timport { redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../../prismicio\";\n\n\t\t\t\texport async function GET(request: NextRequest) {\n\t\t\t\t\tconst client = createClient();\n\n\t\t\t\t\treturn await redirectToPreviewURL({ client, request });\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport { redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../../prismicio\";\n\n\t\t\t\texport async function GET(request) {\n\t\t\t\t\tconst client = createClient();\n\n\t\t\t\t\treturn await redirectToPreviewURL({ client, request });\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\t} else {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport { NextApiRequest, NextApiResponse } from \"next\";\n\t\t\t\timport { setPreviewData, redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../prismicio\";\n\n\t\t\t\texport default async function handler(req: NextApiRequest, res: NextApiResponse) {\n\t\t\t\t\tconst client = createClient({ req });\n\n\t\t\t\t\tawait setPreviewData({ req, res });\n\n\t\t\t\t\treturn await redirectToPreviewURL({ req, res, client });\n\t\t\t\t};\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport { setPreviewData, redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../prismicio\";\n\n\t\t\t\texport default async function handler(req, res) {\n\t\t\t\t\tconst client = createClient({ req });\n\n\t\t\t\t\tawait setPreviewData({ req, res });\n\n\t\t\t\t\treturn await redirectToPreviewURL({ req, res, client });\n\t\t\t\t};\n\t\t\t`;\n\t\t}\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createExitPreviewRoute = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(\n\t\t...[\n\t\t\thasSrcDirectory ? \"src\" : undefined,\n\t\t\thasAppRouter\n\t\t\t\t? `app/api/exit-preview/route.${extension}`\n\t\t\t\t: `pages/api/exit-preview.${extension}`,\n\t\t].filter((segment): segment is NonNullable<typeof segment> =>\n\t\t\tBoolean(segment),\n\t\t),\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet contents: string;\n\n\tif (hasAppRouter) {\n\t\tcontents = source`\n\t\t\timport { exitPreview } from \"@prismicio/next\";\n\n\t\t\texport function GET() {\n\t\t\t\treturn exitPreview();\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport { NextApiRequest, NextApiResponse } from \"next\";\n\t\t\t\timport { exitPreview } from \"@prismicio/next\";\n\n\t\t\t\texport default function handler(req: NextApiRequest, res: NextApiResponse) {\n\t\t\t\t\treturn exitPreview({ req, res });\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport { exitPreview } from \"@prismicio/next\";\n\n\t\t\t\texport default function handler(req, res) {\n\t\t\t\t\treturn exitPreview({ req, res });\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst modifySliceMachineConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\n\tconst project = await helpers.getProject();\n\n\t// Add Slice Simulator URL.\n\tproject.config.localSliceSimulatorURL ||=\n\t\t\"http://localhost:3000/slice-simulator\";\n\n\t// Nest the default Slice Library in the src directory if it exists and\n\t// is empty.\n\tif (\n\t\thasSrcDirectory &&\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 = [\"./src/slices\"];\n\t\t}\n\t}\n\n\tawait helpers.updateSliceMachineConfig(project.config, {\n\t\tformat: options.format,\n\t});\n};\n\nconst createRevalidateRoute = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\n\tif (!hasAppRouter) {\n\t\treturn;\n\t}\n\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(\n\t\t...[\n\t\t\thasSrcDirectory ? \"src\" : undefined,\n\t\t\t`app/api/revalidate/route.${extension}`,\n\t\t].filter((segment): segment is NonNullable<typeof segment> =>\n\t\t\tBoolean(segment),\n\t\t),\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\timport { NextResponse } from \"next/server\";\n\t\timport { revalidateTag } from \"next/cache\";\n\n\t\texport async function POST() {\n\t\t\trevalidateTag(\"prismic\");\n\n\t\t\treturn NextResponse.json({ revalidated: true, now: Date.now() });\n\t\t}\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\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\tmodifySliceMachineConfig(context),\n\t\t\tcreatePrismicIOFile(context),\n\t\t\tcreateSliceSimulatorPage(context),\n\t\t\tcreatePreviewRoute(context),\n\t\t\tcreateExitPreviewRoute(context),\n\t\t\tcreateRevalidateRoute(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies","checkIsTypeScriptProject","checkHasSrcDirectory","checkHasAppRouter","getJSFileExtension","path","checkHasProjectFile","source","PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME","writeProjectFile","rejectIfNecessary"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAM,sBAAsB,OAAO,EAClC,qBAAA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AAI,CAAC,cAAc;AAClB;AAAA,EACA;AAED,QAAM,kBAAkB,MAAMD,qBAAAA,qBAAqB,EAAE,QAAS,CAAA;AAE9D,QAAM,YAAY,MAAME,mBAAA,mBAAmB,EAAE,SAAS,QAAS,CAAA;AACzD,QAAA,WAAWC,gBAAK,KACrB,GAAG;AAAA,IACF,kBAAkB,QAAQ;AAAA,IAC1B,4BAA4B;AAAA,EAAA,EAC3B,OAAO,CAAC,YACT,QAAQ,OAAO,CAAC,CAChB;AAGF,MAAI,MAAMC,GAAAA,oBAAoB,EAAE,UAAU,QAAS,CAAA,GAAG;AACrD;AAAA,EACA;AAED,QAAM,WAAWC,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAWjB,QAAME,oBAAiB;AAAA,IACtB;AAAA,IACA;AAAA,IACA,QAAQ,QAAQ;AAAA,IAChB;AAAA,EAAA,CACA;AACF;AAEO,MAAM,cAA8C,OAC1D,EAAE,qBAAqB,qBAAA,GACvB,YACG;AAEFC,sCAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,oBAAoB,EAAE,qBAAqB,sBAAsB;AAAA,IACjE,yBAAyB,OAAO;AAAA,IAChC,oBAAoB,OAAO;AAAA,IAC3B,yBAAyB,OAAO;AAAA,IAChC,mBAAmB,OAAO;AAAA,IAC1B,uBAAuB,OAAO;AAAA,IAC9B,sBAAsB,OAAO;AAAA,EAC7B,CAAA,CAAC;AAEJ;;"}
|
|
1
|
+
{"version":3,"file":"project-init.cjs","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport {\n\tcheckHasProjectFile,\n\twriteProjectFile,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { source } from \"common-tags\";\n\nimport { buildSrcPath } from \"../lib/buildSrcPath\";\nimport { checkHasAppRouter } from \"../lib/checkHasAppRouter\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSFileExtension } from \"../lib/getJSFileExtension\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\n\nimport type { PluginOptions } from \"../types\";\nimport { PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME } from \"../constants\";\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\"@prismicio/client\": \"latest\",\n\t\t\t\"@prismicio/react\": \"latest\",\n\t\t\t\"@prismicio/next\": \"latest\",\n\t\t},\n\t});\n};\n\ntype CreatePrismicIOFileArgs = SliceMachineContext<PluginOptions>;\n\nconst createPrismicIOFile = async ({\n\thelpers,\n\toptions,\n}: CreatePrismicIOFileArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\tconst hasSrcDirectory = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers,\n\t});\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = await buildSrcPath({\n\t\tfilename: `prismicio.${extension}`,\n\t\thelpers,\n\t});\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet createClientContents: string;\n\n\tif (hasAppRouter) {\n\t\tif (isTypeScriptProject) {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config: prismicNext.CreateClientConfig = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\tfetchOptions:\n\t\t\t\t\t\t\tprocess.env.NODE_ENV === 'production'\n\t\t\t\t\t\t\t\t? { next: { tags: ['prismic'] }, cache: 'force-cache' }\n\t\t\t\t\t\t\t\t: { next: { revalidate: 5 } },\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t} else {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\tfetchOptions:\n\t\t\t\t\t\t\tprocess.env.NODE_ENV === 'production'\n\t\t\t\t\t\t\t\t? { next: { tags: ['prismic'] }, cache: 'force-cache' }\n\t\t\t\t\t\t\t\t: { next: { revalidate: 5 } },\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t}\n\t} else {\n\t\tif (isTypeScriptProject) {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config: prismicNext.CreateClientConfig = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t} else {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t}\n\t}\n\n\tlet contents: string;\n\n\tif (isTypeScriptProject) {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\n\t\t\timport config from \"${hasSrcDirectory ? \"..\" : \".\"}/slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName =\n\t\t\t\tprocess.env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes: prismic.ClientConfig[\"routes\"] = [\n\t\t\t\t// Examples:\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"homepage\",\n\t\t\t\t// \tpath: \"/\",\n\t\t\t\t// },\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"page\",\n\t\t\t\t// \tpath: \"/:uid\",\n\t\t\t\t// },\n\t\t\t];\n\n\t\t\t${createClientContents}\n\t\t`;\n\t} else {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\n\t\t\timport config from \"${hasSrcDirectory ? \"..\" : \".\"}/slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName =\n\t\t\t\tprocess.env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t *\n\t\t\t * @type {prismic.ClientConfig[\"routes\"]}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes = [\n\t\t\t\t// Examples:\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"homepage\",\n\t\t\t\t// \tpath: \"/\",\n\t\t\t\t// },\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"page\",\n\t\t\t\t// \tpath: \"/:uid\",\n\t\t\t\t// },\n\t\t\t];\n\n\t\t\t${createClientContents}\n\t\t`;\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\n\tconst extension = await getJSFileExtension({ helpers, options, jsx: true });\n\tconst filename = await buildSrcPath({\n\t\tfilename: hasAppRouter\n\t\t\t? `app/slice-simulator/page.${extension}`\n\t\t\t: `pages/slice-simulator.${extension}`,\n\t\thelpers,\n\t});\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet contents;\n\n\tif (hasAppRouter) {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport {\n\t\t\t\t\tSliceSimulator,\n\t\t\t\t\tSliceSimulatorParams,\n\t\t\t\t\tgetSlices,\n\t\t\t\t} from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage({\n\t\t\t\t\tsearchParams,\n\t\t\t\t}: SliceSimulatorParams) {\n\t\t\t\t\tconst slices = getSlices(searchParams.state);\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator>\n\t\t\t\t\t\t\t<SliceZone slices={slices} components={components} />\n\t\t\t\t\t\t</SliceSimulator>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport {\n\t\t\t\t\tSliceSimulator,\n\t\t\t\t\tgetSlices,\n\t\t\t\t} from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage({ searchParams }) {\n\t\t\t\t\tconst slices = getSlices(searchParams.state);\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator>\n\t\t\t\t\t\t\t<SliceZone slices={slices} components={components} />\n\t\t\t\t\t\t</SliceSimulator>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\t} else {\n\t\tcontents = source`\n\t\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\timport { components } from \"../slices\";\n\n\t\t\texport default function SliceSimulatorPage() {\n\t\t\t\treturn (\n\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t`;\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createPreviewRoute = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = await buildSrcPath({\n\t\tfilename: hasAppRouter\n\t\t\t? `app/api/preview/route.${extension}`\n\t\t\t: `pages/api/preview.${extension}`,\n\t\thelpers,\n\t});\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet contents: string;\n\n\tif (hasAppRouter) {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport { NextRequest } from \"next/server\";\n\t\t\t\timport { redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../../prismicio\";\n\n\t\t\t\texport async function GET(request: NextRequest) {\n\t\t\t\t\tconst client = createClient();\n\n\t\t\t\t\treturn await redirectToPreviewURL({ client, request });\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport { redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../../prismicio\";\n\n\t\t\t\texport async function GET(request) {\n\t\t\t\t\tconst client = createClient();\n\n\t\t\t\t\treturn await redirectToPreviewURL({ client, request });\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\t} else {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport { NextApiRequest, NextApiResponse } from \"next\";\n\t\t\t\timport { setPreviewData, redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../prismicio\";\n\n\t\t\t\texport default async function handler(req: NextApiRequest, res: NextApiResponse) {\n\t\t\t\t\tconst client = createClient({ req });\n\n\t\t\t\t\tawait setPreviewData({ req, res });\n\n\t\t\t\t\treturn await redirectToPreviewURL({ req, res, client });\n\t\t\t\t};\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport { setPreviewData, redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../prismicio\";\n\n\t\t\t\texport default async function handler(req, res) {\n\t\t\t\t\tconst client = createClient({ req });\n\n\t\t\t\t\tawait setPreviewData({ req, res });\n\n\t\t\t\t\treturn await redirectToPreviewURL({ req, res, client });\n\t\t\t\t};\n\t\t\t`;\n\t\t}\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createExitPreviewRoute = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = await buildSrcPath({\n\t\tfilename: hasAppRouter\n\t\t\t? `app/api/exit-preview/route.${extension}`\n\t\t\t: `pages/api/exit-preview.${extension}`,\n\t\thelpers,\n\t});\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet contents: string;\n\n\tif (hasAppRouter) {\n\t\tcontents = source`\n\t\t\timport { exitPreview } from \"@prismicio/next\";\n\n\t\t\texport function GET() {\n\t\t\t\treturn exitPreview();\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport { NextApiRequest, NextApiResponse } from \"next\";\n\t\t\t\timport { exitPreview } from \"@prismicio/next\";\n\n\t\t\t\texport default function handler(req: NextApiRequest, res: NextApiResponse) {\n\t\t\t\t\treturn exitPreview({ req, res });\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport { exitPreview } from \"@prismicio/next\";\n\n\t\t\t\texport default function handler(req, res) {\n\t\t\t\t\treturn exitPreview({ req, res });\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst modifySliceMachineConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasSrcDirectory = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers,\n\t});\n\tconst project = await helpers.getProject();\n\n\t// Add Slice Simulator URL.\n\tproject.config.localSliceSimulatorURL ||=\n\t\t\"http://localhost:3000/slice-simulator\";\n\n\t// Nest the default Slice Library in the src directory if it exists and\n\t// is empty.\n\tif (\n\t\thasSrcDirectory &&\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 = [\"./src/slices\"];\n\t\t}\n\t}\n\n\tawait helpers.updateSliceMachineConfig(project.config, {\n\t\tformat: options.format,\n\t});\n};\n\nconst createRevalidateRoute = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\n\tif (!hasAppRouter) {\n\t\treturn;\n\t}\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = await buildSrcPath({\n\t\tfilename: `app/api/revalidate/route.${extension}`,\n\t\thelpers,\n\t});\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\timport { NextResponse } from \"next/server\";\n\t\timport { revalidateTag } from \"next/cache\";\n\n\t\texport async function POST() {\n\t\t\trevalidateTag(\"prismic\");\n\n\t\t\treturn NextResponse.json({ revalidated: true, now: Date.now() });\n\t\t}\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\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\tmodifySliceMachineConfig(context),\n\t\t\tcreatePrismicIOFile(context),\n\t\t\tcreateSliceSimulatorPage(context),\n\t\t\tcreatePreviewRoute(context),\n\t\t\tcreateExitPreviewRoute(context),\n\t\t\tcreateRevalidateRoute(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies","checkIsTypeScriptProject","checkHasProjectFile","checkHasAppRouter","getJSFileExtension","buildSrcPath","source","PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME","writeProjectFile","rejectIfNecessary"],"mappings":";;;;;;;;;;AAwBA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,qBAAqB;AAAA,MACrB,oBAAoB;AAAA,MACpB,mBAAmB;AAAA,IACnB;AAAA,EAAA,CACD;AACF;A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MAAM,QAAQ,WAAW;AAAA,IACxB,oBAAoB,EAAE,qBAAqB,sBAAsB;AAAA,IACjE,yBAAyB,OAAO;AAAA,IAChC,oBAAoB,OAAO;AAAA,IAC3B,yBAAyB,OAAO;AAAA,IAChC,mBAAmB,OAAO;AAAA,IAC1B,uBAAuB,OAAO;AAAA,IAC9B,sBAAsB,OAAO;AAAA,EAC7B,CAAA,CAAC;AAEJ;;"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import * as path from "node:path";
|
|
2
1
|
import { checkHasProjectFile, writeProjectFile } from "@slicemachine/plugin-kit/fs";
|
|
3
2
|
import { source } from "common-tags";
|
|
3
|
+
import { buildSrcPath } from "../lib/buildSrcPath.js";
|
|
4
4
|
import { checkHasAppRouter } from "../lib/checkHasAppRouter.js";
|
|
5
|
-
import { checkHasSrcDirectory } from "../lib/checkHasSrcDirectory.js";
|
|
6
5
|
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
|
|
7
6
|
import { getJSFileExtension } from "../lib/getJSFileExtension.js";
|
|
8
7
|
import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
|
|
@@ -21,10 +20,16 @@ const createPrismicIOFile = async ({ helpers, options }) => {
|
|
|
21
20
|
helpers,
|
|
22
21
|
options
|
|
23
22
|
});
|
|
24
|
-
const hasSrcDirectory = await
|
|
23
|
+
const hasSrcDirectory = await checkHasProjectFile({
|
|
24
|
+
filename: "src",
|
|
25
|
+
helpers
|
|
26
|
+
});
|
|
25
27
|
const hasAppRouter = await checkHasAppRouter({ helpers });
|
|
26
28
|
const extension = await getJSFileExtension({ helpers, options });
|
|
27
|
-
const filename =
|
|
29
|
+
const filename = await buildSrcPath({
|
|
30
|
+
filename: `prismicio.${extension}`,
|
|
31
|
+
helpers
|
|
32
|
+
});
|
|
28
33
|
if (await checkHasProjectFile({ filename, helpers })) {
|
|
29
34
|
return;
|
|
30
35
|
}
|
|
@@ -214,13 +219,12 @@ const createSliceSimulatorPage = async ({ helpers, options }) => {
|
|
|
214
219
|
helpers,
|
|
215
220
|
options
|
|
216
221
|
});
|
|
217
|
-
const hasSrcDirectory = await checkHasSrcDirectory({ helpers });
|
|
218
222
|
const hasAppRouter = await checkHasAppRouter({ helpers });
|
|
219
223
|
const extension = await getJSFileExtension({ helpers, options, jsx: true });
|
|
220
|
-
const filename =
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
+
const filename = await buildSrcPath({
|
|
225
|
+
filename: hasAppRouter ? `app/slice-simulator/page.${extension}` : `pages/slice-simulator.${extension}`,
|
|
226
|
+
helpers
|
|
227
|
+
});
|
|
224
228
|
if (await checkHasProjectFile({ filename, helpers })) {
|
|
225
229
|
return;
|
|
226
230
|
}
|
|
@@ -294,17 +298,16 @@ const createSliceSimulatorPage = async ({ helpers, options }) => {
|
|
|
294
298
|
});
|
|
295
299
|
};
|
|
296
300
|
const createPreviewRoute = async ({ helpers, options }) => {
|
|
297
|
-
const hasSrcDirectory = await checkHasSrcDirectory({ helpers });
|
|
298
301
|
const hasAppRouter = await checkHasAppRouter({ helpers });
|
|
299
302
|
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
300
303
|
helpers,
|
|
301
304
|
options
|
|
302
305
|
});
|
|
303
306
|
const extension = await getJSFileExtension({ helpers, options });
|
|
304
|
-
const filename =
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
307
|
+
const filename = await buildSrcPath({
|
|
308
|
+
filename: hasAppRouter ? `app/api/preview/route.${extension}` : `pages/api/preview.${extension}`,
|
|
309
|
+
helpers
|
|
310
|
+
});
|
|
308
311
|
if (await checkHasProjectFile({ filename, helpers })) {
|
|
309
312
|
return;
|
|
310
313
|
}
|
|
@@ -376,17 +379,16 @@ const createPreviewRoute = async ({ helpers, options }) => {
|
|
|
376
379
|
});
|
|
377
380
|
};
|
|
378
381
|
const createExitPreviewRoute = async ({ helpers, options }) => {
|
|
379
|
-
const hasSrcDirectory = await checkHasSrcDirectory({ helpers });
|
|
380
382
|
const hasAppRouter = await checkHasAppRouter({ helpers });
|
|
381
383
|
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
382
384
|
helpers,
|
|
383
385
|
options
|
|
384
386
|
});
|
|
385
387
|
const extension = await getJSFileExtension({ helpers, options });
|
|
386
|
-
const filename =
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
388
|
+
const filename = await buildSrcPath({
|
|
389
|
+
filename: hasAppRouter ? `app/api/exit-preview/route.${extension}` : `pages/api/exit-preview.${extension}`,
|
|
390
|
+
helpers
|
|
391
|
+
});
|
|
390
392
|
if (await checkHasProjectFile({ filename, helpers })) {
|
|
391
393
|
return;
|
|
392
394
|
}
|
|
@@ -428,7 +430,10 @@ const createExitPreviewRoute = async ({ helpers, options }) => {
|
|
|
428
430
|
};
|
|
429
431
|
const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
|
|
430
432
|
var _a;
|
|
431
|
-
const hasSrcDirectory = await
|
|
433
|
+
const hasSrcDirectory = await checkHasProjectFile({
|
|
434
|
+
filename: "src",
|
|
435
|
+
helpers
|
|
436
|
+
});
|
|
432
437
|
const project = await helpers.getProject();
|
|
433
438
|
(_a = project.config).localSliceSimulatorURL || (_a.localSliceSimulatorURL = "http://localhost:3000/slice-simulator");
|
|
434
439
|
if (hasSrcDirectory && project.config.libraries && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
|
|
@@ -448,12 +453,11 @@ const createRevalidateRoute = async ({ helpers, options }) => {
|
|
|
448
453
|
if (!hasAppRouter) {
|
|
449
454
|
return;
|
|
450
455
|
}
|
|
451
|
-
const hasSrcDirectory = await checkHasSrcDirectory({ helpers });
|
|
452
456
|
const extension = await getJSFileExtension({ helpers, options });
|
|
453
|
-
const filename =
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
+
const filename = await buildSrcPath({
|
|
458
|
+
filename: `app/api/revalidate/route.${extension}`,
|
|
459
|
+
helpers
|
|
460
|
+
});
|
|
457
461
|
if (await checkHasProjectFile({ filename, helpers })) {
|
|
458
462
|
return;
|
|
459
463
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-init.js","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport {\n\tcheckHasProjectFile,\n\twriteProjectFile,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { source } from \"common-tags\";\n\nimport { checkHasAppRouter } from \"../lib/checkHasAppRouter\";\nimport { checkHasSrcDirectory } from \"../lib/checkHasSrcDirectory\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSFileExtension } from \"../lib/getJSFileExtension\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\n\nimport type { PluginOptions } from \"../types\";\nimport { PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME } from \"../constants\";\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\"@prismicio/client\": \"latest\",\n\t\t\t\"@prismicio/react\": \"latest\",\n\t\t\t\"@prismicio/next\": \"latest\",\n\t\t},\n\t});\n};\n\ntype CreatePrismicIOFileArgs = SliceMachineContext<PluginOptions>;\n\nconst createPrismicIOFile = async ({\n\thelpers,\n\toptions,\n}: CreatePrismicIOFileArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(\n\t\t...[hasSrcDirectory ? \"src\" : undefined, `prismicio.${extension}`].filter(\n\t\t\t(segment): segment is NonNullable<typeof segment> => Boolean(segment),\n\t\t),\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet createClientContents: string;\n\n\tif (hasAppRouter) {\n\t\tif (isTypeScriptProject) {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config: prismicNext.CreateClientConfig = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\tfetchOptions:\n\t\t\t\t\t\t\tprocess.env.NODE_ENV === 'production'\n\t\t\t\t\t\t\t\t? { next: { tags: ['prismic'] }, cache: 'force-cache' }\n\t\t\t\t\t\t\t\t: { next: { revalidate: 5 } },\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t} else {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\tfetchOptions:\n\t\t\t\t\t\t\tprocess.env.NODE_ENV === 'production'\n\t\t\t\t\t\t\t\t? { next: { tags: ['prismic'] }, cache: 'force-cache' }\n\t\t\t\t\t\t\t\t: { next: { revalidate: 5 } },\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t}\n\t} else {\n\t\tif (isTypeScriptProject) {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config: prismicNext.CreateClientConfig = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t} else {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t}\n\t}\n\n\tlet contents: string;\n\n\tif (isTypeScriptProject) {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\n\t\t\timport config from \"${hasSrcDirectory ? \"..\" : \".\"}/slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName =\n\t\t\t\tprocess.env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes: prismic.ClientConfig[\"routes\"] = [\n\t\t\t\t// Examples:\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"homepage\",\n\t\t\t\t// \tpath: \"/\",\n\t\t\t\t// },\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"page\",\n\t\t\t\t// \tpath: \"/:uid\",\n\t\t\t\t// },\n\t\t\t];\n\n\t\t\t${createClientContents}\n\t\t`;\n\t} else {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\n\t\t\timport config from \"${hasSrcDirectory ? \"..\" : \".\"}/slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName =\n\t\t\t\tprocess.env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t *\n\t\t\t * @type {prismic.ClientConfig[\"routes\"]}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes = [\n\t\t\t\t// Examples:\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"homepage\",\n\t\t\t\t// \tpath: \"/\",\n\t\t\t\t// },\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"page\",\n\t\t\t\t// \tpath: \"/:uid\",\n\t\t\t\t// },\n\t\t\t];\n\n\t\t\t${createClientContents}\n\t\t`;\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\n\tconst extension = await getJSFileExtension({ helpers, options, jsx: true });\n\tconst filename = path.join(\n\t\t...[\n\t\t\thasSrcDirectory ? \"src\" : undefined,\n\t\t\thasAppRouter\n\t\t\t\t? `app/slice-simulator/page.${extension}`\n\t\t\t\t: `pages/slice-simulator.${extension}`,\n\t\t].filter((segment): segment is NonNullable<typeof segment> =>\n\t\t\tBoolean(segment),\n\t\t),\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet contents;\n\n\tif (hasAppRouter) {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport {\n\t\t\t\t\tSliceSimulator,\n\t\t\t\t\tSliceSimulatorParams,\n\t\t\t\t\tgetSlices,\n\t\t\t\t} from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage({\n\t\t\t\t\tsearchParams,\n\t\t\t\t}: SliceSimulatorParams) {\n\t\t\t\t\tconst slices = getSlices(searchParams.state);\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator>\n\t\t\t\t\t\t\t<SliceZone slices={slices} components={components} />\n\t\t\t\t\t\t</SliceSimulator>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport {\n\t\t\t\t\tSliceSimulator,\n\t\t\t\t\tgetSlices,\n\t\t\t\t} from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage({ searchParams }) {\n\t\t\t\t\tconst slices = getSlices(searchParams.state);\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator>\n\t\t\t\t\t\t\t<SliceZone slices={slices} components={components} />\n\t\t\t\t\t\t</SliceSimulator>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\t} else {\n\t\tcontents = source`\n\t\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\timport { components } from \"../slices\";\n\n\t\t\texport default function SliceSimulatorPage() {\n\t\t\t\treturn (\n\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t`;\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createPreviewRoute = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(\n\t\t...[\n\t\t\thasSrcDirectory ? \"src\" : undefined,\n\t\t\thasAppRouter\n\t\t\t\t? `app/api/preview/route.${extension}`\n\t\t\t\t: `pages/api/preview.${extension}`,\n\t\t].filter((segment): segment is NonNullable<typeof segment> =>\n\t\t\tBoolean(segment),\n\t\t),\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet contents: string;\n\n\tif (hasAppRouter) {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport { NextRequest } from \"next/server\";\n\t\t\t\timport { redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../../prismicio\";\n\n\t\t\t\texport async function GET(request: NextRequest) {\n\t\t\t\t\tconst client = createClient();\n\n\t\t\t\t\treturn await redirectToPreviewURL({ client, request });\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport { redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../../prismicio\";\n\n\t\t\t\texport async function GET(request) {\n\t\t\t\t\tconst client = createClient();\n\n\t\t\t\t\treturn await redirectToPreviewURL({ client, request });\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\t} else {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport { NextApiRequest, NextApiResponse } from \"next\";\n\t\t\t\timport { setPreviewData, redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../prismicio\";\n\n\t\t\t\texport default async function handler(req: NextApiRequest, res: NextApiResponse) {\n\t\t\t\t\tconst client = createClient({ req });\n\n\t\t\t\t\tawait setPreviewData({ req, res });\n\n\t\t\t\t\treturn await redirectToPreviewURL({ req, res, client });\n\t\t\t\t};\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport { setPreviewData, redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../prismicio\";\n\n\t\t\t\texport default async function handler(req, res) {\n\t\t\t\t\tconst client = createClient({ req });\n\n\t\t\t\t\tawait setPreviewData({ req, res });\n\n\t\t\t\t\treturn await redirectToPreviewURL({ req, res, client });\n\t\t\t\t};\n\t\t\t`;\n\t\t}\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createExitPreviewRoute = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(\n\t\t...[\n\t\t\thasSrcDirectory ? \"src\" : undefined,\n\t\t\thasAppRouter\n\t\t\t\t? `app/api/exit-preview/route.${extension}`\n\t\t\t\t: `pages/api/exit-preview.${extension}`,\n\t\t].filter((segment): segment is NonNullable<typeof segment> =>\n\t\t\tBoolean(segment),\n\t\t),\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet contents: string;\n\n\tif (hasAppRouter) {\n\t\tcontents = source`\n\t\t\timport { exitPreview } from \"@prismicio/next\";\n\n\t\t\texport function GET() {\n\t\t\t\treturn exitPreview();\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport { NextApiRequest, NextApiResponse } from \"next\";\n\t\t\t\timport { exitPreview } from \"@prismicio/next\";\n\n\t\t\t\texport default function handler(req: NextApiRequest, res: NextApiResponse) {\n\t\t\t\t\treturn exitPreview({ req, res });\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport { exitPreview } from \"@prismicio/next\";\n\n\t\t\t\texport default function handler(req, res) {\n\t\t\t\t\treturn exitPreview({ req, res });\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst modifySliceMachineConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\n\tconst project = await helpers.getProject();\n\n\t// Add Slice Simulator URL.\n\tproject.config.localSliceSimulatorURL ||=\n\t\t\"http://localhost:3000/slice-simulator\";\n\n\t// Nest the default Slice Library in the src directory if it exists and\n\t// is empty.\n\tif (\n\t\thasSrcDirectory &&\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 = [\"./src/slices\"];\n\t\t}\n\t}\n\n\tawait helpers.updateSliceMachineConfig(project.config, {\n\t\tformat: options.format,\n\t});\n};\n\nconst createRevalidateRoute = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\n\tif (!hasAppRouter) {\n\t\treturn;\n\t}\n\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(\n\t\t...[\n\t\t\thasSrcDirectory ? \"src\" : undefined,\n\t\t\t`app/api/revalidate/route.${extension}`,\n\t\t].filter((segment): segment is NonNullable<typeof segment> =>\n\t\t\tBoolean(segment),\n\t\t),\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\timport { NextResponse } from \"next/server\";\n\t\timport { revalidateTag } from \"next/cache\";\n\n\t\texport async function POST() {\n\t\t\trevalidateTag(\"prismic\");\n\n\t\t\treturn NextResponse.json({ revalidated: true, now: Date.now() });\n\t\t}\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\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\tmodifySliceMachineConfig(context),\n\t\t\tcreatePrismicIOFile(context),\n\t\t\tcreateSliceSimulatorPage(context),\n\t\t\tcreatePreviewRoute(context),\n\t\t\tcreateExitPreviewRoute(context),\n\t\t\tcreateRevalidateRoute(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies"],"mappings":";;;;;;;;;AAyBA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,qBAAqB;AAAA,MACrB,oBAAoB;AAAA,MACpB,mBAAmB;AAAA,IACnB;AAAA,EAAA,CACD;AACF;AAIA,MAAM,sBAAsB,OAAO,EAClC,SACA,cAC6B;AACvB,QAAA,sBAAsB,MAAM,yBAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AACD,QAAM,kBAAkB,MAAM,qBAAqB,EAAE,QAAS,CAAA;AAC9D,QAAM,eAAe,MAAM,kBAAkB,EAAE,QAAS,CAAA;AAExD,QAAM,YAAY,MAAM,mBAAmB,EAAE,SAAS,QAAS,CAAA;AAC/D,QAAM,WAAW,KAAK,KACrB,GAAG,CAAC,kBAAkB,QAAQ,QAAW,aAAa,WAAW,EAAE,OAClE,CAAC,YAAoD,QAAQ,OAAO,CAAC,CACrE;AAGF,MAAI,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,\n\tProjectInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport {\n\tcheckHasProjectFile,\n\twriteProjectFile,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { source } from \"common-tags\";\n\nimport { buildSrcPath } from \"../lib/buildSrcPath\";\nimport { checkHasAppRouter } from \"../lib/checkHasAppRouter\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSFileExtension } from \"../lib/getJSFileExtension\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\n\nimport type { PluginOptions } from \"../types\";\nimport { PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME } from \"../constants\";\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\"@prismicio/client\": \"latest\",\n\t\t\t\"@prismicio/react\": \"latest\",\n\t\t\t\"@prismicio/next\": \"latest\",\n\t\t},\n\t});\n};\n\ntype CreatePrismicIOFileArgs = SliceMachineContext<PluginOptions>;\n\nconst createPrismicIOFile = async ({\n\thelpers,\n\toptions,\n}: CreatePrismicIOFileArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\tconst hasSrcDirectory = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers,\n\t});\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = await buildSrcPath({\n\t\tfilename: `prismicio.${extension}`,\n\t\thelpers,\n\t});\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet createClientContents: string;\n\n\tif (hasAppRouter) {\n\t\tif (isTypeScriptProject) {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config: prismicNext.CreateClientConfig = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\tfetchOptions:\n\t\t\t\t\t\t\tprocess.env.NODE_ENV === 'production'\n\t\t\t\t\t\t\t\t? { next: { tags: ['prismic'] }, cache: 'force-cache' }\n\t\t\t\t\t\t\t\t: { next: { revalidate: 5 } },\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t} else {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\tfetchOptions:\n\t\t\t\t\t\t\tprocess.env.NODE_ENV === 'production'\n\t\t\t\t\t\t\t\t? { next: { tags: ['prismic'] }, cache: 'force-cache' }\n\t\t\t\t\t\t\t\t: { next: { revalidate: 5 } },\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t}\n\t} else {\n\t\tif (isTypeScriptProject) {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config: prismicNext.CreateClientConfig = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t} else {\n\t\t\tcreateClientContents = source`\n\t\t\t\t/**\n\t\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t\t * query content from the Prismic API.\n\t\t\t\t *\n\t\t\t\t * @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.\n\t\t\t\t */\n\t\t\t\texport const createClient = (config = {}) => {\n\t\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\t\troutes,\n\t\t\t\t\t\t...config,\n\t\t\t\t\t});\n\n\t\t\t\t\tprismicNext.enableAutoPreviews({\n\t\t\t\t\t\tclient,\n\t\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\t\treq: config.req,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn client;\n\t\t\t\t};\n\t\t\t`;\n\t\t}\n\t}\n\n\tlet contents: string;\n\n\tif (isTypeScriptProject) {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\n\t\t\timport config from \"${hasSrcDirectory ? \"..\" : \".\"}/slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName =\n\t\t\t\tprocess.env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes: prismic.ClientConfig[\"routes\"] = [\n\t\t\t\t// Examples:\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"homepage\",\n\t\t\t\t// \tpath: \"/\",\n\t\t\t\t// },\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"page\",\n\t\t\t\t// \tpath: \"/:uid\",\n\t\t\t\t// },\n\t\t\t];\n\n\t\t\t${createClientContents}\n\t\t`;\n\t} else {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\n\t\t\timport config from \"${hasSrcDirectory ? \"..\" : \".\"}/slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName =\n\t\t\t\tprocess.env.${PRISMIC_ENVIRONMENT_ENVIRONMENT_VARIABLE_NAME} || config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t *\n\t\t\t * @type {prismic.ClientConfig[\"routes\"]}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes = [\n\t\t\t\t// Examples:\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"homepage\",\n\t\t\t\t// \tpath: \"/\",\n\t\t\t\t// },\n\t\t\t\t// {\n\t\t\t\t// \ttype: \"page\",\n\t\t\t\t// \tpath: \"/:uid\",\n\t\t\t\t// },\n\t\t\t];\n\n\t\t\t${createClientContents}\n\t\t`;\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\n\tconst extension = await getJSFileExtension({ helpers, options, jsx: true });\n\tconst filename = await buildSrcPath({\n\t\tfilename: hasAppRouter\n\t\t\t? `app/slice-simulator/page.${extension}`\n\t\t\t: `pages/slice-simulator.${extension}`,\n\t\thelpers,\n\t});\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet contents;\n\n\tif (hasAppRouter) {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport {\n\t\t\t\t\tSliceSimulator,\n\t\t\t\t\tSliceSimulatorParams,\n\t\t\t\t\tgetSlices,\n\t\t\t\t} from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage({\n\t\t\t\t\tsearchParams,\n\t\t\t\t}: SliceSimulatorParams) {\n\t\t\t\t\tconst slices = getSlices(searchParams.state);\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator>\n\t\t\t\t\t\t\t<SliceZone slices={slices} components={components} />\n\t\t\t\t\t\t</SliceSimulator>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport {\n\t\t\t\t\tSliceSimulator,\n\t\t\t\t\tgetSlices,\n\t\t\t\t} from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage({ searchParams }) {\n\t\t\t\t\tconst slices = getSlices(searchParams.state);\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator>\n\t\t\t\t\t\t\t<SliceZone slices={slices} components={components} />\n\t\t\t\t\t\t</SliceSimulator>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\t} else {\n\t\tcontents = source`\n\t\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\timport { components } from \"../slices\";\n\n\t\t\texport default function SliceSimulatorPage() {\n\t\t\t\treturn (\n\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t`;\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createPreviewRoute = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = await buildSrcPath({\n\t\tfilename: hasAppRouter\n\t\t\t? `app/api/preview/route.${extension}`\n\t\t\t: `pages/api/preview.${extension}`,\n\t\thelpers,\n\t});\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet contents: string;\n\n\tif (hasAppRouter) {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport { NextRequest } from \"next/server\";\n\t\t\t\timport { redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../../prismicio\";\n\n\t\t\t\texport async function GET(request: NextRequest) {\n\t\t\t\t\tconst client = createClient();\n\n\t\t\t\t\treturn await redirectToPreviewURL({ client, request });\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport { redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../../prismicio\";\n\n\t\t\t\texport async function GET(request) {\n\t\t\t\t\tconst client = createClient();\n\n\t\t\t\t\treturn await redirectToPreviewURL({ client, request });\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\t} else {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport { NextApiRequest, NextApiResponse } from \"next\";\n\t\t\t\timport { setPreviewData, redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../prismicio\";\n\n\t\t\t\texport default async function handler(req: NextApiRequest, res: NextApiResponse) {\n\t\t\t\t\tconst client = createClient({ req });\n\n\t\t\t\t\tawait setPreviewData({ req, res });\n\n\t\t\t\t\treturn await redirectToPreviewURL({ req, res, client });\n\t\t\t\t};\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport { setPreviewData, redirectToPreviewURL } from \"@prismicio/next\";\n\n\t\t\t\timport { createClient } from \"../../prismicio\";\n\n\t\t\t\texport default async function handler(req, res) {\n\t\t\t\t\tconst client = createClient({ req });\n\n\t\t\t\t\tawait setPreviewData({ req, res });\n\n\t\t\t\t\treturn await redirectToPreviewURL({ req, res, client });\n\t\t\t\t};\n\t\t\t`;\n\t\t}\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createExitPreviewRoute = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = await buildSrcPath({\n\t\tfilename: hasAppRouter\n\t\t\t? `app/api/exit-preview/route.${extension}`\n\t\t\t: `pages/api/exit-preview.${extension}`,\n\t\thelpers,\n\t});\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet contents: string;\n\n\tif (hasAppRouter) {\n\t\tcontents = source`\n\t\t\timport { exitPreview } from \"@prismicio/next\";\n\n\t\t\texport function GET() {\n\t\t\t\treturn exitPreview();\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tif (isTypeScriptProject) {\n\t\t\tcontents = source`\n\t\t\t\timport { NextApiRequest, NextApiResponse } from \"next\";\n\t\t\t\timport { exitPreview } from \"@prismicio/next\";\n\n\t\t\t\texport default function handler(req: NextApiRequest, res: NextApiResponse) {\n\t\t\t\t\treturn exitPreview({ req, res });\n\t\t\t\t}\n\t\t\t`;\n\t\t} else {\n\t\t\tcontents = source`\n\t\t\t\timport { exitPreview } from \"@prismicio/next\";\n\n\t\t\t\texport default function handler(req, res) {\n\t\t\t\t\treturn exitPreview({ req, res });\n\t\t\t\t}\n\t\t\t`;\n\t\t}\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst modifySliceMachineConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasSrcDirectory = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers,\n\t});\n\tconst project = await helpers.getProject();\n\n\t// Add Slice Simulator URL.\n\tproject.config.localSliceSimulatorURL ||=\n\t\t\"http://localhost:3000/slice-simulator\";\n\n\t// Nest the default Slice Library in the src directory if it exists and\n\t// is empty.\n\tif (\n\t\thasSrcDirectory &&\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 = [\"./src/slices\"];\n\t\t}\n\t}\n\n\tawait helpers.updateSliceMachineConfig(project.config, {\n\t\tformat: options.format,\n\t});\n};\n\nconst createRevalidateRoute = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasAppRouter = await checkHasAppRouter({ helpers });\n\n\tif (!hasAppRouter) {\n\t\treturn;\n\t}\n\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = await buildSrcPath({\n\t\tfilename: `app/api/revalidate/route.${extension}`,\n\t\thelpers,\n\t});\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\timport { NextResponse } from \"next/server\";\n\t\timport { revalidateTag } from \"next/cache\";\n\n\t\texport async function POST() {\n\t\t\trevalidateTag(\"prismic\");\n\n\t\t\treturn NextResponse.json({ revalidated: true, now: Date.now() });\n\t\t}\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\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\tmodifySliceMachineConfig(context),\n\t\t\tcreatePrismicIOFile(context),\n\t\t\tcreateSliceSimulatorPage(context),\n\t\t\tcreatePreviewRoute(context),\n\t\t\tcreateExitPreviewRoute(context),\n\t\t\tcreateRevalidateRoute(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies"],"mappings":";;;;;;;;AAwBA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;A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const format = async (input, helpers) => {
|
|
|
15
15
|
return formattedInput.endsWith(";") ? formattedInput.substring(0, formattedInput.length - 1) : formattedInput;
|
|
16
16
|
};
|
|
17
17
|
const snippetRead = async (data, { helpers }) => {
|
|
18
|
-
const { fieldPath
|
|
18
|
+
const { fieldPath } = data;
|
|
19
19
|
const label = "React";
|
|
20
20
|
switch (data.model.type) {
|
|
21
21
|
case "StructuredText": {
|
|
@@ -57,8 +57,8 @@ const snippetRead = async (data, { helpers }) => {
|
|
|
57
57
|
case "Group": {
|
|
58
58
|
const code = await format(commonTags.stripIndent`
|
|
59
59
|
<>
|
|
60
|
-
{${dotPath(fieldPath)}.map((
|
|
61
|
-
// Render the
|
|
60
|
+
{${dotPath(fieldPath)}.map((item) => {
|
|
61
|
+
// Render the item
|
|
62
62
|
})}
|
|
63
63
|
</>
|
|
64
64
|
`, helpers);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snippet-read.cjs","sources":["../../../src/hooks/snippet-read.ts"],"sourcesContent":["import type {\n\tSliceMachineHelpers,\n\tSnippetReadHook,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst dotPath = (...segments: (string | string[])[]): string => {\n\treturn segments.flat().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\tprintWidth: 60,\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
|
|
1
|
+
{"version":3,"file":"snippet-read.cjs","sources":["../../../src/hooks/snippet-read.ts"],"sourcesContent":["import type {\n\tSliceMachineHelpers,\n\tSnippetReadHook,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst dotPath = (...segments: (string | string[])[]): string => {\n\treturn segments.flat().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\tprintWidth: 60,\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 \"StructuredText\": {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tlabel: `${label} (components)`,\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<PrismicRichText 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: `${label} (plain text)`,\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<PrismicText 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 \"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<PrismicNextLink field={${dotPath(fieldPath)}}>Link</PrismicNextLink>\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 \"Image\": {\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\t<PrismicNextImage field={${dotPath(fieldPath)}} />\n\t\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 \"Group\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<>\n\t\t\t\t\t\t{${dotPath(fieldPath)}.map((item) => {\n\t\t\t\t\t\t\t// Render the item\n\t\t\t\t\t\t})}\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 \"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\tcase \"GeoPoint\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<>{${dotPath(fieldPath, \"latitude\")}}, {${dotPath(fieldPath, \"longitude\")}}</>\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 \"Embed\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<div dangerouslySetInnerHTML={{ __html: ${dotPath(fieldPath, \"html\")} }} />\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":["stripIndent"],"mappings":";;;AAQA,MAAM,UAAU,IAAI,aAA2C;AAC9D,SAAO,SAAS,KAAA,EAAO,KAAK,GAAG;AAChC;AAEA,MAAM,SAAS,OAAO,OAAe,YAAgC;AACpE,QAAM,iBAAiB,MAAM,QAAQ,OAAO,OAAO,QAAW;AAAA,IAC7D,qBAAqB;AAAA,IACrB,UAAU;AAAA,MACT,QAAQ;AAAA,MACR,YAAY;AAAA,IACZ;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,kBAAkB;AACf,aAAA;AAAA,QACN;AAAA,UACC,OAAO,GAAG;AAAA,UACV,UAAU;AAAA,UACV,MAAM,MAAM,OACXA;iCAC2B,QAAQ,SAAS;AAAA,SAE5C,OAAO;AAAA,QAER;AAAA,QACD;AAAA,UACC,OAAO,GAAG;AAAA,UACV,UAAU;AAAA,UACV,MAAM,MAAM,OACXA;6BACuB,QAAQ,SAAS;AAAA,SAExC,OAAO;AAAA,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F;;"}
|
|
@@ -13,7 +13,7 @@ const format = async (input, helpers) => {
|
|
|
13
13
|
return formattedInput.endsWith(";") ? formattedInput.substring(0, formattedInput.length - 1) : formattedInput;
|
|
14
14
|
};
|
|
15
15
|
const snippetRead = async (data, { helpers }) => {
|
|
16
|
-
const { fieldPath
|
|
16
|
+
const { fieldPath } = data;
|
|
17
17
|
const label = "React";
|
|
18
18
|
switch (data.model.type) {
|
|
19
19
|
case "StructuredText": {
|
|
@@ -55,8 +55,8 @@ const snippetRead = async (data, { helpers }) => {
|
|
|
55
55
|
case "Group": {
|
|
56
56
|
const code = await format(stripIndent`
|
|
57
57
|
<>
|
|
58
|
-
{${dotPath(fieldPath)}.map((
|
|
59
|
-
// Render the
|
|
58
|
+
{${dotPath(fieldPath)}.map((item) => {
|
|
59
|
+
// Render the item
|
|
60
60
|
})}
|
|
61
61
|
</>
|
|
62
62
|
`, helpers);
|
|
@@ -1 +1 @@
|
|
|
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 { stripIndent } from \"common-tags\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst dotPath = (...segments: (string | string[])[]): string => {\n\treturn segments.flat().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\tprintWidth: 60,\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
|
|
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 { stripIndent } from \"common-tags\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst dotPath = (...segments: (string | string[])[]): string => {\n\treturn segments.flat().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\tprintWidth: 60,\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 \"StructuredText\": {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tlabel: `${label} (components)`,\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<PrismicRichText 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: `${label} (plain text)`,\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<PrismicText 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 \"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<PrismicNextLink field={${dotPath(fieldPath)}}>Link</PrismicNextLink>\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 \"Image\": {\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\t<PrismicNextImage field={${dotPath(fieldPath)}} />\n\t\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 \"Group\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<>\n\t\t\t\t\t\t{${dotPath(fieldPath)}.map((item) => {\n\t\t\t\t\t\t\t// Render the item\n\t\t\t\t\t\t})}\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 \"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\tcase \"GeoPoint\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<>{${dotPath(fieldPath, \"latitude\")}}, {${dotPath(fieldPath, \"longitude\")}}</>\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 \"Embed\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<div dangerouslySetInnerHTML={{ __html: ${dotPath(fieldPath, \"html\")} }} />\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":";AAQA,MAAM,UAAU,IAAI,aAA2C;AAC9D,SAAO,SAAS,KAAA,EAAO,KAAK,GAAG;AAChC;AAEA,MAAM,SAAS,OAAO,OAAe,YAAgC;AACpE,QAAM,iBAAiB,MAAM,QAAQ,OAAO,OAAO,QAAW;AAAA,IAC7D,qBAAqB;AAAA,IACrB,UAAU;AAAA,MACT,QAAQ;AAAA,MACR,YAAY;AAAA,IACZ;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,kBAAkB;AACf,aAAA;AAAA,QACN;AAAA,UACC,OAAO,GAAG;AAAA,UACV,UAAU;AAAA,UACV,MAAM,MAAM,OACX;AAAA,iCAC2B,QAAQ,SAAS;AAAA,SAE5C,OAAO;AAAA,QAER;AAAA,QACD;AAAA,UACC,OAAO,GAAG;AAAA,UACV,UAAU;AAAA,UACV,MAAM,MAAM,OACX;AAAA,6BACuB,QAAQ,SAAS;AAA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,SAAS;AAAA,QAEvB,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,EACD;AACF;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const fs = require("@slicemachine/plugin-kit/fs");
|
|
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 path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
22
|
+
async function buildSrcPath(args) {
|
|
23
|
+
const hasSrcDirectory = await fs.checkHasProjectFile({
|
|
24
|
+
filename: "src",
|
|
25
|
+
helpers: args.helpers
|
|
26
|
+
});
|
|
27
|
+
return hasSrcDirectory ? path__namespace.join("src", args.filename) : args.filename;
|
|
28
|
+
}
|
|
29
|
+
exports.buildSrcPath = buildSrcPath;
|
|
30
|
+
//# sourceMappingURL=buildSrcPath.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildSrcPath.cjs","sources":["../../../src/lib/buildSrcPath.ts"],"sourcesContent":["import * as path from \"node:path\";\n\nimport type { SliceMachineHelpers } from \"@slicemachine/plugin-kit\";\nimport { checkHasProjectFile } from \"@slicemachine/plugin-kit/fs\";\n\nexport async function buildSrcPath(args: {\n\tfilename: string;\n\thelpers: SliceMachineHelpers;\n}): Promise<string> {\n\tconst hasSrcDirectory = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers: args.helpers,\n\t});\n\n\treturn hasSrcDirectory ? path.join(\"src\", args.filename) : args.filename;\n}\n"],"names":["checkHasProjectFile","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAKA,eAAsB,aAAa,MAGlC;AACM,QAAA,kBAAkB,MAAMA,uBAAoB;AAAA,IACjD,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AAED,SAAO,kBAAkBC,gBAAK,KAAK,OAAO,KAAK,QAAQ,IAAI,KAAK;AACjE;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
|
|
3
|
+
async function buildSrcPath(args) {
|
|
4
|
+
const hasSrcDirectory = await checkHasProjectFile({
|
|
5
|
+
filename: "src",
|
|
6
|
+
helpers: args.helpers
|
|
7
|
+
});
|
|
8
|
+
return hasSrcDirectory ? path.join("src", args.filename) : args.filename;
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
buildSrcPath
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=buildSrcPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildSrcPath.js","sources":["../../../src/lib/buildSrcPath.ts"],"sourcesContent":["import * as path from \"node:path\";\n\nimport type { SliceMachineHelpers } from \"@slicemachine/plugin-kit\";\nimport { checkHasProjectFile } from \"@slicemachine/plugin-kit/fs\";\n\nexport async function buildSrcPath(args: {\n\tfilename: string;\n\thelpers: SliceMachineHelpers;\n}): Promise<string> {\n\tconst hasSrcDirectory = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers: args.helpers,\n\t});\n\n\treturn hasSrcDirectory ? path.join(\"src\", args.filename) : args.filename;\n}\n"],"names":[],"mappings":";;AAKA,eAAsB,aAAa,MAGlC;AACM,QAAA,kBAAkB,MAAM,oBAAoB;AAAA,IACjD,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AAED,SAAO,kBAAkB,KAAK,KAAK,OAAO,KAAK,QAAQ,IAAI,KAAK;AACjE;"}
|
|
@@ -1,29 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const fs = require("@slicemachine/plugin-kit/fs");
|
|
4
|
-
const
|
|
5
|
-
const checkHasSrcDirectory = require("./checkHasSrcDirectory.cjs");
|
|
6
|
-
function _interopNamespaceDefault(e) {
|
|
7
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
|
-
if (e) {
|
|
9
|
-
for (const k in e) {
|
|
10
|
-
if (k !== "default") {
|
|
11
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: () => e[k]
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
n.default = e;
|
|
20
|
-
return Object.freeze(n);
|
|
21
|
-
}
|
|
22
|
-
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
4
|
+
const buildSrcPath = require("./buildSrcPath.cjs");
|
|
23
5
|
async function checkHasAppRouter(args) {
|
|
24
|
-
const
|
|
6
|
+
const appRouterPath = await buildSrcPath.buildSrcPath({
|
|
7
|
+
filename: "app",
|
|
8
|
+
helpers: args.helpers
|
|
9
|
+
});
|
|
25
10
|
return await fs.checkHasProjectFile({
|
|
26
|
-
filename:
|
|
11
|
+
filename: appRouterPath,
|
|
27
12
|
helpers: args.helpers
|
|
28
13
|
});
|
|
29
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkHasAppRouter.cjs","sources":["../../../src/lib/checkHasAppRouter.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { checkHasProjectFile } from \"@slicemachine/plugin-kit/fs\";\
|
|
1
|
+
{"version":3,"file":"checkHasAppRouter.cjs","sources":["../../../src/lib/checkHasAppRouter.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { checkHasProjectFile } from \"@slicemachine/plugin-kit/fs\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { buildSrcPath } from \"./buildSrcPath\";\n\ntype CheckHasAppRouterArgs = Pick<\n\tSliceMachineContext<PluginOptions>,\n\t\"helpers\"\n>;\n\nexport async function checkHasAppRouter(\n\targs: CheckHasAppRouterArgs,\n): Promise<boolean> {\n\tconst appRouterPath = await buildSrcPath({\n\t\tfilename: \"app\",\n\t\thelpers: args.helpers,\n\t});\n\n\treturn await checkHasProjectFile({\n\t\tfilename: appRouterPath,\n\t\thelpers: args.helpers,\n\t});\n}\n"],"names":["buildSrcPath","checkHasProjectFile"],"mappings":";;;;AAYA,eAAsB,kBACrB,MAA2B;AAErB,QAAA,gBAAgB,MAAMA,0BAAa;AAAA,IACxC,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AAED,SAAO,MAAMC,GAAAA,oBAAoB;AAAA,IAChC,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AACF;;"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
|
|
2
|
-
import
|
|
3
|
-
import { checkHasSrcDirectory } from "./checkHasSrcDirectory.js";
|
|
2
|
+
import { buildSrcPath } from "./buildSrcPath.js";
|
|
4
3
|
async function checkHasAppRouter(args) {
|
|
5
|
-
const
|
|
4
|
+
const appRouterPath = await buildSrcPath({
|
|
5
|
+
filename: "app",
|
|
6
|
+
helpers: args.helpers
|
|
7
|
+
});
|
|
6
8
|
return await checkHasProjectFile({
|
|
7
|
-
filename:
|
|
9
|
+
filename: appRouterPath,
|
|
8
10
|
helpers: args.helpers
|
|
9
11
|
});
|
|
10
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkHasAppRouter.js","sources":["../../../src/lib/checkHasAppRouter.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { checkHasProjectFile } from \"@slicemachine/plugin-kit/fs\";\
|
|
1
|
+
{"version":3,"file":"checkHasAppRouter.js","sources":["../../../src/lib/checkHasAppRouter.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { checkHasProjectFile } from \"@slicemachine/plugin-kit/fs\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { buildSrcPath } from \"./buildSrcPath\";\n\ntype CheckHasAppRouterArgs = Pick<\n\tSliceMachineContext<PluginOptions>,\n\t\"helpers\"\n>;\n\nexport async function checkHasAppRouter(\n\targs: CheckHasAppRouterArgs,\n): Promise<boolean> {\n\tconst appRouterPath = await buildSrcPath({\n\t\tfilename: \"app\",\n\t\thelpers: args.helpers,\n\t});\n\n\treturn await checkHasProjectFile({\n\t\tfilename: appRouterPath,\n\t\thelpers: args.helpers,\n\t});\n}\n"],"names":[],"mappings":";;AAYA,eAAsB,kBACrB,MAA2B;AAErB,QAAA,gBAAgB,MAAM,aAAa;AAAA,IACxC,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AAED,SAAO,MAAM,oBAAoB;AAAA,IAChC,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AACF;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slicemachine/adapter-next",
|
|
3
|
-
"version": "0.3.43-
|
|
3
|
+
"version": "0.3.43-beta.1",
|
|
4
4
|
"description": "Slice Machine adapter for Next.js.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@prismicio/simulator": "^0.1.4",
|
|
70
|
-
"@prismicio/types-internal": "2.
|
|
71
|
-
"@slicemachine/plugin-kit": "0.4.43-
|
|
70
|
+
"@prismicio/types-internal": "^2.4.1",
|
|
71
|
+
"@slicemachine/plugin-kit": "0.4.43-beta.1",
|
|
72
72
|
"common-tags": "^1.8.2",
|
|
73
73
|
"fp-ts": "^2.13.1",
|
|
74
74
|
"io-ts": "^2.2.20",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"next": "14.1.3",
|
|
96
96
|
"prettier": "3.0.3",
|
|
97
97
|
"prettier-plugin-jsdoc": "1.1.1",
|
|
98
|
-
"prismic-ts-codegen": "0.1.
|
|
98
|
+
"prismic-ts-codegen": "^0.1.20",
|
|
99
99
|
"react": "18.2.0",
|
|
100
100
|
"rollup-plugin-preserve-directives": "0.2.0",
|
|
101
101
|
"size-limit": "8.2.4",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as path from "node:path";
|
|
2
1
|
import type {
|
|
3
2
|
ProjectInitHook,
|
|
4
3
|
ProjectInitHookData,
|
|
@@ -10,8 +9,8 @@ import {
|
|
|
10
9
|
} from "@slicemachine/plugin-kit/fs";
|
|
11
10
|
import { source } from "common-tags";
|
|
12
11
|
|
|
12
|
+
import { buildSrcPath } from "../lib/buildSrcPath";
|
|
13
13
|
import { checkHasAppRouter } from "../lib/checkHasAppRouter";
|
|
14
|
-
import { checkHasSrcDirectory } from "../lib/checkHasSrcDirectory";
|
|
15
14
|
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
|
|
16
15
|
import { getJSFileExtension } from "../lib/getJSFileExtension";
|
|
17
16
|
import { rejectIfNecessary } from "../lib/rejectIfNecessary";
|
|
@@ -45,15 +44,17 @@ const createPrismicIOFile = async ({
|
|
|
45
44
|
helpers,
|
|
46
45
|
options,
|
|
47
46
|
});
|
|
48
|
-
const hasSrcDirectory = await
|
|
47
|
+
const hasSrcDirectory = await checkHasProjectFile({
|
|
48
|
+
filename: "src",
|
|
49
|
+
helpers,
|
|
50
|
+
});
|
|
49
51
|
const hasAppRouter = await checkHasAppRouter({ helpers });
|
|
50
52
|
|
|
51
53
|
const extension = await getJSFileExtension({ helpers, options });
|
|
52
|
-
const filename =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
);
|
|
54
|
+
const filename = await buildSrcPath({
|
|
55
|
+
filename: `prismicio.${extension}`,
|
|
56
|
+
helpers,
|
|
57
|
+
});
|
|
57
58
|
|
|
58
59
|
if (await checkHasProjectFile({ filename, helpers })) {
|
|
59
60
|
return;
|
|
@@ -255,20 +256,15 @@ const createSliceSimulatorPage = async ({
|
|
|
255
256
|
helpers,
|
|
256
257
|
options,
|
|
257
258
|
});
|
|
258
|
-
const hasSrcDirectory = await checkHasSrcDirectory({ helpers });
|
|
259
259
|
const hasAppRouter = await checkHasAppRouter({ helpers });
|
|
260
260
|
|
|
261
261
|
const extension = await getJSFileExtension({ helpers, options, jsx: true });
|
|
262
|
-
const filename =
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
].filter((segment): segment is NonNullable<typeof segment> =>
|
|
269
|
-
Boolean(segment),
|
|
270
|
-
),
|
|
271
|
-
);
|
|
262
|
+
const filename = await buildSrcPath({
|
|
263
|
+
filename: hasAppRouter
|
|
264
|
+
? `app/slice-simulator/page.${extension}`
|
|
265
|
+
: `pages/slice-simulator.${extension}`,
|
|
266
|
+
helpers,
|
|
267
|
+
});
|
|
272
268
|
|
|
273
269
|
if (await checkHasProjectFile({ filename, helpers })) {
|
|
274
270
|
return;
|
|
@@ -350,7 +346,6 @@ const createPreviewRoute = async ({
|
|
|
350
346
|
helpers,
|
|
351
347
|
options,
|
|
352
348
|
}: SliceMachineContext<PluginOptions>) => {
|
|
353
|
-
const hasSrcDirectory = await checkHasSrcDirectory({ helpers });
|
|
354
349
|
const hasAppRouter = await checkHasAppRouter({ helpers });
|
|
355
350
|
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
356
351
|
helpers,
|
|
@@ -358,16 +353,12 @@ const createPreviewRoute = async ({
|
|
|
358
353
|
});
|
|
359
354
|
|
|
360
355
|
const extension = await getJSFileExtension({ helpers, options });
|
|
361
|
-
const filename =
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
].filter((segment): segment is NonNullable<typeof segment> =>
|
|
368
|
-
Boolean(segment),
|
|
369
|
-
),
|
|
370
|
-
);
|
|
356
|
+
const filename = await buildSrcPath({
|
|
357
|
+
filename: hasAppRouter
|
|
358
|
+
? `app/api/preview/route.${extension}`
|
|
359
|
+
: `pages/api/preview.${extension}`,
|
|
360
|
+
helpers,
|
|
361
|
+
});
|
|
371
362
|
|
|
372
363
|
if (await checkHasProjectFile({ filename, helpers })) {
|
|
373
364
|
return;
|
|
@@ -447,7 +438,6 @@ const createExitPreviewRoute = async ({
|
|
|
447
438
|
helpers,
|
|
448
439
|
options,
|
|
449
440
|
}: SliceMachineContext<PluginOptions>) => {
|
|
450
|
-
const hasSrcDirectory = await checkHasSrcDirectory({ helpers });
|
|
451
441
|
const hasAppRouter = await checkHasAppRouter({ helpers });
|
|
452
442
|
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
453
443
|
helpers,
|
|
@@ -455,16 +445,12 @@ const createExitPreviewRoute = async ({
|
|
|
455
445
|
});
|
|
456
446
|
|
|
457
447
|
const extension = await getJSFileExtension({ helpers, options });
|
|
458
|
-
const filename =
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
].filter((segment): segment is NonNullable<typeof segment> =>
|
|
465
|
-
Boolean(segment),
|
|
466
|
-
),
|
|
467
|
-
);
|
|
448
|
+
const filename = await buildSrcPath({
|
|
449
|
+
filename: hasAppRouter
|
|
450
|
+
? `app/api/exit-preview/route.${extension}`
|
|
451
|
+
: `pages/api/exit-preview.${extension}`,
|
|
452
|
+
helpers,
|
|
453
|
+
});
|
|
468
454
|
|
|
469
455
|
if (await checkHasProjectFile({ filename, helpers })) {
|
|
470
456
|
return;
|
|
@@ -514,7 +500,10 @@ const modifySliceMachineConfig = async ({
|
|
|
514
500
|
options,
|
|
515
501
|
actions,
|
|
516
502
|
}: SliceMachineContext<PluginOptions>) => {
|
|
517
|
-
const hasSrcDirectory = await
|
|
503
|
+
const hasSrcDirectory = await checkHasProjectFile({
|
|
504
|
+
filename: "src",
|
|
505
|
+
helpers,
|
|
506
|
+
});
|
|
518
507
|
const project = await helpers.getProject();
|
|
519
508
|
|
|
520
509
|
// Add Slice Simulator URL.
|
|
@@ -552,17 +541,11 @@ const createRevalidateRoute = async ({
|
|
|
552
541
|
return;
|
|
553
542
|
}
|
|
554
543
|
|
|
555
|
-
const hasSrcDirectory = await checkHasSrcDirectory({ helpers });
|
|
556
|
-
|
|
557
544
|
const extension = await getJSFileExtension({ helpers, options });
|
|
558
|
-
const filename =
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
].filter((segment): segment is NonNullable<typeof segment> =>
|
|
563
|
-
Boolean(segment),
|
|
564
|
-
),
|
|
565
|
-
);
|
|
545
|
+
const filename = await buildSrcPath({
|
|
546
|
+
filename: `app/api/revalidate/route.${extension}`,
|
|
547
|
+
helpers,
|
|
548
|
+
});
|
|
566
549
|
|
|
567
550
|
if (await checkHasProjectFile({ filename, helpers })) {
|
|
568
551
|
return;
|
|
@@ -28,7 +28,7 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
|
|
|
28
28
|
data,
|
|
29
29
|
{ helpers },
|
|
30
30
|
) => {
|
|
31
|
-
const { fieldPath
|
|
31
|
+
const { fieldPath } = data;
|
|
32
32
|
|
|
33
33
|
const label = "React";
|
|
34
34
|
|
|
@@ -88,8 +88,8 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
|
|
|
88
88
|
const code = await format(
|
|
89
89
|
stripIndent`
|
|
90
90
|
<>
|
|
91
|
-
{${dotPath(fieldPath)}.map((
|
|
92
|
-
// Render the
|
|
91
|
+
{${dotPath(fieldPath)}.map((item) => {
|
|
92
|
+
// Render the item
|
|
93
93
|
})}
|
|
94
94
|
</>
|
|
95
95
|
`,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
|
|
3
|
+
import type { SliceMachineHelpers } from "@slicemachine/plugin-kit";
|
|
4
|
+
import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
|
|
5
|
+
|
|
6
|
+
export async function buildSrcPath(args: {
|
|
7
|
+
filename: string;
|
|
8
|
+
helpers: SliceMachineHelpers;
|
|
9
|
+
}): Promise<string> {
|
|
10
|
+
const hasSrcDirectory = await checkHasProjectFile({
|
|
11
|
+
filename: "src",
|
|
12
|
+
helpers: args.helpers,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return hasSrcDirectory ? path.join("src", args.filename) : args.filename;
|
|
16
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
2
|
import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
|
|
3
|
-
import * as path from "node:path";
|
|
4
3
|
|
|
5
4
|
import { PluginOptions } from "../types";
|
|
6
|
-
|
|
5
|
+
|
|
6
|
+
import { buildSrcPath } from "./buildSrcPath";
|
|
7
7
|
|
|
8
8
|
type CheckHasAppRouterArgs = Pick<
|
|
9
9
|
SliceMachineContext<PluginOptions>,
|
|
@@ -13,10 +13,13 @@ type CheckHasAppRouterArgs = Pick<
|
|
|
13
13
|
export async function checkHasAppRouter(
|
|
14
14
|
args: CheckHasAppRouterArgs,
|
|
15
15
|
): Promise<boolean> {
|
|
16
|
-
const
|
|
16
|
+
const appRouterPath = await buildSrcPath({
|
|
17
|
+
filename: "app",
|
|
18
|
+
helpers: args.helpers,
|
|
19
|
+
});
|
|
17
20
|
|
|
18
21
|
return await checkHasProjectFile({
|
|
19
|
-
filename:
|
|
22
|
+
filename: appRouterPath,
|
|
20
23
|
helpers: args.helpers,
|
|
21
24
|
});
|
|
22
25
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const fs = require("@slicemachine/plugin-kit/fs");
|
|
4
|
-
async function checkHasSrcDirectory(args) {
|
|
5
|
-
return await fs.checkHasProjectFile({
|
|
6
|
-
filename: "src",
|
|
7
|
-
helpers: args.helpers
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
exports.checkHasSrcDirectory = checkHasSrcDirectory;
|
|
11
|
-
//# sourceMappingURL=checkHasSrcDirectory.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkHasSrcDirectory.cjs","sources":["../../../src/lib/checkHasSrcDirectory.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { checkHasProjectFile } from \"@slicemachine/plugin-kit/fs\";\n\nimport { PluginOptions } from \"../types\";\n\ntype CheckHasSrcDirectoryArgs = Pick<\n\tSliceMachineContext<PluginOptions>,\n\t\"helpers\"\n>;\n\nexport async function checkHasSrcDirectory(\n\targs: CheckHasSrcDirectoryArgs,\n): Promise<boolean> {\n\treturn await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers: args.helpers,\n\t});\n}\n"],"names":["checkHasProjectFile"],"mappings":";;;AAUA,eAAsB,qBACrB,MAA8B;AAE9B,SAAO,MAAMA,GAAAA,oBAAoB;AAAA,IAChC,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AACF;;"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
-
import { PluginOptions } from "../types";
|
|
3
|
-
type CheckHasSrcDirectoryArgs = Pick<SliceMachineContext<PluginOptions>, "helpers">;
|
|
4
|
-
export declare function checkHasSrcDirectory(args: CheckHasSrcDirectoryArgs): Promise<boolean>;
|
|
5
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
|
|
2
|
-
async function checkHasSrcDirectory(args) {
|
|
3
|
-
return await checkHasProjectFile({
|
|
4
|
-
filename: "src",
|
|
5
|
-
helpers: args.helpers
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
export {
|
|
9
|
-
checkHasSrcDirectory
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=checkHasSrcDirectory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkHasSrcDirectory.js","sources":["../../../src/lib/checkHasSrcDirectory.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { checkHasProjectFile } from \"@slicemachine/plugin-kit/fs\";\n\nimport { PluginOptions } from \"../types\";\n\ntype CheckHasSrcDirectoryArgs = Pick<\n\tSliceMachineContext<PluginOptions>,\n\t\"helpers\"\n>;\n\nexport async function checkHasSrcDirectory(\n\targs: CheckHasSrcDirectoryArgs,\n): Promise<boolean> {\n\treturn await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers: args.helpers,\n\t});\n}\n"],"names":[],"mappings":";AAUA,eAAsB,qBACrB,MAA8B;AAE9B,SAAO,MAAM,oBAAoB;AAAA,IAChC,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AACF;"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
-
import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
|
|
3
|
-
|
|
4
|
-
import { PluginOptions } from "../types";
|
|
5
|
-
|
|
6
|
-
type CheckHasSrcDirectoryArgs = Pick<
|
|
7
|
-
SliceMachineContext<PluginOptions>,
|
|
8
|
-
"helpers"
|
|
9
|
-
>;
|
|
10
|
-
|
|
11
|
-
export async function checkHasSrcDirectory(
|
|
12
|
-
args: CheckHasSrcDirectoryArgs,
|
|
13
|
-
): Promise<boolean> {
|
|
14
|
-
return await checkHasProjectFile({
|
|
15
|
-
filename: "src",
|
|
16
|
-
helpers: args.helpers,
|
|
17
|
-
});
|
|
18
|
-
}
|