@slicemachine/adapter-next 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SliceSimulator.cjs +14 -41
- package/dist/SliceSimulator.cjs.map +1 -1
- package/dist/SliceSimulator.d.ts +2 -2
- package/dist/SliceSimulator.js +11 -36
- package/dist/SliceSimulator.js.map +1 -1
- package/dist/_virtual/_commonjsHelpers.cjs +5 -0
- package/dist/_virtual/_commonjsHelpers.cjs.map +1 -0
- package/dist/_virtual/_commonjsHelpers.js +5 -0
- package/dist/_virtual/_commonjsHelpers.js.map +1 -0
- package/dist/_virtual/ponyfill.es2018.cjs +5 -0
- package/dist/_virtual/ponyfill.es2018.cjs.map +1 -0
- package/dist/_virtual/ponyfill.es2018.js +5 -0
- package/dist/_virtual/ponyfill.es2018.js.map +1 -0
- package/dist/constants.cjs +5 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/hooks/customType-asset-delete.cjs +3 -5
- package/dist/hooks/customType-asset-delete.cjs.map +1 -1
- package/dist/hooks/customType-asset-delete.js.map +1 -1
- package/dist/hooks/customType-asset-read.cjs +3 -5
- package/dist/hooks/customType-asset-read.cjs.map +1 -1
- package/dist/hooks/customType-asset-read.js.map +1 -1
- package/dist/hooks/customType-asset-update.cjs +4 -6
- package/dist/hooks/customType-asset-update.cjs.map +1 -1
- package/dist/hooks/customType-asset-update.js.map +1 -1
- package/dist/hooks/customType-create.cjs +4 -6
- package/dist/hooks/customType-create.cjs.map +1 -1
- package/dist/hooks/customType-create.js.map +1 -1
- package/dist/hooks/customType-delete.cjs +3 -5
- package/dist/hooks/customType-delete.cjs.map +1 -1
- package/dist/hooks/customType-delete.js.map +1 -1
- package/dist/hooks/customType-read.cjs +1 -1
- package/dist/hooks/customType-read.cjs.map +1 -1
- package/dist/hooks/customType-read.js.map +1 -1
- package/dist/hooks/customType-rename.cjs +6 -0
- package/dist/hooks/customType-rename.cjs.map +1 -0
- package/dist/hooks/customType-rename.d.ts +1 -0
- package/dist/hooks/customType-rename.js +6 -0
- package/dist/hooks/customType-rename.js.map +1 -0
- package/dist/hooks/customType-update.cjs +1 -1
- package/dist/hooks/customType-update.cjs.map +1 -1
- package/dist/hooks/customType-update.js.map +1 -1
- package/dist/hooks/customTypeLibrary-read.cjs +16 -10
- package/dist/hooks/customTypeLibrary-read.cjs.map +1 -1
- package/dist/hooks/customTypeLibrary-read.js +12 -4
- package/dist/hooks/customTypeLibrary-read.js.map +1 -1
- package/dist/hooks/slice-asset-delete.cjs +3 -5
- package/dist/hooks/slice-asset-delete.cjs.map +1 -1
- package/dist/hooks/slice-asset-delete.js.map +1 -1
- package/dist/hooks/slice-asset-read.cjs +3 -5
- package/dist/hooks/slice-asset-read.cjs.map +1 -1
- package/dist/hooks/slice-asset-read.js.map +1 -1
- package/dist/hooks/slice-asset-update.cjs +4 -6
- package/dist/hooks/slice-asset-update.cjs.map +1 -1
- package/dist/hooks/slice-asset-update.js.map +1 -1
- package/dist/hooks/slice-create.cjs +18 -30
- package/dist/hooks/slice-create.cjs.map +1 -1
- package/dist/hooks/slice-create.js +14 -24
- package/dist/hooks/slice-create.js.map +1 -1
- package/dist/hooks/slice-delete.cjs +6 -18
- package/dist/hooks/slice-delete.cjs.map +1 -1
- package/dist/hooks/slice-delete.js +3 -13
- package/dist/hooks/slice-delete.js.map +1 -1
- package/dist/hooks/slice-read.cjs +41 -7
- package/dist/hooks/slice-read.cjs.map +1 -1
- package/dist/hooks/slice-read.js +22 -6
- package/dist/hooks/slice-read.js.map +1 -1
- package/dist/hooks/slice-rename.cjs +43 -0
- package/dist/hooks/slice-rename.cjs.map +1 -0
- package/dist/hooks/slice-rename.d.ts +3 -0
- package/dist/hooks/slice-rename.js +26 -0
- package/dist/hooks/slice-rename.js.map +1 -0
- package/dist/hooks/slice-update.cjs +7 -34
- package/dist/hooks/slice-update.cjs.map +1 -1
- package/dist/hooks/slice-update.js +6 -13
- package/dist/hooks/slice-update.js.map +1 -1
- package/dist/hooks/sliceLibrary-read.cjs +16 -20
- package/dist/hooks/sliceLibrary-read.cjs.map +1 -1
- package/dist/hooks/sliceLibrary-read.js +12 -13
- package/dist/hooks/sliceLibrary-read.js.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.cjs +31 -94
- package/dist/hooks/sliceSimulator-setup-read.cjs.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.js +31 -75
- package/dist/hooks/sliceSimulator-setup-read.js.map +1 -1
- package/dist/hooks/snippet-read.cjs +33 -18
- package/dist/hooks/snippet-read.cjs.map +1 -1
- package/dist/hooks/snippet-read.js +30 -13
- package/dist/hooks/snippet-read.js.map +1 -1
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/getJSOrTSXFileExtension.cjs +1 -1
- package/dist/lib/getJSOrTSXFileExtension.cjs.map +1 -1
- package/dist/lib/getJSOrTSXFileExtension.js.map +1 -1
- package/dist/lib/isSharedSliceModel.cjs +25 -0
- package/dist/lib/isSharedSliceModel.cjs.map +1 -0
- package/dist/lib/isSharedSliceModel.d.ts +2 -0
- package/dist/lib/isSharedSliceModel.js +8 -0
- package/dist/lib/isSharedSliceModel.js.map +1 -0
- package/dist/lib/pascalCase.cjs +1 -1
- package/dist/lib/pascalCase.cjs.map +1 -1
- package/dist/lib/pascalCase.js.map +1 -1
- package/dist/lib/readJSONFile.cjs +3 -5
- package/dist/lib/readJSONFile.cjs.map +1 -1
- package/dist/lib/readJSONFile.js.map +1 -1
- package/dist/lib/rejectIfNecessary.cjs +1 -1
- package/dist/lib/rejectIfNecessary.cjs.map +1 -1
- package/dist/lib/rejectIfNecessary.js.map +1 -1
- package/dist/lib/updateSliceModelFile.cjs +31 -0
- package/dist/lib/updateSliceModelFile.cjs.map +1 -0
- package/dist/lib/updateSliceModelFile.d.ts +9 -0
- package/dist/lib/updateSliceModelFile.js +14 -0
- package/dist/lib/updateSliceModelFile.js.map +1 -0
- package/dist/lib/upsertGlobalContentTypes.cjs +8 -6
- package/dist/lib/upsertGlobalContentTypes.cjs.map +1 -1
- package/dist/lib/upsertGlobalContentTypes.d.ts +1 -1
- package/dist/lib/upsertGlobalContentTypes.js +4 -0
- package/dist/lib/upsertGlobalContentTypes.js.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.cjs +48 -0
- package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -0
- package/dist/lib/upsertSliceLibraryIndexFile.d.ts +7 -0
- package/dist/lib/upsertSliceLibraryIndexFile.js +31 -0
- package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.cjs +41 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.cjs.map +1 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.js +41 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.js.map +1 -0
- package/dist/node_modules/fetch-blob/file.cjs +55 -0
- package/dist/node_modules/fetch-blob/file.cjs.map +1 -0
- package/dist/node_modules/fetch-blob/file.js +55 -0
- package/dist/node_modules/fetch-blob/file.js.map +1 -0
- package/dist/node_modules/fetch-blob/index.cjs +176 -0
- package/dist/node_modules/fetch-blob/index.cjs.map +1 -0
- package/dist/node_modules/fetch-blob/index.js +176 -0
- package/dist/node_modules/fetch-blob/index.js.map +1 -0
- package/dist/node_modules/fetch-blob/streams.cjs +43 -0
- package/dist/node_modules/fetch-blob/streams.cjs.map +1 -0
- package/dist/node_modules/fetch-blob/streams.js +42 -0
- package/dist/node_modules/fetch-blob/streams.js.map +1 -0
- package/dist/node_modules/formdata-polyfill/esm.min.cjs +115 -0
- package/dist/node_modules/formdata-polyfill/esm.min.cjs.map +1 -0
- package/dist/node_modules/formdata-polyfill/esm.min.js +115 -0
- package/dist/node_modules/formdata-polyfill/esm.min.js.map +1 -0
- package/dist/node_modules/node-domexception/index.cjs +10 -0
- package/dist/node_modules/node-domexception/index.cjs.map +1 -0
- package/dist/node_modules/node-domexception/index.js +9 -0
- package/dist/node_modules/node-domexception/index.js.map +1 -0
- package/dist/node_modules/node-fetch/src/body.cjs +237 -0
- package/dist/node_modules/node-fetch/src/body.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/body.js +237 -0
- package/dist/node_modules/node-fetch/src/body.js.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.cjs +10 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.js +10 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.js.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/base.cjs +17 -0
- package/dist/node_modules/node-fetch/src/errors/base.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/base.js +17 -0
- package/dist/node_modules/node-fetch/src/errors/base.js.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs +14 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.js +14 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.js.map +1 -0
- package/dist/node_modules/node-fetch/src/headers.cjs +173 -0
- package/dist/node_modules/node-fetch/src/headers.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/headers.js +173 -0
- package/dist/node_modules/node-fetch/src/headers.js.map +1 -0
- package/dist/node_modules/node-fetch/src/index.cjs +292 -0
- package/dist/node_modules/node-fetch/src/index.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/index.js +298 -0
- package/dist/node_modules/node-fetch/src/index.js.map +1 -0
- package/dist/node_modules/node-fetch/src/request.cjs +193 -0
- package/dist/node_modules/node-fetch/src/request.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/request.js +193 -0
- package/dist/node_modules/node-fetch/src/request.js.map +1 -0
- package/dist/node_modules/node-fetch/src/response.cjs +110 -0
- package/dist/node_modules/node-fetch/src/response.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/response.js +110 -0
- package/dist/node_modules/node-fetch/src/response.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.cjs +12 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.js +12 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.cjs +8 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.js +8 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is.cjs +28 -0
- package/dist/node_modules/node-fetch/src/utils/is.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is.js +28 -0
- package/dist/node_modules/node-fetch/src/utils/is.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs +350 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.js +350 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.cjs +149 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.js +149 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.js.map +1 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs +3599 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs.map +1 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js +3599 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js.map +1 -0
- package/dist/package.json.cjs +5 -0
- package/dist/package.json.cjs.map +1 -0
- package/dist/{package.js → package.json.js} +1 -1
- package/dist/package.json.js.map +1 -0
- package/dist/plugin.cjs +6 -2
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +5 -1
- package/dist/plugin.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +32 -15
- package/src/constants.ts +5 -0
- package/src/hooks/customType-rename.ts +3 -0
- package/src/hooks/customTypeLibrary-read.ts +13 -4
- package/src/hooks/slice-create.ts +14 -32
- package/src/hooks/slice-delete.ts +3 -21
- package/src/hooks/slice-read.ts +37 -11
- package/src/hooks/slice-rename.ts +44 -0
- package/src/hooks/slice-update.ts +7 -31
- package/src/hooks/sliceLibrary-read.ts +13 -23
- package/src/hooks/sliceSimulator-setup-read.ts +37 -76
- package/src/hooks/snippet-read.ts +42 -22
- package/src/index.ts +0 -6
- package/src/lib/isSharedSliceModel.ts +14 -0
- package/src/lib/updateSliceModelFile.ts +32 -0
- package/src/lib/upsertGlobalContentTypes.ts +3 -0
- package/src/lib/{buildSliceLibraryIndexFileContents.ts → upsertSliceLibraryIndexFile.ts} +19 -9
- package/src/plugin.ts +4 -0
- package/dist/lib/buildSliceLibraryIndexFileContents.cjs +0 -23
- package/dist/lib/buildSliceLibraryIndexFileContents.cjs.map +0 -1
- package/dist/lib/buildSliceLibraryIndexFileContents.d.ts +0 -10
- package/dist/lib/buildSliceLibraryIndexFileContents.js +0 -23
- package/dist/lib/buildSliceLibraryIndexFileContents.js.map +0 -1
- package/dist/package.cjs +0 -5
- package/dist/package.cjs.map +0 -1
- package/dist/package.js.map +0 -1
|
@@ -1,48 +1,38 @@
|
|
|
1
1
|
import type { SliceLibraryReadHook } from "@slicemachine/plugin-kit";
|
|
2
|
-
import * as prismicT from "@prismicio/types";
|
|
3
2
|
import * as fs from "node:fs/promises";
|
|
4
3
|
import * as path from "node:path";
|
|
5
4
|
|
|
5
|
+
import { isSharedSliceModel } from "../lib/isSharedSliceModel";
|
|
6
6
|
import { readJSONFile } from "../lib/readJSONFile";
|
|
7
7
|
|
|
8
8
|
import type { PluginOptions } from "../types";
|
|
9
9
|
|
|
10
|
-
const isSharedSliceModel = (
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
-
input: any,
|
|
13
|
-
): input is prismicT.SharedSliceModel => {
|
|
14
|
-
return (
|
|
15
|
-
typeof input === "object" &&
|
|
16
|
-
input !== null &&
|
|
17
|
-
"type" in input &&
|
|
18
|
-
input.type === prismicT.CustomTypeModelSliceType.SharedSlice
|
|
19
|
-
);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
10
|
export const sliceLibraryRead: SliceLibraryReadHook<PluginOptions> = async (
|
|
23
11
|
data,
|
|
24
12
|
{ helpers },
|
|
25
13
|
) => {
|
|
26
|
-
const
|
|
14
|
+
const dir = helpers.joinPathFromRoot(data.libraryID);
|
|
27
15
|
|
|
28
16
|
// Ensure the directory exists.
|
|
29
|
-
await fs.mkdir(
|
|
17
|
+
await fs.mkdir(dir, { recursive: true });
|
|
30
18
|
|
|
31
|
-
const childDirs = await fs.readdir(
|
|
19
|
+
const childDirs = await fs.readdir(dir, { withFileTypes: true });
|
|
32
20
|
|
|
33
21
|
const sliceIDs: string[] = [];
|
|
34
22
|
await Promise.all(
|
|
35
23
|
childDirs.map(async (childDir) => {
|
|
36
|
-
|
|
24
|
+
if (childDir.isDirectory()) {
|
|
25
|
+
const modelPath = path.join(dir, childDir.name, "model.json");
|
|
37
26
|
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
try {
|
|
28
|
+
const modelContents = await readJSONFile(modelPath);
|
|
40
29
|
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
if (isSharedSliceModel(modelContents)) {
|
|
31
|
+
sliceIDs.push(modelContents.id);
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
// noop
|
|
43
35
|
}
|
|
44
|
-
} catch {
|
|
45
|
-
// noop
|
|
46
36
|
}
|
|
47
37
|
}),
|
|
48
38
|
);
|
|
@@ -4,9 +4,9 @@ import type {
|
|
|
4
4
|
SliceSimulatorSetupStep,
|
|
5
5
|
} from "@slicemachine/plugin-kit";
|
|
6
6
|
import { SliceSimulatorSetupStepValidationMessageType } from "@slicemachine/plugin-kit";
|
|
7
|
-
import {
|
|
7
|
+
import { source } from "common-tags";
|
|
8
8
|
import { createRequire } from "node:module";
|
|
9
|
-
import
|
|
9
|
+
import fetch from "node-fetch";
|
|
10
10
|
|
|
11
11
|
import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension";
|
|
12
12
|
|
|
@@ -14,8 +14,7 @@ import type { PluginOptions } from "../types";
|
|
|
14
14
|
|
|
15
15
|
const REQUIRED_DEPENDENCIES = [
|
|
16
16
|
"@prismicio/react",
|
|
17
|
-
"@prismicio/
|
|
18
|
-
"@prismicio/client@latest",
|
|
17
|
+
"@prismicio/client",
|
|
19
18
|
"@prismicio/helpers",
|
|
20
19
|
];
|
|
21
20
|
|
|
@@ -23,16 +22,19 @@ type Args = SliceMachineContext<PluginOptions>;
|
|
|
23
22
|
|
|
24
23
|
const createStep1 = async ({
|
|
25
24
|
project,
|
|
25
|
+
helpers,
|
|
26
26
|
}: Args): Promise<SliceSimulatorSetupStep> => {
|
|
27
27
|
const require = createRequire(project.root);
|
|
28
28
|
|
|
29
29
|
return {
|
|
30
30
|
title: "Install packages",
|
|
31
|
-
|
|
31
|
+
// TODO: Create a plugin runner helper to provide the correct
|
|
32
|
+
// package manager
|
|
33
|
+
body: source`
|
|
32
34
|
The simulator requires extra dependencies. Run the following command to install them.
|
|
33
35
|
|
|
34
36
|
~~~sh
|
|
35
|
-
npm install --save
|
|
37
|
+
npm install --save ${REQUIRED_DEPENDENCIES.join(" ")}
|
|
36
38
|
~~~
|
|
37
39
|
`,
|
|
38
40
|
validate: async () => {
|
|
@@ -44,7 +46,9 @@ const createStep1 = async ({
|
|
|
44
46
|
// over `import()` because we don't
|
|
45
47
|
// want to load the module. Loading a
|
|
46
48
|
// module could introduce side-effects.
|
|
47
|
-
require.resolve(dependency
|
|
49
|
+
require.resolve(dependency, {
|
|
50
|
+
paths: [helpers.joinPathFromRoot("node_modules")],
|
|
51
|
+
});
|
|
48
52
|
} catch {
|
|
49
53
|
missingDependencies.push(dependency);
|
|
50
54
|
}
|
|
@@ -54,7 +58,7 @@ const createStep1 = async ({
|
|
|
54
58
|
return {
|
|
55
59
|
type: SliceSimulatorSetupStepValidationMessageType.Error,
|
|
56
60
|
title: "Missing all dependencies",
|
|
57
|
-
message:
|
|
61
|
+
message: source`
|
|
58
62
|
Install the required dependencies to continue.
|
|
59
63
|
`,
|
|
60
64
|
};
|
|
@@ -66,9 +70,9 @@ const createStep1 = async ({
|
|
|
66
70
|
.join(", ");
|
|
67
71
|
|
|
68
72
|
return {
|
|
69
|
-
type: SliceSimulatorSetupStepValidationMessageType.
|
|
73
|
+
type: SliceSimulatorSetupStepValidationMessageType.Error,
|
|
70
74
|
title: "Missing some dependencies",
|
|
71
|
-
message:
|
|
75
|
+
message: source`
|
|
72
76
|
The following dependencies are missing: ${formattedMissingDependencies}
|
|
73
77
|
`,
|
|
74
78
|
};
|
|
@@ -81,47 +85,18 @@ const createStep2 = async ({
|
|
|
81
85
|
helpers,
|
|
82
86
|
options,
|
|
83
87
|
}: Args): Promise<SliceSimulatorSetupStep> => {
|
|
84
|
-
const fileName = `slice-simulator.${getJSOrTSXFileExtension}`;
|
|
88
|
+
const fileName = `slice-simulator.${getJSOrTSXFileExtension(options)}`;
|
|
85
89
|
const filePath = helpers.joinPathFromRoot("pages", fileName);
|
|
86
90
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (options.typescript) {
|
|
90
|
-
fileContents = stripIndent`
|
|
91
|
-
import { GetStaticProps } from "next/types";
|
|
92
|
-
import { SliceSimulator } from "@prismicio/slice-simulator-react";
|
|
93
|
-
import { SliceZone } from "@prismicio/react";
|
|
94
|
-
|
|
95
|
-
import state from "../.slicemachine/libraries-state.json";
|
|
96
|
-
import { components } from "../slices";
|
|
97
|
-
|
|
98
|
-
const SliceSimulatorPage = () => {
|
|
99
|
-
return (
|
|
100
|
-
<SliceSimulator
|
|
101
|
-
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
102
|
-
state={state}
|
|
103
|
-
/>
|
|
104
|
-
);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export default SliceSimulatorPage;
|
|
108
|
-
|
|
109
|
-
export const getStaticProps: GetStaticProps = () => {
|
|
110
|
-
return {
|
|
111
|
-
// Exclude this page from production builds.
|
|
112
|
-
notFound: process.env.NODE_ENV === "production",
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
`;
|
|
116
|
-
} else {
|
|
117
|
-
fileContents = stripIndent`
|
|
91
|
+
const fileContents = await helpers.format(
|
|
92
|
+
source`
|
|
118
93
|
import { SliceSimulator } from "@prismicio/slice-simulator-react";
|
|
119
94
|
import { SliceZone } from "@prismicio/react";
|
|
120
95
|
|
|
121
96
|
import state from "../.slicemachine/libraries-state.json";
|
|
122
97
|
import { components } from "../slices";
|
|
123
98
|
|
|
124
|
-
|
|
99
|
+
export default function SliceSimulatorPage() {
|
|
125
100
|
return (
|
|
126
101
|
<SliceSimulator
|
|
127
102
|
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
@@ -129,23 +104,16 @@ const createStep2 = async ({
|
|
|
129
104
|
/>
|
|
130
105
|
);
|
|
131
106
|
};
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
notFound: process.env.NODE_ENV === "production",
|
|
139
|
-
};
|
|
140
|
-
};
|
|
141
|
-
`;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
fileContents = await helpers.format(fileContents, filePath);
|
|
107
|
+
`,
|
|
108
|
+
filePath,
|
|
109
|
+
{
|
|
110
|
+
includeNewlineAtEnd: false,
|
|
111
|
+
},
|
|
112
|
+
);
|
|
145
113
|
|
|
146
114
|
return {
|
|
147
115
|
title: "Create a page for the simulator",
|
|
148
|
-
body:
|
|
116
|
+
body: source`
|
|
149
117
|
In your \`pages\` directory, create a file called \`${fileName}\` and add the following code. This route will be used to simulate and develop your components.
|
|
150
118
|
|
|
151
119
|
~~~tsx
|
|
@@ -160,17 +128,20 @@ const createStep3 = async ({
|
|
|
160
128
|
}: Args): Promise<SliceSimulatorSetupStep> => {
|
|
161
129
|
const filePath = helpers.joinPathFromRoot("sm.json");
|
|
162
130
|
const fileContents = await helpers.format(
|
|
163
|
-
`
|
|
131
|
+
source`
|
|
164
132
|
{
|
|
165
133
|
"localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
|
|
166
134
|
}
|
|
167
135
|
`,
|
|
168
136
|
filePath,
|
|
137
|
+
{
|
|
138
|
+
includeNewlineAtEnd: false,
|
|
139
|
+
},
|
|
169
140
|
);
|
|
170
141
|
|
|
171
142
|
return {
|
|
172
143
|
title: "Update `sm.json`",
|
|
173
|
-
body:
|
|
144
|
+
body: source`
|
|
174
145
|
Update your \`sm.json\` file with a \`localSliceSimulatorURL\` property pointing to your \`slice-simulator\` page.
|
|
175
146
|
|
|
176
147
|
~~~json
|
|
@@ -184,7 +155,7 @@ const createStep3 = async ({
|
|
|
184
155
|
return {
|
|
185
156
|
type: SliceSimulatorSetupStepValidationMessageType.Error,
|
|
186
157
|
title: "Missing `localSliceSimulatorURL` property",
|
|
187
|
-
message:
|
|
158
|
+
message: source`
|
|
188
159
|
A \`localSliceSimulatorURL\` property was not found in your \`sm.json\` file.
|
|
189
160
|
`,
|
|
190
161
|
};
|
|
@@ -199,32 +170,22 @@ const createStep3 = async ({
|
|
|
199
170
|
}
|
|
200
171
|
} catch {
|
|
201
172
|
return {
|
|
202
|
-
type: SliceSimulatorSetupStepValidationMessageType.
|
|
173
|
+
type: SliceSimulatorSetupStepValidationMessageType.Error,
|
|
203
174
|
title: "An invalid URL was provided",
|
|
204
|
-
message:
|
|
175
|
+
message: source`
|
|
205
176
|
The \`localSliceSimulatorURL\` property should be of the shape \`http://localhost:PORT/PATH\`. See the codeblock for an example.
|
|
206
177
|
`,
|
|
207
178
|
};
|
|
208
179
|
}
|
|
209
180
|
|
|
210
181
|
// Check if the URL is accessible.
|
|
211
|
-
const
|
|
212
|
-
if (project.config.localSliceSimulatorURL) {
|
|
213
|
-
http.get(project.config.localSliceSimulatorURL, (res) => {
|
|
214
|
-
if (res.statusCode) {
|
|
215
|
-
resolve(res.statusCode >= 200 && res.statusCode < 300);
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
}
|
|
182
|
+
const res = await fetch(project.config.localSliceSimulatorURL);
|
|
219
183
|
|
|
220
|
-
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
if (!ok) {
|
|
184
|
+
if (!res.ok) {
|
|
224
185
|
return {
|
|
225
|
-
type: SliceSimulatorSetupStepValidationMessageType.
|
|
186
|
+
type: SliceSimulatorSetupStepValidationMessageType.Error,
|
|
226
187
|
title: "Unable to connect to simulator page",
|
|
227
|
-
message:
|
|
188
|
+
message: source`
|
|
228
189
|
Check that the \`localSliceSimulatorURL\` property in \`sm.json\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/technologies/setup-slice-simulator-nextjs) for more details.
|
|
229
190
|
`,
|
|
230
191
|
};
|
|
@@ -1,16 +1,29 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
SliceMachineHelpers,
|
|
3
|
+
SnippetReadHook,
|
|
4
|
+
} from "@slicemachine/plugin-kit";
|
|
2
5
|
import * as prismicT from "@prismicio/types";
|
|
3
6
|
import { stripIndent } from "common-tags";
|
|
4
|
-
import type { Config as PrettierConfig } from "prettier";
|
|
5
7
|
|
|
6
8
|
import type { PluginOptions } from "../types";
|
|
7
9
|
|
|
8
|
-
const prettierOptions: PrettierConfig = { parser: "typescript" };
|
|
9
|
-
|
|
10
10
|
const dotPath = (segments: string[]): string => {
|
|
11
11
|
return segments.join(".");
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
const format = async (input: string, helpers: SliceMachineHelpers) => {
|
|
15
|
+
const formattedInput = await helpers.format(input, undefined, {
|
|
16
|
+
includeNewlineAtEnd: false,
|
|
17
|
+
prettier: {
|
|
18
|
+
parser: "typescript",
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return formattedInput.endsWith(";")
|
|
23
|
+
? formattedInput.substring(0, formattedInput.length - 1)
|
|
24
|
+
: formattedInput;
|
|
25
|
+
};
|
|
26
|
+
|
|
14
27
|
export const snippetRead: SnippetReadHook<PluginOptions> = async (
|
|
15
28
|
data,
|
|
16
29
|
{ helpers },
|
|
@@ -20,16 +33,28 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
|
|
|
20
33
|
const label = "React";
|
|
21
34
|
|
|
22
35
|
switch (data.model.type) {
|
|
36
|
+
case prismicT.CustomTypeModelFieldType.StructuredText: {
|
|
37
|
+
return {
|
|
38
|
+
label,
|
|
39
|
+
language: "tsx",
|
|
40
|
+
code: await format(
|
|
41
|
+
stripIndent`
|
|
42
|
+
<PrismicRichText field={${dotPath(fieldPath)}} />
|
|
43
|
+
`,
|
|
44
|
+
helpers,
|
|
45
|
+
),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
23
49
|
case prismicT.CustomTypeModelFieldType.Link: {
|
|
24
50
|
return {
|
|
25
51
|
label,
|
|
26
52
|
language: "tsx",
|
|
27
|
-
code: await
|
|
53
|
+
code: await format(
|
|
28
54
|
stripIndent`
|
|
29
55
|
<PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
|
|
30
56
|
`,
|
|
31
|
-
|
|
32
|
-
{ prettier: prettierOptions },
|
|
57
|
+
helpers,
|
|
33
58
|
),
|
|
34
59
|
};
|
|
35
60
|
}
|
|
@@ -39,37 +64,34 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
|
|
|
39
64
|
{
|
|
40
65
|
label: `${label} (next/image)`,
|
|
41
66
|
language: "tsx",
|
|
42
|
-
code: await
|
|
67
|
+
code: await format(
|
|
43
68
|
stripIndent`
|
|
44
69
|
<PrismicNextImage field={${dotPath(fieldPath)}} />
|
|
45
70
|
`,
|
|
46
|
-
|
|
47
|
-
{ prettier: prettierOptions },
|
|
71
|
+
helpers,
|
|
48
72
|
),
|
|
49
73
|
},
|
|
50
74
|
{
|
|
51
75
|
label,
|
|
52
76
|
language: "tsx",
|
|
53
|
-
code: await
|
|
77
|
+
code: await format(
|
|
54
78
|
stripIndent`
|
|
55
79
|
<PrismicImage field={${dotPath(fieldPath)}} />
|
|
56
80
|
`,
|
|
57
|
-
|
|
58
|
-
{ prettier: prettierOptions },
|
|
81
|
+
helpers,
|
|
59
82
|
),
|
|
60
83
|
},
|
|
61
84
|
];
|
|
62
85
|
}
|
|
63
86
|
|
|
64
87
|
case prismicT.CustomTypeModelFieldType.Group: {
|
|
65
|
-
const code = await
|
|
88
|
+
const code = await format(
|
|
66
89
|
stripIndent`
|
|
67
90
|
<>{${dotPath(fieldPath)}.map(item => (
|
|
68
91
|
<>{/* Render content for item */}</>
|
|
69
92
|
))}</>
|
|
70
93
|
`,
|
|
71
|
-
|
|
72
|
-
{ prettier: prettierOptions },
|
|
94
|
+
helpers,
|
|
73
95
|
);
|
|
74
96
|
|
|
75
97
|
return {
|
|
@@ -80,15 +102,14 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
|
|
|
80
102
|
}
|
|
81
103
|
|
|
82
104
|
case prismicT.CustomTypeModelFieldType.Slices: {
|
|
83
|
-
const code = await
|
|
105
|
+
const code = await format(
|
|
84
106
|
stripIndent`
|
|
85
107
|
<SliceZone
|
|
86
108
|
slices={${dotPath(fieldPath)}}
|
|
87
109
|
components={components}
|
|
88
110
|
/>
|
|
89
111
|
`,
|
|
90
|
-
|
|
91
|
-
{ prettier: prettierOptions },
|
|
112
|
+
helpers,
|
|
92
113
|
);
|
|
93
114
|
|
|
94
115
|
return {
|
|
@@ -102,12 +123,11 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
|
|
|
102
123
|
return {
|
|
103
124
|
label,
|
|
104
125
|
language: "tsx",
|
|
105
|
-
code: await
|
|
126
|
+
code: await format(
|
|
106
127
|
stripIndent`
|
|
107
128
|
<>{${dotPath(fieldPath)}}</>
|
|
108
129
|
`,
|
|
109
|
-
|
|
110
|
-
{ prettier: prettierOptions },
|
|
130
|
+
helpers,
|
|
111
131
|
),
|
|
112
132
|
};
|
|
113
133
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as prismicT from "@prismicio/types";
|
|
2
|
+
|
|
3
|
+
export const isSharedSliceModel = (
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
5
|
+
input: any,
|
|
6
|
+
): input is prismicT.SharedSliceModel => {
|
|
7
|
+
return (
|
|
8
|
+
typeof input === "object" &&
|
|
9
|
+
input !== null &&
|
|
10
|
+
"type" in input &&
|
|
11
|
+
input.type === prismicT.CustomTypeModelSliceType.SharedSlice &&
|
|
12
|
+
typeof input.id === "string"
|
|
13
|
+
);
|
|
14
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SharedSliceModel } from "@prismicio/types";
|
|
2
|
+
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
3
|
+
import * as fs from "node:fs/promises";
|
|
4
|
+
|
|
5
|
+
import type { PluginOptions } from "../types";
|
|
6
|
+
import { pascalCase } from "./pascalCase";
|
|
7
|
+
|
|
8
|
+
type UpdateSliceModelFileArgs = {
|
|
9
|
+
libraryID: string;
|
|
10
|
+
model: SharedSliceModel;
|
|
11
|
+
} & SliceMachineContext<PluginOptions>;
|
|
12
|
+
|
|
13
|
+
export const updateSliceModelFile = async ({
|
|
14
|
+
libraryID,
|
|
15
|
+
model,
|
|
16
|
+
helpers,
|
|
17
|
+
options,
|
|
18
|
+
}: UpdateSliceModelFileArgs): Promise<void> => {
|
|
19
|
+
const filePath = helpers.joinPathFromRoot(
|
|
20
|
+
libraryID,
|
|
21
|
+
pascalCase(model.name),
|
|
22
|
+
"model.json",
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
let contents = JSON.stringify(model);
|
|
26
|
+
|
|
27
|
+
if (options.format) {
|
|
28
|
+
contents = await helpers.format(contents, filePath);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
await fs.writeFile(filePath, contents);
|
|
32
|
+
};
|
|
@@ -4,6 +4,7 @@ import * as fs from "node:fs/promises";
|
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
|
|
6
6
|
import type { PluginOptions } from "../types";
|
|
7
|
+
import { NON_EDITABLE_FILE_BANNER } from "../constants";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Arguments for `upsertGlobalContentTypes()`.
|
|
@@ -50,6 +51,8 @@ export const upsertGlobalContentTypes = async ({
|
|
|
50
51
|
},
|
|
51
52
|
});
|
|
52
53
|
|
|
54
|
+
contents = `${NON_EDITABLE_FILE_BANNER}\n\n${contents}`;
|
|
55
|
+
|
|
53
56
|
if (options.format) {
|
|
54
57
|
contents = await helpers.format(contents, filePath);
|
|
55
58
|
}
|
|
@@ -1,32 +1,42 @@
|
|
|
1
1
|
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
2
|
import { stripIndent } from "common-tags";
|
|
3
|
+
import * as fs from "node:fs/promises";
|
|
4
|
+
import { NON_EDITABLE_FILE_BANNER } from "../constants";
|
|
3
5
|
|
|
4
6
|
import { PluginOptions } from "../types";
|
|
5
7
|
|
|
6
8
|
import { pascalCase } from "./pascalCase";
|
|
7
9
|
|
|
8
|
-
type
|
|
10
|
+
type UpsertSliceLibraryIndexFileArgs = {
|
|
9
11
|
libraryID: string;
|
|
10
12
|
} & SliceMachineContext<PluginOptions>;
|
|
11
13
|
|
|
12
|
-
export const
|
|
13
|
-
args:
|
|
14
|
-
): Promise<
|
|
14
|
+
export const upsertSliceLibraryIndexFile = async (
|
|
15
|
+
args: UpsertSliceLibraryIndexFileArgs,
|
|
16
|
+
): Promise<void> => {
|
|
15
17
|
const filePath = args.helpers.joinPathFromRoot(
|
|
16
18
|
args.libraryID,
|
|
17
19
|
args.options.typescript ? "index.ts" : "index.js",
|
|
18
20
|
);
|
|
19
|
-
|
|
21
|
+
|
|
22
|
+
const slices = await args.actions.readAllSliceModelsForLibrary({
|
|
20
23
|
libraryID: args.libraryID,
|
|
21
24
|
});
|
|
22
25
|
|
|
23
26
|
let contents = stripIndent`
|
|
27
|
+
${NON_EDITABLE_FILE_BANNER}
|
|
28
|
+
|
|
24
29
|
import dynamic from 'next/dynamic'
|
|
25
30
|
|
|
26
31
|
export const components = {
|
|
27
|
-
${
|
|
28
|
-
(
|
|
29
|
-
|
|
32
|
+
${slices
|
|
33
|
+
.map((slice) => {
|
|
34
|
+
const id = slice.model.id;
|
|
35
|
+
const dirName = pascalCase(slice.model.name);
|
|
36
|
+
|
|
37
|
+
return `${id}: dynamic(() => import('./${dirName}'))`;
|
|
38
|
+
})
|
|
39
|
+
.join(",\n")}
|
|
30
40
|
}
|
|
31
41
|
`;
|
|
32
42
|
|
|
@@ -34,5 +44,5 @@ export const buildSliceLibraryIndexFileContents = async (
|
|
|
34
44
|
contents = await args.helpers.format(contents, filePath);
|
|
35
45
|
}
|
|
36
46
|
|
|
37
|
-
|
|
47
|
+
await fs.writeFile(filePath, contents);
|
|
38
48
|
};
|
package/src/plugin.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { customTypeCreate } from "./hooks/customType-create";
|
|
|
10
10
|
import { customTypeDelete } from "./hooks/customType-delete";
|
|
11
11
|
import { customTypeLibraryRead } from "./hooks/customTypeLibrary-read";
|
|
12
12
|
import { customTypeRead } from "./hooks/customType-read";
|
|
13
|
+
import { customTypeRename } from "./hooks/customType-rename";
|
|
13
14
|
import { customTypeUpdate } from "./hooks/customType-update";
|
|
14
15
|
import { sliceAssetDelete } from "./hooks/slice-asset-delete";
|
|
15
16
|
import { sliceAssetRead } from "./hooks/slice-asset-read";
|
|
@@ -18,6 +19,7 @@ import { sliceCreate } from "./hooks/slice-create";
|
|
|
18
19
|
import { sliceDelete } from "./hooks/slice-delete";
|
|
19
20
|
import { sliceLibraryRead } from "./hooks/sliceLibrary-read";
|
|
20
21
|
import { sliceRead } from "./hooks/slice-read";
|
|
22
|
+
import { sliceRename } from "./hooks/slice-rename";
|
|
21
23
|
import { sliceSimulatorSetupRead } from "./hooks/sliceSimulator-setup-read";
|
|
22
24
|
import { sliceUpdate } from "./hooks/slice-update";
|
|
23
25
|
import { snippetRead } from "./hooks/snippet-read";
|
|
@@ -32,6 +34,7 @@ export const plugin = defineSliceMachinePlugin<PluginOptions>({
|
|
|
32
34
|
setup({ hook }) {
|
|
33
35
|
hook("slice:create", sliceCreate);
|
|
34
36
|
hook("slice:update", sliceUpdate);
|
|
37
|
+
hook("slice:rename", sliceRename);
|
|
35
38
|
hook("slice:delete", sliceDelete);
|
|
36
39
|
hook("slice:read", sliceRead);
|
|
37
40
|
hook("slice:asset:update", sliceAssetUpdate);
|
|
@@ -41,6 +44,7 @@ export const plugin = defineSliceMachinePlugin<PluginOptions>({
|
|
|
41
44
|
|
|
42
45
|
hook("custom-type:create", customTypeCreate);
|
|
43
46
|
hook("custom-type:update", customTypeUpdate);
|
|
47
|
+
hook("custom-type:rename", customTypeRename);
|
|
44
48
|
hook("custom-type:delete", customTypeDelete);
|
|
45
49
|
hook("custom-type:read", customTypeRead);
|
|
46
50
|
hook("custom-type:asset:update", customTypeAssetUpdate);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const commonTags = require("common-tags");
|
|
4
|
-
const pascalCase = require("./pascalCase.cjs");
|
|
5
|
-
const buildSliceLibraryIndexFileContents = async (args) => {
|
|
6
|
-
const filePath = args.helpers.joinPathFromRoot(args.libraryID, args.options.typescript ? "index.ts" : "index.js");
|
|
7
|
-
const sliceLibrary = await args.actions.readSliceLibrary({
|
|
8
|
-
libraryID: args.libraryID
|
|
9
|
-
});
|
|
10
|
-
let contents = commonTags.stripIndent`
|
|
11
|
-
import dynamic from 'next/dynamic'
|
|
12
|
-
|
|
13
|
-
export const components = {
|
|
14
|
-
${sliceLibrary.sliceIDs.map((id) => `${id}: dynamic(() => import('./${pascalCase.pascalCase(id)}')),`)}
|
|
15
|
-
}
|
|
16
|
-
`;
|
|
17
|
-
if (args.options.format) {
|
|
18
|
-
contents = await args.helpers.format(contents, filePath);
|
|
19
|
-
}
|
|
20
|
-
return { filePath, contents };
|
|
21
|
-
};
|
|
22
|
-
exports.buildSliceLibraryIndexFileContents = buildSliceLibraryIndexFileContents;
|
|
23
|
-
//# sourceMappingURL=buildSliceLibraryIndexFileContents.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildSliceLibraryIndexFileContents.cjs","sources":["../../src/lib/buildSliceLibraryIndexFileContents.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { pascalCase } from \"./pascalCase\";\n\ntype BuildSliceLibraryIndexFileContentsArgs = {\n\tlibraryID: string;\n} & SliceMachineContext<PluginOptions>;\n\nexport const buildSliceLibraryIndexFileContents = async (\n\targs: BuildSliceLibraryIndexFileContentsArgs,\n): Promise<{ filePath: string; contents: string }> => {\n\tconst filePath = args.helpers.joinPathFromRoot(\n\t\targs.libraryID,\n\t\targs.options.typescript ? \"index.ts\" : \"index.js\",\n\t);\n\tconst sliceLibrary = await args.actions.readSliceLibrary({\n\t\tlibraryID: args.libraryID,\n\t});\n\n\tlet contents = stripIndent`\n\t\timport dynamic from 'next/dynamic'\n\n\t\texport const components = {\n\t\t\t${sliceLibrary.sliceIDs.map(\n\t\t\t\t(id) => `${id}: dynamic(() => import('./${pascalCase(id)}')),`,\n\t\t\t)}\n\t\t}\n\t`;\n\n\tif (args.options.format) {\n\t\tcontents = await args.helpers.format(contents, filePath);\n\t}\n\n\treturn { filePath, contents };\n};\n"],"names":["stripIndent","pascalCase"],"mappings":";;;;AAWa,MAAA,qCAAqC,OACjD,SACoD;AAC9C,QAAA,WAAW,KAAK,QAAQ,iBAC7B,KAAK,WACL,KAAK,QAAQ,aAAa,aAAa,UAAU;AAElD,QAAM,eAAe,MAAM,KAAK,QAAQ,iBAAiB;AAAA,IACxD,WAAW,KAAK;AAAA,EAAA,CAChB;AAED,MAAI,WAAWA,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA,KAIX,aAAa,SAAS,IACvB,CAAC,OAAO,GAAG,+BAA+BC,WAAAA,WAAW,EAAE,OAAO;AAAA;AAAA;AAK7D,MAAA,KAAK,QAAQ,QAAQ;AACxB,eAAW,MAAM,KAAK,QAAQ,OAAO,UAAU,QAAQ;AAAA,EACvD;AAEM,SAAA,EAAE,UAAU;AACpB;;"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
-
import { PluginOptions } from "../types";
|
|
3
|
-
declare type BuildSliceLibraryIndexFileContentsArgs = {
|
|
4
|
-
libraryID: string;
|
|
5
|
-
} & SliceMachineContext<PluginOptions>;
|
|
6
|
-
export declare const buildSliceLibraryIndexFileContents: (args: BuildSliceLibraryIndexFileContentsArgs) => Promise<{
|
|
7
|
-
filePath: string;
|
|
8
|
-
contents: string;
|
|
9
|
-
}>;
|
|
10
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { stripIndent } from "common-tags";
|
|
2
|
-
import { pascalCase } from "./pascalCase.js";
|
|
3
|
-
const buildSliceLibraryIndexFileContents = async (args) => {
|
|
4
|
-
const filePath = args.helpers.joinPathFromRoot(args.libraryID, args.options.typescript ? "index.ts" : "index.js");
|
|
5
|
-
const sliceLibrary = await args.actions.readSliceLibrary({
|
|
6
|
-
libraryID: args.libraryID
|
|
7
|
-
});
|
|
8
|
-
let contents = stripIndent`
|
|
9
|
-
import dynamic from 'next/dynamic'
|
|
10
|
-
|
|
11
|
-
export const components = {
|
|
12
|
-
${sliceLibrary.sliceIDs.map((id) => `${id}: dynamic(() => import('./${pascalCase(id)}')),`)}
|
|
13
|
-
}
|
|
14
|
-
`;
|
|
15
|
-
if (args.options.format) {
|
|
16
|
-
contents = await args.helpers.format(contents, filePath);
|
|
17
|
-
}
|
|
18
|
-
return { filePath, contents };
|
|
19
|
-
};
|
|
20
|
-
export {
|
|
21
|
-
buildSliceLibraryIndexFileContents
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=buildSliceLibraryIndexFileContents.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildSliceLibraryIndexFileContents.js","sources":["../../src/lib/buildSliceLibraryIndexFileContents.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { pascalCase } from \"./pascalCase\";\n\ntype BuildSliceLibraryIndexFileContentsArgs = {\n\tlibraryID: string;\n} & SliceMachineContext<PluginOptions>;\n\nexport const buildSliceLibraryIndexFileContents = async (\n\targs: BuildSliceLibraryIndexFileContentsArgs,\n): Promise<{ filePath: string; contents: string }> => {\n\tconst filePath = args.helpers.joinPathFromRoot(\n\t\targs.libraryID,\n\t\targs.options.typescript ? \"index.ts\" : \"index.js\",\n\t);\n\tconst sliceLibrary = await args.actions.readSliceLibrary({\n\t\tlibraryID: args.libraryID,\n\t});\n\n\tlet contents = stripIndent`\n\t\timport dynamic from 'next/dynamic'\n\n\t\texport const components = {\n\t\t\t${sliceLibrary.sliceIDs.map(\n\t\t\t\t(id) => `${id}: dynamic(() => import('./${pascalCase(id)}')),`,\n\t\t\t)}\n\t\t}\n\t`;\n\n\tif (args.options.format) {\n\t\tcontents = await args.helpers.format(contents, filePath);\n\t}\n\n\treturn { filePath, contents };\n};\n"],"names":[],"mappings":";;AAWa,MAAA,qCAAqC,OACjD,SACoD;AAC9C,QAAA,WAAW,KAAK,QAAQ,iBAC7B,KAAK,WACL,KAAK,QAAQ,aAAa,aAAa,UAAU;AAElD,QAAM,eAAe,MAAM,KAAK,QAAQ,iBAAiB;AAAA,IACxD,WAAW,KAAK;AAAA,EAAA,CAChB;AAED,MAAI,WAAW;AAAA;AAAA;AAAA;AAAA,KAIX,aAAa,SAAS,IACvB,CAAC,OAAO,GAAG,+BAA+B,WAAW,EAAE,OAAO;AAAA;AAAA;AAK7D,MAAA,KAAK,QAAQ,QAAQ;AACxB,eAAW,MAAM,KAAK,QAAQ,OAAO,UAAU,QAAQ;AAAA,EACvD;AAEM,SAAA,EAAE,UAAU;AACpB;"}
|