@slicemachine/adapter-next 0.0.13-dev-plugins-m2.2 → 0.0.13-dev-plugins-m3.0

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 (39) hide show
  1. package/README.md +1 -1
  2. package/dist/hooks/customType-read.cjs.map +1 -1
  3. package/dist/hooks/customType-read.js.map +1 -1
  4. package/dist/hooks/customTypeLibrary-read.cjs.map +1 -1
  5. package/dist/hooks/customTypeLibrary-read.js.map +1 -1
  6. package/dist/hooks/slice-read.cjs +14 -3
  7. package/dist/hooks/slice-read.cjs.map +1 -1
  8. package/dist/hooks/slice-read.js +14 -3
  9. package/dist/hooks/slice-read.js.map +1 -1
  10. package/dist/hooks/sliceSimulator-setup-read.cjs +7 -3
  11. package/dist/hooks/sliceSimulator-setup-read.cjs.map +1 -1
  12. package/dist/hooks/sliceSimulator-setup-read.js +7 -3
  13. package/dist/hooks/sliceSimulator-setup-read.js.map +1 -1
  14. package/dist/hooks/snippet-read.cjs +5 -23
  15. package/dist/hooks/snippet-read.cjs.map +1 -1
  16. package/dist/hooks/snippet-read.js +5 -6
  17. package/dist/hooks/snippet-read.js.map +1 -1
  18. package/dist/lib/buildSliceDirectoryPath.cjs.map +1 -1
  19. package/dist/lib/buildSliceDirectoryPath.d.ts +2 -2
  20. package/dist/lib/buildSliceDirectoryPath.js.map +1 -1
  21. package/dist/lib/isSharedSliceModel.cjs +1 -19
  22. package/dist/lib/isSharedSliceModel.cjs.map +1 -1
  23. package/dist/lib/isSharedSliceModel.d.ts +335 -2
  24. package/dist/lib/isSharedSliceModel.js +1 -2
  25. package/dist/lib/isSharedSliceModel.js.map +1 -1
  26. package/dist/lib/updateSliceModelFile.cjs.map +1 -1
  27. package/dist/lib/updateSliceModelFile.d.ts +2 -2
  28. package/dist/lib/updateSliceModelFile.js.map +1 -1
  29. package/dist/simulator/index.d.ts +2 -1
  30. package/package.json +7 -6
  31. package/src/hooks/customType-read.ts +2 -2
  32. package/src/hooks/customTypeLibrary-read.ts +2 -2
  33. package/src/hooks/slice-read.ts +22 -7
  34. package/src/hooks/sliceSimulator-setup-read.ts +9 -4
  35. package/src/hooks/snippet-read.ts +5 -6
  36. package/src/lib/buildSliceDirectoryPath.ts +2 -2
  37. package/src/lib/isSharedSliceModel.ts +3 -3
  38. package/src/lib/updateSliceModelFile.ts +2 -2
  39. package/src/simulator/index.ts +2 -2
package/README.md CHANGED
@@ -48,7 +48,7 @@ For more clarity on this project and its structure you can also check out the de
48
48
  ## License
49
49
 
50
50
  ```
51
- Copyright 2013-2022 Prismic <contact@prismic.io> (https://prismic.io)
51
+ Copyright 2013-2023 Prismic <contact@prismic.io> (https://prismic.io)
52
52
 
53
53
  Licensed under the Apache License, Version 2.0 (the "License");
54
54
  you may not use this file except in compliance with the License.
@@ -1 +1 @@
1
- {"version":3,"file":"customType-read.cjs","sources":["../../../src/hooks/customType-read.ts"],"sourcesContent":["import type { CustomTypeReadHook } from \"@slicemachine/plugin-kit\";\nimport * as prismicT from \"@prismicio/types\";\nimport * as path from \"node:path\";\n\nimport { buildCustomTypeDirectoryPath } from \"../lib/buildCustomTypeDirectoryPath\";\nimport { readJSONFile } from \"../lib/readJSONFile\";\n\nimport type { PluginOptions } from \"../types\";\n\nexport const customTypeRead: CustomTypeReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst filePath = path.join(\n\t\tbuildCustomTypeDirectoryPath({ customTypeID: data.id, helpers }),\n\t\t\"index.json\",\n\t);\n\n\tconst model = await readJSONFile<prismicT.CustomTypeModel>(filePath);\n\n\treturn {\n\t\tmodel,\n\t};\n};\n"],"names":["path","buildCustomTypeDirectoryPath","readJSONFile"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AASO,MAAM,iBAAoD,OAChE,MACA,EAAE,cACC;AACG,QAAA,WAAWA,gBAAK,KACrBC,6BAA6B,6BAAA,EAAE,cAAc,KAAK,IAAI,SAAS,GAC/D,YAAY;AAGP,QAAA,QAAQ,MAAMC,0BAAuC,QAAQ;AAE5D,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;;"}
1
+ {"version":3,"file":"customType-read.cjs","sources":["../../../src/hooks/customType-read.ts"],"sourcesContent":["import type { CustomTypeReadHook } from \"@slicemachine/plugin-kit\";\nimport type { CustomType } from \"@prismicio/types-internal/lib/customtypes\";\nimport * as path from \"node:path\";\n\nimport { buildCustomTypeDirectoryPath } from \"../lib/buildCustomTypeDirectoryPath\";\nimport { readJSONFile } from \"../lib/readJSONFile\";\n\nimport type { PluginOptions } from \"../types\";\n\nexport const customTypeRead: CustomTypeReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst filePath = path.join(\n\t\tbuildCustomTypeDirectoryPath({ customTypeID: data.id, helpers }),\n\t\t\"index.json\",\n\t);\n\n\tconst model = await readJSONFile<CustomType>(filePath);\n\n\treturn {\n\t\tmodel,\n\t};\n};\n"],"names":["path","buildCustomTypeDirectoryPath","readJSONFile"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AASO,MAAM,iBAAoD,OAChE,MACA,EAAE,cACC;AACG,QAAA,WAAWA,gBAAK,KACrBC,6BAA6B,6BAAA,EAAE,cAAc,KAAK,IAAI,SAAS,GAC/D,YAAY;AAGP,QAAA,QAAQ,MAAMC,0BAAyB,QAAQ;AAE9C,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"customType-read.js","sources":["../../../src/hooks/customType-read.ts"],"sourcesContent":["import type { CustomTypeReadHook } from \"@slicemachine/plugin-kit\";\nimport * as prismicT from \"@prismicio/types\";\nimport * as path from \"node:path\";\n\nimport { buildCustomTypeDirectoryPath } from \"../lib/buildCustomTypeDirectoryPath\";\nimport { readJSONFile } from \"../lib/readJSONFile\";\n\nimport type { PluginOptions } from \"../types\";\n\nexport const customTypeRead: CustomTypeReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst filePath = path.join(\n\t\tbuildCustomTypeDirectoryPath({ customTypeID: data.id, helpers }),\n\t\t\"index.json\",\n\t);\n\n\tconst model = await readJSONFile<prismicT.CustomTypeModel>(filePath);\n\n\treturn {\n\t\tmodel,\n\t};\n};\n"],"names":[],"mappings":";;;AASO,MAAM,iBAAoD,OAChE,MACA,EAAE,cACC;AACG,QAAA,WAAW,KAAK,KACrB,6BAA6B,EAAE,cAAc,KAAK,IAAI,SAAS,GAC/D,YAAY;AAGP,QAAA,QAAQ,MAAM,aAAuC,QAAQ;AAE5D,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;"}
1
+ {"version":3,"file":"customType-read.js","sources":["../../../src/hooks/customType-read.ts"],"sourcesContent":["import type { CustomTypeReadHook } from \"@slicemachine/plugin-kit\";\nimport type { CustomType } from \"@prismicio/types-internal/lib/customtypes\";\nimport * as path from \"node:path\";\n\nimport { buildCustomTypeDirectoryPath } from \"../lib/buildCustomTypeDirectoryPath\";\nimport { readJSONFile } from \"../lib/readJSONFile\";\n\nimport type { PluginOptions } from \"../types\";\n\nexport const customTypeRead: CustomTypeReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst filePath = path.join(\n\t\tbuildCustomTypeDirectoryPath({ customTypeID: data.id, helpers }),\n\t\t\"index.json\",\n\t);\n\n\tconst model = await readJSONFile<CustomType>(filePath);\n\n\treturn {\n\t\tmodel,\n\t};\n};\n"],"names":[],"mappings":";;;AASO,MAAM,iBAAoD,OAChE,MACA,EAAE,cACC;AACG,QAAA,WAAW,KAAK,KACrB,6BAA6B,EAAE,cAAc,KAAK,IAAI,SAAS,GAC/D,YAAY;AAGP,QAAA,QAAQ,MAAM,aAAyB,QAAQ;AAE9C,SAAA;AAAA,IACN;AAAA,EAAA;AAEF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"customTypeLibrary-read.cjs","sources":["../../../src/hooks/customTypeLibrary-read.ts"],"sourcesContent":["import type { CustomTypeLibraryReadHook } from \"@slicemachine/plugin-kit\";\nimport * as prismicT from \"@prismicio/types\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { buildCustomTypeLibraryDirectoryPath } from \"../lib/buildCustomTypeLibraryDirectoryPath\";\nimport { readJSONFile } from \"../lib/readJSONFile\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst isCustomTypeModel = (\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tinput: any,\n): input is prismicT.CustomTypeModel => {\n\treturn typeof input === \"object\" && input !== null && \"json\" in input;\n};\n\nexport const customTypeLibraryRead: CustomTypeLibraryReadHook<\n\tPluginOptions\n> = async (_data, { helpers }) => {\n\tconst dirPath = buildCustomTypeLibraryDirectoryPath({ helpers });\n\n\t// Ensure the directory exists.\n\tawait fs.mkdir(dirPath, { recursive: true });\n\n\tconst childDirs = await fs.readdir(dirPath);\n\n\tconst ids: string[] = [];\n\tawait Promise.all(\n\t\tchildDirs.map(async (childDir) => {\n\t\t\tconst childDirContents = await fs.readdir(path.join(dirPath, childDir), {\n\t\t\t\twithFileTypes: true,\n\t\t\t});\n\t\t\tconst isCustomTypeDir = childDirContents.some((entry) => {\n\t\t\t\treturn entry.isFile() && entry.name === \"index.json\";\n\t\t\t});\n\n\t\t\tif (isCustomTypeDir) {\n\t\t\t\tconst modelPath = path.join(dirPath, childDir, \"index.json\");\n\n\t\t\t\tconst modelContents = await readJSONFile(modelPath);\n\n\t\t\t\tif (isCustomTypeModel(modelContents)) {\n\t\t\t\t\tids.push(modelContents.id);\n\t\t\t\t}\n\t\t\t}\n\t\t}),\n\t);\n\n\treturn {\n\t\tids: ids.sort(),\n\t};\n};\n"],"names":["buildCustomTypeLibraryDirectoryPath","fs","path","readJSONFile"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAM,oBAAoB,CAEzB,UACsC;AACtC,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU;AACjE;AAEO,MAAM,wBAET,OAAO,OAAO,EAAE,cAAa;AAChC,QAAM,UAAUA,oCAAAA,oCAAoC,EAAE,QAAS,CAAA;AAG/D,QAAMC,cAAG,MAAM,SAAS,EAAE,WAAW,MAAM;AAE3C,QAAM,YAAY,MAAMA,cAAG,QAAQ,OAAO;AAE1C,QAAM,MAAgB,CAAA;AACtB,QAAM,QAAQ,IACb,UAAU,IAAI,OAAO,aAAY;AAC1B,UAAA,mBAAmB,MAAMA,cAAG,QAAQC,gBAAK,KAAK,SAAS,QAAQ,GAAG;AAAA,MACvE,eAAe;AAAA,IAAA,CACf;AACD,UAAM,kBAAkB,iBAAiB,KAAK,CAAC,UAAS;AACvD,aAAO,MAAM,OAAA,KAAY,MAAM,SAAS;AAAA,IAAA,CACxC;AAED,QAAI,iBAAiB;AACpB,YAAM,YAAYA,gBAAK,KAAK,SAAS,UAAU,YAAY;AAErD,YAAA,gBAAgB,MAAMC,0BAAa,SAAS;AAE9C,UAAA,kBAAkB,aAAa,GAAG;AACjC,YAAA,KAAK,cAAc,EAAE;AAAA,MACzB;AAAA,IACD;AAAA,EACD,CAAA,CAAC;AAGI,SAAA;AAAA,IACN,KAAK,IAAI,KAAM;AAAA,EAAA;AAEjB;;"}
1
+ {"version":3,"file":"customTypeLibrary-read.cjs","sources":["../../../src/hooks/customTypeLibrary-read.ts"],"sourcesContent":["import type { CustomTypeLibraryReadHook } from \"@slicemachine/plugin-kit\";\nimport type { CustomType } from \"@prismicio/types-internal/lib/customtypes\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { buildCustomTypeLibraryDirectoryPath } from \"../lib/buildCustomTypeLibraryDirectoryPath\";\nimport { readJSONFile } from \"../lib/readJSONFile\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst isCustomTypeModel = (\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tinput: any,\n): input is CustomType => {\n\treturn typeof input === \"object\" && input !== null && \"json\" in input;\n};\n\nexport const customTypeLibraryRead: CustomTypeLibraryReadHook<\n\tPluginOptions\n> = async (_data, { helpers }) => {\n\tconst dirPath = buildCustomTypeLibraryDirectoryPath({ helpers });\n\n\t// Ensure the directory exists.\n\tawait fs.mkdir(dirPath, { recursive: true });\n\n\tconst childDirs = await fs.readdir(dirPath);\n\n\tconst ids: string[] = [];\n\tawait Promise.all(\n\t\tchildDirs.map(async (childDir) => {\n\t\t\tconst childDirContents = await fs.readdir(path.join(dirPath, childDir), {\n\t\t\t\twithFileTypes: true,\n\t\t\t});\n\t\t\tconst isCustomTypeDir = childDirContents.some((entry) => {\n\t\t\t\treturn entry.isFile() && entry.name === \"index.json\";\n\t\t\t});\n\n\t\t\tif (isCustomTypeDir) {\n\t\t\t\tconst modelPath = path.join(dirPath, childDir, \"index.json\");\n\n\t\t\t\tconst modelContents = await readJSONFile(modelPath);\n\n\t\t\t\tif (isCustomTypeModel(modelContents)) {\n\t\t\t\t\tids.push(modelContents.id);\n\t\t\t\t}\n\t\t\t}\n\t\t}),\n\t);\n\n\treturn {\n\t\tids: ids.sort(),\n\t};\n};\n"],"names":["buildCustomTypeLibraryDirectoryPath","fs","path","readJSONFile"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAM,oBAAoB,CAEzB,UACwB;AACxB,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU;AACjE;AAEO,MAAM,wBAET,OAAO,OAAO,EAAE,cAAa;AAChC,QAAM,UAAUA,oCAAAA,oCAAoC,EAAE,QAAS,CAAA;AAG/D,QAAMC,cAAG,MAAM,SAAS,EAAE,WAAW,MAAM;AAE3C,QAAM,YAAY,MAAMA,cAAG,QAAQ,OAAO;AAE1C,QAAM,MAAgB,CAAA;AACtB,QAAM,QAAQ,IACb,UAAU,IAAI,OAAO,aAAY;AAC1B,UAAA,mBAAmB,MAAMA,cAAG,QAAQC,gBAAK,KAAK,SAAS,QAAQ,GAAG;AAAA,MACvE,eAAe;AAAA,IAAA,CACf;AACD,UAAM,kBAAkB,iBAAiB,KAAK,CAAC,UAAS;AACvD,aAAO,MAAM,OAAA,KAAY,MAAM,SAAS;AAAA,IAAA,CACxC;AAED,QAAI,iBAAiB;AACpB,YAAM,YAAYA,gBAAK,KAAK,SAAS,UAAU,YAAY;AAErD,YAAA,gBAAgB,MAAMC,0BAAa,SAAS;AAE9C,UAAA,kBAAkB,aAAa,GAAG;AACjC,YAAA,KAAK,cAAc,EAAE;AAAA,MACzB;AAAA,IACD;AAAA,EACD,CAAA,CAAC;AAGI,SAAA;AAAA,IACN,KAAK,IAAI,KAAM;AAAA,EAAA;AAEjB;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"customTypeLibrary-read.js","sources":["../../../src/hooks/customTypeLibrary-read.ts"],"sourcesContent":["import type { CustomTypeLibraryReadHook } from \"@slicemachine/plugin-kit\";\nimport * as prismicT from \"@prismicio/types\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { buildCustomTypeLibraryDirectoryPath } from \"../lib/buildCustomTypeLibraryDirectoryPath\";\nimport { readJSONFile } from \"../lib/readJSONFile\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst isCustomTypeModel = (\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tinput: any,\n): input is prismicT.CustomTypeModel => {\n\treturn typeof input === \"object\" && input !== null && \"json\" in input;\n};\n\nexport const customTypeLibraryRead: CustomTypeLibraryReadHook<\n\tPluginOptions\n> = async (_data, { helpers }) => {\n\tconst dirPath = buildCustomTypeLibraryDirectoryPath({ helpers });\n\n\t// Ensure the directory exists.\n\tawait fs.mkdir(dirPath, { recursive: true });\n\n\tconst childDirs = await fs.readdir(dirPath);\n\n\tconst ids: string[] = [];\n\tawait Promise.all(\n\t\tchildDirs.map(async (childDir) => {\n\t\t\tconst childDirContents = await fs.readdir(path.join(dirPath, childDir), {\n\t\t\t\twithFileTypes: true,\n\t\t\t});\n\t\t\tconst isCustomTypeDir = childDirContents.some((entry) => {\n\t\t\t\treturn entry.isFile() && entry.name === \"index.json\";\n\t\t\t});\n\n\t\t\tif (isCustomTypeDir) {\n\t\t\t\tconst modelPath = path.join(dirPath, childDir, \"index.json\");\n\n\t\t\t\tconst modelContents = await readJSONFile(modelPath);\n\n\t\t\t\tif (isCustomTypeModel(modelContents)) {\n\t\t\t\t\tids.push(modelContents.id);\n\t\t\t\t}\n\t\t\t}\n\t\t}),\n\t);\n\n\treturn {\n\t\tids: ids.sort(),\n\t};\n};\n"],"names":[],"mappings":";;;;AAUA,MAAM,oBAAoB,CAEzB,UACsC;AACtC,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU;AACjE;AAEO,MAAM,wBAET,OAAO,OAAO,EAAE,cAAa;AAChC,QAAM,UAAU,oCAAoC,EAAE,QAAS,CAAA;AAG/D,QAAM,GAAG,MAAM,SAAS,EAAE,WAAW,MAAM;AAE3C,QAAM,YAAY,MAAM,GAAG,QAAQ,OAAO;AAE1C,QAAM,MAAgB,CAAA;AACtB,QAAM,QAAQ,IACb,UAAU,IAAI,OAAO,aAAY;AAC1B,UAAA,mBAAmB,MAAM,GAAG,QAAQ,KAAK,KAAK,SAAS,QAAQ,GAAG;AAAA,MACvE,eAAe;AAAA,IAAA,CACf;AACD,UAAM,kBAAkB,iBAAiB,KAAK,CAAC,UAAS;AACvD,aAAO,MAAM,OAAA,KAAY,MAAM,SAAS;AAAA,IAAA,CACxC;AAED,QAAI,iBAAiB;AACpB,YAAM,YAAY,KAAK,KAAK,SAAS,UAAU,YAAY;AAErD,YAAA,gBAAgB,MAAM,aAAa,SAAS;AAE9C,UAAA,kBAAkB,aAAa,GAAG;AACjC,YAAA,KAAK,cAAc,EAAE;AAAA,MACzB;AAAA,IACD;AAAA,EACD,CAAA,CAAC;AAGI,SAAA;AAAA,IACN,KAAK,IAAI,KAAM;AAAA,EAAA;AAEjB;"}
1
+ {"version":3,"file":"customTypeLibrary-read.js","sources":["../../../src/hooks/customTypeLibrary-read.ts"],"sourcesContent":["import type { CustomTypeLibraryReadHook } from \"@slicemachine/plugin-kit\";\nimport type { CustomType } from \"@prismicio/types-internal/lib/customtypes\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { buildCustomTypeLibraryDirectoryPath } from \"../lib/buildCustomTypeLibraryDirectoryPath\";\nimport { readJSONFile } from \"../lib/readJSONFile\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst isCustomTypeModel = (\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tinput: any,\n): input is CustomType => {\n\treturn typeof input === \"object\" && input !== null && \"json\" in input;\n};\n\nexport const customTypeLibraryRead: CustomTypeLibraryReadHook<\n\tPluginOptions\n> = async (_data, { helpers }) => {\n\tconst dirPath = buildCustomTypeLibraryDirectoryPath({ helpers });\n\n\t// Ensure the directory exists.\n\tawait fs.mkdir(dirPath, { recursive: true });\n\n\tconst childDirs = await fs.readdir(dirPath);\n\n\tconst ids: string[] = [];\n\tawait Promise.all(\n\t\tchildDirs.map(async (childDir) => {\n\t\t\tconst childDirContents = await fs.readdir(path.join(dirPath, childDir), {\n\t\t\t\twithFileTypes: true,\n\t\t\t});\n\t\t\tconst isCustomTypeDir = childDirContents.some((entry) => {\n\t\t\t\treturn entry.isFile() && entry.name === \"index.json\";\n\t\t\t});\n\n\t\t\tif (isCustomTypeDir) {\n\t\t\t\tconst modelPath = path.join(dirPath, childDir, \"index.json\");\n\n\t\t\t\tconst modelContents = await readJSONFile(modelPath);\n\n\t\t\t\tif (isCustomTypeModel(modelContents)) {\n\t\t\t\t\tids.push(modelContents.id);\n\t\t\t\t}\n\t\t\t}\n\t\t}),\n\t);\n\n\treturn {\n\t\tids: ids.sort(),\n\t};\n};\n"],"names":[],"mappings":";;;;AAUA,MAAM,oBAAoB,CAEzB,UACwB;AACxB,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU;AACjE;AAEO,MAAM,wBAET,OAAO,OAAO,EAAE,cAAa;AAChC,QAAM,UAAU,oCAAoC,EAAE,QAAS,CAAA;AAG/D,QAAM,GAAG,MAAM,SAAS,EAAE,WAAW,MAAM;AAE3C,QAAM,YAAY,MAAM,GAAG,QAAQ,OAAO;AAE1C,QAAM,MAAgB,CAAA;AACtB,QAAM,QAAQ,IACb,UAAU,IAAI,OAAO,aAAY;AAC1B,UAAA,mBAAmB,MAAM,GAAG,QAAQ,KAAK,KAAK,SAAS,QAAQ,GAAG;AAAA,MACvE,eAAe;AAAA,IAAA,CACf;AACD,UAAM,kBAAkB,iBAAiB,KAAK,CAAC,UAAS;AACvD,aAAO,MAAM,OAAA,KAAY,MAAM,SAAS;AAAA,IAAA,CACxC;AAED,QAAI,iBAAiB;AACpB,YAAM,YAAY,KAAK,KAAK,SAAS,UAAU,YAAY;AAErD,YAAA,gBAAgB,MAAM,aAAa,SAAS;AAE9C,UAAA,kBAAkB,aAAa,GAAG;AACjC,YAAA,KAAK,cAAc,EAAE;AAAA,MACzB;AAAA,IACD;AAAA,EACD,CAAA,CAAC;AAGI,SAAA;AAAA,IACN,KAAK,IAAI,KAAM;AAAA,EAAA;AAEjB;"}
@@ -30,12 +30,17 @@ const sliceRead = async (data, { helpers }) => {
30
30
  });
31
31
  await fs__namespace.mkdir(libraryDir, { recursive: true });
32
32
  const childDirs = await fs__namespace.readdir(libraryDir, { withFileTypes: true });
33
+ const modelReadErrors = [];
33
34
  const [model] = (await Promise.all(childDirs.map(async (childDir) => {
34
35
  if (childDir.isDirectory()) {
35
36
  const modelPath = path__namespace.join(libraryDir, childDir.name, "model.json");
36
- const modelContents = await readJSONFile.readJSONFile(modelPath);
37
- if (isSharedSliceModel.isSharedSliceModel(modelContents) && modelContents.id === data.sliceID) {
38
- return modelContents;
37
+ try {
38
+ const modelContents = await readJSONFile.readJSONFile(modelPath);
39
+ if (isSharedSliceModel.isSharedSliceModel(modelContents) && modelContents.id === data.sliceID) {
40
+ return modelContents;
41
+ }
42
+ } catch (error) {
43
+ modelReadErrors.push(modelPath);
39
44
  }
40
45
  }
41
46
  }))).filter((model2) => Boolean(model2));
@@ -44,6 +49,12 @@ const sliceRead = async (data, { helpers }) => {
44
49
  model
45
50
  };
46
51
  } else {
52
+ if (modelReadErrors.length) {
53
+ throw new Error(`Did not find a Slice model with ID "${data.sliceID}" in the "${data.libraryID}" Slice Library.
54
+
55
+ Those Slice models could not be read:
56
+ - ${modelReadErrors.join("\n - ")}`);
57
+ }
47
58
  throw new Error(`Did not find a Slice model with ID "${data.sliceID}" in the "${data.libraryID}" Slice Library.`);
48
59
  }
49
60
  };
@@ -1 +1 @@
1
- {"version":3,"file":"slice-read.cjs","sources":["../../../src/hooks/slice-read.ts"],"sourcesContent":["import type { SliceReadHook } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { buildSliceLibraryDirectoryPath } from \"../lib/buildSliceLibraryDirectoryPath\";\nimport { isSharedSliceModel } from \"../lib/isSharedSliceModel\";\nimport { readJSONFile } from \"../lib/readJSONFile\";\n\nimport type { PluginOptions } from \"../types\";\n\nexport const sliceRead: SliceReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst libraryDir = buildSliceLibraryDirectoryPath({\n\t\tlibraryID: data.libraryID,\n\t\thelpers,\n\t});\n\n\t// Ensure the directory exists.\n\tawait fs.mkdir(libraryDir, { recursive: true });\n\n\tconst childDirs = await fs.readdir(libraryDir, { withFileTypes: true });\n\n\t// Find the first matching model.\n\tconst [model] = (\n\t\tawait Promise.all(\n\t\t\tchildDirs.map(async (childDir) => {\n\t\t\t\tif (childDir.isDirectory()) {\n\t\t\t\t\tconst modelPath = path.join(libraryDir, childDir.name, \"model.json\");\n\n\t\t\t\t\tconst modelContents = await readJSONFile(modelPath);\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tisSharedSliceModel(modelContents) &&\n\t\t\t\t\t\tmodelContents.id === data.sliceID\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn modelContents;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}),\n\t\t)\n\t).filter((model): model is NonNullable<typeof model> => Boolean(model));\n\n\tif (model) {\n\t\treturn {\n\t\t\tmodel,\n\t\t};\n\t} else {\n\t\tthrow new Error(\n\t\t\t`Did not find a Slice model with ID \"${data.sliceID}\" in the \"${data.libraryID}\" Slice Library.`,\n\t\t);\n\t}\n};\n"],"names":["buildSliceLibraryDirectoryPath","fs","path","readJSONFile","isSharedSliceModel","model"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAUO,MAAM,YAA0C,OACtD,MACA,EAAE,cACC;AACH,QAAM,aAAaA,+BAAAA,+BAA+B;AAAA,IACjD,WAAW,KAAK;AAAA,IAChB;AAAA,EAAA,CACA;AAGD,QAAMC,cAAG,MAAM,YAAY,EAAE,WAAW,MAAM;AAExC,QAAA,YAAY,MAAMA,cAAG,QAAQ,YAAY,EAAE,eAAe,MAAM;AAGhE,QAAA,CAAC,KAAK,KACX,MAAM,QAAQ,IACb,UAAU,IAAI,OAAO,aAAY;AAC5B,QAAA,SAAS,eAAe;AAC3B,YAAM,YAAYC,gBAAK,KAAK,YAAY,SAAS,MAAM,YAAY;AAE7D,YAAA,gBAAgB,MAAMC,0BAAa,SAAS;AAElD,UACCC,mBAAAA,mBAAmB,aAAa,KAChC,cAAc,OAAO,KAAK,SACzB;AACM,eAAA;AAAA,MACP;AAAA,IACD;AAAA,EAAA,CACD,CAAC,GAEF,OAAO,CAACC,WAA8C,QAAQA,MAAK,CAAC;AAEtE,MAAI,OAAO;AACH,WAAA;AAAA,MACN;AAAA,IAAA;AAAA,SAEK;AACN,UAAM,IAAI,MACT,uCAAuC,KAAK,oBAAoB,KAAK,2BAA2B;AAAA,EAEjG;AACF;;"}
1
+ {"version":3,"file":"slice-read.cjs","sources":["../../../src/hooks/slice-read.ts"],"sourcesContent":["import type { SliceReadHook } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { buildSliceLibraryDirectoryPath } from \"../lib/buildSliceLibraryDirectoryPath\";\nimport { isSharedSliceModel } from \"../lib/isSharedSliceModel\";\nimport { readJSONFile } from \"../lib/readJSONFile\";\n\nimport type { PluginOptions } from \"../types\";\n\nexport const sliceRead: SliceReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst libraryDir = buildSliceLibraryDirectoryPath({\n\t\tlibraryID: data.libraryID,\n\t\thelpers,\n\t});\n\n\t// Ensure the directory exists.\n\tawait fs.mkdir(libraryDir, { recursive: true });\n\n\tconst childDirs = await fs.readdir(libraryDir, { withFileTypes: true });\n\n\tconst modelReadErrors: string[] = [];\n\n\t// Find the first matching model.\n\tconst [model] = (\n\t\tawait Promise.all(\n\t\t\tchildDirs.map(async (childDir) => {\n\t\t\t\tif (childDir.isDirectory()) {\n\t\t\t\t\tconst modelPath = path.join(libraryDir, childDir.name, \"model.json\");\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst modelContents = await readJSONFile(modelPath);\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tisSharedSliceModel(modelContents) &&\n\t\t\t\t\t\t\tmodelContents.id === data.sliceID\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn modelContents;\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tmodelReadErrors.push(modelPath);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}),\n\t\t)\n\t).filter((model): model is NonNullable<typeof model> => Boolean(model));\n\n\tif (model) {\n\t\treturn {\n\t\t\tmodel,\n\t\t};\n\t} else {\n\t\tif (modelReadErrors.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Did not find a Slice model with ID \"${data.sliceID}\" in the \"${\n\t\t\t\t\tdata.libraryID\n\t\t\t\t}\" Slice Library.\\n\\nThose Slice models could not be read:\\n - ${modelReadErrors.join(\n\t\t\t\t\t\"\\n - \",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`Did not find a Slice model with ID \"${data.sliceID}\" in the \"${data.libraryID}\" Slice Library.`,\n\t\t);\n\t}\n};\n"],"names":["buildSliceLibraryDirectoryPath","fs","path","readJSONFile","isSharedSliceModel","model"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAUO,MAAM,YAA0C,OACtD,MACA,EAAE,cACC;AACH,QAAM,aAAaA,+BAAAA,+BAA+B;AAAA,IACjD,WAAW,KAAK;AAAA,IAChB;AAAA,EAAA,CACA;AAGD,QAAMC,cAAG,MAAM,YAAY,EAAE,WAAW,MAAM;AAExC,QAAA,YAAY,MAAMA,cAAG,QAAQ,YAAY,EAAE,eAAe,MAAM;AAEtE,QAAM,kBAA4B,CAAA;AAG5B,QAAA,CAAC,KAAK,KACX,MAAM,QAAQ,IACb,UAAU,IAAI,OAAO,aAAY;AAC5B,QAAA,SAAS,eAAe;AAC3B,YAAM,YAAYC,gBAAK,KAAK,YAAY,SAAS,MAAM,YAAY;AAC/D,UAAA;AACG,cAAA,gBAAgB,MAAMC,0BAAa,SAAS;AAElD,YACCC,mBAAAA,mBAAmB,aAAa,KAChC,cAAc,OAAO,KAAK,SACzB;AACM,iBAAA;AAAA,QACP;AAAA,eACO;AACR,wBAAgB,KAAK,SAAS;AAAA,MAC9B;AAAA,IACD;AAAA,EAAA,CACD,CAAC,GAEF,OAAO,CAACC,WAA8C,QAAQA,MAAK,CAAC;AAEtE,MAAI,OAAO;AACH,WAAA;AAAA,MACN;AAAA,IAAA;AAAA,SAEK;AACN,QAAI,gBAAgB,QAAQ;AAC3B,YAAM,IAAI,MACT,uCAAuC,KAAK,oBAC3C,KAAK;AAAA;AAAA;AAAA,MAC4D,gBAAgB,KACjF,QAAQ,GACN;AAAA,IAEJ;AAED,UAAM,IAAI,MACT,uCAAuC,KAAK,oBAAoB,KAAK,2BAA2B;AAAA,EAEjG;AACF;;"}
@@ -10,12 +10,17 @@ const sliceRead = async (data, { helpers }) => {
10
10
  });
11
11
  await fs.mkdir(libraryDir, { recursive: true });
12
12
  const childDirs = await fs.readdir(libraryDir, { withFileTypes: true });
13
+ const modelReadErrors = [];
13
14
  const [model] = (await Promise.all(childDirs.map(async (childDir) => {
14
15
  if (childDir.isDirectory()) {
15
16
  const modelPath = path.join(libraryDir, childDir.name, "model.json");
16
- const modelContents = await readJSONFile(modelPath);
17
- if (isSharedSliceModel(modelContents) && modelContents.id === data.sliceID) {
18
- return modelContents;
17
+ try {
18
+ const modelContents = await readJSONFile(modelPath);
19
+ if (isSharedSliceModel(modelContents) && modelContents.id === data.sliceID) {
20
+ return modelContents;
21
+ }
22
+ } catch (error) {
23
+ modelReadErrors.push(modelPath);
19
24
  }
20
25
  }
21
26
  }))).filter((model2) => Boolean(model2));
@@ -24,6 +29,12 @@ const sliceRead = async (data, { helpers }) => {
24
29
  model
25
30
  };
26
31
  } else {
32
+ if (modelReadErrors.length) {
33
+ throw new Error(`Did not find a Slice model with ID "${data.sliceID}" in the "${data.libraryID}" Slice Library.
34
+
35
+ Those Slice models could not be read:
36
+ - ${modelReadErrors.join("\n - ")}`);
37
+ }
27
38
  throw new Error(`Did not find a Slice model with ID "${data.sliceID}" in the "${data.libraryID}" Slice Library.`);
28
39
  }
29
40
  };
@@ -1 +1 @@
1
- {"version":3,"file":"slice-read.js","sources":["../../../src/hooks/slice-read.ts"],"sourcesContent":["import type { SliceReadHook } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { buildSliceLibraryDirectoryPath } from \"../lib/buildSliceLibraryDirectoryPath\";\nimport { isSharedSliceModel } from \"../lib/isSharedSliceModel\";\nimport { readJSONFile } from \"../lib/readJSONFile\";\n\nimport type { PluginOptions } from \"../types\";\n\nexport const sliceRead: SliceReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst libraryDir = buildSliceLibraryDirectoryPath({\n\t\tlibraryID: data.libraryID,\n\t\thelpers,\n\t});\n\n\t// Ensure the directory exists.\n\tawait fs.mkdir(libraryDir, { recursive: true });\n\n\tconst childDirs = await fs.readdir(libraryDir, { withFileTypes: true });\n\n\t// Find the first matching model.\n\tconst [model] = (\n\t\tawait Promise.all(\n\t\t\tchildDirs.map(async (childDir) => {\n\t\t\t\tif (childDir.isDirectory()) {\n\t\t\t\t\tconst modelPath = path.join(libraryDir, childDir.name, \"model.json\");\n\n\t\t\t\t\tconst modelContents = await readJSONFile(modelPath);\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tisSharedSliceModel(modelContents) &&\n\t\t\t\t\t\tmodelContents.id === data.sliceID\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn modelContents;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}),\n\t\t)\n\t).filter((model): model is NonNullable<typeof model> => Boolean(model));\n\n\tif (model) {\n\t\treturn {\n\t\t\tmodel,\n\t\t};\n\t} else {\n\t\tthrow new Error(\n\t\t\t`Did not find a Slice model with ID \"${data.sliceID}\" in the \"${data.libraryID}\" Slice Library.`,\n\t\t);\n\t}\n};\n"],"names":["model"],"mappings":";;;;;AAUO,MAAM,YAA0C,OACtD,MACA,EAAE,cACC;AACH,QAAM,aAAa,+BAA+B;AAAA,IACjD,WAAW,KAAK;AAAA,IAChB;AAAA,EAAA,CACA;AAGD,QAAM,GAAG,MAAM,YAAY,EAAE,WAAW,MAAM;AAExC,QAAA,YAAY,MAAM,GAAG,QAAQ,YAAY,EAAE,eAAe,MAAM;AAGhE,QAAA,CAAC,KAAK,KACX,MAAM,QAAQ,IACb,UAAU,IAAI,OAAO,aAAY;AAC5B,QAAA,SAAS,eAAe;AAC3B,YAAM,YAAY,KAAK,KAAK,YAAY,SAAS,MAAM,YAAY;AAE7D,YAAA,gBAAgB,MAAM,aAAa,SAAS;AAElD,UACC,mBAAmB,aAAa,KAChC,cAAc,OAAO,KAAK,SACzB;AACM,eAAA;AAAA,MACP;AAAA,IACD;AAAA,EAAA,CACD,CAAC,GAEF,OAAO,CAACA,WAA8C,QAAQA,MAAK,CAAC;AAEtE,MAAI,OAAO;AACH,WAAA;AAAA,MACN;AAAA,IAAA;AAAA,SAEK;AACN,UAAM,IAAI,MACT,uCAAuC,KAAK,oBAAoB,KAAK,2BAA2B;AAAA,EAEjG;AACF;"}
1
+ {"version":3,"file":"slice-read.js","sources":["../../../src/hooks/slice-read.ts"],"sourcesContent":["import type { SliceReadHook } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { buildSliceLibraryDirectoryPath } from \"../lib/buildSliceLibraryDirectoryPath\";\nimport { isSharedSliceModel } from \"../lib/isSharedSliceModel\";\nimport { readJSONFile } from \"../lib/readJSONFile\";\n\nimport type { PluginOptions } from \"../types\";\n\nexport const sliceRead: SliceReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst libraryDir = buildSliceLibraryDirectoryPath({\n\t\tlibraryID: data.libraryID,\n\t\thelpers,\n\t});\n\n\t// Ensure the directory exists.\n\tawait fs.mkdir(libraryDir, { recursive: true });\n\n\tconst childDirs = await fs.readdir(libraryDir, { withFileTypes: true });\n\n\tconst modelReadErrors: string[] = [];\n\n\t// Find the first matching model.\n\tconst [model] = (\n\t\tawait Promise.all(\n\t\t\tchildDirs.map(async (childDir) => {\n\t\t\t\tif (childDir.isDirectory()) {\n\t\t\t\t\tconst modelPath = path.join(libraryDir, childDir.name, \"model.json\");\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst modelContents = await readJSONFile(modelPath);\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tisSharedSliceModel(modelContents) &&\n\t\t\t\t\t\t\tmodelContents.id === data.sliceID\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn modelContents;\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tmodelReadErrors.push(modelPath);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}),\n\t\t)\n\t).filter((model): model is NonNullable<typeof model> => Boolean(model));\n\n\tif (model) {\n\t\treturn {\n\t\t\tmodel,\n\t\t};\n\t} else {\n\t\tif (modelReadErrors.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Did not find a Slice model with ID \"${data.sliceID}\" in the \"${\n\t\t\t\t\tdata.libraryID\n\t\t\t\t}\" Slice Library.\\n\\nThose Slice models could not be read:\\n - ${modelReadErrors.join(\n\t\t\t\t\t\"\\n - \",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`Did not find a Slice model with ID \"${data.sliceID}\" in the \"${data.libraryID}\" Slice Library.`,\n\t\t);\n\t}\n};\n"],"names":["model"],"mappings":";;;;;AAUO,MAAM,YAA0C,OACtD,MACA,EAAE,cACC;AACH,QAAM,aAAa,+BAA+B;AAAA,IACjD,WAAW,KAAK;AAAA,IAChB;AAAA,EAAA,CACA;AAGD,QAAM,GAAG,MAAM,YAAY,EAAE,WAAW,MAAM;AAExC,QAAA,YAAY,MAAM,GAAG,QAAQ,YAAY,EAAE,eAAe,MAAM;AAEtE,QAAM,kBAA4B,CAAA;AAG5B,QAAA,CAAC,KAAK,KACX,MAAM,QAAQ,IACb,UAAU,IAAI,OAAO,aAAY;AAC5B,QAAA,SAAS,eAAe;AAC3B,YAAM,YAAY,KAAK,KAAK,YAAY,SAAS,MAAM,YAAY;AAC/D,UAAA;AACG,cAAA,gBAAgB,MAAM,aAAa,SAAS;AAElD,YACC,mBAAmB,aAAa,KAChC,cAAc,OAAO,KAAK,SACzB;AACM,iBAAA;AAAA,QACP;AAAA,eACO;AACR,wBAAgB,KAAK,SAAS;AAAA,MAC9B;AAAA,IACD;AAAA,EAAA,CACD,CAAC,GAEF,OAAO,CAACA,WAA8C,QAAQA,MAAK,CAAC;AAEtE,MAAI,OAAO;AACH,WAAA;AAAA,MACN;AAAA,IAAA;AAAA,SAEK;AACN,QAAI,gBAAgB,QAAQ;AAC3B,YAAM,IAAI,MACT,uCAAuC,KAAK,oBAC3C,KAAK;AAAA;AAAA;AAAA,MAC4D,gBAAgB,KACjF,QAAQ,GACN;AAAA,IAEJ;AAED,UAAM,IAAI,MACT,uCAAuC,KAAK,oBAAoB,KAAK,2BAA2B;AAAA,EAEjG;AACF;"}
@@ -156,12 +156,16 @@ const createStep3 = async ({ helpers }) => {
156
156
  `
157
157
  };
158
158
  }
159
- const res = await index.default(project.config.localSliceSimulatorURL);
160
- if (!res.ok) {
159
+ let res = void 0;
160
+ try {
161
+ res = await index.default(project.config.localSliceSimulatorURL);
162
+ } catch (error) {
163
+ }
164
+ if (!res || !res.ok) {
161
165
  return {
162
166
  title: "Unable to connect to simulator page",
163
167
  message: commonTags.source`
164
- Check that the \`localSliceSimulatorURL\` property in \`slicemachine.config.json\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/technologies/setup-slice-simulator-nextjs) for more details.
168
+ Check that the \`localSliceSimulatorURL\` property in \`slicemachine.config.json\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/setup-nextjs) for more details.
165
169
  `
166
170
  };
167
171
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sliceSimulator-setup-read.cjs","sources":["../../../src/hooks/sliceSimulator-setup-read.ts"],"sourcesContent":["import type {\n\tSliceMachineContext,\n\tSliceSimulatorSetupReadHook,\n\tSliceSimulatorSetupStep,\n} from \"@slicemachine/plugin-kit\";\nimport { source } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport fetch from \"node-fetch\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\n\t\"@prismicio/react\",\n\t\"@prismicio/client\",\n\t\"@prismicio/helpers\",\n];\n\ntype Args = SliceMachineContext<PluginOptions>;\n\nconst createStep1 = async ({\n\tproject,\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst require = createRequire(project.root);\n\n\treturn {\n\t\ttitle: \"Install packages\",\n\t\tdescription: \"The simulator requires some dependencies.\",\n\t\t// TODO: Create a plugin runner helper to provide the correct\n\t\t// package manager\n\t\tbody: source`\n\t\t\tThe simulator requires extra dependencies. Run the following command to install them.\n\n\t\t\t~~~sh\n\t\t\tnpm install --save ${REQUIRED_DEPENDENCIES.join(\" \")}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst missingDependencies: string[] = [];\n\n\t\t\tfor (const dependency of REQUIRED_DEPENDENCIES) {\n\t\t\t\ttry {\n\t\t\t\t\t// `require.resolve()` is preferred\n\t\t\t\t\t// over `import()` because we don't\n\t\t\t\t\t// want to load the module. Loading a\n\t\t\t\t\t// module could introduce side-effects.\n\t\t\t\t\trequire.resolve(dependency, {\n\t\t\t\t\t\tpaths: [helpers.joinPathFromRoot(\"node_modules\")],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\tmissingDependencies.push(dependency);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing all dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tInstall the required dependencies to continue.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (missingDependencies.length > 0) {\n\t\t\t\tconst formattedMissingDependencies = missingDependencies\n\t\t\t\t\t.map((missingDependency) => `\\`${missingDependency}\\``)\n\t\t\t\t\t.join(\", \");\n\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing some dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe following dependencies are missing: ${formattedMissingDependencies}\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nconst createStep2 = async ({\n\thelpers,\n\toptions,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst fileName = `slice-simulator.${await getJSOrTSXFileExtension({\n\t\thelpers,\n\t\toptions,\n\t})}`;\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tlet fileContents: string;\n\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (isTypeScriptProject) {\n\t\tfileContents = await helpers.format(\n\t\t\tsource`\n\t\t\t\timport { SliceSimulator } 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(): JSX.Element {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t`,\n\t\t\tfilePath,\n\t\t\t{\n\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t},\n\t\t);\n\t} else {\n\t\tfileContents = await helpers.format(\n\t\t\tsource`\n\t\t\t\timport { SliceSimulator } 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\treturn (\n\t\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t`,\n\t\t\tfilePath,\n\t\t\t{\n\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t},\n\t\t);\n\t}\n\n\treturn {\n\t\ttitle: \"Create a page for the simulator\",\n\t\tdescription: `In your \\`pages\\` directory, create a file called \\`${fileName}\\` containing this code.`,\n\t\tbody: source`\n\t\t\tIn your \\`pages\\` directory, create a file called \\`${fileName}\\` and add the following code. This route will be used to simulate and develop your components.\n\n\t\t\t~~~tsx\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t};\n};\n\nconst createStep3 = async ({\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst filePath = helpers.joinPathFromRoot(\"slicemachine.config.json\");\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t{\n\t\t\t\t\"localSliceSimulatorURL\": \"http://localhost:3000/slice-simulator\"\n\t\t\t}\n\t\t`,\n\t\tfilePath,\n\t\t{\n\t\t\tincludeNewlineAtEnd: false,\n\t\t},\n\t);\n\n\treturn {\n\t\ttitle: \"Update `slicemachine.config.json`\",\n\t\tdescription: `Update your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.`,\n\t\tbody: source`\n\t\t\tUpdate your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.\n\n\t\t\t~~~json\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst project = await helpers.getProject();\n\n\t\t\tif (!(\"localSliceSimulatorURL\" in project.config)) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing `localSliceSimulatorURL` property\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tA \\`localSliceSimulatorURL\\` property was not found in your \\`slicemachine.config.json\\` file.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Test if the URL is valid.\n\t\t\ttry {\n\t\t\t\tif (project.config.localSliceSimulatorURL) {\n\t\t\t\t\tnew URL(project.config.localSliceSimulatorURL);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\"Undefined Slice Simulator URL\");\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"An invalid URL was provided\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe \\`localSliceSimulatorURL\\` property should be of the shape \\`http://localhost:PORT/PATH\\`. See the codeblock for an example.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Check if the URL is accessible.\n\t\t\tconst res = await fetch(project.config.localSliceSimulatorURL);\n\n\t\t\tif (!res.ok) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Unable to connect to simulator page\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tCheck that the \\`localSliceSimulatorURL\\` property in \\`slicemachine.config.json\\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/technologies/setup-slice-simulator-nextjs) for more details.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nexport const sliceSimulatorSetupRead: SliceSimulatorSetupReadHook<\n\tPluginOptions\n> = async (_data, context) => {\n\treturn Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(context),\n\t]);\n};\n"],"names":["require","createRequire","source","getJSOrTSXFileExtension","checkIsTypeScriptProject","fetch"],"mappings":"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"}
1
+ {"version":3,"file":"sliceSimulator-setup-read.cjs","sources":["../../../src/hooks/sliceSimulator-setup-read.ts"],"sourcesContent":["import type {\n\tSliceMachineContext,\n\tSliceSimulatorSetupReadHook,\n\tSliceSimulatorSetupStep,\n} from \"@slicemachine/plugin-kit\";\nimport { source } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport fetch, { Response } from \"node-fetch\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\n\t\"@prismicio/react\",\n\t\"@prismicio/client\",\n\t\"@prismicio/helpers\",\n];\n\ntype Args = SliceMachineContext<PluginOptions>;\n\nconst createStep1 = async ({\n\tproject,\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst require = createRequire(project.root);\n\n\treturn {\n\t\ttitle: \"Install packages\",\n\t\tdescription: \"The simulator requires some dependencies.\",\n\t\t// TODO: Create a plugin runner helper to provide the correct\n\t\t// package manager\n\t\tbody: source`\n\t\t\tThe simulator requires extra dependencies. Run the following command to install them.\n\n\t\t\t~~~sh\n\t\t\tnpm install --save ${REQUIRED_DEPENDENCIES.join(\" \")}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst missingDependencies: string[] = [];\n\n\t\t\tfor (const dependency of REQUIRED_DEPENDENCIES) {\n\t\t\t\ttry {\n\t\t\t\t\t// `require.resolve()` is preferred\n\t\t\t\t\t// over `import()` because we don't\n\t\t\t\t\t// want to load the module. Loading a\n\t\t\t\t\t// module could introduce side-effects.\n\t\t\t\t\trequire.resolve(dependency, {\n\t\t\t\t\t\tpaths: [helpers.joinPathFromRoot(\"node_modules\")],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\tmissingDependencies.push(dependency);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing all dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tInstall the required dependencies to continue.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (missingDependencies.length > 0) {\n\t\t\t\tconst formattedMissingDependencies = missingDependencies\n\t\t\t\t\t.map((missingDependency) => `\\`${missingDependency}\\``)\n\t\t\t\t\t.join(\", \");\n\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing some dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe following dependencies are missing: ${formattedMissingDependencies}\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nconst createStep2 = async ({\n\thelpers,\n\toptions,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst fileName = `slice-simulator.${await getJSOrTSXFileExtension({\n\t\thelpers,\n\t\toptions,\n\t})}`;\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tlet fileContents: string;\n\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (isTypeScriptProject) {\n\t\tfileContents = await helpers.format(\n\t\t\tsource`\n\t\t\t\timport { SliceSimulator } 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(): JSX.Element {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t`,\n\t\t\tfilePath,\n\t\t\t{\n\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t},\n\t\t);\n\t} else {\n\t\tfileContents = await helpers.format(\n\t\t\tsource`\n\t\t\t\timport { SliceSimulator } 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\treturn (\n\t\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t`,\n\t\t\tfilePath,\n\t\t\t{\n\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t},\n\t\t);\n\t}\n\n\treturn {\n\t\ttitle: \"Create a page for the simulator\",\n\t\tdescription: `In your \\`pages\\` directory, create a file called \\`${fileName}\\` containing this code.`,\n\t\tbody: source`\n\t\t\tIn your \\`pages\\` directory, create a file called \\`${fileName}\\` and add the following code. This route will be used to simulate and develop your components.\n\n\t\t\t~~~tsx\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t};\n};\n\nconst createStep3 = async ({\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst filePath = helpers.joinPathFromRoot(\"slicemachine.config.json\");\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t{\n\t\t\t\t\"localSliceSimulatorURL\": \"http://localhost:3000/slice-simulator\"\n\t\t\t}\n\t\t`,\n\t\tfilePath,\n\t\t{\n\t\t\tincludeNewlineAtEnd: false,\n\t\t},\n\t);\n\n\treturn {\n\t\ttitle: \"Update `slicemachine.config.json`\",\n\t\tdescription: `Update your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.`,\n\t\tbody: source`\n\t\t\tUpdate your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.\n\n\t\t\t~~~json\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst project = await helpers.getProject();\n\n\t\t\tif (!(\"localSliceSimulatorURL\" in project.config)) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing `localSliceSimulatorURL` property\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tA \\`localSliceSimulatorURL\\` property was not found in your \\`slicemachine.config.json\\` file.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Test if the URL is valid.\n\t\t\ttry {\n\t\t\t\tif (project.config.localSliceSimulatorURL) {\n\t\t\t\t\tnew URL(project.config.localSliceSimulatorURL);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\"Undefined Slice Simulator URL\");\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"An invalid URL was provided\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe \\`localSliceSimulatorURL\\` property should be of the shape \\`http://localhost:PORT/PATH\\`. See the codeblock for an example.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Check if the URL is accessible.\n\t\t\tlet res: Response | undefined = undefined;\n\t\t\ttry {\n\t\t\t\tres = await fetch(project.config.localSliceSimulatorURL);\n\t\t\t} catch (error) {\n\t\t\t\t// Noop, we return if `res` is not defined\n\t\t\t}\n\n\t\t\tif (!res || !res.ok) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Unable to connect to simulator page\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tCheck that the \\`localSliceSimulatorURL\\` property in \\`slicemachine.config.json\\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/setup-nextjs) for more details.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nexport const sliceSimulatorSetupRead: SliceSimulatorSetupReadHook<\n\tPluginOptions\n> = async (_data, context) => {\n\treturn Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(context),\n\t]);\n};\n"],"names":["require","createRequire","source","getJSOrTSXFileExtension","checkIsTypeScriptProject","fetch"],"mappings":"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"}
@@ -154,12 +154,16 @@ const createStep3 = async ({ helpers }) => {
154
154
  `
155
155
  };
156
156
  }
157
- const res = await fetch(project.config.localSliceSimulatorURL);
158
- if (!res.ok) {
157
+ let res = void 0;
158
+ try {
159
+ res = await fetch(project.config.localSliceSimulatorURL);
160
+ } catch (error) {
161
+ }
162
+ if (!res || !res.ok) {
159
163
  return {
160
164
  title: "Unable to connect to simulator page",
161
165
  message: source`
162
- Check that the \`localSliceSimulatorURL\` property in \`slicemachine.config.json\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/technologies/setup-slice-simulator-nextjs) for more details.
166
+ Check that the \`localSliceSimulatorURL\` property in \`slicemachine.config.json\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/setup-nextjs) for more details.
163
167
  `
164
168
  };
165
169
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sliceSimulator-setup-read.js","sources":["../../../src/hooks/sliceSimulator-setup-read.ts"],"sourcesContent":["import type {\n\tSliceMachineContext,\n\tSliceSimulatorSetupReadHook,\n\tSliceSimulatorSetupStep,\n} from \"@slicemachine/plugin-kit\";\nimport { source } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport fetch from \"node-fetch\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\n\t\"@prismicio/react\",\n\t\"@prismicio/client\",\n\t\"@prismicio/helpers\",\n];\n\ntype Args = SliceMachineContext<PluginOptions>;\n\nconst createStep1 = async ({\n\tproject,\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst require = createRequire(project.root);\n\n\treturn {\n\t\ttitle: \"Install packages\",\n\t\tdescription: \"The simulator requires some dependencies.\",\n\t\t// TODO: Create a plugin runner helper to provide the correct\n\t\t// package manager\n\t\tbody: source`\n\t\t\tThe simulator requires extra dependencies. Run the following command to install them.\n\n\t\t\t~~~sh\n\t\t\tnpm install --save ${REQUIRED_DEPENDENCIES.join(\" \")}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst missingDependencies: string[] = [];\n\n\t\t\tfor (const dependency of REQUIRED_DEPENDENCIES) {\n\t\t\t\ttry {\n\t\t\t\t\t// `require.resolve()` is preferred\n\t\t\t\t\t// over `import()` because we don't\n\t\t\t\t\t// want to load the module. Loading a\n\t\t\t\t\t// module could introduce side-effects.\n\t\t\t\t\trequire.resolve(dependency, {\n\t\t\t\t\t\tpaths: [helpers.joinPathFromRoot(\"node_modules\")],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\tmissingDependencies.push(dependency);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing all dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tInstall the required dependencies to continue.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (missingDependencies.length > 0) {\n\t\t\t\tconst formattedMissingDependencies = missingDependencies\n\t\t\t\t\t.map((missingDependency) => `\\`${missingDependency}\\``)\n\t\t\t\t\t.join(\", \");\n\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing some dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe following dependencies are missing: ${formattedMissingDependencies}\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nconst createStep2 = async ({\n\thelpers,\n\toptions,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst fileName = `slice-simulator.${await getJSOrTSXFileExtension({\n\t\thelpers,\n\t\toptions,\n\t})}`;\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tlet fileContents: string;\n\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (isTypeScriptProject) {\n\t\tfileContents = await helpers.format(\n\t\t\tsource`\n\t\t\t\timport { SliceSimulator } 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(): JSX.Element {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t`,\n\t\t\tfilePath,\n\t\t\t{\n\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t},\n\t\t);\n\t} else {\n\t\tfileContents = await helpers.format(\n\t\t\tsource`\n\t\t\t\timport { SliceSimulator } 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\treturn (\n\t\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t`,\n\t\t\tfilePath,\n\t\t\t{\n\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t},\n\t\t);\n\t}\n\n\treturn {\n\t\ttitle: \"Create a page for the simulator\",\n\t\tdescription: `In your \\`pages\\` directory, create a file called \\`${fileName}\\` containing this code.`,\n\t\tbody: source`\n\t\t\tIn your \\`pages\\` directory, create a file called \\`${fileName}\\` and add the following code. This route will be used to simulate and develop your components.\n\n\t\t\t~~~tsx\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t};\n};\n\nconst createStep3 = async ({\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst filePath = helpers.joinPathFromRoot(\"slicemachine.config.json\");\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t{\n\t\t\t\t\"localSliceSimulatorURL\": \"http://localhost:3000/slice-simulator\"\n\t\t\t}\n\t\t`,\n\t\tfilePath,\n\t\t{\n\t\t\tincludeNewlineAtEnd: false,\n\t\t},\n\t);\n\n\treturn {\n\t\ttitle: \"Update `slicemachine.config.json`\",\n\t\tdescription: `Update your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.`,\n\t\tbody: source`\n\t\t\tUpdate your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.\n\n\t\t\t~~~json\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst project = await helpers.getProject();\n\n\t\t\tif (!(\"localSliceSimulatorURL\" in project.config)) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing `localSliceSimulatorURL` property\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tA \\`localSliceSimulatorURL\\` property was not found in your \\`slicemachine.config.json\\` file.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Test if the URL is valid.\n\t\t\ttry {\n\t\t\t\tif (project.config.localSliceSimulatorURL) {\n\t\t\t\t\tnew URL(project.config.localSliceSimulatorURL);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\"Undefined Slice Simulator URL\");\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"An invalid URL was provided\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe \\`localSliceSimulatorURL\\` property should be of the shape \\`http://localhost:PORT/PATH\\`. See the codeblock for an example.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Check if the URL is accessible.\n\t\t\tconst res = await fetch(project.config.localSliceSimulatorURL);\n\n\t\t\tif (!res.ok) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Unable to connect to simulator page\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tCheck that the \\`localSliceSimulatorURL\\` property in \\`slicemachine.config.json\\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/technologies/setup-slice-simulator-nextjs) for more details.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nexport const sliceSimulatorSetupRead: SliceSimulatorSetupReadHook<\n\tPluginOptions\n> = async (_data, context) => {\n\treturn Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(context),\n\t]);\n};\n"],"names":["require"],"mappings":"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"}
1
+ {"version":3,"file":"sliceSimulator-setup-read.js","sources":["../../../src/hooks/sliceSimulator-setup-read.ts"],"sourcesContent":["import type {\n\tSliceMachineContext,\n\tSliceSimulatorSetupReadHook,\n\tSliceSimulatorSetupStep,\n} from \"@slicemachine/plugin-kit\";\nimport { source } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport fetch, { Response } from \"node-fetch\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\n\t\"@prismicio/react\",\n\t\"@prismicio/client\",\n\t\"@prismicio/helpers\",\n];\n\ntype Args = SliceMachineContext<PluginOptions>;\n\nconst createStep1 = async ({\n\tproject,\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst require = createRequire(project.root);\n\n\treturn {\n\t\ttitle: \"Install packages\",\n\t\tdescription: \"The simulator requires some dependencies.\",\n\t\t// TODO: Create a plugin runner helper to provide the correct\n\t\t// package manager\n\t\tbody: source`\n\t\t\tThe simulator requires extra dependencies. Run the following command to install them.\n\n\t\t\t~~~sh\n\t\t\tnpm install --save ${REQUIRED_DEPENDENCIES.join(\" \")}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst missingDependencies: string[] = [];\n\n\t\t\tfor (const dependency of REQUIRED_DEPENDENCIES) {\n\t\t\t\ttry {\n\t\t\t\t\t// `require.resolve()` is preferred\n\t\t\t\t\t// over `import()` because we don't\n\t\t\t\t\t// want to load the module. Loading a\n\t\t\t\t\t// module could introduce side-effects.\n\t\t\t\t\trequire.resolve(dependency, {\n\t\t\t\t\t\tpaths: [helpers.joinPathFromRoot(\"node_modules\")],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\tmissingDependencies.push(dependency);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing all dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tInstall the required dependencies to continue.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (missingDependencies.length > 0) {\n\t\t\t\tconst formattedMissingDependencies = missingDependencies\n\t\t\t\t\t.map((missingDependency) => `\\`${missingDependency}\\``)\n\t\t\t\t\t.join(\", \");\n\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing some dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe following dependencies are missing: ${formattedMissingDependencies}\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nconst createStep2 = async ({\n\thelpers,\n\toptions,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst fileName = `slice-simulator.${await getJSOrTSXFileExtension({\n\t\thelpers,\n\t\toptions,\n\t})}`;\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tlet fileContents: string;\n\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (isTypeScriptProject) {\n\t\tfileContents = await helpers.format(\n\t\t\tsource`\n\t\t\t\timport { SliceSimulator } 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(): JSX.Element {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t`,\n\t\t\tfilePath,\n\t\t\t{\n\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t},\n\t\t);\n\t} else {\n\t\tfileContents = await helpers.format(\n\t\t\tsource`\n\t\t\t\timport { SliceSimulator } 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\treturn (\n\t\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t`,\n\t\t\tfilePath,\n\t\t\t{\n\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t},\n\t\t);\n\t}\n\n\treturn {\n\t\ttitle: \"Create a page for the simulator\",\n\t\tdescription: `In your \\`pages\\` directory, create a file called \\`${fileName}\\` containing this code.`,\n\t\tbody: source`\n\t\t\tIn your \\`pages\\` directory, create a file called \\`${fileName}\\` and add the following code. This route will be used to simulate and develop your components.\n\n\t\t\t~~~tsx\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t};\n};\n\nconst createStep3 = async ({\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst filePath = helpers.joinPathFromRoot(\"slicemachine.config.json\");\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t{\n\t\t\t\t\"localSliceSimulatorURL\": \"http://localhost:3000/slice-simulator\"\n\t\t\t}\n\t\t`,\n\t\tfilePath,\n\t\t{\n\t\t\tincludeNewlineAtEnd: false,\n\t\t},\n\t);\n\n\treturn {\n\t\ttitle: \"Update `slicemachine.config.json`\",\n\t\tdescription: `Update your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.`,\n\t\tbody: source`\n\t\t\tUpdate your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.\n\n\t\t\t~~~json\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst project = await helpers.getProject();\n\n\t\t\tif (!(\"localSliceSimulatorURL\" in project.config)) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing `localSliceSimulatorURL` property\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tA \\`localSliceSimulatorURL\\` property was not found in your \\`slicemachine.config.json\\` file.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Test if the URL is valid.\n\t\t\ttry {\n\t\t\t\tif (project.config.localSliceSimulatorURL) {\n\t\t\t\t\tnew URL(project.config.localSliceSimulatorURL);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\"Undefined Slice Simulator URL\");\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"An invalid URL was provided\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe \\`localSliceSimulatorURL\\` property should be of the shape \\`http://localhost:PORT/PATH\\`. See the codeblock for an example.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Check if the URL is accessible.\n\t\t\tlet res: Response | undefined = undefined;\n\t\t\ttry {\n\t\t\t\tres = await fetch(project.config.localSliceSimulatorURL);\n\t\t\t} catch (error) {\n\t\t\t\t// Noop, we return if `res` is not defined\n\t\t\t}\n\n\t\t\tif (!res || !res.ok) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Unable to connect to simulator page\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tCheck that the \\`localSliceSimulatorURL\\` property in \\`slicemachine.config.json\\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/setup-nextjs) for more details.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nexport const sliceSimulatorSetupRead: SliceSimulatorSetupReadHook<\n\tPluginOptions\n> = async (_data, context) => {\n\treturn Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(context),\n\t]);\n};\n"],"names":["require"],"mappings":"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"}
@@ -1,24 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const prismicT = require("@prismicio/types");
4
3
  const commonTags = require("common-tags");
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 prismicT__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismicT);
22
4
  const dotPath = (segments) => {
23
5
  return segments.join(".");
24
6
  };
@@ -35,7 +17,7 @@ const snippetRead = async (data, { helpers }) => {
35
17
  const { fieldPath } = data;
36
18
  const label = "React";
37
19
  switch (data.model.type) {
38
- case prismicT__namespace.CustomTypeModelFieldType.StructuredText: {
20
+ case "StructuredText": {
39
21
  return {
40
22
  label,
41
23
  language: "tsx",
@@ -44,7 +26,7 @@ const snippetRead = async (data, { helpers }) => {
44
26
  `, helpers)
45
27
  };
46
28
  }
47
- case prismicT__namespace.CustomTypeModelFieldType.Link: {
29
+ case "Link": {
48
30
  return {
49
31
  label,
50
32
  language: "tsx",
@@ -53,7 +35,7 @@ const snippetRead = async (data, { helpers }) => {
53
35
  `, helpers)
54
36
  };
55
37
  }
56
- case prismicT__namespace.CustomTypeModelFieldType.Image: {
38
+ case "Image": {
57
39
  return [
58
40
  {
59
41
  label: `${label} (next/image)`,
@@ -71,7 +53,7 @@ const snippetRead = async (data, { helpers }) => {
71
53
  }
72
54
  ];
73
55
  }
74
- case prismicT__namespace.CustomTypeModelFieldType.Group: {
56
+ case "Group": {
75
57
  const code = await format(commonTags.stripIndent`
76
58
  <>{${dotPath(fieldPath)}.map(item => (
77
59
  <>{/* Render content for item */}</>
@@ -83,7 +65,7 @@ const snippetRead = async (data, { helpers }) => {
83
65
  code
84
66
  };
85
67
  }
86
- case prismicT__namespace.CustomTypeModelFieldType.Slices: {
68
+ case "Slices": {
87
69
  const code = await format(commonTags.stripIndent`
88
70
  <SliceZone
89
71
  slices={${dotPath(fieldPath)}}
@@ -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 * as prismicT from \"@prismicio/types\";\nimport { stripIndent } from \"common-tags\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst dotPath = (segments: string[]): string => {\n\treturn segments.join(\".\");\n};\n\nconst format = async (input: string, helpers: SliceMachineHelpers) => {\n\tconst formattedInput = await helpers.format(input, undefined, {\n\t\tincludeNewlineAtEnd: false,\n\t\tprettier: {\n\t\t\tparser: \"typescript\",\n\t\t},\n\t});\n\n\treturn formattedInput.endsWith(\";\")\n\t\t? formattedInput.substring(0, formattedInput.length - 1)\n\t\t: formattedInput;\n};\n\nexport const snippetRead: SnippetReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst { fieldPath } = data;\n\n\tconst label = \"React\";\n\n\tswitch (data.model.type) {\n\t\tcase prismicT.CustomTypeModelFieldType.StructuredText: {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicRichText field={${dotPath(fieldPath)}} />\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase prismicT.CustomTypeModelFieldType.Link: {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase prismicT.CustomTypeModelFieldType.Image: {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tlabel: `${label} (next/image)`,\n\t\t\t\t\tlanguage: \"tsx\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicNextImage field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tlabel,\n\t\t\t\t\tlanguage: \"tsx\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicImage field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tcase prismicT.CustomTypeModelFieldType.Group: {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<>{${dotPath(fieldPath)}.map(item => (\n\t\t\t\t\t <>{/* Render content for item */}</>\n\t\t\t\t\t))}</>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tcase prismicT.CustomTypeModelFieldType.Slices: {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<SliceZone\n\t\t\t\t\t slices={${dotPath(fieldPath)}}\n\t\t\t\t\t components={components}\n\t\t\t\t\t/>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<>{${dotPath(fieldPath)}}</>\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\t}\n};\n"],"names":["prismicT","stripIndent"],"mappings":";;;;;;;;;;;;;;;;;;;;;AASA,MAAM,UAAU,CAAC,aAA8B;AACvC,SAAA,SAAS,KAAK,GAAG;AACzB;AAEA,MAAM,SAAS,OAAO,OAAe,YAAgC;AACpE,QAAM,iBAAiB,MAAM,QAAQ,OAAO,OAAO,QAAW;AAAA,IAC7D,qBAAqB;AAAA,IACrB,UAAU;AAAA,MACT,QAAQ;AAAA,IACR;AAAA,EAAA,CACD;AAEM,SAAA,eAAe,SAAS,GAAG,IAC/B,eAAe,UAAU,GAAG,eAAe,SAAS,CAAC,IACrD;AACJ;AAEO,MAAM,cAA8C,OAC1D,MACA,EAAE,cACC;AACG,QAAA,EAAE,UAAc,IAAA;AAEtB,QAAM,QAAQ;AAEN,UAAA,KAAK,MAAM,MAAM;AAAA,IACxB,KAAKA,oBAAS,yBAAyB,gBAAgB;AAC/C,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACXC;gCAC2B,QAAQ,SAAS;AAAA,QAE5C,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,IAED,KAAKD,oBAAS,yBAAyB,MAAM;AACrC,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACXC;4BACuB,QAAQ,SAAS;AAAA,QAExC,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,IAED,KAAKD,oBAAS,yBAAyB,OAAO;AACtC,aAAA;AAAA,QACN;AAAA,UACC,OAAO,GAAG;AAAA,UACV,UAAU;AAAA,UACV,MAAM,MAAM,OACXC;kCAC4B,QAAQ,SAAS;AAAA,SAE7C,OAAO;AAAA,QAER;AAAA,QACD;AAAA,UACC;AAAA,UACA,UAAU;AAAA,UACV,MAAM,MAAM,OACXA;8BACwB,QAAQ,SAAS;AAAA,SAEzC,OAAO;AAAA,QAER;AAAA,MAAA;AAAA,IAEF;AAAA,IAED,KAAKD,oBAAS,yBAAyB,OAAO;AACvC,YAAA,OAAO,MAAM,OAClBC;UACM,QAAQ,SAAS;AAAA;AAAA;AAAA,OAIvB,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,KAAKD,oBAAS,yBAAyB,QAAQ;AACxC,YAAA,OAAO,MAAM,OAClBC;;iBAEa,QAAQ,SAAS;AAAA;AAAA;AAAA,OAI9B,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,SAAS;AACD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACXA;WACM,QAAQ,SAAS;AAAA,QAEvB,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,EACD;AACF;;"}
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 => {\n\treturn segments.join(\".\");\n};\n\nconst format = async (input: string, helpers: SliceMachineHelpers) => {\n\tconst formattedInput = await helpers.format(input, undefined, {\n\t\tincludeNewlineAtEnd: false,\n\t\tprettier: {\n\t\t\tparser: \"typescript\",\n\t\t},\n\t});\n\n\treturn formattedInput.endsWith(\";\")\n\t\t? formattedInput.substring(0, formattedInput.length - 1)\n\t\t: formattedInput;\n};\n\nexport const snippetRead: SnippetReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst { fieldPath } = data;\n\n\tconst label = \"React\";\n\n\tswitch (data.model.type) {\n\t\tcase \"StructuredText\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicRichText field={${dotPath(fieldPath)}} />\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase \"Link\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase \"Image\": {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tlabel: `${label} (next/image)`,\n\t\t\t\t\tlanguage: \"tsx\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicNextImage field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tlabel,\n\t\t\t\t\tlanguage: \"tsx\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicImage field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tcase \"Group\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<>{${dotPath(fieldPath)}.map(item => (\n\t\t\t\t\t <>{/* Render content for item */}</>\n\t\t\t\t\t))}</>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tcase \"Slices\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<SliceZone\n\t\t\t\t\t slices={${dotPath(fieldPath)}}\n\t\t\t\t\t components={components}\n\t\t\t\t\t/>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<>{${dotPath(fieldPath)}}</>\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\t}\n};\n"],"names":["stripIndent"],"mappings":";;;AAQA,MAAM,UAAU,CAAC,aAA8B;AACvC,SAAA,SAAS,KAAK,GAAG;AACzB;AAEA,MAAM,SAAS,OAAO,OAAe,YAAgC;AACpE,QAAM,iBAAiB,MAAM,QAAQ,OAAO,OAAO,QAAW;AAAA,IAC7D,qBAAqB;AAAA,IACrB,UAAU;AAAA,MACT,QAAQ;AAAA,IACR;AAAA,EAAA,CACD;AAEM,SAAA,eAAe,SAAS,GAAG,IAC/B,eAAe,UAAU,GAAG,eAAe,SAAS,CAAC,IACrD;AACJ;AAEO,MAAM,cAA8C,OAC1D,MACA,EAAE,cACC;AACG,QAAA,EAAE,UAAc,IAAA;AAEtB,QAAM,QAAQ;AAEN,UAAA,KAAK,MAAM,MAAM;AAAA,IACxB,KAAK,kBAAkB;AACf,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACXA;gCAC2B,QAAQ,SAAS;AAAA,QAE5C,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,IAED,KAAK,QAAQ;AACL,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACXA;4BACuB,QAAQ,SAAS;AAAA,QAExC,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,IAED,KAAK,SAAS;AACN,aAAA;AAAA,QACN;AAAA,UACC,OAAO,GAAG;AAAA,UACV,UAAU;AAAA,UACV,MAAM,MAAM,OACXA;kCAC4B,QAAQ,SAAS;AAAA,SAE7C,OAAO;AAAA,QAER;AAAA,QACD;AAAA,UACC;AAAA,UACA,UAAU;AAAA,UACV,MAAM,MAAM,OACXA;8BACwB,QAAQ,SAAS;AAAA,SAEzC,OAAO;AAAA,QAER;AAAA,MAAA;AAAA,IAEF;AAAA,IAED,KAAK,SAAS;AACP,YAAA,OAAO,MAAM,OAClBA;UACM,QAAQ,SAAS;AAAA;AAAA;AAAA,OAIvB,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,KAAK,UAAU;AACR,YAAA,OAAO,MAAM,OAClBA;;iBAEa,QAAQ,SAAS;AAAA;AAAA;AAAA,OAI9B,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,SAAS;AACD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACXA;WACM,QAAQ,SAAS;AAAA,QAEvB,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,EACD;AACF;;"}
@@ -1,4 +1,3 @@
1
- import * as prismicT from "@prismicio/types";
2
1
  import { stripIndent } from "common-tags";
3
2
  const dotPath = (segments) => {
4
3
  return segments.join(".");
@@ -16,7 +15,7 @@ const snippetRead = async (data, { helpers }) => {
16
15
  const { fieldPath } = data;
17
16
  const label = "React";
18
17
  switch (data.model.type) {
19
- case prismicT.CustomTypeModelFieldType.StructuredText: {
18
+ case "StructuredText": {
20
19
  return {
21
20
  label,
22
21
  language: "tsx",
@@ -25,7 +24,7 @@ const snippetRead = async (data, { helpers }) => {
25
24
  `, helpers)
26
25
  };
27
26
  }
28
- case prismicT.CustomTypeModelFieldType.Link: {
27
+ case "Link": {
29
28
  return {
30
29
  label,
31
30
  language: "tsx",
@@ -34,7 +33,7 @@ const snippetRead = async (data, { helpers }) => {
34
33
  `, helpers)
35
34
  };
36
35
  }
37
- case prismicT.CustomTypeModelFieldType.Image: {
36
+ case "Image": {
38
37
  return [
39
38
  {
40
39
  label: `${label} (next/image)`,
@@ -52,7 +51,7 @@ const snippetRead = async (data, { helpers }) => {
52
51
  }
53
52
  ];
54
53
  }
55
- case prismicT.CustomTypeModelFieldType.Group: {
54
+ case "Group": {
56
55
  const code = await format(stripIndent`
57
56
  <>{${dotPath(fieldPath)}.map(item => (
58
57
  <>{/* Render content for item */}</>
@@ -64,7 +63,7 @@ const snippetRead = async (data, { helpers }) => {
64
63
  code
65
64
  };
66
65
  }
67
- case prismicT.CustomTypeModelFieldType.Slices: {
66
+ case "Slices": {
68
67
  const code = await format(stripIndent`
69
68
  <SliceZone
70
69
  slices={${dotPath(fieldPath)}}
@@ -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 * as prismicT from \"@prismicio/types\";\nimport { stripIndent } from \"common-tags\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst dotPath = (segments: string[]): string => {\n\treturn segments.join(\".\");\n};\n\nconst format = async (input: string, helpers: SliceMachineHelpers) => {\n\tconst formattedInput = await helpers.format(input, undefined, {\n\t\tincludeNewlineAtEnd: false,\n\t\tprettier: {\n\t\t\tparser: \"typescript\",\n\t\t},\n\t});\n\n\treturn formattedInput.endsWith(\";\")\n\t\t? formattedInput.substring(0, formattedInput.length - 1)\n\t\t: formattedInput;\n};\n\nexport const snippetRead: SnippetReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst { fieldPath } = data;\n\n\tconst label = \"React\";\n\n\tswitch (data.model.type) {\n\t\tcase prismicT.CustomTypeModelFieldType.StructuredText: {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicRichText field={${dotPath(fieldPath)}} />\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase prismicT.CustomTypeModelFieldType.Link: {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase prismicT.CustomTypeModelFieldType.Image: {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tlabel: `${label} (next/image)`,\n\t\t\t\t\tlanguage: \"tsx\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicNextImage field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tlabel,\n\t\t\t\t\tlanguage: \"tsx\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicImage field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tcase prismicT.CustomTypeModelFieldType.Group: {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<>{${dotPath(fieldPath)}.map(item => (\n\t\t\t\t\t <>{/* Render content for item */}</>\n\t\t\t\t\t))}</>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tcase prismicT.CustomTypeModelFieldType.Slices: {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<SliceZone\n\t\t\t\t\t slices={${dotPath(fieldPath)}}\n\t\t\t\t\t components={components}\n\t\t\t\t\t/>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<>{${dotPath(fieldPath)}}</>\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\t}\n};\n"],"names":[],"mappings":";;AASA,MAAM,UAAU,CAAC,aAA8B;AACvC,SAAA,SAAS,KAAK,GAAG;AACzB;AAEA,MAAM,SAAS,OAAO,OAAe,YAAgC;AACpE,QAAM,iBAAiB,MAAM,QAAQ,OAAO,OAAO,QAAW;AAAA,IAC7D,qBAAqB;AAAA,IACrB,UAAU;AAAA,MACT,QAAQ;AAAA,IACR;AAAA,EAAA,CACD;AAEM,SAAA,eAAe,SAAS,GAAG,IAC/B,eAAe,UAAU,GAAG,eAAe,SAAS,CAAC,IACrD;AACJ;AAEO,MAAM,cAA8C,OAC1D,MACA,EAAE,cACC;AACG,QAAA,EAAE,UAAc,IAAA;AAEtB,QAAM,QAAQ;AAEN,UAAA,KAAK,MAAM,MAAM;AAAA,IACxB,KAAK,SAAS,yBAAyB,gBAAgB;AAC/C,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,gCAC2B,QAAQ,SAAS;AAAA,QAE5C,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,IAED,KAAK,SAAS,yBAAyB,MAAM;AACrC,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,4BACuB,QAAQ,SAAS;AAAA,QAExC,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,IAED,KAAK,SAAS,yBAAyB,OAAO;AACtC,aAAA;AAAA,QACN;AAAA,UACC,OAAO,GAAG;AAAA,UACV,UAAU;AAAA,UACV,MAAM,MAAM,OACX;AAAA,kCAC4B,QAAQ,SAAS;AAAA,SAE7C,OAAO;AAAA,QAER;AAAA,QACD;AAAA,UACC;AAAA,UACA,UAAU;AAAA,UACV,MAAM,MAAM,OACX;AAAA,8BACwB,QAAQ,SAAS;AAAA,SAEzC,OAAO;AAAA,QAER;AAAA,MAAA;AAAA,IAEF;AAAA,IAED,KAAK,SAAS,yBAAyB,OAAO;AACvC,YAAA,OAAO,MAAM,OAClB;AAAA,UACM,QAAQ,SAAS;AAAA;AAAA;AAAA,OAIvB,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,KAAK,SAAS,yBAAyB,QAAQ;AACxC,YAAA,OAAO,MAAM,OAClB;AAAA;AAAA,iBAEa,QAAQ,SAAS;AAAA;AAAA;AAAA,OAI9B,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,SAAS;AACD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,WACM,QAAQ,SAAS;AAAA,QAEvB,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,EACD;AACF;"}
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 => {\n\treturn segments.join(\".\");\n};\n\nconst format = async (input: string, helpers: SliceMachineHelpers) => {\n\tconst formattedInput = await helpers.format(input, undefined, {\n\t\tincludeNewlineAtEnd: false,\n\t\tprettier: {\n\t\t\tparser: \"typescript\",\n\t\t},\n\t});\n\n\treturn formattedInput.endsWith(\";\")\n\t\t? formattedInput.substring(0, formattedInput.length - 1)\n\t\t: formattedInput;\n};\n\nexport const snippetRead: SnippetReadHook<PluginOptions> = async (\n\tdata,\n\t{ helpers },\n) => {\n\tconst { fieldPath } = data;\n\n\tconst label = \"React\";\n\n\tswitch (data.model.type) {\n\t\tcase \"StructuredText\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicRichText field={${dotPath(fieldPath)}} />\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase \"Link\": {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\n\t\tcase \"Image\": {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tlabel: `${label} (next/image)`,\n\t\t\t\t\tlanguage: \"tsx\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicNextImage field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tlabel,\n\t\t\t\t\tlanguage: \"tsx\",\n\t\t\t\t\tcode: await format(\n\t\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t\t<PrismicImage field={${dotPath(fieldPath)}} />\n\t\t\t\t\t\t`,\n\t\t\t\t\t\thelpers,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tcase \"Group\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<>{${dotPath(fieldPath)}.map(item => (\n\t\t\t\t\t <>{/* Render content for item */}</>\n\t\t\t\t\t))}</>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tcase \"Slices\": {\n\t\t\tconst code = await format(\n\t\t\t\tstripIndent`\n\t\t\t\t\t<SliceZone\n\t\t\t\t\t slices={${dotPath(fieldPath)}}\n\t\t\t\t\t components={components}\n\t\t\t\t\t/>\n\t\t\t\t`,\n\t\t\t\thelpers,\n\t\t\t);\n\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode,\n\t\t\t};\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn {\n\t\t\t\tlabel,\n\t\t\t\tlanguage: \"tsx\",\n\t\t\t\tcode: await format(\n\t\t\t\t\tstripIndent`\n\t\t\t\t\t\t<>{${dotPath(fieldPath)}}</>\n\t\t\t\t\t`,\n\t\t\t\t\thelpers,\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\t}\n};\n"],"names":[],"mappings":";AAQA,MAAM,UAAU,CAAC,aAA8B;AACvC,SAAA,SAAS,KAAK,GAAG;AACzB;AAEA,MAAM,SAAS,OAAO,OAAe,YAAgC;AACpE,QAAM,iBAAiB,MAAM,QAAQ,OAAO,OAAO,QAAW;AAAA,IAC7D,qBAAqB;AAAA,IACrB,UAAU;AAAA,MACT,QAAQ;AAAA,IACR;AAAA,EAAA,CACD;AAEM,SAAA,eAAe,SAAS,GAAG,IAC/B,eAAe,UAAU,GAAG,eAAe,SAAS,CAAC,IACrD;AACJ;AAEO,MAAM,cAA8C,OAC1D,MACA,EAAE,cACC;AACG,QAAA,EAAE,UAAc,IAAA;AAEtB,QAAM,QAAQ;AAEN,UAAA,KAAK,MAAM,MAAM;AAAA,IACxB,KAAK,kBAAkB;AACf,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,gCAC2B,QAAQ,SAAS;AAAA,QAE5C,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,IAED,KAAK,QAAQ;AACL,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,4BACuB,QAAQ,SAAS;AAAA,QAExC,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,IAED,KAAK,SAAS;AACN,aAAA;AAAA,QACN;AAAA,UACC,OAAO,GAAG;AAAA,UACV,UAAU;AAAA,UACV,MAAM,MAAM,OACX;AAAA,kCAC4B,QAAQ,SAAS;AAAA,SAE7C,OAAO;AAAA,QAER;AAAA,QACD;AAAA,UACC;AAAA,UACA,UAAU;AAAA,UACV,MAAM,MAAM,OACX;AAAA,8BACwB,QAAQ,SAAS;AAAA,SAEzC,OAAO;AAAA,QAER;AAAA,MAAA;AAAA,IAEF;AAAA,IAED,KAAK,SAAS;AACP,YAAA,OAAO,MAAM,OAClB;AAAA,UACM,QAAQ,SAAS;AAAA;AAAA;AAAA,OAIvB,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,KAAK,UAAU;AACR,YAAA,OAAO,MAAM,OAClB;AAAA;AAAA,iBAEa,QAAQ,SAAS;AAAA;AAAA;AAAA,OAI9B,OAAO;AAGD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV;AAAA,MAAA;AAAA,IAED;AAAA,IAED,SAAS;AACD,aAAA;AAAA,QACN;AAAA,QACA,UAAU;AAAA,QACV,MAAM,MAAM,OACX;AAAA,WACM,QAAQ,SAAS;AAAA,QAEvB,OAAO;AAAA,MAAA;AAAA,IAGT;AAAA,EACD;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"buildSliceDirectoryPath.cjs","sources":["../../../src/lib/buildSliceDirectoryPath.ts"],"sourcesContent":["import { SharedSliceModel } from \"@prismicio/types\";\nimport { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport * as path from \"node:path\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { buildSliceLibraryDirectoryPath } from \"./buildSliceLibraryDirectoryPath\";\nimport { pascalCase } from \"./pascalCase\";\n\ntype BuildSliceDirectoryPathArgs = {\n\tlibraryID: string;\n\tmodel: SharedSliceModel;\n\thelpers: SliceMachineContext<PluginOptions>[\"helpers\"];\n};\n\nexport const buildSliceDirectoryPath = (\n\targs: BuildSliceDirectoryPathArgs,\n): string => {\n\treturn path.join(\n\t\tbuildSliceLibraryDirectoryPath({\n\t\t\tlibraryID: args.libraryID,\n\t\t\thelpers: args.helpers,\n\t\t}),\n\t\tpascalCase(args.model.name),\n\t);\n};\n"],"names":["path","buildSliceLibraryDirectoryPath","pascalCase"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAea,MAAA,0BAA0B,CACtC,SACW;AACJ,SAAAA,gBAAK,KACXC,8DAA+B;AAAA,IAC9B,WAAW,KAAK;AAAA,IAChB,SAAS,KAAK;AAAA,EACd,CAAA,GACDC,WAAAA,WAAW,KAAK,MAAM,IAAI,CAAC;AAE7B;;"}
1
+ {"version":3,"file":"buildSliceDirectoryPath.cjs","sources":["../../../src/lib/buildSliceDirectoryPath.ts"],"sourcesContent":["import type { SharedSlice } from \"@prismicio/types-internal/lib/customtypes\";\nimport { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport * as path from \"node:path\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { buildSliceLibraryDirectoryPath } from \"./buildSliceLibraryDirectoryPath\";\nimport { pascalCase } from \"./pascalCase\";\n\ntype BuildSliceDirectoryPathArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n\thelpers: SliceMachineContext<PluginOptions>[\"helpers\"];\n};\n\nexport const buildSliceDirectoryPath = (\n\targs: BuildSliceDirectoryPathArgs,\n): string => {\n\treturn path.join(\n\t\tbuildSliceLibraryDirectoryPath({\n\t\t\tlibraryID: args.libraryID,\n\t\t\thelpers: args.helpers,\n\t\t}),\n\t\tpascalCase(args.model.name),\n\t);\n};\n"],"names":["path","buildSliceLibraryDirectoryPath","pascalCase"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAea,MAAA,0BAA0B,CACtC,SACW;AACJ,SAAAA,gBAAK,KACXC,8DAA+B;AAAA,IAC9B,WAAW,KAAK;AAAA,IAChB,SAAS,KAAK;AAAA,EACd,CAAA,GACDC,WAAAA,WAAW,KAAK,MAAM,IAAI,CAAC;AAE7B;;"}
@@ -1,9 +1,9 @@
1
- import { SharedSliceModel } from "@prismicio/types";
1
+ import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
2
2
  import { SliceMachineContext } from "@slicemachine/plugin-kit";
3
3
  import { PluginOptions } from "../types";
4
4
  type BuildSliceDirectoryPathArgs = {
5
5
  libraryID: string;
6
- model: SharedSliceModel;
6
+ model: SharedSlice;
7
7
  helpers: SliceMachineContext<PluginOptions>["helpers"];
8
8
  };
9
9
  export declare const buildSliceDirectoryPath: (args: BuildSliceDirectoryPathArgs) => string;
@@ -1 +1 @@
1
- {"version":3,"file":"buildSliceDirectoryPath.js","sources":["../../../src/lib/buildSliceDirectoryPath.ts"],"sourcesContent":["import { SharedSliceModel } from \"@prismicio/types\";\nimport { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport * as path from \"node:path\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { buildSliceLibraryDirectoryPath } from \"./buildSliceLibraryDirectoryPath\";\nimport { pascalCase } from \"./pascalCase\";\n\ntype BuildSliceDirectoryPathArgs = {\n\tlibraryID: string;\n\tmodel: SharedSliceModel;\n\thelpers: SliceMachineContext<PluginOptions>[\"helpers\"];\n};\n\nexport const buildSliceDirectoryPath = (\n\targs: BuildSliceDirectoryPathArgs,\n): string => {\n\treturn path.join(\n\t\tbuildSliceLibraryDirectoryPath({\n\t\t\tlibraryID: args.libraryID,\n\t\t\thelpers: args.helpers,\n\t\t}),\n\t\tpascalCase(args.model.name),\n\t);\n};\n"],"names":[],"mappings":";;;AAea,MAAA,0BAA0B,CACtC,SACW;AACJ,SAAA,KAAK,KACX,+BAA+B;AAAA,IAC9B,WAAW,KAAK;AAAA,IAChB,SAAS,KAAK;AAAA,EACd,CAAA,GACD,WAAW,KAAK,MAAM,IAAI,CAAC;AAE7B;"}
1
+ {"version":3,"file":"buildSliceDirectoryPath.js","sources":["../../../src/lib/buildSliceDirectoryPath.ts"],"sourcesContent":["import type { SharedSlice } from \"@prismicio/types-internal/lib/customtypes\";\nimport { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport * as path from \"node:path\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { buildSliceLibraryDirectoryPath } from \"./buildSliceLibraryDirectoryPath\";\nimport { pascalCase } from \"./pascalCase\";\n\ntype BuildSliceDirectoryPathArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n\thelpers: SliceMachineContext<PluginOptions>[\"helpers\"];\n};\n\nexport const buildSliceDirectoryPath = (\n\targs: BuildSliceDirectoryPathArgs,\n): string => {\n\treturn path.join(\n\t\tbuildSliceLibraryDirectoryPath({\n\t\t\tlibraryID: args.libraryID,\n\t\t\thelpers: args.helpers,\n\t\t}),\n\t\tpascalCase(args.model.name),\n\t);\n};\n"],"names":[],"mappings":";;;AAea,MAAA,0BAA0B,CACtC,SACW;AACJ,SAAA,KAAK,KACX,+BAA+B;AAAA,IAC9B,WAAW,KAAK;AAAA,IAChB,SAAS,KAAK;AAAA,EACd,CAAA,GACD,WAAW,KAAK,MAAM,IAAI,CAAC;AAE7B;"}
@@ -1,25 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const prismicT = require("@prismicio/types");
4
- function _interopNamespaceDefault(e) {
5
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
6
- if (e) {
7
- for (const k in e) {
8
- if (k !== "default") {
9
- const d = Object.getOwnPropertyDescriptor(e, k);
10
- Object.defineProperty(n, k, d.get ? d : {
11
- enumerable: true,
12
- get: () => e[k]
13
- });
14
- }
15
- }
16
- }
17
- n.default = e;
18
- return Object.freeze(n);
19
- }
20
- const prismicT__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismicT);
21
3
  const isSharedSliceModel = (input) => {
22
- return typeof input === "object" && input !== null && "type" in input && input.type === prismicT__namespace.CustomTypeModelSliceType.SharedSlice && typeof input.id === "string";
4
+ return typeof input === "object" && input !== null && "type" in input && input.type === "SharedSlice" && typeof input.id === "string";
23
5
  };
24
6
  exports.isSharedSliceModel = isSharedSliceModel;
25
7
  //# sourceMappingURL=isSharedSliceModel.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"isSharedSliceModel.cjs","sources":["../../../src/lib/isSharedSliceModel.ts"],"sourcesContent":["import * as prismicT from \"@prismicio/types\";\n\nexport const isSharedSliceModel = (\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n\tinput: any,\n): input is prismicT.SharedSliceModel => {\n\treturn (\n\t\ttypeof input === \"object\" &&\n\t\tinput !== null &&\n\t\t\"type\" in input &&\n\t\tinput.type === prismicT.CustomTypeModelSliceType.SharedSlice &&\n\t\ttypeof input.id === \"string\"\n\t);\n};\n"],"names":["prismicT"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEa,MAAA,qBAAqB,CAEjC,UACuC;AACvC,SACC,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAASA,oBAAS,yBAAyB,eACjD,OAAO,MAAM,OAAO;AAEtB;;"}
1
+ {"version":3,"file":"isSharedSliceModel.cjs","sources":["../../../src/lib/isSharedSliceModel.ts"],"sourcesContent":["import type { SharedSlice } from \"@prismicio/types-internal/lib/customtypes\";\n\nexport const isSharedSliceModel = (\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n\tinput: any,\n): input is SharedSlice => {\n\treturn (\n\t\ttypeof input === \"object\" &&\n\t\tinput !== null &&\n\t\t\"type\" in input &&\n\t\tinput.type === \"SharedSlice\" &&\n\t\ttypeof input.id === \"string\"\n\t);\n};\n"],"names":[],"mappings":";;AAEa,MAAA,qBAAqB,CAEjC,UACyB;AACzB,SACC,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS,iBACf,OAAO,MAAM,OAAO;AAEtB;;"}
@@ -1,2 +1,335 @@
1
- import * as prismicT from "@prismicio/types";
2
- export declare const isSharedSliceModel: (input: any) => input is prismicT.SharedSliceModel<string, prismicT.SharedSliceModelVariation<string, Record<string, prismicT.CustomTypeModelFieldForGroup>, Record<string, prismicT.CustomTypeModelFieldForGroup>>>;
1
+ export declare const isSharedSliceModel: (input: any) => input is {
2
+ id: string;
3
+ type: "SharedSlice";
4
+ name: string;
5
+ variations: readonly ({
6
+ id: string;
7
+ name: string;
8
+ description: string;
9
+ imageUrl: string;
10
+ docURL: string;
11
+ version: string;
12
+ } & {
13
+ display?: string | undefined;
14
+ primary?: {
15
+ [x: string]: ({
16
+ type: "Color";
17
+ } & {
18
+ fieldset?: string | null | undefined;
19
+ config?: {
20
+ label?: string | null | undefined;
21
+ placeholder?: string | undefined;
22
+ } | undefined;
23
+ }) | ({
24
+ type: "Boolean";
25
+ } & {
26
+ config?: {
27
+ label?: string | null | undefined;
28
+ default_value?: boolean | undefined;
29
+ placeholder_true?: string | undefined;
30
+ placeholder_false?: string | undefined;
31
+ } | undefined;
32
+ }) | ({
33
+ type: "Embed";
34
+ } & {
35
+ fieldset?: string | null | undefined;
36
+ config?: {
37
+ label?: string | null | undefined;
38
+ placeholder?: string | undefined;
39
+ useAsTitle?: boolean | undefined;
40
+ } | undefined;
41
+ }) | ({
42
+ type: "GeoPoint";
43
+ } & {
44
+ fieldset?: string | null | undefined;
45
+ config?: {
46
+ label?: string | null | undefined;
47
+ } | undefined;
48
+ }) | ({
49
+ type: "Date";
50
+ } & {
51
+ fieldset?: string | null | undefined;
52
+ config?: {
53
+ label?: string | null | undefined;
54
+ placeholder?: string | undefined;
55
+ default?: string | undefined;
56
+ } | undefined;
57
+ }) | ({
58
+ type: "Number";
59
+ } & {
60
+ fieldset?: string | null | undefined;
61
+ config?: {
62
+ label?: string | null | undefined;
63
+ placeholder?: string | undefined;
64
+ min?: number | undefined;
65
+ max?: number | undefined;
66
+ step?: number | undefined;
67
+ } | undefined;
68
+ }) | ({
69
+ type: "Range";
70
+ } & {
71
+ fieldset?: string | null | undefined;
72
+ config?: {
73
+ label?: string | null | undefined;
74
+ placeholder?: string | undefined;
75
+ min?: number | undefined;
76
+ max?: number | undefined;
77
+ step?: number | undefined;
78
+ } | undefined;
79
+ }) | ({
80
+ type: "StructuredText";
81
+ } & {
82
+ fieldset?: string | null | undefined;
83
+ config?: {
84
+ label?: string | null | undefined;
85
+ placeholder?: string | undefined;
86
+ useAsTitle?: boolean | undefined;
87
+ single?: string | undefined;
88
+ multi?: string | undefined;
89
+ imageConstraint?: {
90
+ width?: number | null | undefined;
91
+ height?: number | null | undefined;
92
+ } | undefined;
93
+ labels?: readonly string[] | undefined;
94
+ allowTargetBlank?: boolean | undefined;
95
+ } | undefined;
96
+ }) | ({
97
+ type: "Select";
98
+ } & {
99
+ fieldset?: string | null | undefined;
100
+ config?: {
101
+ label?: string | null | undefined;
102
+ placeholder?: string | undefined;
103
+ default_value?: string | undefined;
104
+ options?: readonly string[] | undefined;
105
+ } | undefined;
106
+ }) | ({
107
+ type: "Separator";
108
+ } & {
109
+ config?: {
110
+ label?: string | null | undefined;
111
+ } | undefined;
112
+ }) | ({
113
+ type: "Text";
114
+ } & {
115
+ fieldset?: string | null | undefined;
116
+ config?: {
117
+ label?: string | null | undefined;
118
+ useAsTitle?: boolean | undefined;
119
+ placeholder?: string | undefined;
120
+ } | undefined;
121
+ }) | ({
122
+ type: "Timestamp";
123
+ } & {
124
+ fieldset?: string | null | undefined;
125
+ config?: {
126
+ label?: string | null | undefined;
127
+ placeholder?: string | undefined;
128
+ default?: string | undefined;
129
+ } | undefined;
130
+ }) | ({
131
+ type: "Link";
132
+ } & {
133
+ fieldset?: string | null | undefined;
134
+ config?: {
135
+ label?: string | null | undefined;
136
+ useAsTitle?: boolean | undefined;
137
+ placeholder?: string | undefined;
138
+ select?: "document" | "media" | "web" | null | undefined;
139
+ customtypes?: readonly string[] | undefined;
140
+ masks?: readonly string[] | undefined;
141
+ tags?: readonly string[] | undefined;
142
+ allowTargetBlank?: boolean | undefined;
143
+ } | undefined;
144
+ }) | ({
145
+ type: "Image";
146
+ } & {
147
+ fieldset?: string | null | undefined;
148
+ config?: {
149
+ label?: string | null | undefined;
150
+ placeholder?: string | undefined;
151
+ constraint?: {
152
+ width?: number | null | undefined;
153
+ height?: number | null | undefined;
154
+ } | undefined;
155
+ thumbnails?: readonly ({
156
+ name: string;
157
+ } & {
158
+ width?: number | null | undefined;
159
+ height?: number | null | undefined;
160
+ })[] | undefined;
161
+ } | undefined;
162
+ }) | ({
163
+ type: "IntegrationFields";
164
+ } & {
165
+ fieldset?: string | null | undefined;
166
+ config?: {
167
+ label?: string | null | undefined;
168
+ placeholder?: string | undefined;
169
+ catalog?: string | undefined;
170
+ } | undefined;
171
+ });
172
+ } | undefined;
173
+ items?: {
174
+ [x: string]: ({
175
+ type: "Color";
176
+ } & {
177
+ fieldset?: string | null | undefined;
178
+ config?: {
179
+ label?: string | null | undefined;
180
+ placeholder?: string | undefined;
181
+ } | undefined;
182
+ }) | ({
183
+ type: "Boolean";
184
+ } & {
185
+ config?: {
186
+ label?: string | null | undefined;
187
+ default_value?: boolean | undefined;
188
+ placeholder_true?: string | undefined;
189
+ placeholder_false?: string | undefined;
190
+ } | undefined;
191
+ }) | ({
192
+ type: "Embed";
193
+ } & {
194
+ fieldset?: string | null | undefined;
195
+ config?: {
196
+ label?: string | null | undefined;
197
+ placeholder?: string | undefined;
198
+ useAsTitle?: boolean | undefined;
199
+ } | undefined;
200
+ }) | ({
201
+ type: "GeoPoint";
202
+ } & {
203
+ fieldset?: string | null | undefined;
204
+ config?: {
205
+ label?: string | null | undefined;
206
+ } | undefined;
207
+ }) | ({
208
+ type: "Date";
209
+ } & {
210
+ fieldset?: string | null | undefined;
211
+ config?: {
212
+ label?: string | null | undefined;
213
+ placeholder?: string | undefined;
214
+ default?: string | undefined;
215
+ } | undefined;
216
+ }) | ({
217
+ type: "Number";
218
+ } & {
219
+ fieldset?: string | null | undefined;
220
+ config?: {
221
+ label?: string | null | undefined;
222
+ placeholder?: string | undefined;
223
+ min?: number | undefined;
224
+ max?: number | undefined;
225
+ step?: number | undefined;
226
+ } | undefined;
227
+ }) | ({
228
+ type: "Range";
229
+ } & {
230
+ fieldset?: string | null | undefined;
231
+ config?: {
232
+ label?: string | null | undefined;
233
+ placeholder?: string | undefined;
234
+ min?: number | undefined;
235
+ max?: number | undefined;
236
+ step?: number | undefined;
237
+ } | undefined;
238
+ }) | ({
239
+ type: "StructuredText";
240
+ } & {
241
+ fieldset?: string | null | undefined;
242
+ config?: {
243
+ label?: string | null | undefined;
244
+ placeholder?: string | undefined;
245
+ useAsTitle?: boolean | undefined;
246
+ single?: string | undefined;
247
+ multi?: string | undefined;
248
+ imageConstraint?: {
249
+ width?: number | null | undefined;
250
+ height?: number | null | undefined;
251
+ } | undefined;
252
+ labels?: readonly string[] | undefined;
253
+ allowTargetBlank?: boolean | undefined;
254
+ } | undefined;
255
+ }) | ({
256
+ type: "Select";
257
+ } & {
258
+ fieldset?: string | null | undefined;
259
+ config?: {
260
+ label?: string | null | undefined;
261
+ placeholder?: string | undefined;
262
+ default_value?: string | undefined;
263
+ options?: readonly string[] | undefined;
264
+ } | undefined;
265
+ }) | ({
266
+ type: "Separator";
267
+ } & {
268
+ config?: {
269
+ label?: string | null | undefined;
270
+ } | undefined;
271
+ }) | ({
272
+ type: "Text";
273
+ } & {
274
+ fieldset?: string | null | undefined;
275
+ config?: {
276
+ label?: string | null | undefined;
277
+ useAsTitle?: boolean | undefined;
278
+ placeholder?: string | undefined;
279
+ } | undefined;
280
+ }) | ({
281
+ type: "Timestamp";
282
+ } & {
283
+ fieldset?: string | null | undefined;
284
+ config?: {
285
+ label?: string | null | undefined;
286
+ placeholder?: string | undefined;
287
+ default?: string | undefined;
288
+ } | undefined;
289
+ }) | ({
290
+ type: "Link";
291
+ } & {
292
+ fieldset?: string | null | undefined;
293
+ config?: {
294
+ label?: string | null | undefined;
295
+ useAsTitle?: boolean | undefined;
296
+ placeholder?: string | undefined;
297
+ select?: "document" | "media" | "web" | null | undefined;
298
+ customtypes?: readonly string[] | undefined;
299
+ masks?: readonly string[] | undefined;
300
+ tags?: readonly string[] | undefined;
301
+ allowTargetBlank?: boolean | undefined;
302
+ } | undefined;
303
+ }) | ({
304
+ type: "Image";
305
+ } & {
306
+ fieldset?: string | null | undefined;
307
+ config?: {
308
+ label?: string | null | undefined;
309
+ placeholder?: string | undefined;
310
+ constraint?: {
311
+ width?: number | null | undefined;
312
+ height?: number | null | undefined;
313
+ } | undefined;
314
+ thumbnails?: readonly ({
315
+ name: string;
316
+ } & {
317
+ width?: number | null | undefined;
318
+ height?: number | null | undefined;
319
+ })[] | undefined;
320
+ } | undefined;
321
+ }) | ({
322
+ type: "IntegrationFields";
323
+ } & {
324
+ fieldset?: string | null | undefined;
325
+ config?: {
326
+ label?: string | null | undefined;
327
+ placeholder?: string | undefined;
328
+ catalog?: string | undefined;
329
+ } | undefined;
330
+ });
331
+ } | undefined;
332
+ })[];
333
+ } & {
334
+ description?: string | undefined;
335
+ };
@@ -1,6 +1,5 @@
1
- import * as prismicT from "@prismicio/types";
2
1
  const isSharedSliceModel = (input) => {
3
- return typeof input === "object" && input !== null && "type" in input && input.type === prismicT.CustomTypeModelSliceType.SharedSlice && typeof input.id === "string";
2
+ return typeof input === "object" && input !== null && "type" in input && input.type === "SharedSlice" && typeof input.id === "string";
4
3
  };
5
4
  export {
6
5
  isSharedSliceModel
@@ -1 +1 @@
1
- {"version":3,"file":"isSharedSliceModel.js","sources":["../../../src/lib/isSharedSliceModel.ts"],"sourcesContent":["import * as prismicT from \"@prismicio/types\";\n\nexport const isSharedSliceModel = (\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n\tinput: any,\n): input is prismicT.SharedSliceModel => {\n\treturn (\n\t\ttypeof input === \"object\" &&\n\t\tinput !== null &&\n\t\t\"type\" in input &&\n\t\tinput.type === prismicT.CustomTypeModelSliceType.SharedSlice &&\n\t\ttypeof input.id === \"string\"\n\t);\n};\n"],"names":[],"mappings":";AAEa,MAAA,qBAAqB,CAEjC,UACuC;AACvC,SACC,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS,SAAS,yBAAyB,eACjD,OAAO,MAAM,OAAO;AAEtB;"}
1
+ {"version":3,"file":"isSharedSliceModel.js","sources":["../../../src/lib/isSharedSliceModel.ts"],"sourcesContent":["import type { SharedSlice } from \"@prismicio/types-internal/lib/customtypes\";\n\nexport const isSharedSliceModel = (\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n\tinput: any,\n): input is SharedSlice => {\n\treturn (\n\t\ttypeof input === \"object\" &&\n\t\tinput !== null &&\n\t\t\"type\" in input &&\n\t\tinput.type === \"SharedSlice\" &&\n\t\ttypeof input.id === \"string\"\n\t);\n};\n"],"names":[],"mappings":"AAEa,MAAA,qBAAqB,CAEjC,UACyB;AACzB,SACC,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS,iBACf,OAAO,MAAM,OAAO;AAEtB;"}
@@ -1 +1 @@
1
- {"version":3,"file":"updateSliceModelFile.cjs","sources":["../../../src/lib/updateSliceModelFile.ts"],"sourcesContent":["import { SharedSliceModel } from \"@prismicio/types\";\nimport { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\n\nimport { buildSliceDirectoryPath } from \"./buildSliceDirectoryPath\";\n\ntype UpdateSliceModelFileArgs = {\n\tlibraryID: string;\n\tmodel: SharedSliceModel;\n} & SliceMachineContext<PluginOptions>;\n\nexport const updateSliceModelFile = async ({\n\tlibraryID,\n\tmodel,\n\thelpers,\n\toptions,\n}: UpdateSliceModelFileArgs): Promise<void> => {\n\tconst filePath = path.join(\n\t\tbuildSliceDirectoryPath({ libraryID, model, helpers }),\n\t\t\"model.json\",\n\t);\n\n\tlet contents = JSON.stringify(model);\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":["path","buildSliceDirectoryPath","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAcO,MAAM,uBAAuB,OAAO,EAC1C,WACA,OACA,SACA,cAC6C;AACvC,QAAA,WAAWA,gBAAK,KACrBC,gDAAwB,EAAE,WAAW,OAAO,QAAA,CAAS,GACrD,YAAY;AAGT,MAAA,WAAW,KAAK,UAAU,KAAK;AAEnC,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAAC,cAAG,UAAU,UAAU,QAAQ;AACtC;;"}
1
+ {"version":3,"file":"updateSliceModelFile.cjs","sources":["../../../src/lib/updateSliceModelFile.ts"],"sourcesContent":["import type { SharedSlice } from \"@prismicio/types-internal/lib/customtypes\";\nimport { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\n\nimport { buildSliceDirectoryPath } from \"./buildSliceDirectoryPath\";\n\ntype UpdateSliceModelFileArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n} & SliceMachineContext<PluginOptions>;\n\nexport const updateSliceModelFile = async ({\n\tlibraryID,\n\tmodel,\n\thelpers,\n\toptions,\n}: UpdateSliceModelFileArgs): Promise<void> => {\n\tconst filePath = path.join(\n\t\tbuildSliceDirectoryPath({ libraryID, model, helpers }),\n\t\t\"model.json\",\n\t);\n\n\tlet contents = JSON.stringify(model);\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":["path","buildSliceDirectoryPath","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAcO,MAAM,uBAAuB,OAAO,EAC1C,WACA,OACA,SACA,cAC6C;AACvC,QAAA,WAAWA,gBAAK,KACrBC,gDAAwB,EAAE,WAAW,OAAO,QAAA,CAAS,GACrD,YAAY;AAGT,MAAA,WAAW,KAAK,UAAU,KAAK;AAEnC,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAAC,cAAG,UAAU,UAAU,QAAQ;AACtC;;"}
@@ -1,9 +1,9 @@
1
- import { SharedSliceModel } from "@prismicio/types";
1
+ import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
2
2
  import { SliceMachineContext } from "@slicemachine/plugin-kit";
3
3
  import type { PluginOptions } from "../types";
4
4
  type UpdateSliceModelFileArgs = {
5
5
  libraryID: string;
6
- model: SharedSliceModel;
6
+ model: SharedSlice;
7
7
  } & SliceMachineContext<PluginOptions>;
8
8
  export declare const updateSliceModelFile: ({ libraryID, model, helpers, options, }: UpdateSliceModelFileArgs) => Promise<void>;
9
9
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"updateSliceModelFile.js","sources":["../../../src/lib/updateSliceModelFile.ts"],"sourcesContent":["import { SharedSliceModel } from \"@prismicio/types\";\nimport { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\n\nimport { buildSliceDirectoryPath } from \"./buildSliceDirectoryPath\";\n\ntype UpdateSliceModelFileArgs = {\n\tlibraryID: string;\n\tmodel: SharedSliceModel;\n} & SliceMachineContext<PluginOptions>;\n\nexport const updateSliceModelFile = async ({\n\tlibraryID,\n\tmodel,\n\thelpers,\n\toptions,\n}: UpdateSliceModelFileArgs): Promise<void> => {\n\tconst filePath = path.join(\n\t\tbuildSliceDirectoryPath({ libraryID, model, helpers }),\n\t\t\"model.json\",\n\t);\n\n\tlet contents = JSON.stringify(model);\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":[],"mappings":";;;AAcO,MAAM,uBAAuB,OAAO,EAC1C,WACA,OACA,SACA,cAC6C;AACvC,QAAA,WAAW,KAAK,KACrB,wBAAwB,EAAE,WAAW,OAAO,QAAA,CAAS,GACrD,YAAY;AAGT,MAAA,WAAW,KAAK,UAAU,KAAK;AAEnC,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;"}
1
+ {"version":3,"file":"updateSliceModelFile.js","sources":["../../../src/lib/updateSliceModelFile.ts"],"sourcesContent":["import type { SharedSlice } from \"@prismicio/types-internal/lib/customtypes\";\nimport { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\n\nimport { buildSliceDirectoryPath } from \"./buildSliceDirectoryPath\";\n\ntype UpdateSliceModelFileArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n} & SliceMachineContext<PluginOptions>;\n\nexport const updateSliceModelFile = async ({\n\tlibraryID,\n\tmodel,\n\thelpers,\n\toptions,\n}: UpdateSliceModelFileArgs): Promise<void> => {\n\tconst filePath = path.join(\n\t\tbuildSliceDirectoryPath({ libraryID, model, helpers }),\n\t\t\"model.json\",\n\t);\n\n\tlet contents = JSON.stringify(model);\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":[],"mappings":";;;AAcO,MAAM,uBAAuB,OAAO,EAC1C,WACA,OACA,SACA,cAC6C;AACvC,QAAA,WAAW,KAAK,KACrB,wBAAwB,EAAE,WAAW,OAAO,QAAA,CAAS,GACrD,YAAY;AAGT,MAAA,WAAW,KAAK,UAAU,KAAK;AAEnC,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;"}
@@ -1 +1,2 @@
1
- export { SliceSimulator, SliceSimulatorProps, SliceSimulatorSliceZoneProps, } from "./SliceSimulator";
1
+ export { SliceSimulator } from "./SliceSimulator";
2
+ export type { SliceSimulatorProps, SliceSimulatorSliceZoneProps, } from "./SliceSimulator";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slicemachine/adapter-next",
3
- "version": "0.0.13-dev-plugins-m2.2",
3
+ "version": "0.0.13-dev-plugins-m3.0",
4
4
  "description": "Slice Machine adapter for Next.js.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -8,7 +8,8 @@
8
8
  ],
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "ssh://git@github.com/prismicio/slicemachine-adapter-next.git"
11
+ "url": "ssh://git@github.com/prismicio/slice-machine.git",
12
+ "directory": "packages/adapter-next"
12
13
  },
13
14
  "license": "Apache-2.0",
14
15
  "author": "Prismic <contact@prismic.io> (https://prismic.io)",
@@ -57,8 +58,8 @@
57
58
  },
58
59
  "dependencies": {
59
60
  "@prismicio/slice-simulator-core": "^0.2.7",
60
- "@prismicio/types": "^0.2.7",
61
- "@slicemachine/plugin-kit": "0.1.8-dev-plugins-m2.2",
61
+ "@prismicio/types-internal": "2.0.0-alpha.9",
62
+ "@slicemachine/plugin-kit": "0.1.8-dev-plugins-m3.0",
62
63
  "common-tags": "^1.8.2",
63
64
  "fs-extra": "^11.1.0",
64
65
  "node-fetch": "^3.3.1",
@@ -79,7 +80,7 @@
79
80
  "@vitest/coverage-c8": "^0.27.3",
80
81
  "better-npm-audit": "^3.7.3",
81
82
  "depcheck": "^1.4.3",
82
- "eslint": "^8.36.0",
83
+ "eslint": "^8.37.0",
83
84
  "eslint-config-prettier": "^8.7.0",
84
85
  "eslint-plugin-prettier": "^4.2.1",
85
86
  "eslint-plugin-tsdoc": "^0.2.17",
@@ -103,5 +104,5 @@
103
104
  "publishConfig": {
104
105
  "access": "public"
105
106
  },
106
- "gitHead": "4d33351e21b2aa33b141c1e75a8d5172cdbd3ebb"
107
+ "gitHead": "9223acb43eebf3f0e1731090b48c44ebd96f4aae"
107
108
  }
@@ -1,5 +1,5 @@
1
1
  import type { CustomTypeReadHook } from "@slicemachine/plugin-kit";
2
- import * as prismicT from "@prismicio/types";
2
+ import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
3
3
  import * as path from "node:path";
4
4
 
5
5
  import { buildCustomTypeDirectoryPath } from "../lib/buildCustomTypeDirectoryPath";
@@ -16,7 +16,7 @@ export const customTypeRead: CustomTypeReadHook<PluginOptions> = async (
16
16
  "index.json",
17
17
  );
18
18
 
19
- const model = await readJSONFile<prismicT.CustomTypeModel>(filePath);
19
+ const model = await readJSONFile<CustomType>(filePath);
20
20
 
21
21
  return {
22
22
  model,
@@ -1,5 +1,5 @@
1
1
  import type { CustomTypeLibraryReadHook } from "@slicemachine/plugin-kit";
2
- import * as prismicT from "@prismicio/types";
2
+ import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
3
3
  import * as fs from "node:fs/promises";
4
4
  import * as path from "node:path";
5
5
 
@@ -11,7 +11,7 @@ import type { PluginOptions } from "../types";
11
11
  const isCustomTypeModel = (
12
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
13
  input: any,
14
- ): input is prismicT.CustomTypeModel => {
14
+ ): input is CustomType => {
15
15
  return typeof input === "object" && input !== null && "json" in input;
16
16
  };
17
17
 
@@ -22,20 +22,25 @@ export const sliceRead: SliceReadHook<PluginOptions> = async (
22
22
 
23
23
  const childDirs = await fs.readdir(libraryDir, { withFileTypes: true });
24
24
 
25
+ const modelReadErrors: string[] = [];
26
+
25
27
  // Find the first matching model.
26
28
  const [model] = (
27
29
  await Promise.all(
28
30
  childDirs.map(async (childDir) => {
29
31
  if (childDir.isDirectory()) {
30
32
  const modelPath = path.join(libraryDir, childDir.name, "model.json");
33
+ try {
34
+ const modelContents = await readJSONFile(modelPath);
31
35
 
32
- const modelContents = await readJSONFile(modelPath);
33
-
34
- if (
35
- isSharedSliceModel(modelContents) &&
36
- modelContents.id === data.sliceID
37
- ) {
38
- return modelContents;
36
+ if (
37
+ isSharedSliceModel(modelContents) &&
38
+ modelContents.id === data.sliceID
39
+ ) {
40
+ return modelContents;
41
+ }
42
+ } catch (error) {
43
+ modelReadErrors.push(modelPath);
39
44
  }
40
45
  }
41
46
  }),
@@ -47,6 +52,16 @@ export const sliceRead: SliceReadHook<PluginOptions> = async (
47
52
  model,
48
53
  };
49
54
  } else {
55
+ if (modelReadErrors.length) {
56
+ throw new Error(
57
+ `Did not find a Slice model with ID "${data.sliceID}" in the "${
58
+ data.libraryID
59
+ }" Slice Library.\n\nThose Slice models could not be read:\n - ${modelReadErrors.join(
60
+ "\n - ",
61
+ )}`,
62
+ );
63
+ }
64
+
50
65
  throw new Error(
51
66
  `Did not find a Slice model with ID "${data.sliceID}" in the "${data.libraryID}" Slice Library.`,
52
67
  );
@@ -5,7 +5,7 @@ import type {
5
5
  } from "@slicemachine/plugin-kit";
6
6
  import { source } from "common-tags";
7
7
  import { createRequire } from "node:module";
8
- import fetch from "node-fetch";
8
+ import fetch, { Response } from "node-fetch";
9
9
 
10
10
  import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
11
11
  import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension";
@@ -209,13 +209,18 @@ const createStep3 = async ({
209
209
  }
210
210
 
211
211
  // Check if the URL is accessible.
212
- const res = await fetch(project.config.localSliceSimulatorURL);
212
+ let res: Response | undefined = undefined;
213
+ try {
214
+ res = await fetch(project.config.localSliceSimulatorURL);
215
+ } catch (error) {
216
+ // Noop, we return if `res` is not defined
217
+ }
213
218
 
214
- if (!res.ok) {
219
+ if (!res || !res.ok) {
215
220
  return {
216
221
  title: "Unable to connect to simulator page",
217
222
  message: source`
218
- Check that the \`localSliceSimulatorURL\` property in \`slicemachine.config.json\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/technologies/setup-slice-simulator-nextjs) for more details.
223
+ Check that the \`localSliceSimulatorURL\` property in \`slicemachine.config.json\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/setup-nextjs) for more details.
219
224
  `,
220
225
  };
221
226
  }
@@ -2,7 +2,6 @@ import type {
2
2
  SliceMachineHelpers,
3
3
  SnippetReadHook,
4
4
  } from "@slicemachine/plugin-kit";
5
- import * as prismicT from "@prismicio/types";
6
5
  import { stripIndent } from "common-tags";
7
6
 
8
7
  import type { PluginOptions } from "../types";
@@ -33,7 +32,7 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
33
32
  const label = "React";
34
33
 
35
34
  switch (data.model.type) {
36
- case prismicT.CustomTypeModelFieldType.StructuredText: {
35
+ case "StructuredText": {
37
36
  return {
38
37
  label,
39
38
  language: "tsx",
@@ -46,7 +45,7 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
46
45
  };
47
46
  }
48
47
 
49
- case prismicT.CustomTypeModelFieldType.Link: {
48
+ case "Link": {
50
49
  return {
51
50
  label,
52
51
  language: "tsx",
@@ -59,7 +58,7 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
59
58
  };
60
59
  }
61
60
 
62
- case prismicT.CustomTypeModelFieldType.Image: {
61
+ case "Image": {
63
62
  return [
64
63
  {
65
64
  label: `${label} (next/image)`,
@@ -84,7 +83,7 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
84
83
  ];
85
84
  }
86
85
 
87
- case prismicT.CustomTypeModelFieldType.Group: {
86
+ case "Group": {
88
87
  const code = await format(
89
88
  stripIndent`
90
89
  <>{${dotPath(fieldPath)}.map(item => (
@@ -101,7 +100,7 @@ export const snippetRead: SnippetReadHook<PluginOptions> = async (
101
100
  };
102
101
  }
103
102
 
104
- case prismicT.CustomTypeModelFieldType.Slices: {
103
+ case "Slices": {
105
104
  const code = await format(
106
105
  stripIndent`
107
106
  <SliceZone
@@ -1,4 +1,4 @@
1
- import { SharedSliceModel } from "@prismicio/types";
1
+ import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
2
2
  import { SliceMachineContext } from "@slicemachine/plugin-kit";
3
3
  import * as path from "node:path";
4
4
 
@@ -9,7 +9,7 @@ import { pascalCase } from "./pascalCase";
9
9
 
10
10
  type BuildSliceDirectoryPathArgs = {
11
11
  libraryID: string;
12
- model: SharedSliceModel;
12
+ model: SharedSlice;
13
13
  helpers: SliceMachineContext<PluginOptions>["helpers"];
14
14
  };
15
15
 
@@ -1,14 +1,14 @@
1
- import * as prismicT from "@prismicio/types";
1
+ import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
2
2
 
3
3
  export const isSharedSliceModel = (
4
4
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
5
5
  input: any,
6
- ): input is prismicT.SharedSliceModel => {
6
+ ): input is SharedSlice => {
7
7
  return (
8
8
  typeof input === "object" &&
9
9
  input !== null &&
10
10
  "type" in input &&
11
- input.type === prismicT.CustomTypeModelSliceType.SharedSlice &&
11
+ input.type === "SharedSlice" &&
12
12
  typeof input.id === "string"
13
13
  );
14
14
  };
@@ -1,4 +1,4 @@
1
- import { SharedSliceModel } from "@prismicio/types";
1
+ import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
2
2
  import { SliceMachineContext } from "@slicemachine/plugin-kit";
3
3
  import * as fs from "node:fs/promises";
4
4
  import * as path from "node:path";
@@ -9,7 +9,7 @@ import { buildSliceDirectoryPath } from "./buildSliceDirectoryPath";
9
9
 
10
10
  type UpdateSliceModelFileArgs = {
11
11
  libraryID: string;
12
- model: SharedSliceModel;
12
+ model: SharedSlice;
13
13
  } & SliceMachineContext<PluginOptions>;
14
14
 
15
15
  export const updateSliceModelFile = async ({
@@ -1,5 +1,5 @@
1
- export {
2
- SliceSimulator,
1
+ export { SliceSimulator } from "./SliceSimulator";
2
+ export type {
3
3
  SliceSimulatorProps,
4
4
  SliceSimulatorSliceZoneProps,
5
5
  } from "./SliceSimulator";