@slicemachine/adapter-nuxt 0.3.10 → 0.3.11-dev-next-release.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/dist/hooks/project-init.cjs +26 -29
  2. package/dist/hooks/project-init.cjs.map +1 -1
  3. package/dist/hooks/project-init.js +26 -28
  4. package/dist/hooks/project-init.js.map +1 -1
  5. package/dist/hooks/slice-create.cjs +28 -46
  6. package/dist/hooks/slice-create.cjs.map +1 -1
  7. package/dist/hooks/slice-create.js +28 -28
  8. package/dist/hooks/slice-create.js.map +1 -1
  9. package/dist/lib/checkHasSrcDirectory.cjs +5 -2
  10. package/dist/lib/checkHasSrcDirectory.cjs.map +1 -1
  11. package/dist/lib/checkHasSrcDirectory.js +5 -2
  12. package/dist/lib/checkHasSrcDirectory.js.map +1 -1
  13. package/dist/lib/checkIsTypeScriptProject.cjs +2 -3
  14. package/dist/lib/checkIsTypeScriptProject.cjs.map +1 -1
  15. package/dist/lib/checkIsTypeScriptProject.js +2 -3
  16. package/dist/lib/checkIsTypeScriptProject.js.map +1 -1
  17. package/dist/lib/getJSFileExtension.cjs +12 -0
  18. package/dist/lib/getJSFileExtension.cjs.map +1 -0
  19. package/dist/lib/getJSFileExtension.d.ts +5 -0
  20. package/dist/lib/getJSFileExtension.js +12 -0
  21. package/dist/lib/getJSFileExtension.js.map +1 -0
  22. package/dist/lib/upsertSliceLibraryIndexFile.cjs +30 -22
  23. package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -1
  24. package/dist/lib/upsertSliceLibraryIndexFile.js +30 -21
  25. package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -1
  26. package/dist/plugin.cjs +178 -36
  27. package/dist/plugin.cjs.map +1 -1
  28. package/dist/plugin.js +178 -36
  29. package/dist/plugin.js.map +1 -1
  30. package/dist/types.d.ts +22 -0
  31. package/package.json +4 -6
  32. package/src/hooks/project-init.ts +32 -36
  33. package/src/hooks/slice-create.ts +39 -34
  34. package/src/lib/checkHasSrcDirectory.ts +5 -2
  35. package/src/lib/checkIsTypeScriptProject.ts +5 -4
  36. package/src/lib/getJSFileExtension.ts +22 -0
  37. package/src/lib/upsertSliceLibraryIndexFile.ts +55 -36
  38. package/src/plugin.ts +247 -37
  39. package/src/types.ts +25 -0
  40. package/dist/hooks/customType-asset-delete.cjs +0 -31
  41. package/dist/hooks/customType-asset-delete.cjs.map +0 -1
  42. package/dist/hooks/customType-asset-delete.d.ts +0 -3
  43. package/dist/hooks/customType-asset-delete.js +0 -14
  44. package/dist/hooks/customType-asset-delete.js.map +0 -1
  45. package/dist/hooks/customType-asset-read.cjs +0 -34
  46. package/dist/hooks/customType-asset-read.cjs.map +0 -1
  47. package/dist/hooks/customType-asset-read.d.ts +0 -3
  48. package/dist/hooks/customType-asset-read.js +0 -17
  49. package/dist/hooks/customType-asset-read.js.map +0 -1
  50. package/dist/hooks/customType-asset-update.cjs +0 -34
  51. package/dist/hooks/customType-asset-update.cjs.map +0 -1
  52. package/dist/hooks/customType-asset-update.d.ts +0 -3
  53. package/dist/hooks/customType-asset-update.js +0 -16
  54. package/dist/hooks/customType-asset-update.js.map +0 -1
  55. package/dist/hooks/customType-create.cjs +0 -43
  56. package/dist/hooks/customType-create.cjs.map +0 -1
  57. package/dist/hooks/customType-create.d.ts +0 -3
  58. package/dist/hooks/customType-create.js +0 -25
  59. package/dist/hooks/customType-create.js.map +0 -1
  60. package/dist/hooks/customType-delete.cjs +0 -32
  61. package/dist/hooks/customType-delete.cjs.map +0 -1
  62. package/dist/hooks/customType-delete.d.ts +0 -3
  63. package/dist/hooks/customType-delete.js +0 -15
  64. package/dist/hooks/customType-delete.js.map +0 -1
  65. package/dist/hooks/customType-read.cjs +0 -31
  66. package/dist/hooks/customType-read.cjs.map +0 -1
  67. package/dist/hooks/customType-read.d.ts +0 -3
  68. package/dist/hooks/customType-read.js +0 -14
  69. package/dist/hooks/customType-read.js.map +0 -1
  70. package/dist/hooks/customType-rename.cjs +0 -6
  71. package/dist/hooks/customType-rename.cjs.map +0 -1
  72. package/dist/hooks/customType-rename.d.ts +0 -1
  73. package/dist/hooks/customType-rename.js +0 -6
  74. package/dist/hooks/customType-rename.js.map +0 -1
  75. package/dist/hooks/customType-update.cjs +0 -6
  76. package/dist/hooks/customType-update.cjs.map +0 -1
  77. package/dist/hooks/customType-update.d.ts +0 -1
  78. package/dist/hooks/customType-update.js +0 -6
  79. package/dist/hooks/customType-update.js.map +0 -1
  80. package/dist/hooks/customTypeLibrary-read.cjs +0 -55
  81. package/dist/hooks/customTypeLibrary-read.cjs.map +0 -1
  82. package/dist/hooks/customTypeLibrary-read.d.ts +0 -3
  83. package/dist/hooks/customTypeLibrary-read.js +0 -37
  84. package/dist/hooks/customTypeLibrary-read.js.map +0 -1
  85. package/dist/hooks/slice-asset-delete.cjs +0 -33
  86. package/dist/hooks/slice-asset-delete.cjs.map +0 -1
  87. package/dist/hooks/slice-asset-delete.d.ts +0 -3
  88. package/dist/hooks/slice-asset-delete.js +0 -16
  89. package/dist/hooks/slice-asset-delete.js.map +0 -1
  90. package/dist/hooks/slice-asset-read.cjs +0 -36
  91. package/dist/hooks/slice-asset-read.cjs.map +0 -1
  92. package/dist/hooks/slice-asset-read.d.ts +0 -3
  93. package/dist/hooks/slice-asset-read.js +0 -19
  94. package/dist/hooks/slice-asset-read.js.map +0 -1
  95. package/dist/hooks/slice-asset-update.cjs +0 -36
  96. package/dist/hooks/slice-asset-update.cjs.map +0 -1
  97. package/dist/hooks/slice-asset-update.d.ts +0 -3
  98. package/dist/hooks/slice-asset-update.js +0 -18
  99. package/dist/hooks/slice-asset-update.js.map +0 -1
  100. package/dist/hooks/slice-delete.cjs +0 -41
  101. package/dist/hooks/slice-delete.cjs.map +0 -1
  102. package/dist/hooks/slice-delete.d.ts +0 -3
  103. package/dist/hooks/slice-delete.js +0 -24
  104. package/dist/hooks/slice-delete.js.map +0 -1
  105. package/dist/hooks/slice-read.cjs +0 -62
  106. package/dist/hooks/slice-read.cjs.map +0 -1
  107. package/dist/hooks/slice-read.d.ts +0 -3
  108. package/dist/hooks/slice-read.js +0 -44
  109. package/dist/hooks/slice-read.js.map +0 -1
  110. package/dist/hooks/slice-rename.cjs +0 -51
  111. package/dist/hooks/slice-rename.cjs.map +0 -1
  112. package/dist/hooks/slice-rename.d.ts +0 -3
  113. package/dist/hooks/slice-rename.js +0 -34
  114. package/dist/hooks/slice-rename.js.map +0 -1
  115. package/dist/hooks/slice-update.cjs +0 -14
  116. package/dist/hooks/slice-update.cjs.map +0 -1
  117. package/dist/hooks/slice-update.d.ts +0 -3
  118. package/dist/hooks/slice-update.js +0 -14
  119. package/dist/hooks/slice-update.js.map +0 -1
  120. package/dist/hooks/sliceLibrary-read.cjs +0 -52
  121. package/dist/hooks/sliceLibrary-read.cjs.map +0 -1
  122. package/dist/hooks/sliceLibrary-read.d.ts +0 -3
  123. package/dist/hooks/sliceLibrary-read.js +0 -34
  124. package/dist/hooks/sliceLibrary-read.js.map +0 -1
  125. package/dist/lib/buildCustomTypeAssetPath.cjs +0 -29
  126. package/dist/lib/buildCustomTypeAssetPath.cjs.map +0 -1
  127. package/dist/lib/buildCustomTypeAssetPath.d.ts +0 -9
  128. package/dist/lib/buildCustomTypeAssetPath.js +0 -12
  129. package/dist/lib/buildCustomTypeAssetPath.js.map +0 -1
  130. package/dist/lib/buildCustomTypeDirectoryPath.cjs +0 -26
  131. package/dist/lib/buildCustomTypeDirectoryPath.cjs.map +0 -1
  132. package/dist/lib/buildCustomTypeDirectoryPath.d.ts +0 -8
  133. package/dist/lib/buildCustomTypeDirectoryPath.js +0 -9
  134. package/dist/lib/buildCustomTypeDirectoryPath.js.map +0 -1
  135. package/dist/lib/buildCustomTypeLibraryDirectoryPath.cjs +0 -7
  136. package/dist/lib/buildCustomTypeLibraryDirectoryPath.cjs.map +0 -1
  137. package/dist/lib/buildCustomTypeLibraryDirectoryPath.d.ts +0 -7
  138. package/dist/lib/buildCustomTypeLibraryDirectoryPath.js +0 -7
  139. package/dist/lib/buildCustomTypeLibraryDirectoryPath.js.map +0 -1
  140. package/dist/lib/buildSliceAssetPath.cjs +0 -34
  141. package/dist/lib/buildSliceAssetPath.cjs.map +0 -1
  142. package/dist/lib/buildSliceAssetPath.d.ts +0 -11
  143. package/dist/lib/buildSliceAssetPath.js +0 -17
  144. package/dist/lib/buildSliceAssetPath.js.map +0 -1
  145. package/dist/lib/buildSliceDirectoryPath.cjs +0 -30
  146. package/dist/lib/buildSliceDirectoryPath.cjs.map +0 -1
  147. package/dist/lib/buildSliceDirectoryPath.d.ts +0 -10
  148. package/dist/lib/buildSliceDirectoryPath.js +0 -13
  149. package/dist/lib/buildSliceDirectoryPath.js.map +0 -1
  150. package/dist/lib/buildSliceLibraryDirectoryPath.cjs +0 -7
  151. package/dist/lib/buildSliceLibraryDirectoryPath.cjs.map +0 -1
  152. package/dist/lib/buildSliceLibraryDirectoryPath.d.ts +0 -8
  153. package/dist/lib/buildSliceLibraryDirectoryPath.js +0 -7
  154. package/dist/lib/buildSliceLibraryDirectoryPath.js.map +0 -1
  155. package/dist/lib/checkPathExists.cjs +0 -30
  156. package/dist/lib/checkPathExists.cjs.map +0 -1
  157. package/dist/lib/checkPathExists.d.ts +0 -2
  158. package/dist/lib/checkPathExists.js +0 -13
  159. package/dist/lib/checkPathExists.js.map +0 -1
  160. package/dist/lib/isSharedSliceModel.cjs +0 -7
  161. package/dist/lib/isSharedSliceModel.cjs.map +0 -1
  162. package/dist/lib/isSharedSliceModel.d.ts +0 -335
  163. package/dist/lib/isSharedSliceModel.js +0 -7
  164. package/dist/lib/isSharedSliceModel.js.map +0 -1
  165. package/dist/lib/readJSONFile.cjs +0 -26
  166. package/dist/lib/readJSONFile.cjs.map +0 -1
  167. package/dist/lib/readJSONFile.d.ts +0 -1
  168. package/dist/lib/readJSONFile.js +0 -9
  169. package/dist/lib/readJSONFile.js.map +0 -1
  170. package/dist/lib/updateSliceModelFile.cjs +0 -33
  171. package/dist/lib/updateSliceModelFile.cjs.map +0 -1
  172. package/dist/lib/updateSliceModelFile.d.ts +0 -9
  173. package/dist/lib/updateSliceModelFile.js +0 -15
  174. package/dist/lib/updateSliceModelFile.js.map +0 -1
  175. package/dist/lib/upsertGlobalContentTypes.cjs +0 -56
  176. package/dist/lib/upsertGlobalContentTypes.cjs.map +0 -1
  177. package/dist/lib/upsertGlobalContentTypes.d.ts +0 -12
  178. package/dist/lib/upsertGlobalContentTypes.js +0 -38
  179. package/dist/lib/upsertGlobalContentTypes.js.map +0 -1
  180. package/src/hooks/customType-asset-delete.ts +0 -18
  181. package/src/hooks/customType-asset-read.ts +0 -22
  182. package/src/hooks/customType-asset-update.ts +0 -20
  183. package/src/hooks/customType-create.ts +0 -45
  184. package/src/hooks/customType-delete.ts +0 -21
  185. package/src/hooks/customType-read.ts +0 -24
  186. package/src/hooks/customType-rename.ts +0 -3
  187. package/src/hooks/customType-update.ts +0 -3
  188. package/src/hooks/customTypeLibrary-read.ts +0 -58
  189. package/src/hooks/slice-asset-delete.ts +0 -21
  190. package/src/hooks/slice-asset-read.ts +0 -25
  191. package/src/hooks/slice-asset-update.ts +0 -23
  192. package/src/hooks/slice-delete.ts +0 -41
  193. package/src/hooks/slice-read.ts +0 -69
  194. package/src/hooks/slice-rename.ts +0 -46
  195. package/src/hooks/slice-update.ts +0 -19
  196. package/src/hooks/sliceLibrary-read.ts +0 -48
  197. package/src/lib/buildCustomTypeAssetPath.ts +0 -24
  198. package/src/lib/buildCustomTypeDirectoryPath.ts +0 -20
  199. package/src/lib/buildCustomTypeLibraryDirectoryPath.ts +0 -13
  200. package/src/lib/buildSliceAssetPath.ts +0 -32
  201. package/src/lib/buildSliceDirectoryPath.ts +0 -26
  202. package/src/lib/buildSliceLibraryDirectoryPath.ts +0 -14
  203. package/src/lib/checkPathExists.ts +0 -12
  204. package/src/lib/isSharedSliceModel.ts +0 -14
  205. package/src/lib/readJSONFile.ts +0 -7
  206. package/src/lib/updateSliceModelFile.ts +0 -33
  207. package/src/lib/upsertGlobalContentTypes.ts +0 -61
@@ -1,46 +0,0 @@
1
- import type { SliceRenameHook } from "@slicemachine/plugin-kit";
2
- import * as fse from "fs-extra";
3
-
4
- import { buildSliceDirectoryPath } from "../lib/buildSliceDirectoryPath";
5
- import { rejectIfNecessary } from "../lib/rejectIfNecessary";
6
- import { updateSliceModelFile } from "../lib/updateSliceModelFile";
7
- import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes";
8
- import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile";
9
-
10
- import type { PluginOptions } from "../types";
11
-
12
- export const sliceRename: SliceRenameHook<PluginOptions> = async (
13
- data,
14
- context,
15
- ) => {
16
- const { model: currentModel } = await context.actions.readSliceModel({
17
- libraryID: data.libraryID,
18
- sliceID: data.model.id,
19
- });
20
-
21
- await fse.move(
22
- buildSliceDirectoryPath({
23
- libraryID: data.libraryID,
24
- model: currentModel,
25
- helpers: context.helpers,
26
- }),
27
- buildSliceDirectoryPath({
28
- libraryID: data.libraryID,
29
- model: data.model,
30
- helpers: context.helpers,
31
- }),
32
- );
33
-
34
- await updateSliceModelFile({
35
- libraryID: data.libraryID,
36
- model: data.model,
37
- ...context,
38
- });
39
-
40
- rejectIfNecessary(
41
- await Promise.allSettled([
42
- upsertGlobalContentTypes(context),
43
- upsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context }),
44
- ]),
45
- );
46
- };
@@ -1,19 +0,0 @@
1
- import type { SliceUpdateHook } from "@slicemachine/plugin-kit";
2
-
3
- import { updateSliceModelFile } from "../lib/updateSliceModelFile";
4
- import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes";
5
-
6
- import type { PluginOptions } from "../types";
7
-
8
- export const sliceUpdate: SliceUpdateHook<PluginOptions> = async (
9
- data,
10
- context,
11
- ) => {
12
- await updateSliceModelFile({
13
- libraryID: data.libraryID,
14
- model: data.model,
15
- ...context,
16
- });
17
-
18
- await upsertGlobalContentTypes(context);
19
- };
@@ -1,48 +0,0 @@
1
- import type { SliceLibraryReadHook } from "@slicemachine/plugin-kit";
2
- import * as fs from "node:fs/promises";
3
- import * as path from "node:path";
4
-
5
- import { buildSliceLibraryDirectoryPath } from "../lib/buildSliceLibraryDirectoryPath";
6
- import { isSharedSliceModel } from "../lib/isSharedSliceModel";
7
- import { readJSONFile } from "../lib/readJSONFile";
8
-
9
- import type { PluginOptions } from "../types";
10
-
11
- export const sliceLibraryRead: SliceLibraryReadHook<PluginOptions> = async (
12
- data,
13
- { helpers },
14
- ) => {
15
- const dir = buildSliceLibraryDirectoryPath({
16
- libraryID: data.libraryID,
17
- helpers,
18
- });
19
-
20
- // Ensure the directory exists.
21
- await fs.mkdir(dir, { recursive: true });
22
-
23
- const childDirs = await fs.readdir(dir, { withFileTypes: true });
24
-
25
- const sliceIDs: string[] = [];
26
- await Promise.all(
27
- childDirs.map(async (childDir) => {
28
- if (childDir.isDirectory()) {
29
- const modelPath = path.join(dir, childDir.name, "model.json");
30
-
31
- try {
32
- const modelContents = await readJSONFile(modelPath);
33
-
34
- if (isSharedSliceModel(modelContents)) {
35
- sliceIDs.push(modelContents.id);
36
- }
37
- } catch {
38
- // noop
39
- }
40
- }
41
- }),
42
- );
43
-
44
- return {
45
- id: data.libraryID,
46
- sliceIDs: sliceIDs.sort(),
47
- };
48
- };
@@ -1,24 +0,0 @@
1
- import { SliceMachineContext } from "@slicemachine/plugin-kit";
2
- import * as path from "node:path";
3
-
4
- import { PluginOptions } from "../types";
5
-
6
- import { buildCustomTypeDirectoryPath } from "./buildCustomTypeDirectoryPath";
7
-
8
- type BuildCustomTypeAssetPathArgs = {
9
- customTypeID: string;
10
- assetID: string;
11
- helpers: SliceMachineContext<PluginOptions>["helpers"];
12
- };
13
-
14
- export const buildCustomTypeAssetPath = (
15
- args: BuildCustomTypeAssetPathArgs,
16
- ): string => {
17
- return path.join(
18
- buildCustomTypeDirectoryPath({
19
- customTypeID: args.customTypeID,
20
- helpers: args.helpers,
21
- }),
22
- args.assetID,
23
- );
24
- };
@@ -1,20 +0,0 @@
1
- import { SliceMachineContext } from "@slicemachine/plugin-kit";
2
- import * as path from "node:path";
3
-
4
- import { PluginOptions } from "../types";
5
-
6
- import { buildCustomTypeLibraryDirectoryPath } from "./buildCustomTypeLibraryDirectoryPath";
7
-
8
- type BuildCustomTypeDirectoryPathArgs = {
9
- customTypeID: string;
10
- helpers: SliceMachineContext<PluginOptions>["helpers"];
11
- };
12
-
13
- export const buildCustomTypeDirectoryPath = (
14
- args: BuildCustomTypeDirectoryPathArgs,
15
- ): string => {
16
- return path.join(
17
- buildCustomTypeLibraryDirectoryPath({ helpers: args.helpers }),
18
- args.customTypeID,
19
- );
20
- };
@@ -1,13 +0,0 @@
1
- import { SliceMachineContext } from "@slicemachine/plugin-kit";
2
-
3
- import { PluginOptions } from "../types";
4
-
5
- type BuildCustomTypeLibraryDirectoryPathArgs = {
6
- helpers: SliceMachineContext<PluginOptions>["helpers"];
7
- };
8
-
9
- export const buildCustomTypeLibraryDirectoryPath = (
10
- args: BuildCustomTypeLibraryDirectoryPathArgs,
11
- ): string => {
12
- return args.helpers.joinPathFromRoot("customtypes");
13
- };
@@ -1,32 +0,0 @@
1
- import { SliceMachineContext } from "@slicemachine/plugin-kit";
2
- import * as path from "node:path";
3
-
4
- import { PluginOptions } from "../types";
5
-
6
- import { buildSliceDirectoryPath } from "./buildSliceDirectoryPath";
7
-
8
- type BuildSliceAssetPathArgs = {
9
- libraryID: string;
10
- sliceID: string;
11
- assetID: string;
12
- actions: SliceMachineContext<PluginOptions>["actions"];
13
- helpers: SliceMachineContext<PluginOptions>["helpers"];
14
- };
15
-
16
- export const buildSliceAssetPath = async (
17
- args: BuildSliceAssetPathArgs,
18
- ): Promise<string> => {
19
- const { model } = await args.actions.readSliceModel({
20
- libraryID: args.libraryID,
21
- sliceID: args.sliceID,
22
- });
23
-
24
- return path.join(
25
- buildSliceDirectoryPath({
26
- libraryID: args.libraryID,
27
- model,
28
- helpers: args.helpers,
29
- }),
30
- args.assetID,
31
- );
32
- };
@@ -1,26 +0,0 @@
1
- import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
2
- import { SliceMachineContext } from "@slicemachine/plugin-kit";
3
- import * as path from "node:path";
4
-
5
- import { PluginOptions } from "../types";
6
-
7
- import { buildSliceLibraryDirectoryPath } from "./buildSliceLibraryDirectoryPath";
8
- import { pascalCase } from "./pascalCase";
9
-
10
- type BuildSliceDirectoryPathArgs = {
11
- libraryID: string;
12
- model: SharedSlice;
13
- helpers: SliceMachineContext<PluginOptions>["helpers"];
14
- };
15
-
16
- export const buildSliceDirectoryPath = (
17
- args: BuildSliceDirectoryPathArgs,
18
- ): string => {
19
- return path.join(
20
- buildSliceLibraryDirectoryPath({
21
- libraryID: args.libraryID,
22
- helpers: args.helpers,
23
- }),
24
- pascalCase(args.model.name),
25
- );
26
- };
@@ -1,14 +0,0 @@
1
- import { SliceMachineContext } from "@slicemachine/plugin-kit";
2
-
3
- import { PluginOptions } from "../types";
4
-
5
- type BuildSliceLibraryDirectoryPathArgs = {
6
- libraryID: string;
7
- helpers: SliceMachineContext<PluginOptions>["helpers"];
8
- };
9
-
10
- export const buildSliceLibraryDirectoryPath = (
11
- args: BuildSliceLibraryDirectoryPathArgs,
12
- ): string => {
13
- return args.helpers.joinPathFromRoot(args.libraryID);
14
- };
@@ -1,12 +0,0 @@
1
- import * as fs from "node:fs/promises";
2
- import { PathLike } from "node:fs";
3
-
4
- export const checkPathExists = async (path: PathLike): Promise<boolean> => {
5
- try {
6
- await fs.access(path);
7
-
8
- return true;
9
- } catch {
10
- return false;
11
- }
12
- };
@@ -1,14 +0,0 @@
1
- import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
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 SharedSlice => {
7
- return (
8
- typeof input === "object" &&
9
- input !== null &&
10
- "type" in input &&
11
- input.type === "SharedSlice" &&
12
- typeof input.id === "string"
13
- );
14
- };
@@ -1,7 +0,0 @@
1
- import * as fs from "node:fs/promises";
2
-
3
- export const readJSONFile = async <T = unknown>(path: string): Promise<T> => {
4
- const contents = await fs.readFile(path, "utf8");
5
-
6
- return JSON.parse(contents);
7
- };
@@ -1,33 +0,0 @@
1
- import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
2
- import { SliceMachineContext } from "@slicemachine/plugin-kit";
3
- import * as fs from "node:fs/promises";
4
- import * as path from "node:path";
5
-
6
- import type { PluginOptions } from "../types";
7
-
8
- import { buildSliceDirectoryPath } from "./buildSliceDirectoryPath";
9
-
10
- type UpdateSliceModelFileArgs = {
11
- libraryID: string;
12
- model: SharedSlice;
13
- } & SliceMachineContext<PluginOptions>;
14
-
15
- export const updateSliceModelFile = async ({
16
- libraryID,
17
- model,
18
- helpers,
19
- options,
20
- }: UpdateSliceModelFileArgs): Promise<void> => {
21
- const filePath = path.join(
22
- buildSliceDirectoryPath({ libraryID, model, helpers }),
23
- "model.json",
24
- );
25
-
26
- let contents = JSON.stringify(model);
27
-
28
- if (options.format) {
29
- contents = await helpers.format(contents, filePath);
30
- }
31
-
32
- await fs.writeFile(filePath, contents);
33
- };
@@ -1,61 +0,0 @@
1
- import type { SliceMachineContext } from "@slicemachine/plugin-kit";
2
- import { detectTypesProvider, generateTypes } from "prismic-ts-codegen";
3
- import * as fs from "node:fs/promises";
4
- import * as path from "node:path";
5
-
6
- import type { PluginOptions } from "../types";
7
- import { NON_EDITABLE_FILE_BANNER } from "../constants";
8
-
9
- /**
10
- * Arguments for `upsertGlobalContentTypes()`.
11
- */
12
- type UpsertGlobalTypesArgs = SliceMachineContext<PluginOptions>;
13
-
14
- /**
15
- * Creates a globally accessible TypeScript file containing types representing
16
- * the Prismic repository's content.
17
- */
18
- export const upsertGlobalContentTypes = async ({
19
- actions,
20
- helpers,
21
- options,
22
- project,
23
- }: UpsertGlobalTypesArgs): Promise<void> => {
24
- const filePath = helpers.joinPathFromRoot("prismicio-types.d.ts");
25
-
26
- const [customTypeModelDescriptors, sharedSliceModelDescriptors] =
27
- await Promise.all([
28
- actions.readAllCustomTypeModels(),
29
- actions.readAllSliceModels(),
30
- ]);
31
-
32
- const customTypeModels = customTypeModelDescriptors.map(
33
- (customTypeModelDescriptors) => {
34
- return customTypeModelDescriptors.model;
35
- },
36
- );
37
- const sharedSliceModels = sharedSliceModelDescriptors.map(
38
- (sharedSliceModelDescriptors) => {
39
- return sharedSliceModelDescriptors.model;
40
- },
41
- );
42
-
43
- let contents = generateTypes({
44
- customTypeModels,
45
- sharedSliceModels,
46
- clientIntegration: {
47
- includeCreateClientInterface: true,
48
- includeContentNamespace: true,
49
- },
50
- typesProvider: await detectTypesProvider({ cwd: project.root }),
51
- });
52
-
53
- contents = `${NON_EDITABLE_FILE_BANNER}\n\n${contents}`;
54
-
55
- if (options.format) {
56
- contents = await helpers.format(contents, filePath);
57
- }
58
-
59
- await fs.mkdir(path.dirname(filePath), { recursive: true });
60
- await fs.writeFile(filePath, contents);
61
- };