@slicemachine/adapter-nuxt 0.3.10-dev-next-release.9 → 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
|
@@ -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
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
-
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
|
|
5
|
-
import { PluginOptions } from "../types";
|
|
6
|
-
|
|
7
|
-
import { buildSliceLibraryDirectoryPath } from "./buildSliceLibraryDirectoryPath";
|
|
8
|
-
import { pascalCase } from "./pascalCase";
|
|
9
|
-
|
|
10
|
-
type BuildSliceDirectoryPathArgs = {
|
|
11
|
-
libraryID: string;
|
|
12
|
-
model: SharedSlice;
|
|
13
|
-
helpers: SliceMachineContext<PluginOptions>["helpers"];
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const buildSliceDirectoryPath = (
|
|
17
|
-
args: BuildSliceDirectoryPathArgs,
|
|
18
|
-
): string => {
|
|
19
|
-
return path.join(
|
|
20
|
-
buildSliceLibraryDirectoryPath({
|
|
21
|
-
libraryID: args.libraryID,
|
|
22
|
-
helpers: args.helpers,
|
|
23
|
-
}),
|
|
24
|
-
pascalCase(args.model.name),
|
|
25
|
-
);
|
|
26
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
-
|
|
3
|
-
import { PluginOptions } from "../types";
|
|
4
|
-
|
|
5
|
-
type BuildSliceLibraryDirectoryPathArgs = {
|
|
6
|
-
libraryID: string;
|
|
7
|
-
helpers: SliceMachineContext<PluginOptions>["helpers"];
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const buildSliceLibraryDirectoryPath = (
|
|
11
|
-
args: BuildSliceLibraryDirectoryPathArgs,
|
|
12
|
-
): string => {
|
|
13
|
-
return args.helpers.joinPathFromRoot(args.libraryID);
|
|
14
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
-
|
|
3
|
-
export const isSharedSliceModel = (
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
|
|
5
|
-
input: any,
|
|
6
|
-
): input is SharedSlice => {
|
|
7
|
-
return (
|
|
8
|
-
typeof input === "object" &&
|
|
9
|
-
input !== null &&
|
|
10
|
-
"type" in input &&
|
|
11
|
-
input.type === "SharedSlice" &&
|
|
12
|
-
typeof input.id === "string"
|
|
13
|
-
);
|
|
14
|
-
};
|
package/src/lib/readJSONFile.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
-
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
3
|
-
import * as fs from "node:fs/promises";
|
|
4
|
-
import * as path from "node:path";
|
|
5
|
-
|
|
6
|
-
import type { PluginOptions } from "../types";
|
|
7
|
-
|
|
8
|
-
import { buildSliceDirectoryPath } from "./buildSliceDirectoryPath";
|
|
9
|
-
|
|
10
|
-
type UpdateSliceModelFileArgs = {
|
|
11
|
-
libraryID: string;
|
|
12
|
-
model: SharedSlice;
|
|
13
|
-
} & SliceMachineContext<PluginOptions>;
|
|
14
|
-
|
|
15
|
-
export const updateSliceModelFile = async ({
|
|
16
|
-
libraryID,
|
|
17
|
-
model,
|
|
18
|
-
helpers,
|
|
19
|
-
options,
|
|
20
|
-
}: UpdateSliceModelFileArgs): Promise<void> => {
|
|
21
|
-
const filePath = path.join(
|
|
22
|
-
buildSliceDirectoryPath({ libraryID, model, helpers }),
|
|
23
|
-
"model.json",
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
let contents = JSON.stringify(model);
|
|
27
|
-
|
|
28
|
-
if (options.format) {
|
|
29
|
-
contents = await helpers.format(contents, filePath);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
await fs.writeFile(filePath, contents);
|
|
33
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
-
import { detectTypesProvider, generateTypes } from "prismic-ts-codegen";
|
|
3
|
-
import * as fs from "node:fs/promises";
|
|
4
|
-
import * as path from "node:path";
|
|
5
|
-
|
|
6
|
-
import type { PluginOptions } from "../types";
|
|
7
|
-
import { NON_EDITABLE_FILE_BANNER } from "../constants";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Arguments for `upsertGlobalContentTypes()`.
|
|
11
|
-
*/
|
|
12
|
-
type UpsertGlobalTypesArgs = SliceMachineContext<PluginOptions>;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Creates a globally accessible TypeScript file containing types representing
|
|
16
|
-
* the Prismic repository's content.
|
|
17
|
-
*/
|
|
18
|
-
export const upsertGlobalContentTypes = async ({
|
|
19
|
-
actions,
|
|
20
|
-
helpers,
|
|
21
|
-
options,
|
|
22
|
-
project,
|
|
23
|
-
}: UpsertGlobalTypesArgs): Promise<void> => {
|
|
24
|
-
const filePath = helpers.joinPathFromRoot("prismicio-types.d.ts");
|
|
25
|
-
|
|
26
|
-
const [customTypeModelDescriptors, sharedSliceModelDescriptors] =
|
|
27
|
-
await Promise.all([
|
|
28
|
-
actions.readAllCustomTypeModels(),
|
|
29
|
-
actions.readAllSliceModels(),
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
const customTypeModels = customTypeModelDescriptors.map(
|
|
33
|
-
(customTypeModelDescriptors) => {
|
|
34
|
-
return customTypeModelDescriptors.model;
|
|
35
|
-
},
|
|
36
|
-
);
|
|
37
|
-
const sharedSliceModels = sharedSliceModelDescriptors.map(
|
|
38
|
-
(sharedSliceModelDescriptors) => {
|
|
39
|
-
return sharedSliceModelDescriptors.model;
|
|
40
|
-
},
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
let contents = generateTypes({
|
|
44
|
-
customTypeModels,
|
|
45
|
-
sharedSliceModels,
|
|
46
|
-
clientIntegration: {
|
|
47
|
-
includeCreateClientInterface: true,
|
|
48
|
-
includeContentNamespace: true,
|
|
49
|
-
},
|
|
50
|
-
typesProvider: await detectTypesProvider({ cwd: project.root }),
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
contents = `${NON_EDITABLE_FILE_BANNER}\n\n${contents}`;
|
|
54
|
-
|
|
55
|
-
if (options.format) {
|
|
56
|
-
contents = await helpers.format(contents, filePath);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
60
|
-
await fs.writeFile(filePath, contents);
|
|
61
|
-
};
|