@slicemachine/adapter-next 0.3.10 → 0.3.11-dev-next-release.2
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/documentation-read.cjs +7 -6
- package/dist/hooks/documentation-read.cjs.map +1 -1
- package/dist/hooks/documentation-read.js +7 -6
- package/dist/hooks/documentation-read.js.map +1 -1
- package/dist/hooks/project-init.cjs +51 -58
- package/dist/hooks/project-init.cjs.map +1 -1
- package/dist/hooks/project-init.js +51 -57
- package/dist/hooks/project-init.js.map +1 -1
- package/dist/hooks/slice-create.cjs +29 -44
- package/dist/hooks/slice-create.cjs.map +1 -1
- package/dist/hooks/slice-create.js +29 -26
- package/dist/hooks/slice-create.js.map +1 -1
- package/dist/lib/checkHasAppRouter.cjs +23 -2
- package/dist/lib/checkHasAppRouter.cjs.map +1 -1
- package/dist/lib/checkHasAppRouter.js +6 -2
- package/dist/lib/checkHasAppRouter.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/upsertSliceLibraryIndexFile.cjs +29 -21
- package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.js +29 -20
- 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/package.json +5 -7
- package/src/hooks/documentation-read.ts +9 -7
- package/src/hooks/project-init.ts +58 -69
- package/src/hooks/slice-create.ts +39 -31
- package/src/lib/checkHasAppRouter.ts +6 -6
- package/src/lib/checkHasSrcDirectory.ts +5 -2
- package/src/lib/checkIsTypeScriptProject.ts +5 -4
- package/src/lib/upsertSliceLibraryIndexFile.ts +53 -33
- package/src/plugin.ts +245 -37
- 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 -63
|
@@ -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(options.generatedTypesFilePath || "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(\n\t\toptions.generatedTypesFilePath || \"prismicio-types.d.ts\",\n\t);\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;AAC1C,QAAM,WAAW,QAAQ,iBACxB,QAAQ,0BAA0B,sBAAsB;AAGzD,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
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { SliceRenameHook } from "@slicemachine/plugin-kit";
|
|
2
|
-
import * as fse from "fs-extra";
|
|
3
|
-
|
|
4
|
-
import { buildSliceDirectoryPath } from "../lib/buildSliceDirectoryPath";
|
|
5
|
-
import { rejectIfNecessary } from "../lib/rejectIfNecessary";
|
|
6
|
-
import { updateSliceModelFile } from "../lib/updateSliceModelFile";
|
|
7
|
-
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes";
|
|
8
|
-
import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile";
|
|
9
|
-
|
|
10
|
-
import type { PluginOptions } from "../types";
|
|
11
|
-
|
|
12
|
-
export const sliceRename: SliceRenameHook<PluginOptions> = async (
|
|
13
|
-
data,
|
|
14
|
-
context,
|
|
15
|
-
) => {
|
|
16
|
-
const { model: currentModel } = await context.actions.readSliceModel({
|
|
17
|
-
libraryID: data.libraryID,
|
|
18
|
-
sliceID: data.model.id,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
await fse.move(
|
|
22
|
-
buildSliceDirectoryPath({
|
|
23
|
-
libraryID: data.libraryID,
|
|
24
|
-
model: currentModel,
|
|
25
|
-
helpers: context.helpers,
|
|
26
|
-
}),
|
|
27
|
-
buildSliceDirectoryPath({
|
|
28
|
-
libraryID: data.libraryID,
|
|
29
|
-
model: data.model,
|
|
30
|
-
helpers: context.helpers,
|
|
31
|
-
}),
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
await updateSliceModelFile({
|
|
35
|
-
libraryID: data.libraryID,
|
|
36
|
-
model: data.model,
|
|
37
|
-
...context,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
rejectIfNecessary(
|
|
41
|
-
await Promise.allSettled([
|
|
42
|
-
upsertGlobalContentTypes(context),
|
|
43
|
-
upsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context }),
|
|
44
|
-
]),
|
|
45
|
-
);
|
|
46
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { SliceUpdateHook } from "@slicemachine/plugin-kit";
|
|
2
|
-
|
|
3
|
-
import { updateSliceModelFile } from "../lib/updateSliceModelFile";
|
|
4
|
-
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes";
|
|
5
|
-
|
|
6
|
-
import type { PluginOptions } from "../types";
|
|
7
|
-
|
|
8
|
-
export const sliceUpdate: SliceUpdateHook<PluginOptions> = async (
|
|
9
|
-
data,
|
|
10
|
-
context,
|
|
11
|
-
) => {
|
|
12
|
-
await updateSliceModelFile({
|
|
13
|
-
libraryID: data.libraryID,
|
|
14
|
-
model: data.model,
|
|
15
|
-
...context,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
await upsertGlobalContentTypes(context);
|
|
19
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { SliceLibraryReadHook } from "@slicemachine/plugin-kit";
|
|
2
|
-
import * as fs from "node:fs/promises";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
|
|
5
|
-
import { buildSliceLibraryDirectoryPath } from "../lib/buildSliceLibraryDirectoryPath";
|
|
6
|
-
import { isSharedSliceModel } from "../lib/isSharedSliceModel";
|
|
7
|
-
import { readJSONFile } from "../lib/readJSONFile";
|
|
8
|
-
|
|
9
|
-
import type { PluginOptions } from "../types";
|
|
10
|
-
|
|
11
|
-
export const sliceLibraryRead: SliceLibraryReadHook<PluginOptions> = async (
|
|
12
|
-
data,
|
|
13
|
-
{ helpers },
|
|
14
|
-
) => {
|
|
15
|
-
const dir = buildSliceLibraryDirectoryPath({
|
|
16
|
-
libraryID: data.libraryID,
|
|
17
|
-
helpers,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// Ensure the directory exists.
|
|
21
|
-
await fs.mkdir(dir, { recursive: true });
|
|
22
|
-
|
|
23
|
-
const childDirs = await fs.readdir(dir, { withFileTypes: true });
|
|
24
|
-
|
|
25
|
-
const sliceIDs: string[] = [];
|
|
26
|
-
await Promise.all(
|
|
27
|
-
childDirs.map(async (childDir) => {
|
|
28
|
-
if (childDir.isDirectory()) {
|
|
29
|
-
const modelPath = path.join(dir, childDir.name, "model.json");
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
const modelContents = await readJSONFile(modelPath);
|
|
33
|
-
|
|
34
|
-
if (isSharedSliceModel(modelContents)) {
|
|
35
|
-
sliceIDs.push(modelContents.id);
|
|
36
|
-
}
|
|
37
|
-
} catch {
|
|
38
|
-
// noop
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
id: data.libraryID,
|
|
46
|
-
sliceIDs: sliceIDs.sort(),
|
|
47
|
-
};
|
|
48
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
|
|
4
|
-
import { PluginOptions } from "../types";
|
|
5
|
-
|
|
6
|
-
import { buildCustomTypeDirectoryPath } from "./buildCustomTypeDirectoryPath";
|
|
7
|
-
|
|
8
|
-
type BuildCustomTypeAssetPathArgs = {
|
|
9
|
-
customTypeID: string;
|
|
10
|
-
assetID: string;
|
|
11
|
-
helpers: SliceMachineContext<PluginOptions>["helpers"];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const buildCustomTypeAssetPath = (
|
|
15
|
-
args: BuildCustomTypeAssetPathArgs,
|
|
16
|
-
): string => {
|
|
17
|
-
return path.join(
|
|
18
|
-
buildCustomTypeDirectoryPath({
|
|
19
|
-
customTypeID: args.customTypeID,
|
|
20
|
-
helpers: args.helpers,
|
|
21
|
-
}),
|
|
22
|
-
args.assetID,
|
|
23
|
-
);
|
|
24
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
|
|
4
|
-
import { PluginOptions } from "../types";
|
|
5
|
-
|
|
6
|
-
import { buildCustomTypeLibraryDirectoryPath } from "./buildCustomTypeLibraryDirectoryPath";
|
|
7
|
-
|
|
8
|
-
type BuildCustomTypeDirectoryPathArgs = {
|
|
9
|
-
customTypeID: string;
|
|
10
|
-
helpers: SliceMachineContext<PluginOptions>["helpers"];
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const buildCustomTypeDirectoryPath = (
|
|
14
|
-
args: BuildCustomTypeDirectoryPathArgs,
|
|
15
|
-
): string => {
|
|
16
|
-
return path.join(
|
|
17
|
-
buildCustomTypeLibraryDirectoryPath({ helpers: args.helpers }),
|
|
18
|
-
args.customTypeID,
|
|
19
|
-
);
|
|
20
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
-
|
|
3
|
-
import { PluginOptions } from "../types";
|
|
4
|
-
|
|
5
|
-
type BuildCustomTypeLibraryDirectoryPathArgs = {
|
|
6
|
-
helpers: SliceMachineContext<PluginOptions>["helpers"];
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const buildCustomTypeLibraryDirectoryPath = (
|
|
10
|
-
args: BuildCustomTypeLibraryDirectoryPathArgs,
|
|
11
|
-
): string => {
|
|
12
|
-
return args.helpers.joinPathFromRoot("customtypes");
|
|
13
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
|
|
4
|
-
import { PluginOptions } from "../types";
|
|
5
|
-
|
|
6
|
-
import { buildSliceDirectoryPath } from "./buildSliceDirectoryPath";
|
|
7
|
-
|
|
8
|
-
type BuildSliceAssetPathArgs = {
|
|
9
|
-
libraryID: string;
|
|
10
|
-
sliceID: string;
|
|
11
|
-
assetID: string;
|
|
12
|
-
actions: SliceMachineContext<PluginOptions>["actions"];
|
|
13
|
-
helpers: SliceMachineContext<PluginOptions>["helpers"];
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const buildSliceAssetPath = async (
|
|
17
|
-
args: BuildSliceAssetPathArgs,
|
|
18
|
-
): Promise<string> => {
|
|
19
|
-
const { model } = await args.actions.readSliceModel({
|
|
20
|
-
libraryID: args.libraryID,
|
|
21
|
-
sliceID: args.sliceID,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
return path.join(
|
|
25
|
-
buildSliceDirectoryPath({
|
|
26
|
-
libraryID: args.libraryID,
|
|
27
|
-
model,
|
|
28
|
-
helpers: args.helpers,
|
|
29
|
-
}),
|
|
30
|
-
args.assetID,
|
|
31
|
-
);
|
|
32
|
-
};
|