@slicemachine/adapter-next 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SliceSimulator.cjs +14 -41
- package/dist/SliceSimulator.cjs.map +1 -1
- package/dist/SliceSimulator.d.ts +2 -2
- package/dist/SliceSimulator.js +11 -36
- package/dist/SliceSimulator.js.map +1 -1
- package/dist/_virtual/_commonjsHelpers.cjs +5 -0
- package/dist/_virtual/_commonjsHelpers.cjs.map +1 -0
- package/dist/_virtual/_commonjsHelpers.js +5 -0
- package/dist/_virtual/_commonjsHelpers.js.map +1 -0
- package/dist/_virtual/ponyfill.es2018.cjs +5 -0
- package/dist/_virtual/ponyfill.es2018.cjs.map +1 -0
- package/dist/_virtual/ponyfill.es2018.js +5 -0
- package/dist/_virtual/ponyfill.es2018.js.map +1 -0
- package/dist/constants.cjs +5 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/hooks/customType-asset-delete.cjs +3 -5
- package/dist/hooks/customType-asset-delete.cjs.map +1 -1
- package/dist/hooks/customType-asset-delete.js.map +1 -1
- package/dist/hooks/customType-asset-read.cjs +3 -5
- package/dist/hooks/customType-asset-read.cjs.map +1 -1
- package/dist/hooks/customType-asset-read.js.map +1 -1
- package/dist/hooks/customType-asset-update.cjs +4 -6
- package/dist/hooks/customType-asset-update.cjs.map +1 -1
- package/dist/hooks/customType-asset-update.js.map +1 -1
- package/dist/hooks/customType-create.cjs +4 -6
- package/dist/hooks/customType-create.cjs.map +1 -1
- package/dist/hooks/customType-create.js.map +1 -1
- package/dist/hooks/customType-delete.cjs +3 -5
- package/dist/hooks/customType-delete.cjs.map +1 -1
- package/dist/hooks/customType-delete.js.map +1 -1
- package/dist/hooks/customType-read.cjs +1 -1
- package/dist/hooks/customType-read.cjs.map +1 -1
- package/dist/hooks/customType-read.js.map +1 -1
- package/dist/hooks/customType-rename.cjs +6 -0
- package/dist/hooks/customType-rename.cjs.map +1 -0
- package/dist/hooks/customType-rename.d.ts +1 -0
- package/dist/hooks/customType-rename.js +6 -0
- package/dist/hooks/customType-rename.js.map +1 -0
- package/dist/hooks/customType-update.cjs +1 -1
- package/dist/hooks/customType-update.cjs.map +1 -1
- package/dist/hooks/customType-update.js.map +1 -1
- package/dist/hooks/customTypeLibrary-read.cjs +16 -10
- package/dist/hooks/customTypeLibrary-read.cjs.map +1 -1
- package/dist/hooks/customTypeLibrary-read.js +12 -4
- package/dist/hooks/customTypeLibrary-read.js.map +1 -1
- package/dist/hooks/slice-asset-delete.cjs +3 -5
- package/dist/hooks/slice-asset-delete.cjs.map +1 -1
- package/dist/hooks/slice-asset-delete.js.map +1 -1
- package/dist/hooks/slice-asset-read.cjs +3 -5
- package/dist/hooks/slice-asset-read.cjs.map +1 -1
- package/dist/hooks/slice-asset-read.js.map +1 -1
- package/dist/hooks/slice-asset-update.cjs +4 -6
- package/dist/hooks/slice-asset-update.cjs.map +1 -1
- package/dist/hooks/slice-asset-update.js.map +1 -1
- package/dist/hooks/slice-create.cjs +18 -30
- package/dist/hooks/slice-create.cjs.map +1 -1
- package/dist/hooks/slice-create.js +14 -24
- package/dist/hooks/slice-create.js.map +1 -1
- package/dist/hooks/slice-delete.cjs +6 -18
- package/dist/hooks/slice-delete.cjs.map +1 -1
- package/dist/hooks/slice-delete.js +3 -13
- package/dist/hooks/slice-delete.js.map +1 -1
- package/dist/hooks/slice-read.cjs +41 -7
- package/dist/hooks/slice-read.cjs.map +1 -1
- package/dist/hooks/slice-read.js +22 -6
- package/dist/hooks/slice-read.js.map +1 -1
- package/dist/hooks/slice-rename.cjs +43 -0
- package/dist/hooks/slice-rename.cjs.map +1 -0
- package/dist/hooks/slice-rename.d.ts +3 -0
- package/dist/hooks/slice-rename.js +26 -0
- package/dist/hooks/slice-rename.js.map +1 -0
- package/dist/hooks/slice-update.cjs +7 -34
- package/dist/hooks/slice-update.cjs.map +1 -1
- package/dist/hooks/slice-update.js +6 -13
- package/dist/hooks/slice-update.js.map +1 -1
- package/dist/hooks/sliceLibrary-read.cjs +16 -20
- package/dist/hooks/sliceLibrary-read.cjs.map +1 -1
- package/dist/hooks/sliceLibrary-read.js +12 -13
- package/dist/hooks/sliceLibrary-read.js.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.cjs +31 -94
- package/dist/hooks/sliceSimulator-setup-read.cjs.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.js +31 -75
- package/dist/hooks/sliceSimulator-setup-read.js.map +1 -1
- package/dist/hooks/snippet-read.cjs +33 -18
- package/dist/hooks/snippet-read.cjs.map +1 -1
- package/dist/hooks/snippet-read.js +30 -13
- package/dist/hooks/snippet-read.js.map +1 -1
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/getJSOrTSXFileExtension.cjs +1 -1
- package/dist/lib/getJSOrTSXFileExtension.cjs.map +1 -1
- package/dist/lib/getJSOrTSXFileExtension.js.map +1 -1
- package/dist/lib/isSharedSliceModel.cjs +25 -0
- package/dist/lib/isSharedSliceModel.cjs.map +1 -0
- package/dist/lib/isSharedSliceModel.d.ts +2 -0
- package/dist/lib/isSharedSliceModel.js +8 -0
- package/dist/lib/isSharedSliceModel.js.map +1 -0
- package/dist/lib/pascalCase.cjs +1 -1
- package/dist/lib/pascalCase.cjs.map +1 -1
- package/dist/lib/pascalCase.js.map +1 -1
- package/dist/lib/readJSONFile.cjs +3 -5
- package/dist/lib/readJSONFile.cjs.map +1 -1
- package/dist/lib/readJSONFile.js.map +1 -1
- package/dist/lib/rejectIfNecessary.cjs +1 -1
- package/dist/lib/rejectIfNecessary.cjs.map +1 -1
- package/dist/lib/rejectIfNecessary.js.map +1 -1
- package/dist/lib/updateSliceModelFile.cjs +31 -0
- package/dist/lib/updateSliceModelFile.cjs.map +1 -0
- package/dist/lib/updateSliceModelFile.d.ts +9 -0
- package/dist/lib/updateSliceModelFile.js +14 -0
- package/dist/lib/updateSliceModelFile.js.map +1 -0
- package/dist/lib/upsertGlobalContentTypes.cjs +8 -6
- package/dist/lib/upsertGlobalContentTypes.cjs.map +1 -1
- package/dist/lib/upsertGlobalContentTypes.d.ts +1 -1
- package/dist/lib/upsertGlobalContentTypes.js +4 -0
- package/dist/lib/upsertGlobalContentTypes.js.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.cjs +48 -0
- package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -0
- package/dist/lib/upsertSliceLibraryIndexFile.d.ts +7 -0
- package/dist/lib/upsertSliceLibraryIndexFile.js +31 -0
- package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.cjs +41 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.cjs.map +1 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.js +41 -0
- package/dist/node_modules/data-uri-to-buffer/dist/index.js.map +1 -0
- package/dist/node_modules/fetch-blob/file.cjs +55 -0
- package/dist/node_modules/fetch-blob/file.cjs.map +1 -0
- package/dist/node_modules/fetch-blob/file.js +55 -0
- package/dist/node_modules/fetch-blob/file.js.map +1 -0
- package/dist/node_modules/fetch-blob/index.cjs +176 -0
- package/dist/node_modules/fetch-blob/index.cjs.map +1 -0
- package/dist/node_modules/fetch-blob/index.js +176 -0
- package/dist/node_modules/fetch-blob/index.js.map +1 -0
- package/dist/node_modules/fetch-blob/streams.cjs +43 -0
- package/dist/node_modules/fetch-blob/streams.cjs.map +1 -0
- package/dist/node_modules/fetch-blob/streams.js +42 -0
- package/dist/node_modules/fetch-blob/streams.js.map +1 -0
- package/dist/node_modules/formdata-polyfill/esm.min.cjs +115 -0
- package/dist/node_modules/formdata-polyfill/esm.min.cjs.map +1 -0
- package/dist/node_modules/formdata-polyfill/esm.min.js +115 -0
- package/dist/node_modules/formdata-polyfill/esm.min.js.map +1 -0
- package/dist/node_modules/node-domexception/index.cjs +10 -0
- package/dist/node_modules/node-domexception/index.cjs.map +1 -0
- package/dist/node_modules/node-domexception/index.js +9 -0
- package/dist/node_modules/node-domexception/index.js.map +1 -0
- package/dist/node_modules/node-fetch/src/body.cjs +237 -0
- package/dist/node_modules/node-fetch/src/body.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/body.js +237 -0
- package/dist/node_modules/node-fetch/src/body.js.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.cjs +10 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.js +10 -0
- package/dist/node_modules/node-fetch/src/errors/abort-error.js.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/base.cjs +17 -0
- package/dist/node_modules/node-fetch/src/errors/base.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/base.js +17 -0
- package/dist/node_modules/node-fetch/src/errors/base.js.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs +14 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.js +14 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.js.map +1 -0
- package/dist/node_modules/node-fetch/src/headers.cjs +173 -0
- package/dist/node_modules/node-fetch/src/headers.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/headers.js +173 -0
- package/dist/node_modules/node-fetch/src/headers.js.map +1 -0
- package/dist/node_modules/node-fetch/src/index.cjs +292 -0
- package/dist/node_modules/node-fetch/src/index.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/index.js +298 -0
- package/dist/node_modules/node-fetch/src/index.js.map +1 -0
- package/dist/node_modules/node-fetch/src/request.cjs +193 -0
- package/dist/node_modules/node-fetch/src/request.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/request.js +193 -0
- package/dist/node_modules/node-fetch/src/request.js.map +1 -0
- package/dist/node_modules/node-fetch/src/response.cjs +110 -0
- package/dist/node_modules/node-fetch/src/response.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/response.js +110 -0
- package/dist/node_modules/node-fetch/src/response.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.cjs +12 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.js +12 -0
- package/dist/node_modules/node-fetch/src/utils/get-search.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.cjs +8 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.js +8 -0
- package/dist/node_modules/node-fetch/src/utils/is-redirect.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is.cjs +28 -0
- package/dist/node_modules/node-fetch/src/utils/is.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/is.js +28 -0
- package/dist/node_modules/node-fetch/src/utils/is.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs +350 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.js +350 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.js.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.cjs +149 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.cjs.map +1 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.js +149 -0
- package/dist/node_modules/node-fetch/src/utils/referrer.js.map +1 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs +3599 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs.map +1 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js +3599 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js.map +1 -0
- package/dist/package.json.cjs +5 -0
- package/dist/package.json.cjs.map +1 -0
- package/dist/{package.js → package.json.js} +1 -1
- package/dist/package.json.js.map +1 -0
- package/dist/plugin.cjs +6 -2
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +5 -1
- package/dist/plugin.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +32 -15
- package/src/constants.ts +5 -0
- package/src/hooks/customType-rename.ts +3 -0
- package/src/hooks/customTypeLibrary-read.ts +13 -4
- package/src/hooks/slice-create.ts +14 -32
- package/src/hooks/slice-delete.ts +3 -21
- package/src/hooks/slice-read.ts +37 -11
- package/src/hooks/slice-rename.ts +44 -0
- package/src/hooks/slice-update.ts +7 -31
- package/src/hooks/sliceLibrary-read.ts +13 -23
- package/src/hooks/sliceSimulator-setup-read.ts +37 -76
- package/src/hooks/snippet-read.ts +42 -22
- package/src/index.ts +0 -6
- package/src/lib/isSharedSliceModel.ts +14 -0
- package/src/lib/updateSliceModelFile.ts +32 -0
- package/src/lib/upsertGlobalContentTypes.ts +3 -0
- package/src/lib/{buildSliceLibraryIndexFileContents.ts → upsertSliceLibraryIndexFile.ts} +19 -9
- package/src/plugin.ts +4 -0
- package/dist/lib/buildSliceLibraryIndexFileContents.cjs +0 -23
- package/dist/lib/buildSliceLibraryIndexFileContents.cjs.map +0 -1
- package/dist/lib/buildSliceLibraryIndexFileContents.d.ts +0 -10
- package/dist/lib/buildSliceLibraryIndexFileContents.js +0 -23
- package/dist/lib/buildSliceLibraryIndexFileContents.js.map +0 -1
- package/dist/package.cjs +0 -5
- package/dist/package.cjs.map +0 -1
- package/dist/package.js.map +0 -1
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const fs = require("node:fs/promises");
|
|
4
4
|
const path = require("node:path");
|
|
5
5
|
const readJSONFile = require("../lib/readJSONFile.cjs");
|
|
6
|
-
function
|
|
7
|
-
if (e && e.__esModule)
|
|
8
|
-
return e;
|
|
6
|
+
function _interopNamespaceDefault(e) {
|
|
9
7
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
8
|
if (e) {
|
|
11
9
|
for (const k in e) {
|
|
@@ -21,8 +19,8 @@ function _interopNamespace(e) {
|
|
|
21
19
|
n.default = e;
|
|
22
20
|
return Object.freeze(n);
|
|
23
21
|
}
|
|
24
|
-
const fs__namespace = /* @__PURE__ */
|
|
25
|
-
const path__namespace = /* @__PURE__ */
|
|
22
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
23
|
+
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
26
24
|
const isCustomTypeModel = (input) => {
|
|
27
25
|
return typeof input === "object" && input !== null && "json" in input;
|
|
28
26
|
};
|
|
@@ -32,10 +30,18 @@ const customTypeLibraryRead = async (_data, { helpers }) => {
|
|
|
32
30
|
const childDirs = await fs__namespace.readdir(dirPath);
|
|
33
31
|
const ids = [];
|
|
34
32
|
await Promise.all(childDirs.map(async (childDir) => {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
const childDirContents = await fs__namespace.readdir(path__namespace.join(dirPath, childDir), {
|
|
34
|
+
withFileTypes: true
|
|
35
|
+
});
|
|
36
|
+
const isCustomTypeDir = childDirContents.some((entry) => {
|
|
37
|
+
return entry.isFile() && entry.name === "index.json";
|
|
38
|
+
});
|
|
39
|
+
if (isCustomTypeDir) {
|
|
40
|
+
const modelPath = path__namespace.join(dirPath, childDir, "index.json");
|
|
41
|
+
const modelContents = await readJSONFile.readJSONFile(modelPath);
|
|
42
|
+
if (isCustomTypeModel(modelContents)) {
|
|
43
|
+
ids.push(modelContents.id);
|
|
44
|
+
}
|
|
39
45
|
}
|
|
40
46
|
}));
|
|
41
47
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customTypeLibrary-read.cjs","sources":["
|
|
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 { 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 = helpers.joinPathFromRoot(\"customtypes\");\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":["fs","path","readJSONFile"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AASA,MAAM,oBAAoB,CAEzB,UACsC;AACtC,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU;AACjE;AAEO,MAAM,wBAET,OAAO,OAAO,EAAE,cAAa;AAC1B,QAAA,UAAU,QAAQ,iBAAiB,aAAa;AAGtD,QAAMA,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;;"}
|
|
@@ -10,10 +10,18 @@ const customTypeLibraryRead = async (_data, { helpers }) => {
|
|
|
10
10
|
const childDirs = await fs.readdir(dirPath);
|
|
11
11
|
const ids = [];
|
|
12
12
|
await Promise.all(childDirs.map(async (childDir) => {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const childDirContents = await fs.readdir(path.join(dirPath, childDir), {
|
|
14
|
+
withFileTypes: true
|
|
15
|
+
});
|
|
16
|
+
const isCustomTypeDir = childDirContents.some((entry) => {
|
|
17
|
+
return entry.isFile() && entry.name === "index.json";
|
|
18
|
+
});
|
|
19
|
+
if (isCustomTypeDir) {
|
|
20
|
+
const modelPath = path.join(dirPath, childDir, "index.json");
|
|
21
|
+
const modelContents = await readJSONFile(modelPath);
|
|
22
|
+
if (isCustomTypeModel(modelContents)) {
|
|
23
|
+
ids.push(modelContents.id);
|
|
24
|
+
}
|
|
17
25
|
}
|
|
18
26
|
}));
|
|
19
27
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customTypeLibrary-read.js","sources":["
|
|
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 { 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 = helpers.joinPathFromRoot(\"customtypes\");\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":";;;AASA,MAAM,oBAAoB,CAEzB,UACsC;AACtC,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU;AACjE;AAEO,MAAM,wBAET,OAAO,OAAO,EAAE,cAAa;AAC1B,QAAA,UAAU,QAAQ,iBAAiB,aAAa;AAGtD,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,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const fs = require("node:fs/promises");
|
|
4
4
|
const pascalCase = require("../lib/pascalCase.cjs");
|
|
5
|
-
function
|
|
6
|
-
if (e && e.__esModule)
|
|
7
|
-
return e;
|
|
5
|
+
function _interopNamespaceDefault(e) {
|
|
8
6
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
9
7
|
if (e) {
|
|
10
8
|
for (const k in e) {
|
|
@@ -20,7 +18,7 @@ function _interopNamespace(e) {
|
|
|
20
18
|
n.default = e;
|
|
21
19
|
return Object.freeze(n);
|
|
22
20
|
}
|
|
23
|
-
const fs__namespace = /* @__PURE__ */
|
|
21
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
24
22
|
const sliceAssetDelete = async (data, context) => {
|
|
25
23
|
const filePath = context.helpers.joinPathFromRoot(data.libraryID, pascalCase.pascalCase(data.sliceID), data.assetID);
|
|
26
24
|
await fs__namespace.rm(filePath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice-asset-delete.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"slice-asset-delete.cjs","sources":["../../../src/hooks/slice-asset-delete.ts"],"sourcesContent":["import type { SliceAssetDeleteHook } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\n\nimport { pascalCase } from \"../lib/pascalCase\";\n\nimport type { PluginOptions } from \"../types\";\n\nexport const sliceAssetDelete: SliceAssetDeleteHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\tconst filePath = context.helpers.joinPathFromRoot(\n\t\tdata.libraryID,\n\t\tpascalCase(data.sliceID),\n\t\tdata.assetID,\n\t);\n\n\tawait fs.rm(filePath);\n};\n"],"names":["pascalCase","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAOa,MAAA,mBAAwD,OACpE,MACA,YACG;AACG,QAAA,WAAW,QAAQ,QAAQ,iBAChC,KAAK,WACLA,WAAA,WAAW,KAAK,OAAO,GACvB,KAAK,OAAO;AAGP,QAAAC,cAAG,GAAG,QAAQ;AACrB;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice-asset-delete.js","sources":["
|
|
1
|
+
{"version":3,"file":"slice-asset-delete.js","sources":["../../../src/hooks/slice-asset-delete.ts"],"sourcesContent":["import type { SliceAssetDeleteHook } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\n\nimport { pascalCase } from \"../lib/pascalCase\";\n\nimport type { PluginOptions } from \"../types\";\n\nexport const sliceAssetDelete: SliceAssetDeleteHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\tconst filePath = context.helpers.joinPathFromRoot(\n\t\tdata.libraryID,\n\t\tpascalCase(data.sliceID),\n\t\tdata.assetID,\n\t);\n\n\tawait fs.rm(filePath);\n};\n"],"names":[],"mappings":";;AAOa,MAAA,mBAAwD,OACpE,MACA,YACG;AACG,QAAA,WAAW,QAAQ,QAAQ,iBAChC,KAAK,WACL,WAAW,KAAK,OAAO,GACvB,KAAK,OAAO;AAGP,QAAA,GAAG,GAAG,QAAQ;AACrB;"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const fs = require("node:fs/promises");
|
|
4
4
|
const pascalCase = require("../lib/pascalCase.cjs");
|
|
5
|
-
function
|
|
6
|
-
if (e && e.__esModule)
|
|
7
|
-
return e;
|
|
5
|
+
function _interopNamespaceDefault(e) {
|
|
8
6
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
9
7
|
if (e) {
|
|
10
8
|
for (const k in e) {
|
|
@@ -20,7 +18,7 @@ function _interopNamespace(e) {
|
|
|
20
18
|
n.default = e;
|
|
21
19
|
return Object.freeze(n);
|
|
22
20
|
}
|
|
23
|
-
const fs__namespace = /* @__PURE__ */
|
|
21
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
24
22
|
const sliceAssetRead = async (data, context) => {
|
|
25
23
|
const filePath = context.helpers.joinPathFromRoot(data.libraryID, pascalCase.pascalCase(data.sliceID), data.assetID);
|
|
26
24
|
const assetData = await fs__namespace.readFile(filePath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice-asset-read.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"slice-asset-read.cjs","sources":["../../../src/hooks/slice-asset-read.ts"],"sourcesContent":["import type { SliceAssetReadHook } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\n\nimport { pascalCase } from \"../lib/pascalCase\";\n\nimport type { PluginOptions } from \"../types\";\n\nexport const sliceAssetRead: SliceAssetReadHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\tconst filePath = context.helpers.joinPathFromRoot(\n\t\tdata.libraryID,\n\t\tpascalCase(data.sliceID),\n\t\tdata.assetID,\n\t);\n\n\tconst assetData = await fs.readFile(filePath);\n\n\treturn {\n\t\tdata: assetData,\n\t};\n};\n"],"names":["pascalCase","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAOa,MAAA,iBAAoD,OAChE,MACA,YACG;AACG,QAAA,WAAW,QAAQ,QAAQ,iBAChC,KAAK,WACLA,WAAA,WAAW,KAAK,OAAO,GACvB,KAAK,OAAO;AAGb,QAAM,YAAY,MAAMC,cAAG,SAAS,QAAQ;AAErC,SAAA;AAAA,IACN,MAAM;AAAA,EAAA;AAER;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice-asset-read.js","sources":["
|
|
1
|
+
{"version":3,"file":"slice-asset-read.js","sources":["../../../src/hooks/slice-asset-read.ts"],"sourcesContent":["import type { SliceAssetReadHook } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\n\nimport { pascalCase } from \"../lib/pascalCase\";\n\nimport type { PluginOptions } from \"../types\";\n\nexport const sliceAssetRead: SliceAssetReadHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\tconst filePath = context.helpers.joinPathFromRoot(\n\t\tdata.libraryID,\n\t\tpascalCase(data.sliceID),\n\t\tdata.assetID,\n\t);\n\n\tconst assetData = await fs.readFile(filePath);\n\n\treturn {\n\t\tdata: assetData,\n\t};\n};\n"],"names":[],"mappings":";;AAOa,MAAA,iBAAoD,OAChE,MACA,YACG;AACG,QAAA,WAAW,QAAQ,QAAQ,iBAChC,KAAK,WACL,WAAW,KAAK,OAAO,GACvB,KAAK,OAAO;AAGb,QAAM,YAAY,MAAM,GAAG,SAAS,QAAQ;AAErC,SAAA;AAAA,IACN,MAAM;AAAA,EAAA;AAER;"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const fs = require("node:fs/promises");
|
|
4
4
|
const path = require("node:path");
|
|
5
5
|
const pascalCase = require("../lib/pascalCase.cjs");
|
|
6
|
-
function
|
|
7
|
-
if (e && e.__esModule)
|
|
8
|
-
return e;
|
|
6
|
+
function _interopNamespaceDefault(e) {
|
|
9
7
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
8
|
if (e) {
|
|
11
9
|
for (const k in e) {
|
|
@@ -21,8 +19,8 @@ function _interopNamespace(e) {
|
|
|
21
19
|
n.default = e;
|
|
22
20
|
return Object.freeze(n);
|
|
23
21
|
}
|
|
24
|
-
const fs__namespace = /* @__PURE__ */
|
|
25
|
-
const path__namespace = /* @__PURE__ */
|
|
22
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
23
|
+
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
26
24
|
const sliceAssetUpdate = async (data, context) => {
|
|
27
25
|
const filePath = context.helpers.joinPathFromRoot(data.libraryID, pascalCase.pascalCase(data.sliceID), data.asset.id);
|
|
28
26
|
await fs__namespace.mkdir(path__namespace.dirname(filePath), { recursive: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice-asset-update.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"slice-asset-update.cjs","sources":["../../../src/hooks/slice-asset-update.ts"],"sourcesContent":["import type { SliceAssetUpdateHook } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { pascalCase } from \"../lib/pascalCase\";\n\nimport type { PluginOptions } from \"../types\";\n\nexport const sliceAssetUpdate: SliceAssetUpdateHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\tconst filePath = context.helpers.joinPathFromRoot(\n\t\tdata.libraryID,\n\t\tpascalCase(data.sliceID),\n\t\tdata.asset.id,\n\t);\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\tawait fs.writeFile(filePath, data.asset.data);\n};\n"],"names":["pascalCase","fs","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAQa,MAAA,mBAAwD,OACpE,MACA,YACG;AACH,QAAM,WAAW,QAAQ,QAAQ,iBAChC,KAAK,WACLA,sBAAW,KAAK,OAAO,GACvB,KAAK,MAAM,EAAE;AAGR,QAAAC,cAAG,MAAMC,gBAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAA,CAAM;AAC1D,QAAMD,cAAG,UAAU,UAAU,KAAK,MAAM,IAAI;AAC7C;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice-asset-update.js","sources":["
|
|
1
|
+
{"version":3,"file":"slice-asset-update.js","sources":["../../../src/hooks/slice-asset-update.ts"],"sourcesContent":["import type { SliceAssetUpdateHook } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { pascalCase } from \"../lib/pascalCase\";\n\nimport type { PluginOptions } from \"../types\";\n\nexport const sliceAssetUpdate: SliceAssetUpdateHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\tconst filePath = context.helpers.joinPathFromRoot(\n\t\tdata.libraryID,\n\t\tpascalCase(data.sliceID),\n\t\tdata.asset.id,\n\t);\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\tawait fs.writeFile(filePath, data.asset.data);\n};\n"],"names":[],"mappings":";;;AAQa,MAAA,mBAAwD,OACpE,MACA,YACG;AACH,QAAM,WAAW,QAAQ,QAAQ,iBAChC,KAAK,WACL,WAAW,KAAK,OAAO,GACvB,KAAK,MAAM,EAAE;AAGR,QAAA,GAAG,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAA,CAAM;AAC1D,QAAM,GAAG,UAAU,UAAU,KAAK,MAAM,IAAI;AAC7C;"}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const commonTags = require("common-tags");
|
|
4
4
|
const fs = require("node:fs/promises");
|
|
5
5
|
const path = require("node:path");
|
|
6
|
-
const
|
|
6
|
+
const upsertSliceLibraryIndexFile = require("../lib/upsertSliceLibraryIndexFile.cjs");
|
|
7
7
|
const getJSOrTSXFileExtension = require("../lib/getJSOrTSXFileExtension.cjs");
|
|
8
8
|
const pascalCase = require("../lib/pascalCase.cjs");
|
|
9
9
|
const rejectIfNecessary = require("../lib/rejectIfNecessary.cjs");
|
|
10
10
|
const upsertGlobalContentTypes = require("../lib/upsertGlobalContentTypes.cjs");
|
|
11
|
-
function
|
|
12
|
-
if (e && e.__esModule)
|
|
13
|
-
return e;
|
|
11
|
+
function _interopNamespaceDefault(e) {
|
|
14
12
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
15
13
|
if (e) {
|
|
16
14
|
for (const k in e) {
|
|
@@ -26,8 +24,8 @@ function _interopNamespace(e) {
|
|
|
26
24
|
n.default = e;
|
|
27
25
|
return Object.freeze(n);
|
|
28
26
|
}
|
|
29
|
-
const fs__namespace = /* @__PURE__ */
|
|
30
|
-
const path__namespace = /* @__PURE__ */
|
|
27
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
28
|
+
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
31
29
|
const createModelFile = async ({ dir, data, helpers, options }) => {
|
|
32
30
|
const filePath = path__namespace.join(dir, "model.json");
|
|
33
31
|
let contents = JSON.stringify(data.model);
|
|
@@ -39,22 +37,22 @@ const createModelFile = async ({ dir, data, helpers, options }) => {
|
|
|
39
37
|
const createComponentFile = async ({ dir, data, helpers, options }) => {
|
|
40
38
|
const filePath = path__namespace.join(dir, `index.${getJSOrTSXFileExtension.getJSOrTSXFileExtension(options)}`);
|
|
41
39
|
const model = data.model;
|
|
42
|
-
const
|
|
40
|
+
const pascalName = pascalCase.pascalCase(model.name);
|
|
43
41
|
let contents;
|
|
44
42
|
if (options.typescript) {
|
|
45
43
|
contents = commonTags.stripIndent`
|
|
44
|
+
import { Content } from "@prismicio/client";
|
|
46
45
|
import { SliceComponentProps } from "@prismicio/react";
|
|
47
|
-
import { ${pascalID}Slice } from "./types";
|
|
48
46
|
|
|
49
47
|
/**
|
|
50
|
-
* Props for \`${
|
|
48
|
+
* Props for \`${pascalName}\`.
|
|
51
49
|
*/
|
|
52
|
-
export type ${
|
|
50
|
+
export type ${pascalName}Props = SliceComponentProps<Content.${pascalName}Slice>;
|
|
53
51
|
|
|
54
52
|
/**
|
|
55
53
|
* Component for "${model.name}" Slices.
|
|
56
54
|
*/
|
|
57
|
-
const ${
|
|
55
|
+
const ${pascalName} = ({ slice }: ${pascalName}Props): React.Element => {
|
|
58
56
|
return (
|
|
59
57
|
<section
|
|
60
58
|
data-slice-type={slice.slice_type}
|
|
@@ -65,16 +63,16 @@ const createComponentFile = async ({ dir, data, helpers, options }) => {
|
|
|
65
63
|
);
|
|
66
64
|
};
|
|
67
65
|
|
|
68
|
-
export default ${
|
|
66
|
+
export default ${pascalName}
|
|
69
67
|
`;
|
|
70
68
|
} else {
|
|
71
69
|
contents = commonTags.stripIndent`
|
|
72
70
|
/**
|
|
73
|
-
* @typedef {import("
|
|
74
|
-
* @typedef {import("@prismicio/react").SliceComponentProps<${
|
|
75
|
-
* @param {${
|
|
71
|
+
* @typedef {import("@prismicio/client").Content.${pascalName}Slice} ${pascalName}Slice
|
|
72
|
+
* @typedef {import("@prismicio/react").SliceComponentProps<${pascalName}Slice>} ${pascalName}Props
|
|
73
|
+
* @param {${pascalName}Props}
|
|
76
74
|
*/
|
|
77
|
-
const ${
|
|
75
|
+
const ${pascalName} = ({ slice }) => {
|
|
78
76
|
return (
|
|
79
77
|
<section
|
|
80
78
|
data-slice-type={slice.slice_type}
|
|
@@ -85,7 +83,7 @@ const createComponentFile = async ({ dir, data, helpers, options }) => {
|
|
|
85
83
|
);
|
|
86
84
|
};
|
|
87
85
|
|
|
88
|
-
export default ${
|
|
86
|
+
export default ${pascalName};
|
|
89
87
|
`;
|
|
90
88
|
}
|
|
91
89
|
if (options.format) {
|
|
@@ -93,18 +91,8 @@ const createComponentFile = async ({ dir, data, helpers, options }) => {
|
|
|
93
91
|
}
|
|
94
92
|
await fs__namespace.writeFile(filePath, contents);
|
|
95
93
|
};
|
|
96
|
-
const upsertSliceLibraryIndexFile = async ({ data, actions, helpers, project, options }) => {
|
|
97
|
-
const { filePath, contents } = await buildSliceLibraryIndexFileContents.buildSliceLibraryIndexFileContents({
|
|
98
|
-
libraryID: data.libraryID,
|
|
99
|
-
actions,
|
|
100
|
-
helpers,
|
|
101
|
-
project,
|
|
102
|
-
options
|
|
103
|
-
});
|
|
104
|
-
await fs__namespace.writeFile(filePath, contents);
|
|
105
|
-
};
|
|
106
94
|
const sliceCreate = async (data, context) => {
|
|
107
|
-
const dir = context.helpers.joinPathFromRoot(data.libraryID, pascalCase.pascalCase(data.model.
|
|
95
|
+
const dir = context.helpers.joinPathFromRoot(data.libraryID, pascalCase.pascalCase(data.model.name));
|
|
108
96
|
await fs__namespace.mkdir(dir, { recursive: true });
|
|
109
97
|
rejectIfNecessary.rejectIfNecessary(await Promise.allSettled([
|
|
110
98
|
createModelFile({ dir, data, ...context }),
|
|
@@ -112,7 +100,7 @@ const sliceCreate = async (data, context) => {
|
|
|
112
100
|
]));
|
|
113
101
|
rejectIfNecessary.rejectIfNecessary(await Promise.allSettled([
|
|
114
102
|
upsertGlobalContentTypes.upsertGlobalContentTypes(context),
|
|
115
|
-
upsertSliceLibraryIndexFile({ data, ...context })
|
|
103
|
+
upsertSliceLibraryIndexFile.upsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context })
|
|
116
104
|
]));
|
|
117
105
|
};
|
|
118
106
|
exports.sliceCreate = sliceCreate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice-create.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"slice-create.cjs","sources":["../../../src/hooks/slice-create.ts"],"sourcesContent":["import type {\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\nimport { pascalCase } from \"../lib/pascalCase\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertGlobalContentTypes } from \"../lib/upsertGlobalContentTypes\";\n\nimport type { PluginOptions } from \"../types\";\n\ntype Args = {\n\tdir: string;\n\tdata: SliceCreateHookData;\n} & SliceMachineContext<PluginOptions>;\n\nconst createModelFile = async ({ dir, data, helpers, options }: Args) => {\n\tconst filePath = path.join(dir, \"model.json\");\n\n\tlet contents = JSON.stringify(data.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\nconst createComponentFile = async ({ dir, data, helpers, options }: Args) => {\n\tconst filePath = path.join(dir, `index.${getJSOrTSXFileExtension(options)}`);\n\tconst model = data.model;\n\tconst pascalName = pascalCase(model.name);\n\n\tlet contents: string;\n\n\tif (options.typescript) {\n\t\tcontents = stripIndent`\n\t\t\timport { Content } from \"@prismicio/client\";\n\t\t\timport { SliceComponentProps } from \"@prismicio/react\";\n\n\t\t\t/**\n\t\t\t * Props for \\`${pascalName}\\`.\n\t\t\t */\n\t\t\texport type ${pascalName}Props = SliceComponentProps<Content.${pascalName}Slice>;\n\n\t\t\t/**\n\t\t\t * Component for \"${model.name}\" Slices.\n\t\t\t */\n\t\t\tconst ${pascalName} = ({ slice }: ${pascalName}Props): React.Element => {\n\t\t\t\treturn (\n\t\t\t\t\t<section\n\t\t\t\t\t\tdata-slice-type={slice.slice_type}\n\t\t\t\t\t\tdata-slice-variation={slice.variation}\n\t\t\t\t\t>\n\t\t\t\t\t\tPlaceholder component for ${model.id} (variation: {slice.variation}) Slices\n\t\t\t\t\t</section>\n\t\t\t\t);\n\t\t\t};\n\n\t\t\texport default ${pascalName}\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\t/**\n\t\t\t * @typedef {import(\"@prismicio/client\").Content.${pascalName}Slice} ${pascalName}Slice\n\t\t\t * @typedef {import(\"@prismicio/react\").SliceComponentProps<${pascalName}Slice>} ${pascalName}Props\n\t\t\t * @param {${pascalName}Props}\n\t\t\t */\n\t\t\tconst ${pascalName} = ({ slice }) => {\n\t\t\t\treturn (\n\t\t\t\t\t<section\n\t\t\t\t\t\tdata-slice-type={slice.slice_type}\n\t\t\t\t\t\tdata-slice-variation={slice.variation}\n\t\t\t\t\t>\n\t\t\t\t\t\tPlaceholder component for ${model.id} (variation: {slice.variation}) Slices\n\t\t\t\t\t</section>\n\t\t\t\t);\n\t\t\t};\n\n\t\t\texport default ${pascalName};\n\t\t`;\n\t}\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\nexport const sliceCreate: SliceCreateHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\tconst dir = context.helpers.joinPathFromRoot(\n\t\tdata.libraryID,\n\t\tpascalCase(data.model.name),\n\t);\n\n\tawait fs.mkdir(dir, { recursive: true });\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tcreateModelFile({ dir, data, ...context }),\n\t\t\tcreateComponentFile({ dir, data, ...context }),\n\t\t]),\n\t);\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupsertGlobalContentTypes(context),\n\t\t\tupsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context }),\n\t\t]),\n\t);\n};\n"],"names":["path","fs","getJSOrTSXFileExtension","pascalCase","stripIndent","rejectIfNecessary","upsertGlobalContentTypes","upsertSliceLibraryIndexFile"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,kBAAkB,OAAO,EAAE,KAAK,MAAM,SAAS,cAAmB;AACvE,QAAM,WAAWA,gBAAK,KAAK,KAAK,YAAY;AAE5C,MAAI,WAAW,KAAK,UAAU,KAAK,KAAK;AAExC,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAAC,cAAG,UAAU,UAAU,QAAQ;AACtC;AAEA,MAAM,sBAAsB,OAAO,EAAE,KAAK,MAAM,SAAS,cAAmB;AAC3E,QAAM,WAAWD,gBAAK,KAAK,KAAK,SAASE,gDAAwB,OAAO,GAAG;AAC3E,QAAM,QAAQ,KAAK;AACb,QAAA,aAAaC,WAAAA,WAAW,MAAM,IAAI;AAEpC,MAAA;AAEJ,MAAI,QAAQ,YAAY;AACZ,eAAAC,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA,oBAKO;AAAA;AAAA,iBAEH,iDAAiD;AAAA;AAAA;AAAA,uBAG3C,MAAM;AAAA;AAAA,WAElB,4BAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAML,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKpB;AAAA;AAAA,EAAA,OAEZ;AACK,eAAAA,WAAAA;AAAAA;AAAAA,sDAEyC,oBAAoB;AAAA,iEACT,qBAAqB;AAAA,gBACtE;AAAA;AAAA,WAEL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAMuB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKpB;AAAA;AAAA,EAElB;AAED,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAAH,cAAG,UAAU,UAAU,QAAQ;AACtC;AAEa,MAAA,cAA8C,OAC1D,MACA,YACG;AACG,QAAA,MAAM,QAAQ,QAAQ,iBAC3B,KAAK,WACLE,WAAAA,WAAW,KAAK,MAAM,IAAI,CAAC;AAG5B,QAAMF,cAAG,MAAM,KAAK,EAAE,WAAW,MAAM;AAGtCI,sCAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,gBAAgB,EAAE,KAAK,MAAM,GAAG,SAAS;AAAA,IACzC,oBAAoB,EAAE,KAAK,MAAM,GAAG,SAAS;AAAA,EAC7C,CAAA,CAAC;AAIFA,sCAAA,MAAM,QAAQ,WAAW;AAAA,IACxBC,yBAAAA,yBAAyB,OAAO;AAAA,IAChCC,wDAA4B,EAAE,WAAW,KAAK,WAAW,GAAG,SAAS;AAAA,EACrE,CAAA,CAAC;AAEJ;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { stripIndent } from "common-tags";
|
|
2
2
|
import * as fs from "node:fs/promises";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile.js";
|
|
5
5
|
import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension.js";
|
|
6
6
|
import { pascalCase } from "../lib/pascalCase.js";
|
|
7
7
|
import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
|
|
@@ -17,22 +17,22 @@ const createModelFile = async ({ dir, data, helpers, options }) => {
|
|
|
17
17
|
const createComponentFile = async ({ dir, data, helpers, options }) => {
|
|
18
18
|
const filePath = path.join(dir, `index.${getJSOrTSXFileExtension(options)}`);
|
|
19
19
|
const model = data.model;
|
|
20
|
-
const
|
|
20
|
+
const pascalName = pascalCase(model.name);
|
|
21
21
|
let contents;
|
|
22
22
|
if (options.typescript) {
|
|
23
23
|
contents = stripIndent`
|
|
24
|
+
import { Content } from "@prismicio/client";
|
|
24
25
|
import { SliceComponentProps } from "@prismicio/react";
|
|
25
|
-
import { ${pascalID}Slice } from "./types";
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Props for \`${
|
|
28
|
+
* Props for \`${pascalName}\`.
|
|
29
29
|
*/
|
|
30
|
-
export type ${
|
|
30
|
+
export type ${pascalName}Props = SliceComponentProps<Content.${pascalName}Slice>;
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Component for "${model.name}" Slices.
|
|
34
34
|
*/
|
|
35
|
-
const ${
|
|
35
|
+
const ${pascalName} = ({ slice }: ${pascalName}Props): React.Element => {
|
|
36
36
|
return (
|
|
37
37
|
<section
|
|
38
38
|
data-slice-type={slice.slice_type}
|
|
@@ -43,16 +43,16 @@ const createComponentFile = async ({ dir, data, helpers, options }) => {
|
|
|
43
43
|
);
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
export default ${
|
|
46
|
+
export default ${pascalName}
|
|
47
47
|
`;
|
|
48
48
|
} else {
|
|
49
49
|
contents = stripIndent`
|
|
50
50
|
/**
|
|
51
|
-
* @typedef {import("
|
|
52
|
-
* @typedef {import("@prismicio/react").SliceComponentProps<${
|
|
53
|
-
* @param {${
|
|
51
|
+
* @typedef {import("@prismicio/client").Content.${pascalName}Slice} ${pascalName}Slice
|
|
52
|
+
* @typedef {import("@prismicio/react").SliceComponentProps<${pascalName}Slice>} ${pascalName}Props
|
|
53
|
+
* @param {${pascalName}Props}
|
|
54
54
|
*/
|
|
55
|
-
const ${
|
|
55
|
+
const ${pascalName} = ({ slice }) => {
|
|
56
56
|
return (
|
|
57
57
|
<section
|
|
58
58
|
data-slice-type={slice.slice_type}
|
|
@@ -63,7 +63,7 @@ const createComponentFile = async ({ dir, data, helpers, options }) => {
|
|
|
63
63
|
);
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
export default ${
|
|
66
|
+
export default ${pascalName};
|
|
67
67
|
`;
|
|
68
68
|
}
|
|
69
69
|
if (options.format) {
|
|
@@ -71,18 +71,8 @@ const createComponentFile = async ({ dir, data, helpers, options }) => {
|
|
|
71
71
|
}
|
|
72
72
|
await fs.writeFile(filePath, contents);
|
|
73
73
|
};
|
|
74
|
-
const upsertSliceLibraryIndexFile = async ({ data, actions, helpers, project, options }) => {
|
|
75
|
-
const { filePath, contents } = await buildSliceLibraryIndexFileContents({
|
|
76
|
-
libraryID: data.libraryID,
|
|
77
|
-
actions,
|
|
78
|
-
helpers,
|
|
79
|
-
project,
|
|
80
|
-
options
|
|
81
|
-
});
|
|
82
|
-
await fs.writeFile(filePath, contents);
|
|
83
|
-
};
|
|
84
74
|
const sliceCreate = async (data, context) => {
|
|
85
|
-
const dir = context.helpers.joinPathFromRoot(data.libraryID, pascalCase(data.model.
|
|
75
|
+
const dir = context.helpers.joinPathFromRoot(data.libraryID, pascalCase(data.model.name));
|
|
86
76
|
await fs.mkdir(dir, { recursive: true });
|
|
87
77
|
rejectIfNecessary(await Promise.allSettled([
|
|
88
78
|
createModelFile({ dir, data, ...context }),
|
|
@@ -90,7 +80,7 @@ const sliceCreate = async (data, context) => {
|
|
|
90
80
|
]));
|
|
91
81
|
rejectIfNecessary(await Promise.allSettled([
|
|
92
82
|
upsertGlobalContentTypes(context),
|
|
93
|
-
upsertSliceLibraryIndexFile({ data, ...context })
|
|
83
|
+
upsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context })
|
|
94
84
|
]));
|
|
95
85
|
};
|
|
96
86
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice-create.js","sources":["
|
|
1
|
+
{"version":3,"file":"slice-create.js","sources":["../../../src/hooks/slice-create.ts"],"sourcesContent":["import type {\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\nimport { pascalCase } from \"../lib/pascalCase\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertGlobalContentTypes } from \"../lib/upsertGlobalContentTypes\";\n\nimport type { PluginOptions } from \"../types\";\n\ntype Args = {\n\tdir: string;\n\tdata: SliceCreateHookData;\n} & SliceMachineContext<PluginOptions>;\n\nconst createModelFile = async ({ dir, data, helpers, options }: Args) => {\n\tconst filePath = path.join(dir, \"model.json\");\n\n\tlet contents = JSON.stringify(data.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\nconst createComponentFile = async ({ dir, data, helpers, options }: Args) => {\n\tconst filePath = path.join(dir, `index.${getJSOrTSXFileExtension(options)}`);\n\tconst model = data.model;\n\tconst pascalName = pascalCase(model.name);\n\n\tlet contents: string;\n\n\tif (options.typescript) {\n\t\tcontents = stripIndent`\n\t\t\timport { Content } from \"@prismicio/client\";\n\t\t\timport { SliceComponentProps } from \"@prismicio/react\";\n\n\t\t\t/**\n\t\t\t * Props for \\`${pascalName}\\`.\n\t\t\t */\n\t\t\texport type ${pascalName}Props = SliceComponentProps<Content.${pascalName}Slice>;\n\n\t\t\t/**\n\t\t\t * Component for \"${model.name}\" Slices.\n\t\t\t */\n\t\t\tconst ${pascalName} = ({ slice }: ${pascalName}Props): React.Element => {\n\t\t\t\treturn (\n\t\t\t\t\t<section\n\t\t\t\t\t\tdata-slice-type={slice.slice_type}\n\t\t\t\t\t\tdata-slice-variation={slice.variation}\n\t\t\t\t\t>\n\t\t\t\t\t\tPlaceholder component for ${model.id} (variation: {slice.variation}) Slices\n\t\t\t\t\t</section>\n\t\t\t\t);\n\t\t\t};\n\n\t\t\texport default ${pascalName}\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\t/**\n\t\t\t * @typedef {import(\"@prismicio/client\").Content.${pascalName}Slice} ${pascalName}Slice\n\t\t\t * @typedef {import(\"@prismicio/react\").SliceComponentProps<${pascalName}Slice>} ${pascalName}Props\n\t\t\t * @param {${pascalName}Props}\n\t\t\t */\n\t\t\tconst ${pascalName} = ({ slice }) => {\n\t\t\t\treturn (\n\t\t\t\t\t<section\n\t\t\t\t\t\tdata-slice-type={slice.slice_type}\n\t\t\t\t\t\tdata-slice-variation={slice.variation}\n\t\t\t\t\t>\n\t\t\t\t\t\tPlaceholder component for ${model.id} (variation: {slice.variation}) Slices\n\t\t\t\t\t</section>\n\t\t\t\t);\n\t\t\t};\n\n\t\t\texport default ${pascalName};\n\t\t`;\n\t}\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\nexport const sliceCreate: SliceCreateHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\tconst dir = context.helpers.joinPathFromRoot(\n\t\tdata.libraryID,\n\t\tpascalCase(data.model.name),\n\t);\n\n\tawait fs.mkdir(dir, { recursive: true });\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tcreateModelFile({ dir, data, ...context }),\n\t\t\tcreateComponentFile({ dir, data, ...context }),\n\t\t]),\n\t);\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupsertGlobalContentTypes(context),\n\t\t\tupsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context }),\n\t\t]),\n\t);\n};\n"],"names":[],"mappings":";;;;;;;;AAsBA,MAAM,kBAAkB,OAAO,EAAE,KAAK,MAAM,SAAS,cAAmB;AACvE,QAAM,WAAW,KAAK,KAAK,KAAK,YAAY;AAE5C,MAAI,WAAW,KAAK,UAAU,KAAK,KAAK;AAExC,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;AAEA,MAAM,sBAAsB,OAAO,EAAE,KAAK,MAAM,SAAS,cAAmB;AAC3E,QAAM,WAAW,KAAK,KAAK,KAAK,SAAS,wBAAwB,OAAO,GAAG;AAC3E,QAAM,QAAQ,KAAK;AACb,QAAA,aAAa,WAAW,MAAM,IAAI;AAEpC,MAAA;AAEJ,MAAI,QAAQ,YAAY;AACZ,eAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKO;AAAA;AAAA,iBAEH,iDAAiD;AAAA;AAAA;AAAA,uBAG3C,MAAM;AAAA;AAAA,WAElB,4BAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAML,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKpB;AAAA;AAAA,EAAA,OAEZ;AACK,eAAA;AAAA;AAAA,sDAEyC,oBAAoB;AAAA,iEACT,qBAAqB;AAAA,gBACtE;AAAA;AAAA,WAEL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAMuB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKpB;AAAA;AAAA,EAElB;AAED,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;AAEa,MAAA,cAA8C,OAC1D,MACA,YACG;AACG,QAAA,MAAM,QAAQ,QAAQ,iBAC3B,KAAK,WACL,WAAW,KAAK,MAAM,IAAI,CAAC;AAG5B,QAAM,GAAG,MAAM,KAAK,EAAE,WAAW,MAAM;AAGtC,oBAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,gBAAgB,EAAE,KAAK,MAAM,GAAG,SAAS;AAAA,IACzC,oBAAoB,EAAE,KAAK,MAAM,GAAG,SAAS;AAAA,EAC7C,CAAA,CAAC;AAIF,oBAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,yBAAyB,OAAO;AAAA,IAChC,4BAA4B,EAAE,WAAW,KAAK,WAAW,GAAG,SAAS;AAAA,EACrE,CAAA,CAAC;AAEJ;"}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const fs = require("node:fs/promises");
|
|
4
|
-
const buildSliceLibraryIndexFileContents = require("../lib/buildSliceLibraryIndexFileContents.cjs");
|
|
5
4
|
const pascalCase = require("../lib/pascalCase.cjs");
|
|
6
5
|
const rejectIfNecessary = require("../lib/rejectIfNecessary.cjs");
|
|
7
6
|
const upsertGlobalContentTypes = require("../lib/upsertGlobalContentTypes.cjs");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return e;
|
|
7
|
+
const upsertSliceLibraryIndexFile = require("../lib/upsertSliceLibraryIndexFile.cjs");
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
11
9
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
12
10
|
if (e) {
|
|
13
11
|
for (const k in e) {
|
|
@@ -23,26 +21,16 @@ function _interopNamespace(e) {
|
|
|
23
21
|
n.default = e;
|
|
24
22
|
return Object.freeze(n);
|
|
25
23
|
}
|
|
26
|
-
const fs__namespace = /* @__PURE__ */
|
|
24
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
27
25
|
const deleteSliceDir = async ({ data, helpers }) => {
|
|
28
|
-
const dir = helpers.joinPathFromRoot(data.libraryID, pascalCase.pascalCase(data.model.
|
|
26
|
+
const dir = helpers.joinPathFromRoot(data.libraryID, pascalCase.pascalCase(data.model.name));
|
|
29
27
|
await fs__namespace.rm(dir, { recursive: true });
|
|
30
28
|
};
|
|
31
|
-
const updateSliceLibraryIndexFile = async ({ data, actions, helpers, project, options }) => {
|
|
32
|
-
const { filePath, contents } = await buildSliceLibraryIndexFileContents.buildSliceLibraryIndexFileContents({
|
|
33
|
-
libraryID: data.libraryID,
|
|
34
|
-
actions,
|
|
35
|
-
helpers,
|
|
36
|
-
project,
|
|
37
|
-
options
|
|
38
|
-
});
|
|
39
|
-
await fs__namespace.writeFile(filePath, contents);
|
|
40
|
-
};
|
|
41
29
|
const sliceDelete = async (data, context) => {
|
|
42
30
|
await deleteSliceDir({ data, ...context });
|
|
43
31
|
rejectIfNecessary.rejectIfNecessary(await Promise.allSettled([
|
|
44
32
|
upsertGlobalContentTypes.upsertGlobalContentTypes(context),
|
|
45
|
-
|
|
33
|
+
upsertSliceLibraryIndexFile.upsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context })
|
|
46
34
|
]));
|
|
47
35
|
};
|
|
48
36
|
exports.sliceDelete = sliceDelete;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice-delete.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"slice-delete.cjs","sources":["../../../src/hooks/slice-delete.ts"],"sourcesContent":["import type {\n\tSliceDeleteHook,\n\tSliceDeleteHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\n\nimport { pascalCase } from \"../lib/pascalCase\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertGlobalContentTypes } from \"../lib/upsertGlobalContentTypes\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\n\nimport type { PluginOptions } from \"../types\";\n\ntype Args = {\n\tdata: SliceDeleteHookData;\n} & SliceMachineContext<PluginOptions>;\n\nconst deleteSliceDir = async ({ data, helpers }: Args) => {\n\tconst dir = helpers.joinPathFromRoot(\n\t\tdata.libraryID,\n\t\tpascalCase(data.model.name),\n\t);\n\n\tawait fs.rm(dir, { recursive: true });\n};\n\nexport const sliceDelete: SliceDeleteHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\tawait deleteSliceDir({ data, ...context });\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupsertGlobalContentTypes(context),\n\t\t\tupsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context }),\n\t\t]),\n\t);\n};\n"],"names":["pascalCase","fs","rejectIfNecessary","upsertGlobalContentTypes","upsertSliceLibraryIndexFile"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAM,iBAAiB,OAAO,EAAE,MAAM,cAAmB;AAClD,QAAA,MAAM,QAAQ,iBACnB,KAAK,WACLA,WAAW,WAAA,KAAK,MAAM,IAAI,CAAC;AAG5B,QAAMC,cAAG,GAAG,KAAK,EAAE,WAAW,MAAM;AACrC;AAEa,MAAA,cAA8C,OAC1D,MACA,YACG;AACH,QAAM,eAAe,EAAE,MAAM,GAAG,QAAS,CAAA;AAGxCC,sCAAA,MAAM,QAAQ,WAAW;AAAA,IACxBC,yBAAAA,yBAAyB,OAAO;AAAA,IAChCC,wDAA4B,EAAE,WAAW,KAAK,WAAW,GAAG,SAAS;AAAA,EACrE,CAAA,CAAC;AAEJ;;"}
|
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
import * as fs from "node:fs/promises";
|
|
2
|
-
import { buildSliceLibraryIndexFileContents } from "../lib/buildSliceLibraryIndexFileContents.js";
|
|
3
2
|
import { pascalCase } from "../lib/pascalCase.js";
|
|
4
3
|
import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
|
|
5
4
|
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes.js";
|
|
5
|
+
import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile.js";
|
|
6
6
|
const deleteSliceDir = async ({ data, helpers }) => {
|
|
7
|
-
const dir = helpers.joinPathFromRoot(data.libraryID, pascalCase(data.model.
|
|
7
|
+
const dir = helpers.joinPathFromRoot(data.libraryID, pascalCase(data.model.name));
|
|
8
8
|
await fs.rm(dir, { recursive: true });
|
|
9
9
|
};
|
|
10
|
-
const updateSliceLibraryIndexFile = async ({ data, actions, helpers, project, options }) => {
|
|
11
|
-
const { filePath, contents } = await buildSliceLibraryIndexFileContents({
|
|
12
|
-
libraryID: data.libraryID,
|
|
13
|
-
actions,
|
|
14
|
-
helpers,
|
|
15
|
-
project,
|
|
16
|
-
options
|
|
17
|
-
});
|
|
18
|
-
await fs.writeFile(filePath, contents);
|
|
19
|
-
};
|
|
20
10
|
const sliceDelete = async (data, context) => {
|
|
21
11
|
await deleteSliceDir({ data, ...context });
|
|
22
12
|
rejectIfNecessary(await Promise.allSettled([
|
|
23
13
|
upsertGlobalContentTypes(context),
|
|
24
|
-
|
|
14
|
+
upsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context })
|
|
25
15
|
]));
|
|
26
16
|
};
|
|
27
17
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice-delete.js","sources":["
|
|
1
|
+
{"version":3,"file":"slice-delete.js","sources":["../../../src/hooks/slice-delete.ts"],"sourcesContent":["import type {\n\tSliceDeleteHook,\n\tSliceDeleteHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\n\nimport { pascalCase } from \"../lib/pascalCase\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertGlobalContentTypes } from \"../lib/upsertGlobalContentTypes\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\n\nimport type { PluginOptions } from \"../types\";\n\ntype Args = {\n\tdata: SliceDeleteHookData;\n} & SliceMachineContext<PluginOptions>;\n\nconst deleteSliceDir = async ({ data, helpers }: Args) => {\n\tconst dir = helpers.joinPathFromRoot(\n\t\tdata.libraryID,\n\t\tpascalCase(data.model.name),\n\t);\n\n\tawait fs.rm(dir, { recursive: true });\n};\n\nexport const sliceDelete: SliceDeleteHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\tawait deleteSliceDir({ data, ...context });\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupsertGlobalContentTypes(context),\n\t\t\tupsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context }),\n\t\t]),\n\t);\n};\n"],"names":[],"mappings":";;;;;AAkBA,MAAM,iBAAiB,OAAO,EAAE,MAAM,cAAmB;AAClD,QAAA,MAAM,QAAQ,iBACnB,KAAK,WACL,WAAW,KAAK,MAAM,IAAI,CAAC;AAG5B,QAAM,GAAG,GAAG,KAAK,EAAE,WAAW,MAAM;AACrC;AAEa,MAAA,cAA8C,OAC1D,MACA,YACG;AACH,QAAM,eAAe,EAAE,MAAM,GAAG,QAAS,CAAA;AAGxC,oBAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,yBAAyB,OAAO;AAAA,IAChC,4BAA4B,EAAE,WAAW,KAAK,WAAW,GAAG,SAAS;AAAA,EACrE,CAAA,CAAC;AAEJ;"}
|