@slicemachine/adapter-nuxt 0.3.10-dev-next-release.10 → 0.3.10-dev-next-release.11
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/hooks/project-init.cjs +26 -29
- package/dist/hooks/project-init.cjs.map +1 -1
- package/dist/hooks/project-init.js +26 -28
- package/dist/hooks/project-init.js.map +1 -1
- package/dist/hooks/slice-create.cjs +28 -46
- package/dist/hooks/slice-create.cjs.map +1 -1
- package/dist/hooks/slice-create.js +28 -28
- package/dist/hooks/slice-create.js.map +1 -1
- package/dist/lib/checkHasSrcDirectory.cjs +5 -2
- package/dist/lib/checkHasSrcDirectory.cjs.map +1 -1
- package/dist/lib/checkHasSrcDirectory.js +5 -2
- package/dist/lib/checkHasSrcDirectory.js.map +1 -1
- package/dist/lib/checkIsTypeScriptProject.cjs +2 -3
- package/dist/lib/checkIsTypeScriptProject.cjs.map +1 -1
- package/dist/lib/checkIsTypeScriptProject.js +2 -3
- package/dist/lib/checkIsTypeScriptProject.js.map +1 -1
- package/dist/lib/getJSFileExtension.cjs +12 -0
- package/dist/lib/getJSFileExtension.cjs.map +1 -0
- package/dist/lib/getJSFileExtension.d.ts +5 -0
- package/dist/lib/getJSFileExtension.js +12 -0
- package/dist/lib/getJSFileExtension.js.map +1 -0
- package/dist/lib/upsertSliceLibraryIndexFile.cjs +30 -22
- package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.js +30 -21
- package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -1
- package/dist/plugin.cjs +178 -36
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +178 -36
- package/dist/plugin.js.map +1 -1
- package/dist/types.d.ts +22 -0
- package/package.json +3 -5
- package/src/hooks/project-init.ts +32 -36
- package/src/hooks/slice-create.ts +39 -34
- package/src/lib/checkHasSrcDirectory.ts +5 -2
- package/src/lib/checkIsTypeScriptProject.ts +5 -4
- package/src/lib/getJSFileExtension.ts +22 -0
- package/src/lib/upsertSliceLibraryIndexFile.ts +55 -36
- package/src/plugin.ts +247 -37
- package/src/types.ts +25 -0
- package/dist/hooks/customType-asset-delete.cjs +0 -31
- package/dist/hooks/customType-asset-delete.cjs.map +0 -1
- package/dist/hooks/customType-asset-delete.d.ts +0 -3
- package/dist/hooks/customType-asset-delete.js +0 -14
- package/dist/hooks/customType-asset-delete.js.map +0 -1
- package/dist/hooks/customType-asset-read.cjs +0 -34
- package/dist/hooks/customType-asset-read.cjs.map +0 -1
- package/dist/hooks/customType-asset-read.d.ts +0 -3
- package/dist/hooks/customType-asset-read.js +0 -17
- package/dist/hooks/customType-asset-read.js.map +0 -1
- package/dist/hooks/customType-asset-update.cjs +0 -34
- package/dist/hooks/customType-asset-update.cjs.map +0 -1
- package/dist/hooks/customType-asset-update.d.ts +0 -3
- package/dist/hooks/customType-asset-update.js +0 -16
- package/dist/hooks/customType-asset-update.js.map +0 -1
- package/dist/hooks/customType-create.cjs +0 -43
- package/dist/hooks/customType-create.cjs.map +0 -1
- package/dist/hooks/customType-create.d.ts +0 -3
- package/dist/hooks/customType-create.js +0 -25
- package/dist/hooks/customType-create.js.map +0 -1
- package/dist/hooks/customType-delete.cjs +0 -32
- package/dist/hooks/customType-delete.cjs.map +0 -1
- package/dist/hooks/customType-delete.d.ts +0 -3
- package/dist/hooks/customType-delete.js +0 -15
- package/dist/hooks/customType-delete.js.map +0 -1
- package/dist/hooks/customType-read.cjs +0 -31
- package/dist/hooks/customType-read.cjs.map +0 -1
- package/dist/hooks/customType-read.d.ts +0 -3
- package/dist/hooks/customType-read.js +0 -14
- package/dist/hooks/customType-read.js.map +0 -1
- package/dist/hooks/customType-rename.cjs +0 -6
- package/dist/hooks/customType-rename.cjs.map +0 -1
- package/dist/hooks/customType-rename.d.ts +0 -1
- package/dist/hooks/customType-rename.js +0 -6
- package/dist/hooks/customType-rename.js.map +0 -1
- package/dist/hooks/customType-update.cjs +0 -6
- package/dist/hooks/customType-update.cjs.map +0 -1
- package/dist/hooks/customType-update.d.ts +0 -1
- package/dist/hooks/customType-update.js +0 -6
- package/dist/hooks/customType-update.js.map +0 -1
- package/dist/hooks/customTypeLibrary-read.cjs +0 -55
- package/dist/hooks/customTypeLibrary-read.cjs.map +0 -1
- package/dist/hooks/customTypeLibrary-read.d.ts +0 -3
- package/dist/hooks/customTypeLibrary-read.js +0 -37
- package/dist/hooks/customTypeLibrary-read.js.map +0 -1
- package/dist/hooks/slice-asset-delete.cjs +0 -33
- package/dist/hooks/slice-asset-delete.cjs.map +0 -1
- package/dist/hooks/slice-asset-delete.d.ts +0 -3
- package/dist/hooks/slice-asset-delete.js +0 -16
- package/dist/hooks/slice-asset-delete.js.map +0 -1
- package/dist/hooks/slice-asset-read.cjs +0 -36
- package/dist/hooks/slice-asset-read.cjs.map +0 -1
- package/dist/hooks/slice-asset-read.d.ts +0 -3
- package/dist/hooks/slice-asset-read.js +0 -19
- package/dist/hooks/slice-asset-read.js.map +0 -1
- package/dist/hooks/slice-asset-update.cjs +0 -36
- package/dist/hooks/slice-asset-update.cjs.map +0 -1
- package/dist/hooks/slice-asset-update.d.ts +0 -3
- package/dist/hooks/slice-asset-update.js +0 -18
- package/dist/hooks/slice-asset-update.js.map +0 -1
- package/dist/hooks/slice-delete.cjs +0 -41
- package/dist/hooks/slice-delete.cjs.map +0 -1
- package/dist/hooks/slice-delete.d.ts +0 -3
- package/dist/hooks/slice-delete.js +0 -24
- package/dist/hooks/slice-delete.js.map +0 -1
- package/dist/hooks/slice-read.cjs +0 -62
- package/dist/hooks/slice-read.cjs.map +0 -1
- package/dist/hooks/slice-read.d.ts +0 -3
- package/dist/hooks/slice-read.js +0 -44
- package/dist/hooks/slice-read.js.map +0 -1
- package/dist/hooks/slice-rename.cjs +0 -51
- package/dist/hooks/slice-rename.cjs.map +0 -1
- package/dist/hooks/slice-rename.d.ts +0 -3
- package/dist/hooks/slice-rename.js +0 -34
- package/dist/hooks/slice-rename.js.map +0 -1
- package/dist/hooks/slice-update.cjs +0 -14
- package/dist/hooks/slice-update.cjs.map +0 -1
- package/dist/hooks/slice-update.d.ts +0 -3
- package/dist/hooks/slice-update.js +0 -14
- package/dist/hooks/slice-update.js.map +0 -1
- package/dist/hooks/sliceLibrary-read.cjs +0 -52
- package/dist/hooks/sliceLibrary-read.cjs.map +0 -1
- package/dist/hooks/sliceLibrary-read.d.ts +0 -3
- package/dist/hooks/sliceLibrary-read.js +0 -34
- package/dist/hooks/sliceLibrary-read.js.map +0 -1
- package/dist/lib/buildCustomTypeAssetPath.cjs +0 -29
- package/dist/lib/buildCustomTypeAssetPath.cjs.map +0 -1
- package/dist/lib/buildCustomTypeAssetPath.d.ts +0 -9
- package/dist/lib/buildCustomTypeAssetPath.js +0 -12
- package/dist/lib/buildCustomTypeAssetPath.js.map +0 -1
- package/dist/lib/buildCustomTypeDirectoryPath.cjs +0 -26
- package/dist/lib/buildCustomTypeDirectoryPath.cjs.map +0 -1
- package/dist/lib/buildCustomTypeDirectoryPath.d.ts +0 -8
- package/dist/lib/buildCustomTypeDirectoryPath.js +0 -9
- package/dist/lib/buildCustomTypeDirectoryPath.js.map +0 -1
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.cjs +0 -7
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.cjs.map +0 -1
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.d.ts +0 -7
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.js +0 -7
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.js.map +0 -1
- package/dist/lib/buildSliceAssetPath.cjs +0 -34
- package/dist/lib/buildSliceAssetPath.cjs.map +0 -1
- package/dist/lib/buildSliceAssetPath.d.ts +0 -11
- package/dist/lib/buildSliceAssetPath.js +0 -17
- package/dist/lib/buildSliceAssetPath.js.map +0 -1
- package/dist/lib/buildSliceDirectoryPath.cjs +0 -30
- package/dist/lib/buildSliceDirectoryPath.cjs.map +0 -1
- package/dist/lib/buildSliceDirectoryPath.d.ts +0 -10
- package/dist/lib/buildSliceDirectoryPath.js +0 -13
- package/dist/lib/buildSliceDirectoryPath.js.map +0 -1
- package/dist/lib/buildSliceLibraryDirectoryPath.cjs +0 -7
- package/dist/lib/buildSliceLibraryDirectoryPath.cjs.map +0 -1
- package/dist/lib/buildSliceLibraryDirectoryPath.d.ts +0 -8
- package/dist/lib/buildSliceLibraryDirectoryPath.js +0 -7
- package/dist/lib/buildSliceLibraryDirectoryPath.js.map +0 -1
- package/dist/lib/checkPathExists.cjs +0 -30
- package/dist/lib/checkPathExists.cjs.map +0 -1
- package/dist/lib/checkPathExists.d.ts +0 -2
- package/dist/lib/checkPathExists.js +0 -13
- package/dist/lib/checkPathExists.js.map +0 -1
- package/dist/lib/isSharedSliceModel.cjs +0 -7
- package/dist/lib/isSharedSliceModel.cjs.map +0 -1
- package/dist/lib/isSharedSliceModel.d.ts +0 -335
- package/dist/lib/isSharedSliceModel.js +0 -7
- package/dist/lib/isSharedSliceModel.js.map +0 -1
- package/dist/lib/readJSONFile.cjs +0 -26
- package/dist/lib/readJSONFile.cjs.map +0 -1
- package/dist/lib/readJSONFile.d.ts +0 -1
- package/dist/lib/readJSONFile.js +0 -9
- package/dist/lib/readJSONFile.js.map +0 -1
- package/dist/lib/updateSliceModelFile.cjs +0 -33
- package/dist/lib/updateSliceModelFile.cjs.map +0 -1
- package/dist/lib/updateSliceModelFile.d.ts +0 -9
- package/dist/lib/updateSliceModelFile.js +0 -15
- package/dist/lib/updateSliceModelFile.js.map +0 -1
- package/dist/lib/upsertGlobalContentTypes.cjs +0 -56
- package/dist/lib/upsertGlobalContentTypes.cjs.map +0 -1
- package/dist/lib/upsertGlobalContentTypes.d.ts +0 -12
- package/dist/lib/upsertGlobalContentTypes.js +0 -38
- package/dist/lib/upsertGlobalContentTypes.js.map +0 -1
- package/src/hooks/customType-asset-delete.ts +0 -18
- package/src/hooks/customType-asset-read.ts +0 -22
- package/src/hooks/customType-asset-update.ts +0 -20
- package/src/hooks/customType-create.ts +0 -45
- package/src/hooks/customType-delete.ts +0 -21
- package/src/hooks/customType-read.ts +0 -24
- package/src/hooks/customType-rename.ts +0 -3
- package/src/hooks/customType-update.ts +0 -3
- package/src/hooks/customTypeLibrary-read.ts +0 -58
- package/src/hooks/slice-asset-delete.ts +0 -21
- package/src/hooks/slice-asset-read.ts +0 -25
- package/src/hooks/slice-asset-update.ts +0 -23
- package/src/hooks/slice-delete.ts +0 -41
- package/src/hooks/slice-read.ts +0 -69
- package/src/hooks/slice-rename.ts +0 -46
- package/src/hooks/slice-update.ts +0 -19
- package/src/hooks/sliceLibrary-read.ts +0 -48
- package/src/lib/buildCustomTypeAssetPath.ts +0 -24
- package/src/lib/buildCustomTypeDirectoryPath.ts +0 -20
- package/src/lib/buildCustomTypeLibraryDirectoryPath.ts +0 -13
- package/src/lib/buildSliceAssetPath.ts +0 -32
- package/src/lib/buildSliceDirectoryPath.ts +0 -26
- package/src/lib/buildSliceLibraryDirectoryPath.ts +0 -14
- package/src/lib/checkPathExists.ts +0 -12
- package/src/lib/isSharedSliceModel.ts +0 -14
- package/src/lib/readJSONFile.ts +0 -7
- package/src/lib/updateSliceModelFile.ts +0 -33
- package/src/lib/upsertGlobalContentTypes.ts +0 -61
package/dist/lib/readJSONFile.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"readJSONFile.js","sources":["../../../src/lib/readJSONFile.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\n\nexport const readJSONFile = async <T = unknown>(path: string): Promise<T> => {\n\tconst contents = await fs.readFile(path, \"utf8\");\n\n\treturn JSON.parse(contents);\n};\n"],"names":[],"mappings":";AAEa,MAAA,eAAe,OAAoB,SAA4B;AAC3E,QAAM,WAAW,MAAM,GAAG,SAAS,MAAM,MAAM;AAExC,SAAA,KAAK,MAAM,QAAQ;AAC3B;"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const fs = require("node:fs/promises");
|
|
4
|
-
const path = require("node:path");
|
|
5
|
-
const buildSliceDirectoryPath = require("./buildSliceDirectoryPath.cjs");
|
|
6
|
-
function _interopNamespaceDefault(e) {
|
|
7
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
|
-
if (e) {
|
|
9
|
-
for (const k in e) {
|
|
10
|
-
if (k !== "default") {
|
|
11
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: () => e[k]
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
n.default = e;
|
|
20
|
-
return Object.freeze(n);
|
|
21
|
-
}
|
|
22
|
-
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
23
|
-
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
24
|
-
const updateSliceModelFile = async ({ libraryID, model, helpers, options }) => {
|
|
25
|
-
const filePath = path__namespace.join(buildSliceDirectoryPath.buildSliceDirectoryPath({ libraryID, model, helpers }), "model.json");
|
|
26
|
-
let contents = JSON.stringify(model);
|
|
27
|
-
if (options.format) {
|
|
28
|
-
contents = await helpers.format(contents, filePath);
|
|
29
|
-
}
|
|
30
|
-
await fs__namespace.writeFile(filePath, contents);
|
|
31
|
-
};
|
|
32
|
-
exports.updateSliceModelFile = updateSliceModelFile;
|
|
33
|
-
//# sourceMappingURL=updateSliceModelFile.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateSliceModelFile.cjs","sources":["../../../src/lib/updateSliceModelFile.ts"],"sourcesContent":["import type { SharedSlice } from \"@prismicio/types-internal/lib/customtypes\";\nimport { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\n\nimport { buildSliceDirectoryPath } from \"./buildSliceDirectoryPath\";\n\ntype UpdateSliceModelFileArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n} & SliceMachineContext<PluginOptions>;\n\nexport const updateSliceModelFile = async ({\n\tlibraryID,\n\tmodel,\n\thelpers,\n\toptions,\n}: UpdateSliceModelFileArgs): Promise<void> => {\n\tconst filePath = path.join(\n\t\tbuildSliceDirectoryPath({ libraryID, model, helpers }),\n\t\t\"model.json\",\n\t);\n\n\tlet contents = JSON.stringify(model);\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":["path","buildSliceDirectoryPath","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAcO,MAAM,uBAAuB,OAAO,EAC1C,WACA,OACA,SACA,cAC6C;AACvC,QAAA,WAAWA,gBAAK,KACrBC,gDAAwB,EAAE,WAAW,OAAO,QAAA,CAAS,GACrD,YAAY;AAGT,MAAA,WAAW,KAAK,UAAU,KAAK;AAEnC,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAAC,cAAG,UAAU,UAAU,QAAQ;AACtC;;"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
-
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
3
|
-
import type { PluginOptions } from "../types";
|
|
4
|
-
type UpdateSliceModelFileArgs = {
|
|
5
|
-
libraryID: string;
|
|
6
|
-
model: SharedSlice;
|
|
7
|
-
} & SliceMachineContext<PluginOptions>;
|
|
8
|
-
export declare const updateSliceModelFile: ({ libraryID, model, helpers, options, }: UpdateSliceModelFileArgs) => Promise<void>;
|
|
9
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs/promises";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import { buildSliceDirectoryPath } from "./buildSliceDirectoryPath.js";
|
|
4
|
-
const updateSliceModelFile = async ({ libraryID, model, helpers, options }) => {
|
|
5
|
-
const filePath = path.join(buildSliceDirectoryPath({ libraryID, model, helpers }), "model.json");
|
|
6
|
-
let contents = JSON.stringify(model);
|
|
7
|
-
if (options.format) {
|
|
8
|
-
contents = await helpers.format(contents, filePath);
|
|
9
|
-
}
|
|
10
|
-
await fs.writeFile(filePath, contents);
|
|
11
|
-
};
|
|
12
|
-
export {
|
|
13
|
-
updateSliceModelFile
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=updateSliceModelFile.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateSliceModelFile.js","sources":["../../../src/lib/updateSliceModelFile.ts"],"sourcesContent":["import type { SharedSlice } from \"@prismicio/types-internal/lib/customtypes\";\nimport { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\n\nimport { buildSliceDirectoryPath } from \"./buildSliceDirectoryPath\";\n\ntype UpdateSliceModelFileArgs = {\n\tlibraryID: string;\n\tmodel: SharedSlice;\n} & SliceMachineContext<PluginOptions>;\n\nexport const updateSliceModelFile = async ({\n\tlibraryID,\n\tmodel,\n\thelpers,\n\toptions,\n}: UpdateSliceModelFileArgs): Promise<void> => {\n\tconst filePath = path.join(\n\t\tbuildSliceDirectoryPath({ libraryID, model, helpers }),\n\t\t\"model.json\",\n\t);\n\n\tlet contents = JSON.stringify(model);\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":[],"mappings":";;;AAcO,MAAM,uBAAuB,OAAO,EAC1C,WACA,OACA,SACA,cAC6C;AACvC,QAAA,WAAW,KAAK,KACrB,wBAAwB,EAAE,WAAW,OAAO,QAAA,CAAS,GACrD,YAAY;AAGT,MAAA,WAAW,KAAK,UAAU,KAAK;AAEnC,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const prismicTsCodegen = require("prismic-ts-codegen");
|
|
4
|
-
const fs = require("node:fs/promises");
|
|
5
|
-
const path = require("node:path");
|
|
6
|
-
const constants = require("../constants.cjs");
|
|
7
|
-
function _interopNamespaceDefault(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__ */ _interopNamespaceDefault(fs);
|
|
24
|
-
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
25
|
-
const upsertGlobalContentTypes = async ({ actions, helpers, options, project }) => {
|
|
26
|
-
const filePath = helpers.joinPathFromRoot("prismicio-types.d.ts");
|
|
27
|
-
const [customTypeModelDescriptors, sharedSliceModelDescriptors] = await Promise.all([
|
|
28
|
-
actions.readAllCustomTypeModels(),
|
|
29
|
-
actions.readAllSliceModels()
|
|
30
|
-
]);
|
|
31
|
-
const customTypeModels = customTypeModelDescriptors.map((customTypeModelDescriptors2) => {
|
|
32
|
-
return customTypeModelDescriptors2.model;
|
|
33
|
-
});
|
|
34
|
-
const sharedSliceModels = sharedSliceModelDescriptors.map((sharedSliceModelDescriptors2) => {
|
|
35
|
-
return sharedSliceModelDescriptors2.model;
|
|
36
|
-
});
|
|
37
|
-
let contents = prismicTsCodegen.generateTypes({
|
|
38
|
-
customTypeModels,
|
|
39
|
-
sharedSliceModels,
|
|
40
|
-
clientIntegration: {
|
|
41
|
-
includeCreateClientInterface: true,
|
|
42
|
-
includeContentNamespace: true
|
|
43
|
-
},
|
|
44
|
-
typesProvider: await prismicTsCodegen.detectTypesProvider({ cwd: project.root })
|
|
45
|
-
});
|
|
46
|
-
contents = `${constants.NON_EDITABLE_FILE_BANNER}
|
|
47
|
-
|
|
48
|
-
${contents}`;
|
|
49
|
-
if (options.format) {
|
|
50
|
-
contents = await helpers.format(contents, filePath);
|
|
51
|
-
}
|
|
52
|
-
await fs__namespace.mkdir(path__namespace.dirname(filePath), { recursive: true });
|
|
53
|
-
await fs__namespace.writeFile(filePath, contents);
|
|
54
|
-
};
|
|
55
|
-
exports.upsertGlobalContentTypes = upsertGlobalContentTypes;
|
|
56
|
-
//# sourceMappingURL=upsertGlobalContentTypes.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"upsertGlobalContentTypes.cjs","sources":["../../../src/lib/upsertGlobalContentTypes.ts"],"sourcesContent":["import type { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { detectTypesProvider, generateTypes } from \"prismic-ts-codegen\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\n/**\n * Arguments for `upsertGlobalContentTypes()`.\n */\ntype UpsertGlobalTypesArgs = SliceMachineContext<PluginOptions>;\n\n/**\n * Creates a globally accessible TypeScript file containing types representing\n * the Prismic repository's content.\n */\nexport const upsertGlobalContentTypes = async ({\n\tactions,\n\thelpers,\n\toptions,\n\tproject,\n}: UpsertGlobalTypesArgs): Promise<void> => {\n\tconst filePath = helpers.joinPathFromRoot(\"prismicio-types.d.ts\");\n\n\tconst [customTypeModelDescriptors, sharedSliceModelDescriptors] =\n\t\tawait Promise.all([\n\t\t\tactions.readAllCustomTypeModels(),\n\t\t\tactions.readAllSliceModels(),\n\t\t]);\n\n\tconst customTypeModels = customTypeModelDescriptors.map(\n\t\t(customTypeModelDescriptors) => {\n\t\t\treturn customTypeModelDescriptors.model;\n\t\t},\n\t);\n\tconst sharedSliceModels = sharedSliceModelDescriptors.map(\n\t\t(sharedSliceModelDescriptors) => {\n\t\t\treturn sharedSliceModelDescriptors.model;\n\t\t},\n\t);\n\n\tlet contents = generateTypes({\n\t\tcustomTypeModels,\n\t\tsharedSliceModels,\n\t\tclientIntegration: {\n\t\t\tincludeCreateClientInterface: true,\n\t\t\tincludeContentNamespace: true,\n\t\t},\n\t\ttypesProvider: await detectTypesProvider({ cwd: project.root }),\n\t});\n\n\tcontents = `${NON_EDITABLE_FILE_BANNER}\\n\\n${contents}`;\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":["customTypeModelDescriptors","sharedSliceModelDescriptors","generateTypes","detectTypesProvider","NON_EDITABLE_FILE_BANNER","fs","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAiBO,MAAM,2BAA2B,OAAO,EAC9C,SACA,SACA,SACA,cAC0C;AACpC,QAAA,WAAW,QAAQ,iBAAiB,sBAAsB;AAEhE,QAAM,CAAC,4BAA4B,2BAA2B,IAC7D,MAAM,QAAQ,IAAI;AAAA,IACjB,QAAQ,wBAAyB;AAAA,IACjC,QAAQ,mBAAoB;AAAA,EAAA,CAC5B;AAEF,QAAM,mBAAmB,2BAA2B,IACnD,CAACA,gCAA8B;AAC9B,WAAOA,4BAA2B;AAAA,EAAA,CAClC;AAEF,QAAM,oBAAoB,4BAA4B,IACrD,CAACC,iCAA+B;AAC/B,WAAOA,6BAA4B;AAAA,EAAA,CACnC;AAGF,MAAI,WAAWC,iBAAAA,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,MAClB,8BAA8B;AAAA,MAC9B,yBAAyB;AAAA,IACzB;AAAA,IACD,eAAe,MAAMC,iBAAAA,oBAAoB,EAAE,KAAK,QAAQ,MAAM;AAAA,EAAA,CAC9D;AAED,aAAW,GAAGC;;EAA+B;AAE7C,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAAC,cAAG,MAAMC,gBAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAA,CAAM;AACpD,QAAAD,cAAG,UAAU,UAAU,QAAQ;AACtC;;"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
-
import type { PluginOptions } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* Arguments for `upsertGlobalContentTypes()`.
|
|
5
|
-
*/
|
|
6
|
-
type UpsertGlobalTypesArgs = SliceMachineContext<PluginOptions>;
|
|
7
|
-
/**
|
|
8
|
-
* Creates a globally accessible TypeScript file containing types representing
|
|
9
|
-
* the Prismic repository's content.
|
|
10
|
-
*/
|
|
11
|
-
export declare const upsertGlobalContentTypes: ({ actions, helpers, options, project, }: UpsertGlobalTypesArgs) => Promise<void>;
|
|
12
|
-
export {};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { generateTypes, detectTypesProvider } from "prismic-ts-codegen";
|
|
2
|
-
import * as fs from "node:fs/promises";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
import { NON_EDITABLE_FILE_BANNER } from "../constants.js";
|
|
5
|
-
const upsertGlobalContentTypes = async ({ actions, helpers, options, project }) => {
|
|
6
|
-
const filePath = helpers.joinPathFromRoot("prismicio-types.d.ts");
|
|
7
|
-
const [customTypeModelDescriptors, sharedSliceModelDescriptors] = await Promise.all([
|
|
8
|
-
actions.readAllCustomTypeModels(),
|
|
9
|
-
actions.readAllSliceModels()
|
|
10
|
-
]);
|
|
11
|
-
const customTypeModels = customTypeModelDescriptors.map((customTypeModelDescriptors2) => {
|
|
12
|
-
return customTypeModelDescriptors2.model;
|
|
13
|
-
});
|
|
14
|
-
const sharedSliceModels = sharedSliceModelDescriptors.map((sharedSliceModelDescriptors2) => {
|
|
15
|
-
return sharedSliceModelDescriptors2.model;
|
|
16
|
-
});
|
|
17
|
-
let contents = generateTypes({
|
|
18
|
-
customTypeModels,
|
|
19
|
-
sharedSliceModels,
|
|
20
|
-
clientIntegration: {
|
|
21
|
-
includeCreateClientInterface: true,
|
|
22
|
-
includeContentNamespace: true
|
|
23
|
-
},
|
|
24
|
-
typesProvider: await detectTypesProvider({ cwd: project.root })
|
|
25
|
-
});
|
|
26
|
-
contents = `${NON_EDITABLE_FILE_BANNER}
|
|
27
|
-
|
|
28
|
-
${contents}`;
|
|
29
|
-
if (options.format) {
|
|
30
|
-
contents = await helpers.format(contents, filePath);
|
|
31
|
-
}
|
|
32
|
-
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
33
|
-
await fs.writeFile(filePath, contents);
|
|
34
|
-
};
|
|
35
|
-
export {
|
|
36
|
-
upsertGlobalContentTypes
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=upsertGlobalContentTypes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"upsertGlobalContentTypes.js","sources":["../../../src/lib/upsertGlobalContentTypes.ts"],"sourcesContent":["import type { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { detectTypesProvider, generateTypes } from \"prismic-ts-codegen\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\n/**\n * Arguments for `upsertGlobalContentTypes()`.\n */\ntype UpsertGlobalTypesArgs = SliceMachineContext<PluginOptions>;\n\n/**\n * Creates a globally accessible TypeScript file containing types representing\n * the Prismic repository's content.\n */\nexport const upsertGlobalContentTypes = async ({\n\tactions,\n\thelpers,\n\toptions,\n\tproject,\n}: UpsertGlobalTypesArgs): Promise<void> => {\n\tconst filePath = helpers.joinPathFromRoot(\"prismicio-types.d.ts\");\n\n\tconst [customTypeModelDescriptors, sharedSliceModelDescriptors] =\n\t\tawait Promise.all([\n\t\t\tactions.readAllCustomTypeModels(),\n\t\t\tactions.readAllSliceModels(),\n\t\t]);\n\n\tconst customTypeModels = customTypeModelDescriptors.map(\n\t\t(customTypeModelDescriptors) => {\n\t\t\treturn customTypeModelDescriptors.model;\n\t\t},\n\t);\n\tconst sharedSliceModels = sharedSliceModelDescriptors.map(\n\t\t(sharedSliceModelDescriptors) => {\n\t\t\treturn sharedSliceModelDescriptors.model;\n\t\t},\n\t);\n\n\tlet contents = generateTypes({\n\t\tcustomTypeModels,\n\t\tsharedSliceModels,\n\t\tclientIntegration: {\n\t\t\tincludeCreateClientInterface: true,\n\t\t\tincludeContentNamespace: true,\n\t\t},\n\t\ttypesProvider: await detectTypesProvider({ cwd: project.root }),\n\t});\n\n\tcontents = `${NON_EDITABLE_FILE_BANNER}\\n\\n${contents}`;\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":["customTypeModelDescriptors","sharedSliceModelDescriptors"],"mappings":";;;;AAiBO,MAAM,2BAA2B,OAAO,EAC9C,SACA,SACA,SACA,cAC0C;AACpC,QAAA,WAAW,QAAQ,iBAAiB,sBAAsB;AAEhE,QAAM,CAAC,4BAA4B,2BAA2B,IAC7D,MAAM,QAAQ,IAAI;AAAA,IACjB,QAAQ,wBAAyB;AAAA,IACjC,QAAQ,mBAAoB;AAAA,EAAA,CAC5B;AAEF,QAAM,mBAAmB,2BAA2B,IACnD,CAACA,gCAA8B;AAC9B,WAAOA,4BAA2B;AAAA,EAAA,CAClC;AAEF,QAAM,oBAAoB,4BAA4B,IACrD,CAACC,iCAA+B;AAC/B,WAAOA,6BAA4B;AAAA,EAAA,CACnC;AAGF,MAAI,WAAW,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,MAClB,8BAA8B;AAAA,MAC9B,yBAAyB;AAAA,IACzB;AAAA,IACD,eAAe,MAAM,oBAAoB,EAAE,KAAK,QAAQ,MAAM;AAAA,EAAA,CAC9D;AAED,aAAW,GAAG;AAAA;AAAA,EAA+B;AAE7C,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAA,GAAG,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAA,CAAM;AACpD,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { CustomTypeAssetDeleteHook } from "@slicemachine/plugin-kit";
|
|
2
|
-
import * as fs from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
import { buildCustomTypeAssetPath } from "../lib/buildCustomTypeAssetPath";
|
|
5
|
-
|
|
6
|
-
import type { PluginOptions } from "../types";
|
|
7
|
-
|
|
8
|
-
export const customTypeAssetDelete: CustomTypeAssetDeleteHook<
|
|
9
|
-
PluginOptions
|
|
10
|
-
> = async (data, context) => {
|
|
11
|
-
const filePath = buildCustomTypeAssetPath({
|
|
12
|
-
customTypeID: data.customTypeID,
|
|
13
|
-
assetID: data.assetID,
|
|
14
|
-
helpers: context.helpers,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
await fs.rm(filePath);
|
|
18
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { CustomTypeAssetReadHook } from "@slicemachine/plugin-kit";
|
|
2
|
-
import * as fs from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
import { buildCustomTypeAssetPath } from "../lib/buildCustomTypeAssetPath";
|
|
5
|
-
|
|
6
|
-
import type { PluginOptions } from "../types";
|
|
7
|
-
|
|
8
|
-
export const customTypeAssetRead: CustomTypeAssetReadHook<
|
|
9
|
-
PluginOptions
|
|
10
|
-
> = async (data, context) => {
|
|
11
|
-
const filePath = buildCustomTypeAssetPath({
|
|
12
|
-
customTypeID: data.customTypeID,
|
|
13
|
-
assetID: data.assetID,
|
|
14
|
-
helpers: context.helpers,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const assetData = await fs.readFile(filePath);
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
data: assetData,
|
|
21
|
-
};
|
|
22
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { CustomTypeAssetUpdateHook } from "@slicemachine/plugin-kit";
|
|
2
|
-
import * as fs from "node:fs/promises";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
|
|
5
|
-
import { buildCustomTypeAssetPath } from "../lib/buildCustomTypeAssetPath";
|
|
6
|
-
|
|
7
|
-
import type { PluginOptions } from "../types";
|
|
8
|
-
|
|
9
|
-
export const customTypeAssetUpdate: CustomTypeAssetUpdateHook<
|
|
10
|
-
PluginOptions
|
|
11
|
-
> = async (data, context) => {
|
|
12
|
-
const filePath = buildCustomTypeAssetPath({
|
|
13
|
-
customTypeID: data.customTypeID,
|
|
14
|
-
assetID: data.asset.id,
|
|
15
|
-
helpers: context.helpers,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
19
|
-
await fs.writeFile(filePath, data.asset.data);
|
|
20
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CustomTypeCreateHook,
|
|
3
|
-
CustomTypeCreateHookData,
|
|
4
|
-
SliceMachineContext,
|
|
5
|
-
} from "@slicemachine/plugin-kit";
|
|
6
|
-
import * as fs from "node:fs/promises";
|
|
7
|
-
import * as path from "node:path";
|
|
8
|
-
|
|
9
|
-
import { buildCustomTypeDirectoryPath } from "../lib/buildCustomTypeDirectoryPath";
|
|
10
|
-
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes";
|
|
11
|
-
|
|
12
|
-
import type { PluginOptions } from "../types";
|
|
13
|
-
|
|
14
|
-
type Args = {
|
|
15
|
-
dir: string;
|
|
16
|
-
data: CustomTypeCreateHookData;
|
|
17
|
-
} & SliceMachineContext<PluginOptions>;
|
|
18
|
-
|
|
19
|
-
const createModelFile = async ({ dir, data, helpers, options }: Args) => {
|
|
20
|
-
const filePath = path.join(dir, "index.json");
|
|
21
|
-
|
|
22
|
-
let contents = JSON.stringify(data.model);
|
|
23
|
-
|
|
24
|
-
if (options.format) {
|
|
25
|
-
contents = await helpers.format(contents, filePath);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
await fs.writeFile(filePath, contents);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const customTypeCreate: CustomTypeCreateHook<PluginOptions> = async (
|
|
32
|
-
data,
|
|
33
|
-
context,
|
|
34
|
-
) => {
|
|
35
|
-
const dir = buildCustomTypeDirectoryPath({
|
|
36
|
-
customTypeID: data.model.id,
|
|
37
|
-
helpers: context.helpers,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
await fs.mkdir(dir, { recursive: true });
|
|
41
|
-
|
|
42
|
-
await createModelFile({ dir, data, ...context });
|
|
43
|
-
|
|
44
|
-
await upsertGlobalContentTypes(context);
|
|
45
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { CustomTypeDeleteHook } from "@slicemachine/plugin-kit";
|
|
2
|
-
import * as fs from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
import { buildCustomTypeDirectoryPath } from "../lib/buildCustomTypeDirectoryPath";
|
|
5
|
-
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes";
|
|
6
|
-
|
|
7
|
-
import type { PluginOptions } from "../types";
|
|
8
|
-
|
|
9
|
-
export const customTypeDelete: CustomTypeDeleteHook<PluginOptions> = async (
|
|
10
|
-
data,
|
|
11
|
-
context,
|
|
12
|
-
) => {
|
|
13
|
-
const dir = buildCustomTypeDirectoryPath({
|
|
14
|
-
customTypeID: data.model.id,
|
|
15
|
-
helpers: context.helpers,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
await fs.rm(dir, { recursive: true });
|
|
19
|
-
|
|
20
|
-
await upsertGlobalContentTypes(context);
|
|
21
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { CustomTypeReadHook } from "@slicemachine/plugin-kit";
|
|
2
|
-
import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
|
|
5
|
-
import { buildCustomTypeDirectoryPath } from "../lib/buildCustomTypeDirectoryPath";
|
|
6
|
-
import { readJSONFile } from "../lib/readJSONFile";
|
|
7
|
-
|
|
8
|
-
import type { PluginOptions } from "../types";
|
|
9
|
-
|
|
10
|
-
export const customTypeRead: CustomTypeReadHook<PluginOptions> = async (
|
|
11
|
-
data,
|
|
12
|
-
{ helpers },
|
|
13
|
-
) => {
|
|
14
|
-
const filePath = path.join(
|
|
15
|
-
buildCustomTypeDirectoryPath({ customTypeID: data.id, helpers }),
|
|
16
|
-
"index.json",
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
const model = await readJSONFile<CustomType>(filePath);
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
model,
|
|
23
|
-
};
|
|
24
|
-
};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { CustomTypeLibraryReadHook } from "@slicemachine/plugin-kit";
|
|
2
|
-
import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
3
|
-
import * as fs from "node:fs/promises";
|
|
4
|
-
import * as path from "node:path";
|
|
5
|
-
|
|
6
|
-
import { buildCustomTypeLibraryDirectoryPath } from "../lib/buildCustomTypeLibraryDirectoryPath";
|
|
7
|
-
import { readJSONFile } from "../lib/readJSONFile";
|
|
8
|
-
|
|
9
|
-
import type { PluginOptions } from "../types";
|
|
10
|
-
|
|
11
|
-
const isCustomTypeModel = (
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
-
input: any,
|
|
14
|
-
): input is CustomType => {
|
|
15
|
-
return typeof input === "object" && input !== null && "json" in input;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const customTypeLibraryRead: CustomTypeLibraryReadHook<
|
|
19
|
-
PluginOptions
|
|
20
|
-
> = async (_data, { helpers }) => {
|
|
21
|
-
const dir = buildCustomTypeLibraryDirectoryPath({ helpers });
|
|
22
|
-
|
|
23
|
-
// Ensure the directory exists.
|
|
24
|
-
await fs.mkdir(dir, { recursive: true });
|
|
25
|
-
|
|
26
|
-
const childDirs = await fs.readdir(dir, { withFileTypes: true });
|
|
27
|
-
|
|
28
|
-
const ids: string[] = [];
|
|
29
|
-
await Promise.all(
|
|
30
|
-
childDirs.map(async (childDir) => {
|
|
31
|
-
if (childDir.isDirectory()) {
|
|
32
|
-
const childDirContents = await fs.readdir(
|
|
33
|
-
path.join(dir, childDir.name),
|
|
34
|
-
{
|
|
35
|
-
withFileTypes: true,
|
|
36
|
-
},
|
|
37
|
-
);
|
|
38
|
-
const isCustomTypeDir = childDirContents.some((entry) => {
|
|
39
|
-
return entry.isFile() && entry.name === "index.json";
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
if (isCustomTypeDir) {
|
|
43
|
-
const modelPath = path.join(dir, childDir.name, "index.json");
|
|
44
|
-
|
|
45
|
-
const modelContents = await readJSONFile(modelPath);
|
|
46
|
-
|
|
47
|
-
if (isCustomTypeModel(modelContents)) {
|
|
48
|
-
ids.push(modelContents.id);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}),
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
ids: ids.sort(),
|
|
57
|
-
};
|
|
58
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { SliceAssetDeleteHook } from "@slicemachine/plugin-kit";
|
|
2
|
-
import * as fs from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
import { buildSliceAssetPath } from "../lib/buildSliceAssetPath";
|
|
5
|
-
|
|
6
|
-
import type { PluginOptions } from "../types";
|
|
7
|
-
|
|
8
|
-
export const sliceAssetDelete: SliceAssetDeleteHook<PluginOptions> = async (
|
|
9
|
-
data,
|
|
10
|
-
context,
|
|
11
|
-
) => {
|
|
12
|
-
const filePath = await buildSliceAssetPath({
|
|
13
|
-
libraryID: data.libraryID,
|
|
14
|
-
sliceID: data.sliceID,
|
|
15
|
-
assetID: data.assetID,
|
|
16
|
-
helpers: context.helpers,
|
|
17
|
-
actions: context.actions,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
await fs.rm(filePath);
|
|
21
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { SliceAssetReadHook } from "@slicemachine/plugin-kit";
|
|
2
|
-
import * as fs from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
import { buildSliceAssetPath } from "../lib/buildSliceAssetPath";
|
|
5
|
-
|
|
6
|
-
import type { PluginOptions } from "../types";
|
|
7
|
-
|
|
8
|
-
export const sliceAssetRead: SliceAssetReadHook<PluginOptions> = async (
|
|
9
|
-
data,
|
|
10
|
-
context,
|
|
11
|
-
) => {
|
|
12
|
-
const filePath = await buildSliceAssetPath({
|
|
13
|
-
libraryID: data.libraryID,
|
|
14
|
-
sliceID: data.sliceID,
|
|
15
|
-
assetID: data.assetID,
|
|
16
|
-
helpers: context.helpers,
|
|
17
|
-
actions: context.actions,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const assetData = await fs.readFile(filePath);
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
data: assetData,
|
|
24
|
-
};
|
|
25
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { SliceAssetUpdateHook } from "@slicemachine/plugin-kit";
|
|
2
|
-
import * as fs from "node:fs/promises";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
|
|
5
|
-
import { buildSliceAssetPath } from "../lib/buildSliceAssetPath";
|
|
6
|
-
|
|
7
|
-
import type { PluginOptions } from "../types";
|
|
8
|
-
|
|
9
|
-
export const sliceAssetUpdate: SliceAssetUpdateHook<PluginOptions> = async (
|
|
10
|
-
data,
|
|
11
|
-
context,
|
|
12
|
-
) => {
|
|
13
|
-
const filePath = await buildSliceAssetPath({
|
|
14
|
-
libraryID: data.libraryID,
|
|
15
|
-
sliceID: data.sliceID,
|
|
16
|
-
assetID: data.asset.id,
|
|
17
|
-
helpers: context.helpers,
|
|
18
|
-
actions: context.actions,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
22
|
-
await fs.writeFile(filePath, data.asset.data);
|
|
23
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
SliceDeleteHook,
|
|
3
|
-
SliceDeleteHookData,
|
|
4
|
-
SliceMachineContext,
|
|
5
|
-
} from "@slicemachine/plugin-kit";
|
|
6
|
-
import * as fs from "node:fs/promises";
|
|
7
|
-
|
|
8
|
-
import { buildSliceDirectoryPath } from "../lib/buildSliceDirectoryPath";
|
|
9
|
-
import { rejectIfNecessary } from "../lib/rejectIfNecessary";
|
|
10
|
-
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes";
|
|
11
|
-
import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile";
|
|
12
|
-
|
|
13
|
-
import type { PluginOptions } from "../types";
|
|
14
|
-
|
|
15
|
-
type Args = {
|
|
16
|
-
data: SliceDeleteHookData;
|
|
17
|
-
} & SliceMachineContext<PluginOptions>;
|
|
18
|
-
|
|
19
|
-
const deleteSliceDir = async ({ data, helpers }: Args) => {
|
|
20
|
-
const dir = buildSliceDirectoryPath({
|
|
21
|
-
libraryID: data.libraryID,
|
|
22
|
-
model: data.model,
|
|
23
|
-
helpers,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
await fs.rm(dir, { recursive: true });
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const sliceDelete: SliceDeleteHook<PluginOptions> = async (
|
|
30
|
-
data,
|
|
31
|
-
context,
|
|
32
|
-
) => {
|
|
33
|
-
await deleteSliceDir({ data, ...context });
|
|
34
|
-
|
|
35
|
-
rejectIfNecessary(
|
|
36
|
-
await Promise.allSettled([
|
|
37
|
-
upsertGlobalContentTypes(context),
|
|
38
|
-
upsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context }),
|
|
39
|
-
]),
|
|
40
|
-
);
|
|
41
|
-
};
|
package/src/hooks/slice-read.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { SliceReadHook } from "@slicemachine/plugin-kit";
|
|
2
|
-
import * as fs from "node:fs/promises";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
|
|
5
|
-
import { buildSliceLibraryDirectoryPath } from "../lib/buildSliceLibraryDirectoryPath";
|
|
6
|
-
import { isSharedSliceModel } from "../lib/isSharedSliceModel";
|
|
7
|
-
import { readJSONFile } from "../lib/readJSONFile";
|
|
8
|
-
|
|
9
|
-
import type { PluginOptions } from "../types";
|
|
10
|
-
|
|
11
|
-
export const sliceRead: SliceReadHook<PluginOptions> = async (
|
|
12
|
-
data,
|
|
13
|
-
{ helpers },
|
|
14
|
-
) => {
|
|
15
|
-
const libraryDir = buildSliceLibraryDirectoryPath({
|
|
16
|
-
libraryID: data.libraryID,
|
|
17
|
-
helpers,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// Ensure the directory exists.
|
|
21
|
-
await fs.mkdir(libraryDir, { recursive: true });
|
|
22
|
-
|
|
23
|
-
const childDirs = await fs.readdir(libraryDir, { withFileTypes: true });
|
|
24
|
-
|
|
25
|
-
const modelReadErrors: string[] = [];
|
|
26
|
-
|
|
27
|
-
// Find the first matching model.
|
|
28
|
-
const [model] = (
|
|
29
|
-
await Promise.all(
|
|
30
|
-
childDirs.map(async (childDir) => {
|
|
31
|
-
if (childDir.isDirectory()) {
|
|
32
|
-
const modelPath = path.join(libraryDir, childDir.name, "model.json");
|
|
33
|
-
try {
|
|
34
|
-
const modelContents = await readJSONFile(modelPath);
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
isSharedSliceModel(modelContents) &&
|
|
38
|
-
modelContents.id === data.sliceID
|
|
39
|
-
) {
|
|
40
|
-
return modelContents;
|
|
41
|
-
}
|
|
42
|
-
} catch (error) {
|
|
43
|
-
modelReadErrors.push(modelPath);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}),
|
|
47
|
-
)
|
|
48
|
-
).filter((model): model is NonNullable<typeof model> => Boolean(model));
|
|
49
|
-
|
|
50
|
-
if (model) {
|
|
51
|
-
return {
|
|
52
|
-
model,
|
|
53
|
-
};
|
|
54
|
-
} else {
|
|
55
|
-
if (modelReadErrors.length) {
|
|
56
|
-
throw new Error(
|
|
57
|
-
`Did not find a Slice model with ID "${data.sliceID}" in the "${
|
|
58
|
-
data.libraryID
|
|
59
|
-
}" Slice Library.\n\nThose Slice models could not be read:\n - ${modelReadErrors.join(
|
|
60
|
-
"\n - ",
|
|
61
|
-
)}`,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
throw new Error(
|
|
66
|
-
`Did not find a Slice model with ID "${data.sliceID}" in the "${data.libraryID}" Slice Library.`,
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
};
|