@slicemachine/adapter-next 0.0.1 → 0.0.3
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 +93 -0
- package/dist/SliceSimulator.cjs.map +1 -0
- package/dist/SliceSimulator.d.ts +29 -0
- package/dist/SliceSimulator.js +74 -0
- package/dist/SliceSimulator.js.map +1 -0
- package/dist/hooks/customType-asset-delete.cjs +28 -0
- package/dist/hooks/customType-asset-delete.cjs.map +1 -0
- package/dist/hooks/customType-asset-delete.d.ts +3 -0
- package/dist/hooks/customType-asset-delete.js +9 -0
- package/dist/hooks/customType-asset-delete.js.map +1 -0
- package/dist/hooks/customType-asset-read.cjs +31 -0
- package/dist/hooks/customType-asset-read.cjs.map +1 -0
- package/dist/hooks/customType-asset-read.d.ts +3 -0
- package/dist/hooks/customType-asset-read.js +12 -0
- package/dist/hooks/customType-asset-read.js.map +1 -0
- package/dist/hooks/customType-asset-update.cjs +31 -0
- package/dist/hooks/customType-asset-update.cjs.map +1 -0
- package/dist/hooks/customType-asset-update.d.ts +3 -0
- package/dist/hooks/customType-asset-update.js +11 -0
- package/dist/hooks/customType-asset-update.js.map +1 -0
- package/dist/hooks/customType-create.cjs +41 -0
- package/dist/hooks/customType-create.cjs.map +1 -0
- package/dist/hooks/customType-create.d.ts +3 -0
- package/dist/hooks/customType-create.js +21 -0
- package/dist/hooks/customType-create.js.map +1 -0
- package/dist/hooks/customType-delete.cjs +30 -0
- package/dist/hooks/customType-delete.cjs.map +1 -0
- package/dist/hooks/customType-delete.d.ts +3 -0
- package/dist/hooks/customType-delete.js +11 -0
- package/dist/hooks/customType-delete.js.map +1 -0
- package/dist/hooks/customType-read.cjs +12 -0
- package/dist/hooks/customType-read.cjs.map +1 -0
- package/dist/hooks/customType-read.d.ts +3 -0
- package/dist/hooks/customType-read.js +12 -0
- package/dist/hooks/customType-read.js.map +1 -0
- 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 +6 -0
- package/dist/hooks/customType-update.cjs.map +1 -0
- package/dist/hooks/customType-update.d.ts +1 -0
- package/dist/hooks/customType-update.js +6 -0
- package/dist/hooks/customType-update.js.map +1 -0
- package/dist/hooks/customTypeLibrary-read.cjs +54 -0
- package/dist/hooks/customTypeLibrary-read.cjs.map +1 -0
- package/dist/hooks/customTypeLibrary-read.d.ts +3 -0
- package/dist/hooks/customTypeLibrary-read.js +34 -0
- package/dist/hooks/customTypeLibrary-read.js.map +1 -0
- package/dist/hooks/slice-asset-delete.cjs +29 -0
- package/dist/hooks/slice-asset-delete.cjs.map +1 -0
- package/dist/hooks/slice-asset-delete.d.ts +3 -0
- package/dist/hooks/slice-asset-delete.js +10 -0
- package/dist/hooks/slice-asset-delete.js.map +1 -0
- package/dist/hooks/slice-asset-read.cjs +32 -0
- package/dist/hooks/slice-asset-read.cjs.map +1 -0
- package/dist/hooks/slice-asset-read.d.ts +3 -0
- package/dist/hooks/slice-asset-read.js +13 -0
- package/dist/hooks/slice-asset-read.js.map +1 -0
- package/dist/hooks/slice-asset-update.cjs +32 -0
- package/dist/hooks/slice-asset-update.cjs.map +1 -0
- package/dist/hooks/slice-asset-update.d.ts +3 -0
- package/dist/hooks/slice-asset-update.js +12 -0
- package/dist/hooks/slice-asset-update.js.map +1 -0
- package/dist/hooks/slice-create.cjs +109 -0
- package/dist/hooks/slice-create.cjs.map +1 -0
- package/dist/hooks/slice-create.d.ts +3 -0
- package/dist/hooks/slice-create.js +89 -0
- package/dist/hooks/slice-create.js.map +1 -0
- package/dist/hooks/slice-delete.cjs +39 -0
- package/dist/hooks/slice-delete.cjs.map +1 -0
- package/dist/hooks/slice-delete.d.ts +3 -0
- package/dist/hooks/slice-delete.js +20 -0
- package/dist/hooks/slice-delete.js.map +1 -0
- package/dist/hooks/slice-read.cjs +49 -0
- package/dist/hooks/slice-read.cjs.map +1 -0
- package/dist/hooks/slice-read.d.ts +3 -0
- package/dist/hooks/slice-read.js +29 -0
- package/dist/hooks/slice-read.js.map +1 -0
- package/dist/hooks/slice-rename.cjs +45 -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 +14 -0
- package/dist/hooks/slice-update.cjs.map +1 -0
- package/dist/hooks/slice-update.d.ts +3 -0
- package/dist/hooks/slice-update.js +14 -0
- package/dist/hooks/slice-update.js.map +1 -0
- package/dist/hooks/sliceLibrary-read.cjs +50 -0
- package/dist/hooks/sliceLibrary-read.cjs.map +1 -0
- package/dist/hooks/sliceLibrary-read.d.ts +3 -0
- package/dist/hooks/sliceLibrary-read.js +30 -0
- package/dist/hooks/sliceLibrary-read.js.map +1 -0
- package/dist/hooks/sliceSimulator-setup-read.cjs +217 -0
- package/dist/hooks/sliceSimulator-setup-read.cjs.map +1 -0
- package/dist/hooks/sliceSimulator-setup-read.d.ts +3 -0
- package/dist/hooks/sliceSimulator-setup-read.js +198 -0
- package/dist/hooks/sliceSimulator-setup-read.js.map +1 -0
- package/dist/hooks/snippet-read.cjs +96 -0
- package/dist/hooks/snippet-read.cjs.map +1 -0
- package/dist/hooks/snippet-read.d.ts +3 -0
- package/dist/hooks/snippet-read.js +77 -0
- package/dist/hooks/snippet-read.js.map +1 -0
- package/dist/index.cjs +6 -698
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -45
- package/dist/index.js +6 -669
- package/dist/index.js.map +1 -1
- package/dist/lib/getJSOrTSXFileExtension.cjs +13 -0
- package/dist/lib/getJSOrTSXFileExtension.cjs.map +1 -0
- package/dist/lib/getJSOrTSXFileExtension.d.ts +2 -0
- package/dist/lib/getJSOrTSXFileExtension.js +13 -0
- package/dist/lib/getJSOrTSXFileExtension.js.map +1 -0
- package/dist/lib/isSharedSliceModel.cjs +27 -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 +8 -0
- package/dist/lib/pascalCase.cjs.map +1 -0
- package/dist/lib/pascalCase.d.ts +8 -0
- package/dist/lib/pascalCase.js +8 -0
- package/dist/lib/pascalCase.js.map +1 -0
- package/dist/lib/readJSONFile.cjs +28 -0
- package/dist/lib/readJSONFile.cjs.map +1 -0
- package/dist/lib/readJSONFile.d.ts +1 -0
- package/dist/lib/readJSONFile.js +9 -0
- package/dist/lib/readJSONFile.js.map +1 -0
- package/dist/lib/rejectIfNecessary.cjs +10 -0
- package/dist/lib/rejectIfNecessary.cjs.map +1 -0
- package/dist/lib/rejectIfNecessary.d.ts +1 -0
- package/dist/lib/rejectIfNecessary.js +10 -0
- package/dist/lib/rejectIfNecessary.js.map +1 -0
- package/dist/lib/updateSliceModelFile.cjs +33 -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 +53 -0
- package/dist/lib/upsertGlobalContentTypes.cjs.map +1 -0
- package/dist/lib/upsertGlobalContentTypes.d.ts +12 -0
- package/dist/lib/upsertGlobalContentTypes.js +33 -0
- package/dist/lib/upsertGlobalContentTypes.js.map +1 -0
- package/dist/lib/upsertSliceLibraryIndexFile.cjs +47 -0
- package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -0
- package/dist/lib/upsertSliceLibraryIndexFile.d.ts +7 -0
- package/dist/lib/upsertSliceLibraryIndexFile.js +28 -0
- package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -0
- package/dist/package.cjs +5 -0
- package/dist/package.cjs.map +1 -0
- package/dist/package.js +5 -0
- package/dist/package.js.map +1 -0
- package/dist/plugin.cjs +56 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +56 -0
- package/dist/plugin.js.map +1 -0
- package/dist/types.d.ts +9 -0
- package/package.json +28 -23
- package/src/hooks/customType-asset-delete.ts +16 -0
- package/src/hooks/customType-asset-read.ts +20 -0
- package/src/hooks/customType-asset-update.ts +18 -0
- package/src/hooks/customType-create.ts +5 -20
- package/src/hooks/customType-delete.ts +6 -2
- package/src/hooks/customType-read.ts +5 -1
- package/src/hooks/customType-rename.ts +3 -0
- package/src/hooks/{customType-library-read.ts → customTypeLibrary-read.ts} +16 -4
- package/src/hooks/slice-asset-delete.ts +19 -0
- package/src/hooks/slice-asset-read.ts +23 -0
- package/src/hooks/slice-asset-update.ts +21 -0
- package/src/hooks/slice-create.ts +27 -52
- package/src/hooks/slice-delete.ts +11 -21
- package/src/hooks/slice-read.ts +38 -8
- package/src/hooks/slice-rename.ts +44 -0
- package/src/hooks/slice-update.ts +9 -48
- package/src/hooks/sliceLibrary-read.ts +44 -0
- package/src/lib/isSharedSliceModel.ts +14 -0
- package/src/lib/rejectIfNecessary.ts +16 -0
- package/src/lib/updateSliceModelFile.ts +32 -0
- package/src/lib/upsertGlobalContentTypes.ts +59 -0
- package/src/lib/{buildSliceLibraryIndexFileContents.ts → upsertSliceLibraryIndexFile.ts} +14 -9
- package/src/plugin.ts +24 -8
- package/src/hooks/slice-library-read.ts +0 -51
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customType-update.cjs","sources":["../../src/hooks/customType-update.ts"],"sourcesContent":["import { customTypeCreate } from \"./customType-create\";\n\nexport const customTypeUpdate = customTypeCreate;\n"],"names":["customTypeCreate"],"mappings":";;;AAEO,MAAM,mBAAmBA,iBAAAA;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const customTypeUpdate: import("@slicemachine/plugin-kit").CustomTypeCreateHook<import("..").PluginOptions>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customType-update.js","sources":["../../src/hooks/customType-update.ts"],"sourcesContent":["import { customTypeCreate } from \"./customType-create\";\n\nexport const customTypeUpdate = customTypeCreate;\n"],"names":[],"mappings":";AAEO,MAAM,mBAAmB;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const fs = require("node:fs/promises");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const readJSONFile = require("../lib/readJSONFile.cjs");
|
|
6
|
+
function _interopNamespace(e) {
|
|
7
|
+
if (e && e.__esModule)
|
|
8
|
+
return e;
|
|
9
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
|
+
if (e) {
|
|
11
|
+
for (const k in e) {
|
|
12
|
+
if (k !== "default") {
|
|
13
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: () => e[k]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespace(fs);
|
|
25
|
+
const path__namespace = /* @__PURE__ */ _interopNamespace(path);
|
|
26
|
+
const isCustomTypeModel = (input) => {
|
|
27
|
+
return typeof input === "object" && input !== null && "json" in input;
|
|
28
|
+
};
|
|
29
|
+
const customTypeLibraryRead = async (_data, { helpers }) => {
|
|
30
|
+
const dirPath = helpers.joinPathFromRoot("customtypes");
|
|
31
|
+
await fs__namespace.mkdir(dirPath, { recursive: true });
|
|
32
|
+
const childDirs = await fs__namespace.readdir(dirPath);
|
|
33
|
+
const ids = [];
|
|
34
|
+
await Promise.all(childDirs.map(async (childDir) => {
|
|
35
|
+
const childDirContents = await fs__namespace.readdir(path__namespace.join(dirPath, childDir), {
|
|
36
|
+
withFileTypes: true
|
|
37
|
+
});
|
|
38
|
+
const isCustomTypeDir = childDirContents.some((entry) => {
|
|
39
|
+
return entry.isFile() && entry.name === "index.json";
|
|
40
|
+
});
|
|
41
|
+
if (isCustomTypeDir) {
|
|
42
|
+
const modelPath = path__namespace.join(dirPath, childDir, "index.json");
|
|
43
|
+
const modelContents = await readJSONFile.readJSONFile(modelPath);
|
|
44
|
+
if (isCustomTypeModel(modelContents)) {
|
|
45
|
+
ids.push(modelContents.id);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
49
|
+
return {
|
|
50
|
+
ids: ids.sort()
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
exports.customTypeLibraryRead = customTypeLibraryRead;
|
|
54
|
+
//# sourceMappingURL=customTypeLibrary-read.cjs.map
|
|
@@ -0,0 +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 { 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;;"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { readJSONFile } from "../lib/readJSONFile.js";
|
|
4
|
+
const isCustomTypeModel = (input) => {
|
|
5
|
+
return typeof input === "object" && input !== null && "json" in input;
|
|
6
|
+
};
|
|
7
|
+
const customTypeLibraryRead = async (_data, { helpers }) => {
|
|
8
|
+
const dirPath = helpers.joinPathFromRoot("customtypes");
|
|
9
|
+
await fs.mkdir(dirPath, { recursive: true });
|
|
10
|
+
const childDirs = await fs.readdir(dirPath);
|
|
11
|
+
const ids = [];
|
|
12
|
+
await Promise.all(childDirs.map(async (childDir) => {
|
|
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
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}));
|
|
27
|
+
return {
|
|
28
|
+
ids: ids.sort()
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
customTypeLibraryRead
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=customTypeLibrary-read.js.map
|
|
@@ -0,0 +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 { 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;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const fs = require("node:fs/promises");
|
|
4
|
+
const pascalCase = require("../lib/pascalCase.cjs");
|
|
5
|
+
function _interopNamespace(e) {
|
|
6
|
+
if (e && e.__esModule)
|
|
7
|
+
return e;
|
|
8
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
9
|
+
if (e) {
|
|
10
|
+
for (const k in e) {
|
|
11
|
+
if (k !== "default") {
|
|
12
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: () => e[k]
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespace(fs);
|
|
24
|
+
const sliceAssetDelete = async (data, context) => {
|
|
25
|
+
const filePath = context.helpers.joinPathFromRoot(data.libraryID, pascalCase.pascalCase(data.sliceID), data.assetID);
|
|
26
|
+
await fs__namespace.rm(filePath);
|
|
27
|
+
};
|
|
28
|
+
exports.sliceAssetDelete = sliceAssetDelete;
|
|
29
|
+
//# sourceMappingURL=slice-asset-delete.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import { pascalCase } from "../lib/pascalCase.js";
|
|
3
|
+
const sliceAssetDelete = async (data, context) => {
|
|
4
|
+
const filePath = context.helpers.joinPathFromRoot(data.libraryID, pascalCase(data.sliceID), data.assetID);
|
|
5
|
+
await fs.rm(filePath);
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
sliceAssetDelete
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=slice-asset-delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const fs = require("node:fs/promises");
|
|
4
|
+
const pascalCase = require("../lib/pascalCase.cjs");
|
|
5
|
+
function _interopNamespace(e) {
|
|
6
|
+
if (e && e.__esModule)
|
|
7
|
+
return e;
|
|
8
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
9
|
+
if (e) {
|
|
10
|
+
for (const k in e) {
|
|
11
|
+
if (k !== "default") {
|
|
12
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: () => e[k]
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespace(fs);
|
|
24
|
+
const sliceAssetRead = async (data, context) => {
|
|
25
|
+
const filePath = context.helpers.joinPathFromRoot(data.libraryID, pascalCase.pascalCase(data.sliceID), data.assetID);
|
|
26
|
+
const assetData = await fs__namespace.readFile(filePath);
|
|
27
|
+
return {
|
|
28
|
+
data: assetData
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
exports.sliceAssetRead = sliceAssetRead;
|
|
32
|
+
//# sourceMappingURL=slice-asset-read.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import { pascalCase } from "../lib/pascalCase.js";
|
|
3
|
+
const sliceAssetRead = async (data, context) => {
|
|
4
|
+
const filePath = context.helpers.joinPathFromRoot(data.libraryID, pascalCase(data.sliceID), data.assetID);
|
|
5
|
+
const assetData = await fs.readFile(filePath);
|
|
6
|
+
return {
|
|
7
|
+
data: assetData
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
sliceAssetRead
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=slice-asset-read.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const fs = require("node:fs/promises");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const pascalCase = require("../lib/pascalCase.cjs");
|
|
6
|
+
function _interopNamespace(e) {
|
|
7
|
+
if (e && e.__esModule)
|
|
8
|
+
return e;
|
|
9
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
|
+
if (e) {
|
|
11
|
+
for (const k in e) {
|
|
12
|
+
if (k !== "default") {
|
|
13
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: () => e[k]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespace(fs);
|
|
25
|
+
const path__namespace = /* @__PURE__ */ _interopNamespace(path);
|
|
26
|
+
const sliceAssetUpdate = async (data, context) => {
|
|
27
|
+
const filePath = context.helpers.joinPathFromRoot(data.libraryID, pascalCase.pascalCase(data.sliceID), data.asset.id);
|
|
28
|
+
await fs__namespace.mkdir(path__namespace.dirname(filePath), { recursive: true });
|
|
29
|
+
await fs__namespace.writeFile(filePath, data.asset.data);
|
|
30
|
+
};
|
|
31
|
+
exports.sliceAssetUpdate = sliceAssetUpdate;
|
|
32
|
+
//# sourceMappingURL=slice-asset-update.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { pascalCase } from "../lib/pascalCase.js";
|
|
4
|
+
const sliceAssetUpdate = async (data, context) => {
|
|
5
|
+
const filePath = context.helpers.joinPathFromRoot(data.libraryID, pascalCase(data.sliceID), data.asset.id);
|
|
6
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
7
|
+
await fs.writeFile(filePath, data.asset.data);
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
sliceAssetUpdate
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=slice-asset-update.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const commonTags = require("common-tags");
|
|
4
|
+
const fs = require("node:fs/promises");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
const upsertSliceLibraryIndexFile = require("../lib/upsertSliceLibraryIndexFile.cjs");
|
|
7
|
+
const getJSOrTSXFileExtension = require("../lib/getJSOrTSXFileExtension.cjs");
|
|
8
|
+
const pascalCase = require("../lib/pascalCase.cjs");
|
|
9
|
+
const rejectIfNecessary = require("../lib/rejectIfNecessary.cjs");
|
|
10
|
+
const upsertGlobalContentTypes = require("../lib/upsertGlobalContentTypes.cjs");
|
|
11
|
+
function _interopNamespace(e) {
|
|
12
|
+
if (e && e.__esModule)
|
|
13
|
+
return e;
|
|
14
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
15
|
+
if (e) {
|
|
16
|
+
for (const k in e) {
|
|
17
|
+
if (k !== "default") {
|
|
18
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: () => e[k]
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
n.default = e;
|
|
27
|
+
return Object.freeze(n);
|
|
28
|
+
}
|
|
29
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespace(fs);
|
|
30
|
+
const path__namespace = /* @__PURE__ */ _interopNamespace(path);
|
|
31
|
+
const createModelFile = async ({ dir, data, helpers, options }) => {
|
|
32
|
+
const filePath = path__namespace.join(dir, "model.json");
|
|
33
|
+
let contents = JSON.stringify(data.model);
|
|
34
|
+
if (options.format) {
|
|
35
|
+
contents = await helpers.format(contents, filePath);
|
|
36
|
+
}
|
|
37
|
+
await fs__namespace.writeFile(filePath, contents);
|
|
38
|
+
};
|
|
39
|
+
const createComponentFile = async ({ dir, data, helpers, options }) => {
|
|
40
|
+
const filePath = path__namespace.join(dir, `index.${getJSOrTSXFileExtension.getJSOrTSXFileExtension(options)}`);
|
|
41
|
+
const model = data.model;
|
|
42
|
+
const pascalName = pascalCase.pascalCase(model.name);
|
|
43
|
+
let contents;
|
|
44
|
+
if (options.typescript) {
|
|
45
|
+
contents = commonTags.stripIndent`
|
|
46
|
+
import { SliceComponentProps } from "@prismicio/react";
|
|
47
|
+
import { ${pascalName}Slice } from "./types";
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Props for \`${pascalName}\`.
|
|
51
|
+
*/
|
|
52
|
+
export type ${pascalName}Props = SliceComponentProps<${pascalName}Slice>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Component for "${model.name}" Slices.
|
|
56
|
+
*/
|
|
57
|
+
const ${pascalName} = ({ slice }: ${pascalName}Props): React.Element => {
|
|
58
|
+
return (
|
|
59
|
+
<section
|
|
60
|
+
data-slice-type={slice.slice_type}
|
|
61
|
+
data-slice-variation={slice.variation}
|
|
62
|
+
>
|
|
63
|
+
Placeholder component for ${model.id} (variation: {slice.variation}) Slices
|
|
64
|
+
</section>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export default ${pascalName}
|
|
69
|
+
`;
|
|
70
|
+
} else {
|
|
71
|
+
contents = commonTags.stripIndent`
|
|
72
|
+
/**
|
|
73
|
+
* @typedef {import("./types").${pascalName}Slice} ${pascalName}Slice
|
|
74
|
+
* @typedef {import("@prismicio/react").SliceComponentProps<${pascalName}Slice>} ${pascalName}Props
|
|
75
|
+
* @param {${pascalName}Props}
|
|
76
|
+
*/
|
|
77
|
+
const ${pascalName} = ({ slice }) => {
|
|
78
|
+
return (
|
|
79
|
+
<section
|
|
80
|
+
data-slice-type={slice.slice_type}
|
|
81
|
+
data-slice-variation={slice.variation}
|
|
82
|
+
>
|
|
83
|
+
Placeholder component for ${model.id} (variation: {slice.variation}) Slices
|
|
84
|
+
</section>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default ${pascalName};
|
|
89
|
+
`;
|
|
90
|
+
}
|
|
91
|
+
if (options.format) {
|
|
92
|
+
contents = await helpers.format(contents, filePath);
|
|
93
|
+
}
|
|
94
|
+
await fs__namespace.writeFile(filePath, contents);
|
|
95
|
+
};
|
|
96
|
+
const sliceCreate = async (data, context) => {
|
|
97
|
+
const dir = context.helpers.joinPathFromRoot(data.libraryID, pascalCase.pascalCase(data.model.name));
|
|
98
|
+
await fs__namespace.mkdir(dir, { recursive: true });
|
|
99
|
+
rejectIfNecessary.rejectIfNecessary(await Promise.allSettled([
|
|
100
|
+
createModelFile({ dir, data, ...context }),
|
|
101
|
+
createComponentFile({ dir, data, ...context })
|
|
102
|
+
]));
|
|
103
|
+
rejectIfNecessary.rejectIfNecessary(await Promise.allSettled([
|
|
104
|
+
upsertGlobalContentTypes.upsertGlobalContentTypes(context),
|
|
105
|
+
upsertSliceLibraryIndexFile.upsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context })
|
|
106
|
+
]));
|
|
107
|
+
};
|
|
108
|
+
exports.sliceCreate = sliceCreate;
|
|
109
|
+
//# sourceMappingURL=slice-create.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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 { SliceComponentProps } from \"@prismicio/react\";\n\t\t\timport { ${pascalName}Slice } from \"./types\";\n\n\t\t\t/**\n\t\t\t * Props for \\`${pascalName}\\`.\n\t\t\t */\n\t\t\texport type ${pascalName}Props = SliceComponentProps<${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(\"./types\").${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,cAEC;AAAA;AAAA;AAAA,oBAGM;AAAA;AAAA,iBAEH,yCAAyC;AAAA;AAAA;AAAA,uBAGnC,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,oCAEuB,oBAAoB;AAAA,iEACS,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;;"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { stripIndent } from "common-tags";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile.js";
|
|
5
|
+
import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension.js";
|
|
6
|
+
import { pascalCase } from "../lib/pascalCase.js";
|
|
7
|
+
import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
|
|
8
|
+
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes.js";
|
|
9
|
+
const createModelFile = async ({ dir, data, helpers, options }) => {
|
|
10
|
+
const filePath = path.join(dir, "model.json");
|
|
11
|
+
let contents = JSON.stringify(data.model);
|
|
12
|
+
if (options.format) {
|
|
13
|
+
contents = await helpers.format(contents, filePath);
|
|
14
|
+
}
|
|
15
|
+
await fs.writeFile(filePath, contents);
|
|
16
|
+
};
|
|
17
|
+
const createComponentFile = async ({ dir, data, helpers, options }) => {
|
|
18
|
+
const filePath = path.join(dir, `index.${getJSOrTSXFileExtension(options)}`);
|
|
19
|
+
const model = data.model;
|
|
20
|
+
const pascalName = pascalCase(model.name);
|
|
21
|
+
let contents;
|
|
22
|
+
if (options.typescript) {
|
|
23
|
+
contents = stripIndent`
|
|
24
|
+
import { SliceComponentProps } from "@prismicio/react";
|
|
25
|
+
import { ${pascalName}Slice } from "./types";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Props for \`${pascalName}\`.
|
|
29
|
+
*/
|
|
30
|
+
export type ${pascalName}Props = SliceComponentProps<${pascalName}Slice>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Component for "${model.name}" Slices.
|
|
34
|
+
*/
|
|
35
|
+
const ${pascalName} = ({ slice }: ${pascalName}Props): React.Element => {
|
|
36
|
+
return (
|
|
37
|
+
<section
|
|
38
|
+
data-slice-type={slice.slice_type}
|
|
39
|
+
data-slice-variation={slice.variation}
|
|
40
|
+
>
|
|
41
|
+
Placeholder component for ${model.id} (variation: {slice.variation}) Slices
|
|
42
|
+
</section>
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default ${pascalName}
|
|
47
|
+
`;
|
|
48
|
+
} else {
|
|
49
|
+
contents = stripIndent`
|
|
50
|
+
/**
|
|
51
|
+
* @typedef {import("./types").${pascalName}Slice} ${pascalName}Slice
|
|
52
|
+
* @typedef {import("@prismicio/react").SliceComponentProps<${pascalName}Slice>} ${pascalName}Props
|
|
53
|
+
* @param {${pascalName}Props}
|
|
54
|
+
*/
|
|
55
|
+
const ${pascalName} = ({ slice }) => {
|
|
56
|
+
return (
|
|
57
|
+
<section
|
|
58
|
+
data-slice-type={slice.slice_type}
|
|
59
|
+
data-slice-variation={slice.variation}
|
|
60
|
+
>
|
|
61
|
+
Placeholder component for ${model.id} (variation: {slice.variation}) Slices
|
|
62
|
+
</section>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export default ${pascalName};
|
|
67
|
+
`;
|
|
68
|
+
}
|
|
69
|
+
if (options.format) {
|
|
70
|
+
contents = await helpers.format(contents, filePath);
|
|
71
|
+
}
|
|
72
|
+
await fs.writeFile(filePath, contents);
|
|
73
|
+
};
|
|
74
|
+
const sliceCreate = async (data, context) => {
|
|
75
|
+
const dir = context.helpers.joinPathFromRoot(data.libraryID, pascalCase(data.model.name));
|
|
76
|
+
await fs.mkdir(dir, { recursive: true });
|
|
77
|
+
rejectIfNecessary(await Promise.allSettled([
|
|
78
|
+
createModelFile({ dir, data, ...context }),
|
|
79
|
+
createComponentFile({ dir, data, ...context })
|
|
80
|
+
]));
|
|
81
|
+
rejectIfNecessary(await Promise.allSettled([
|
|
82
|
+
upsertGlobalContentTypes(context),
|
|
83
|
+
upsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context })
|
|
84
|
+
]));
|
|
85
|
+
};
|
|
86
|
+
export {
|
|
87
|
+
sliceCreate
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=slice-create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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 { SliceComponentProps } from \"@prismicio/react\";\n\t\t\timport { ${pascalName}Slice } from \"./types\";\n\n\t\t\t/**\n\t\t\t * Props for \\`${pascalName}\\`.\n\t\t\t */\n\t\t\texport type ${pascalName}Props = SliceComponentProps<${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(\"./types\").${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,cAEC;AAAA;AAAA;AAAA,oBAGM;AAAA;AAAA,iBAEH,yCAAyC;AAAA;AAAA;AAAA,uBAGnC,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,oCAEuB,oBAAoB;AAAA,iEACS,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;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const fs = require("node:fs/promises");
|
|
4
|
+
const pascalCase = require("../lib/pascalCase.cjs");
|
|
5
|
+
const rejectIfNecessary = require("../lib/rejectIfNecessary.cjs");
|
|
6
|
+
const upsertGlobalContentTypes = require("../lib/upsertGlobalContentTypes.cjs");
|
|
7
|
+
const upsertSliceLibraryIndexFile = require("../lib/upsertSliceLibraryIndexFile.cjs");
|
|
8
|
+
function _interopNamespace(e) {
|
|
9
|
+
if (e && e.__esModule)
|
|
10
|
+
return e;
|
|
11
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
12
|
+
if (e) {
|
|
13
|
+
for (const k in e) {
|
|
14
|
+
if (k !== "default") {
|
|
15
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: () => e[k]
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
n.default = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespace(fs);
|
|
27
|
+
const deleteSliceDir = async ({ data, helpers }) => {
|
|
28
|
+
const dir = helpers.joinPathFromRoot(data.libraryID, pascalCase.pascalCase(data.model.name));
|
|
29
|
+
await fs__namespace.rm(dir, { recursive: true });
|
|
30
|
+
};
|
|
31
|
+
const sliceDelete = async (data, context) => {
|
|
32
|
+
await deleteSliceDir({ data, ...context });
|
|
33
|
+
rejectIfNecessary.rejectIfNecessary(await Promise.allSettled([
|
|
34
|
+
upsertGlobalContentTypes.upsertGlobalContentTypes(context),
|
|
35
|
+
upsertSliceLibraryIndexFile.upsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context })
|
|
36
|
+
]));
|
|
37
|
+
};
|
|
38
|
+
exports.sliceDelete = sliceDelete;
|
|
39
|
+
//# sourceMappingURL=slice-delete.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import { pascalCase } from "../lib/pascalCase.js";
|
|
3
|
+
import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
|
|
4
|
+
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes.js";
|
|
5
|
+
import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile.js";
|
|
6
|
+
const deleteSliceDir = async ({ data, helpers }) => {
|
|
7
|
+
const dir = helpers.joinPathFromRoot(data.libraryID, pascalCase(data.model.name));
|
|
8
|
+
await fs.rm(dir, { recursive: true });
|
|
9
|
+
};
|
|
10
|
+
const sliceDelete = async (data, context) => {
|
|
11
|
+
await deleteSliceDir({ data, ...context });
|
|
12
|
+
rejectIfNecessary(await Promise.allSettled([
|
|
13
|
+
upsertGlobalContentTypes(context),
|
|
14
|
+
upsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context })
|
|
15
|
+
]));
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
sliceDelete
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=slice-delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;"}
|