@slicemachine/adapter-next 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/documentation-read.cjs.map +1 -1
- package/dist/hooks/documentation-read.js.map +1 -1
- package/dist/hooks/project-init.cjs +51 -52
- package/dist/hooks/project-init.cjs.map +1 -1
- package/dist/hooks/project-init.js +51 -51
- 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 +4 -6
- package/src/hooks/documentation-read.ts +2 -1
- package/src/hooks/project-init.ts +58 -63
- 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
|
@@ -3,31 +3,34 @@ import type {
|
|
|
3
3
|
SliceCreateHookData,
|
|
4
4
|
SliceMachineContext,
|
|
5
5
|
} from "@slicemachine/plugin-kit";
|
|
6
|
+
import {
|
|
7
|
+
upsertGlobalTypeScriptTypes,
|
|
8
|
+
writeSliceFile,
|
|
9
|
+
writeSliceModel,
|
|
10
|
+
} from "@slicemachine/plugin-kit/fs";
|
|
6
11
|
import { stripIndent } from "common-tags";
|
|
7
|
-
import * as fs from "node:fs/promises";
|
|
8
|
-
import * as path from "node:path";
|
|
9
12
|
|
|
10
|
-
import { buildSliceDirectoryPath } from "../lib/buildSliceDirectoryPath";
|
|
11
13
|
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
|
|
12
14
|
import { getJSFileExtension } from "../lib/getJSFileExtension";
|
|
13
15
|
import { pascalCase } from "../lib/pascalCase";
|
|
14
16
|
import { rejectIfNecessary } from "../lib/rejectIfNecessary";
|
|
15
|
-
import { updateSliceModelFile } from "../lib/updateSliceModelFile";
|
|
16
|
-
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes";
|
|
17
17
|
import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile";
|
|
18
18
|
|
|
19
19
|
import type { PluginOptions } from "../types";
|
|
20
20
|
|
|
21
21
|
type Args = {
|
|
22
|
-
dir: string;
|
|
23
22
|
data: SliceCreateHookData;
|
|
24
23
|
} & SliceMachineContext<PluginOptions>;
|
|
25
24
|
|
|
26
|
-
const createComponentFile = async ({
|
|
25
|
+
const createComponentFile = async ({
|
|
26
|
+
data,
|
|
27
|
+
helpers,
|
|
28
|
+
actions,
|
|
29
|
+
options,
|
|
30
|
+
}: Args) => {
|
|
27
31
|
const extension = await getJSFileExtension({ helpers, options, jsx: true });
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const pascalName = pascalCase(model.name);
|
|
32
|
+
const filename = `index.${extension}`;
|
|
33
|
+
const pascalName = pascalCase(data.model.name);
|
|
31
34
|
|
|
32
35
|
let contents: string;
|
|
33
36
|
|
|
@@ -47,7 +50,7 @@ const createComponentFile = async ({ dir, data, helpers, options }: Args) => {
|
|
|
47
50
|
export type ${pascalName}Props = SliceComponentProps<Content.${pascalName}Slice>;
|
|
48
51
|
|
|
49
52
|
/**
|
|
50
|
-
* Component for "${model.name}" Slices.
|
|
53
|
+
* Component for "${data.model.name}" Slices.
|
|
51
54
|
*/
|
|
52
55
|
const ${pascalName} = ({ slice }: ${pascalName}Props): JSX.Element => {
|
|
53
56
|
return (
|
|
@@ -55,7 +58,7 @@ const createComponentFile = async ({ dir, data, helpers, options }: Args) => {
|
|
|
55
58
|
data-slice-type={slice.slice_type}
|
|
56
59
|
data-slice-variation={slice.variation}
|
|
57
60
|
>
|
|
58
|
-
Placeholder component for ${model.id} (variation: {slice.variation}) Slices
|
|
61
|
+
Placeholder component for ${data.model.id} (variation: {slice.variation}) Slices
|
|
59
62
|
</section>
|
|
60
63
|
);
|
|
61
64
|
};
|
|
@@ -75,7 +78,7 @@ const createComponentFile = async ({ dir, data, helpers, options }: Args) => {
|
|
|
75
78
|
data-slice-type={slice.slice_type}
|
|
76
79
|
data-slice-variation={slice.variation}
|
|
77
80
|
>
|
|
78
|
-
Placeholder component for ${model.id} (variation: {slice.variation}) Slices
|
|
81
|
+
Placeholder component for ${data.model.id} (variation: {slice.variation}) Slices
|
|
79
82
|
</section>
|
|
80
83
|
);
|
|
81
84
|
};
|
|
@@ -84,40 +87,45 @@ const createComponentFile = async ({ dir, data, helpers, options }: Args) => {
|
|
|
84
87
|
`;
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
await writeSliceFile({
|
|
91
|
+
libraryID: data.libraryID,
|
|
92
|
+
model: data.model,
|
|
93
|
+
filename,
|
|
94
|
+
contents,
|
|
95
|
+
format: options.format,
|
|
96
|
+
actions,
|
|
97
|
+
helpers,
|
|
98
|
+
});
|
|
92
99
|
};
|
|
93
100
|
|
|
94
101
|
export const sliceCreate: SliceCreateHook<PluginOptions> = async (
|
|
95
102
|
data,
|
|
96
103
|
context,
|
|
97
104
|
) => {
|
|
98
|
-
const dir = buildSliceDirectoryPath({
|
|
99
|
-
libraryID: data.libraryID,
|
|
100
|
-
model: data.model,
|
|
101
|
-
helpers: context.helpers,
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
await fs.mkdir(dir, { recursive: true });
|
|
105
|
-
|
|
106
105
|
rejectIfNecessary(
|
|
107
106
|
await Promise.allSettled([
|
|
108
|
-
|
|
107
|
+
writeSliceModel({
|
|
109
108
|
libraryID: data.libraryID,
|
|
110
109
|
model: data.model,
|
|
111
|
-
|
|
110
|
+
format: context.options.format,
|
|
111
|
+
helpers: context.helpers,
|
|
112
112
|
}),
|
|
113
|
-
createComponentFile({
|
|
113
|
+
createComponentFile({ data, ...context }),
|
|
114
114
|
]),
|
|
115
115
|
);
|
|
116
116
|
|
|
117
117
|
rejectIfNecessary(
|
|
118
118
|
await Promise.allSettled([
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
upsertSliceLibraryIndexFile({
|
|
120
|
+
libraryID: data.libraryID,
|
|
121
|
+
...context,
|
|
122
|
+
}),
|
|
123
|
+
upsertGlobalTypeScriptTypes({
|
|
124
|
+
filename: context.options.generatedTypesFilePath,
|
|
125
|
+
format: context.options.format,
|
|
126
|
+
helpers: context.helpers,
|
|
127
|
+
actions: context.actions,
|
|
128
|
+
}),
|
|
121
129
|
]),
|
|
122
130
|
);
|
|
123
131
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
+
import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
|
|
3
|
+
import * as path from "node:path";
|
|
2
4
|
|
|
3
5
|
import { PluginOptions } from "../types";
|
|
4
6
|
import { checkHasSrcDirectory } from "./checkHasSrcDirectory";
|
|
5
|
-
import { checkPathExists } from "./checkPathExists";
|
|
6
7
|
|
|
7
8
|
type CheckHasAppRouterArgs = Pick<
|
|
8
9
|
SliceMachineContext<PluginOptions>,
|
|
@@ -14,9 +15,8 @@ export async function checkHasAppRouter(
|
|
|
14
15
|
): Promise<boolean> {
|
|
15
16
|
const hasSrcDirectory = await checkHasSrcDirectory({ helpers: args.helpers });
|
|
16
17
|
|
|
17
|
-
return await
|
|
18
|
-
hasSrcDirectory
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
);
|
|
18
|
+
return await checkHasProjectFile({
|
|
19
|
+
filename: hasSrcDirectory ? path.join("src", "app") : "app",
|
|
20
|
+
helpers: args.helpers,
|
|
21
|
+
});
|
|
22
22
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
+
import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
|
|
2
3
|
|
|
3
4
|
import { PluginOptions } from "../types";
|
|
4
|
-
import { checkPathExists } from "./checkPathExists";
|
|
5
5
|
|
|
6
6
|
type CheckHasSrcDirectoryArgs = Pick<
|
|
7
7
|
SliceMachineContext<PluginOptions>,
|
|
@@ -11,5 +11,8 @@ type CheckHasSrcDirectoryArgs = Pick<
|
|
|
11
11
|
export async function checkHasSrcDirectory(
|
|
12
12
|
args: CheckHasSrcDirectoryArgs,
|
|
13
13
|
): Promise<boolean> {
|
|
14
|
-
return await
|
|
14
|
+
return await checkHasProjectFile({
|
|
15
|
+
filename: "src",
|
|
16
|
+
helpers: args.helpers,
|
|
17
|
+
});
|
|
15
18
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
+
import { checkIsTypeScriptProject as baseCheckIsTypeScriptProject } from "@slicemachine/plugin-kit/fs";
|
|
2
3
|
|
|
3
4
|
import { PluginOptions } from "../types";
|
|
4
|
-
import { checkPathExists } from "./checkPathExists";
|
|
5
5
|
|
|
6
6
|
type CheckIsTypeScriptProjectArgs = {
|
|
7
7
|
helpers: SliceMachineContext<PluginOptions>["helpers"];
|
|
@@ -11,7 +11,8 @@ type CheckIsTypeScriptProjectArgs = {
|
|
|
11
11
|
export const checkIsTypeScriptProject = async (
|
|
12
12
|
args: CheckIsTypeScriptProjectArgs,
|
|
13
13
|
): Promise<boolean> => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
return (
|
|
15
|
+
args.options.typescript ??
|
|
16
|
+
baseCheckIsTypeScriptProject({ helpers: args.helpers })
|
|
17
|
+
);
|
|
17
18
|
};
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
+
import {
|
|
3
|
+
buildSliceDirectoryPath,
|
|
4
|
+
buildSliceLibraryDirectoryPath,
|
|
5
|
+
writeProjectFile,
|
|
6
|
+
} from "@slicemachine/plugin-kit/fs";
|
|
2
7
|
import { stripIndent } from "common-tags";
|
|
3
|
-
import * as fs from "node:fs/promises";
|
|
4
8
|
import * as path from "node:path";
|
|
5
9
|
import { NON_EDITABLE_FILE_BANNER } from "../constants";
|
|
6
10
|
|
|
7
11
|
import { PluginOptions } from "../types";
|
|
8
12
|
|
|
9
13
|
import { pascalCase } from "./pascalCase";
|
|
10
|
-
import { buildSliceLibraryDirectoryPath } from "./buildSliceLibraryDirectoryPath";
|
|
11
14
|
import { getJSFileExtension } from "./getJSFileExtension";
|
|
12
15
|
|
|
13
16
|
type UpsertSliceLibraryIndexFileArgs = {
|
|
@@ -17,18 +20,6 @@ type UpsertSliceLibraryIndexFileArgs = {
|
|
|
17
20
|
export const upsertSliceLibraryIndexFile = async (
|
|
18
21
|
args: UpsertSliceLibraryIndexFileArgs,
|
|
19
22
|
): Promise<void> => {
|
|
20
|
-
const extension = await getJSFileExtension({
|
|
21
|
-
helpers: args.helpers,
|
|
22
|
-
options: args.options,
|
|
23
|
-
});
|
|
24
|
-
const filePath = path.join(
|
|
25
|
-
buildSliceLibraryDirectoryPath({
|
|
26
|
-
libraryID: args.libraryID,
|
|
27
|
-
helpers: args.helpers,
|
|
28
|
-
}),
|
|
29
|
-
`index.${extension}`,
|
|
30
|
-
);
|
|
31
|
-
|
|
32
23
|
const slices = await args.actions.readAllSliceModelsForLibrary({
|
|
33
24
|
libraryID: args.libraryID,
|
|
34
25
|
});
|
|
@@ -42,28 +33,44 @@ export const upsertSliceLibraryIndexFile = async (
|
|
|
42
33
|
import dynamic from 'next/dynamic'
|
|
43
34
|
|
|
44
35
|
export const components = {
|
|
45
|
-
${
|
|
46
|
-
.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
36
|
+
${(
|
|
37
|
+
await Promise.all(
|
|
38
|
+
slices.map(async (slice) => {
|
|
39
|
+
const id = slice.model.id;
|
|
40
|
+
const dirName = path.basename(
|
|
41
|
+
await buildSliceDirectoryPath({
|
|
42
|
+
model: slice.model,
|
|
43
|
+
helpers: args.helpers,
|
|
44
|
+
libraryID: args.libraryID,
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return `${id}: dynamic(() => import('./${dirName}'))`;
|
|
49
|
+
}),
|
|
50
|
+
)
|
|
51
|
+
).join(",\n")}
|
|
53
52
|
}
|
|
54
53
|
`;
|
|
55
54
|
} else {
|
|
56
55
|
contents = stripIndent`
|
|
57
56
|
${NON_EDITABLE_FILE_BANNER}
|
|
58
57
|
|
|
59
|
-
${
|
|
60
|
-
.
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
${(
|
|
59
|
+
await Promise.all(
|
|
60
|
+
slices.map(async (slice) => {
|
|
61
|
+
const dirName = path.basename(
|
|
62
|
+
await buildSliceDirectoryPath({
|
|
63
|
+
model: slice.model,
|
|
64
|
+
helpers: args.helpers,
|
|
65
|
+
libraryID: args.libraryID,
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
const componentName = pascalCase(slice.model.name);
|
|
63
69
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
return `import ${componentName} from "./${dirName}";`;
|
|
71
|
+
}),
|
|
72
|
+
)
|
|
73
|
+
).join("\n")}
|
|
67
74
|
|
|
68
75
|
export const components = {
|
|
69
76
|
${slices
|
|
@@ -78,9 +85,22 @@ export const upsertSliceLibraryIndexFile = async (
|
|
|
78
85
|
`;
|
|
79
86
|
}
|
|
80
87
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
const extension = await getJSFileExtension({
|
|
89
|
+
helpers: args.helpers,
|
|
90
|
+
options: args.options,
|
|
91
|
+
});
|
|
92
|
+
const filePath = path.join(
|
|
93
|
+
buildSliceLibraryDirectoryPath({
|
|
94
|
+
libraryID: args.libraryID,
|
|
95
|
+
helpers: args.helpers,
|
|
96
|
+
}),
|
|
97
|
+
`index.${extension}`,
|
|
98
|
+
);
|
|
84
99
|
|
|
85
|
-
await
|
|
100
|
+
await writeProjectFile({
|
|
101
|
+
filename: filePath,
|
|
102
|
+
contents,
|
|
103
|
+
format: args.options.format,
|
|
104
|
+
helpers: args.helpers,
|
|
105
|
+
});
|
|
86
106
|
};
|
package/src/plugin.ts
CHANGED
|
@@ -1,30 +1,35 @@
|
|
|
1
1
|
import { defineSliceMachinePlugin } from "@slicemachine/plugin-kit";
|
|
2
|
+
import {
|
|
3
|
+
deleteCustomTypeDirectory,
|
|
4
|
+
deleteCustomTypeFile,
|
|
5
|
+
deleteSliceDirectory,
|
|
6
|
+
deleteSliceFile,
|
|
7
|
+
readCustomTypeFile,
|
|
8
|
+
readCustomTypeLibrary,
|
|
9
|
+
readCustomTypeModel,
|
|
10
|
+
readSliceFile,
|
|
11
|
+
readSliceLibrary,
|
|
12
|
+
readSliceModel,
|
|
13
|
+
renameCustomType,
|
|
14
|
+
renameSlice,
|
|
15
|
+
upsertGlobalTypeScriptTypes,
|
|
16
|
+
writeCustomTypeFile,
|
|
17
|
+
writeCustomTypeModel,
|
|
18
|
+
writeSliceFile,
|
|
19
|
+
writeSliceModel,
|
|
20
|
+
} from "@slicemachine/plugin-kit/fs";
|
|
21
|
+
|
|
22
|
+
import { rejectIfNecessary } from "./lib/rejectIfNecessary";
|
|
23
|
+
import { upsertSliceLibraryIndexFile } from "./lib/upsertSliceLibraryIndexFile";
|
|
2
24
|
|
|
3
25
|
import { name as pkgName } from "../package.json";
|
|
4
26
|
import { PluginOptions } from "./types";
|
|
5
27
|
|
|
28
|
+
import { documentationRead } from "./hooks/documentation-read";
|
|
6
29
|
import { projectInit } from "./hooks/project-init";
|
|
7
|
-
import { customTypeAssetDelete } from "./hooks/customType-asset-delete";
|
|
8
|
-
import { customTypeAssetRead } from "./hooks/customType-asset-read";
|
|
9
|
-
import { customTypeAssetUpdate } from "./hooks/customType-asset-update";
|
|
10
|
-
import { customTypeCreate } from "./hooks/customType-create";
|
|
11
|
-
import { customTypeDelete } from "./hooks/customType-delete";
|
|
12
|
-
import { customTypeLibraryRead } from "./hooks/customTypeLibrary-read";
|
|
13
|
-
import { customTypeRead } from "./hooks/customType-read";
|
|
14
|
-
import { customTypeRename } from "./hooks/customType-rename";
|
|
15
|
-
import { customTypeUpdate } from "./hooks/customType-update";
|
|
16
|
-
import { sliceAssetDelete } from "./hooks/slice-asset-delete";
|
|
17
|
-
import { sliceAssetRead } from "./hooks/slice-asset-read";
|
|
18
|
-
import { sliceAssetUpdate } from "./hooks/slice-asset-update";
|
|
19
30
|
import { sliceCreate } from "./hooks/slice-create";
|
|
20
|
-
import { sliceDelete } from "./hooks/slice-delete";
|
|
21
|
-
import { sliceLibraryRead } from "./hooks/sliceLibrary-read";
|
|
22
|
-
import { sliceRead } from "./hooks/slice-read";
|
|
23
|
-
import { sliceRename } from "./hooks/slice-rename";
|
|
24
|
-
import { sliceUpdate } from "./hooks/slice-update";
|
|
25
|
-
import { snippetRead } from "./hooks/snippet-read";
|
|
26
|
-
import { documentationRead } from "./hooks/documentation-read";
|
|
27
31
|
import { sliceSimulatorSetupRead } from "./hooks/sliceSimulator-setup-read";
|
|
32
|
+
import { snippetRead } from "./hooks/snippet-read";
|
|
28
33
|
|
|
29
34
|
export const plugin = defineSliceMachinePlugin<PluginOptions>({
|
|
30
35
|
meta: {
|
|
@@ -35,32 +40,235 @@ export const plugin = defineSliceMachinePlugin<PluginOptions>({
|
|
|
35
40
|
lazyLoadSlices: true,
|
|
36
41
|
},
|
|
37
42
|
setup({ hook }) {
|
|
43
|
+
////////////////////////////////////////////////////////////////
|
|
44
|
+
// project:*
|
|
45
|
+
////////////////////////////////////////////////////////////////
|
|
46
|
+
|
|
38
47
|
hook("project:init", projectInit);
|
|
39
48
|
|
|
49
|
+
////////////////////////////////////////////////////////////////
|
|
50
|
+
// slice:*
|
|
51
|
+
////////////////////////////////////////////////////////////////
|
|
52
|
+
|
|
40
53
|
hook("slice:create", sliceCreate);
|
|
41
|
-
hook("slice:update",
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
hook("
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
hook("slice:update", async (data, context) => {
|
|
55
|
+
await writeSliceModel({
|
|
56
|
+
libraryID: data.libraryID,
|
|
57
|
+
model: data.model,
|
|
58
|
+
...context,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
await upsertGlobalTypeScriptTypes({
|
|
62
|
+
filename: context.options.generatedTypesFilePath,
|
|
63
|
+
format: context.options.format,
|
|
64
|
+
...context,
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
hook("slice:rename", async (data, context) => {
|
|
68
|
+
await renameSlice({
|
|
69
|
+
libraryID: data.libraryID,
|
|
70
|
+
model: data.model,
|
|
71
|
+
format: context.options.format,
|
|
72
|
+
...context,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
rejectIfNecessary(
|
|
76
|
+
await Promise.allSettled([
|
|
77
|
+
upsertSliceLibraryIndexFile({
|
|
78
|
+
libraryID: data.libraryID,
|
|
79
|
+
...context,
|
|
80
|
+
}),
|
|
81
|
+
upsertGlobalTypeScriptTypes({
|
|
82
|
+
filename: context.options.generatedTypesFilePath,
|
|
83
|
+
format: context.options.format,
|
|
84
|
+
...context,
|
|
85
|
+
}),
|
|
86
|
+
]),
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
hook("slice:delete", async (data, context) => {
|
|
90
|
+
await deleteSliceDirectory({
|
|
91
|
+
libraryID: data.libraryID,
|
|
92
|
+
model: data.model,
|
|
93
|
+
...context,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
rejectIfNecessary(
|
|
97
|
+
await Promise.allSettled([
|
|
98
|
+
upsertSliceLibraryIndexFile({
|
|
99
|
+
libraryID: data.libraryID,
|
|
100
|
+
...context,
|
|
101
|
+
}),
|
|
102
|
+
upsertGlobalTypeScriptTypes({
|
|
103
|
+
filename: context.options.generatedTypesFilePath,
|
|
104
|
+
format: context.options.format,
|
|
105
|
+
...context,
|
|
106
|
+
}),
|
|
107
|
+
]),
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
hook("slice:read", async (data, context) => {
|
|
111
|
+
return await readSliceModel({
|
|
112
|
+
libraryID: data.libraryID,
|
|
113
|
+
sliceID: data.sliceID,
|
|
114
|
+
...context,
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
hook("slice:asset:update", async (data, context) => {
|
|
118
|
+
await writeSliceFile({
|
|
119
|
+
libraryID: data.libraryID,
|
|
120
|
+
sliceID: data.sliceID,
|
|
121
|
+
filename: data.asset.id,
|
|
122
|
+
contents: data.asset.data,
|
|
123
|
+
...context,
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
hook("slice:asset:delete", async (data, context) => {
|
|
127
|
+
await deleteSliceFile({
|
|
128
|
+
libraryID: data.libraryID,
|
|
129
|
+
sliceID: data.sliceID,
|
|
130
|
+
filename: data.assetID,
|
|
131
|
+
...context,
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
hook("slice:asset:read", async (data, context) => {
|
|
135
|
+
const file = await readSliceFile({
|
|
136
|
+
libraryID: data.libraryID,
|
|
137
|
+
sliceID: data.sliceID,
|
|
138
|
+
filename: data.assetID,
|
|
139
|
+
...context,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
data: file,
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
////////////////////////////////////////////////////////////////
|
|
148
|
+
// slice-library:*
|
|
149
|
+
////////////////////////////////////////////////////////////////
|
|
150
|
+
|
|
151
|
+
hook("slice-library:read", async (data, context) => {
|
|
152
|
+
return await readSliceLibrary({
|
|
153
|
+
libraryID: data.libraryID,
|
|
154
|
+
...context,
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
////////////////////////////////////////////////////////////////
|
|
159
|
+
// custom-type:*
|
|
160
|
+
////////////////////////////////////////////////////////////////
|
|
161
|
+
|
|
162
|
+
hook("custom-type:create", async (data, context) => {
|
|
163
|
+
await writeCustomTypeModel({
|
|
164
|
+
model: data.model,
|
|
165
|
+
format: context.options.format,
|
|
166
|
+
...context,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
await upsertGlobalTypeScriptTypes({
|
|
170
|
+
filename: context.options.generatedTypesFilePath,
|
|
171
|
+
format: context.options.format,
|
|
172
|
+
...context,
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
hook("custom-type:update", async (data, context) => {
|
|
176
|
+
await writeCustomTypeModel({
|
|
177
|
+
model: data.model,
|
|
178
|
+
format: context.options.format,
|
|
179
|
+
...context,
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
await upsertGlobalTypeScriptTypes({
|
|
183
|
+
filename: context.options.generatedTypesFilePath,
|
|
184
|
+
format: context.options.format,
|
|
185
|
+
...context,
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
hook("custom-type:rename", async (data, context) => {
|
|
189
|
+
await renameCustomType({
|
|
190
|
+
model: data.model,
|
|
191
|
+
format: context.options.format,
|
|
192
|
+
...context,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
await upsertGlobalTypeScriptTypes({
|
|
196
|
+
filename: context.options.generatedTypesFilePath,
|
|
197
|
+
format: context.options.format,
|
|
198
|
+
...context,
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
hook("custom-type:delete", async (data, context) => {
|
|
202
|
+
await deleteCustomTypeDirectory({
|
|
203
|
+
customTypeID: data.model.id,
|
|
204
|
+
...context,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
await upsertGlobalTypeScriptTypes({
|
|
208
|
+
filename: context.options.generatedTypesFilePath,
|
|
209
|
+
format: context.options.format,
|
|
210
|
+
...context,
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
hook("custom-type:read", async (data, context) => {
|
|
214
|
+
return await readCustomTypeModel({
|
|
215
|
+
customTypeID: data.id,
|
|
216
|
+
...context,
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
hook("custom-type:asset:update", async (data, context) => {
|
|
220
|
+
await writeCustomTypeFile({
|
|
221
|
+
customTypeID: data.customTypeID,
|
|
222
|
+
filename: data.asset.id,
|
|
223
|
+
contents: data.asset.data,
|
|
224
|
+
...context,
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
hook("custom-type:asset:delete", async (data, context) => {
|
|
228
|
+
await deleteCustomTypeFile({
|
|
229
|
+
customTypeID: data.customTypeID,
|
|
230
|
+
filename: data.assetID,
|
|
231
|
+
...context,
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
hook("custom-type:asset:read", async (data, context) => {
|
|
235
|
+
const file = await readCustomTypeFile({
|
|
236
|
+
customTypeID: data.customTypeID,
|
|
237
|
+
filename: data.assetID,
|
|
238
|
+
...context,
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
return {
|
|
242
|
+
data: file,
|
|
243
|
+
};
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
////////////////////////////////////////////////////////////////
|
|
247
|
+
// custom-type-library:*
|
|
248
|
+
////////////////////////////////////////////////////////////////
|
|
249
|
+
|
|
250
|
+
hook("custom-type-library:read", async (_data, context) => {
|
|
251
|
+
return await readCustomTypeLibrary({
|
|
252
|
+
helpers: context.helpers,
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
////////////////////////////////////////////////////////////////
|
|
257
|
+
// snippet:*
|
|
258
|
+
////////////////////////////////////////////////////////////////
|
|
59
259
|
|
|
60
260
|
hook("snippet:read", snippetRead);
|
|
61
261
|
|
|
262
|
+
////////////////////////////////////////////////////////////////
|
|
263
|
+
// documentation:*
|
|
264
|
+
////////////////////////////////////////////////////////////////
|
|
265
|
+
|
|
62
266
|
hook("documentation:read", documentationRead);
|
|
63
267
|
|
|
268
|
+
////////////////////////////////////////////////////////////////
|
|
269
|
+
// slice-simulator:*
|
|
270
|
+
////////////////////////////////////////////////////////////////
|
|
271
|
+
|
|
64
272
|
hook("slice-simulator:setup:read", sliceSimulatorSetupRead);
|
|
65
273
|
},
|
|
66
274
|
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const fs = require("node:fs/promises");
|
|
4
|
-
const buildCustomTypeAssetPath = require("../lib/buildCustomTypeAssetPath.cjs");
|
|
5
|
-
function _interopNamespaceDefault(e) {
|
|
6
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
7
|
-
if (e) {
|
|
8
|
-
for (const k in e) {
|
|
9
|
-
if (k !== "default") {
|
|
10
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: () => e[k]
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
n.default = e;
|
|
19
|
-
return Object.freeze(n);
|
|
20
|
-
}
|
|
21
|
-
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
22
|
-
const customTypeAssetDelete = async (data, context) => {
|
|
23
|
-
const filePath = buildCustomTypeAssetPath.buildCustomTypeAssetPath({
|
|
24
|
-
customTypeID: data.customTypeID,
|
|
25
|
-
assetID: data.assetID,
|
|
26
|
-
helpers: context.helpers
|
|
27
|
-
});
|
|
28
|
-
await fs__namespace.rm(filePath);
|
|
29
|
-
};
|
|
30
|
-
exports.customTypeAssetDelete = customTypeAssetDelete;
|
|
31
|
-
//# sourceMappingURL=customType-asset-delete.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"customType-asset-delete.cjs","sources":["../../../src/hooks/customType-asset-delete.ts"],"sourcesContent":["import type { CustomTypeAssetDeleteHook } from \"@slicemachine/plugin-kit\";\nimport * as fs from \"node:fs/promises\";\n\nimport { buildCustomTypeAssetPath } from \"../lib/buildCustomTypeAssetPath\";\n\nimport type { PluginOptions } from \"../types\";\n\nexport const customTypeAssetDelete: CustomTypeAssetDeleteHook<\n\tPluginOptions\n> = async (data, context) => {\n\tconst filePath = buildCustomTypeAssetPath({\n\t\tcustomTypeID: data.customTypeID,\n\t\tassetID: data.assetID,\n\t\thelpers: context.helpers,\n\t});\n\n\tawait fs.rm(filePath);\n};\n"],"names":["buildCustomTypeAssetPath","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAOa,MAAA,wBAET,OAAO,MAAM,YAAW;AAC3B,QAAM,WAAWA,yBAAAA,yBAAyB;AAAA,IACzC,cAAc,KAAK;AAAA,IACnB,SAAS,KAAK;AAAA,IACd,SAAS,QAAQ;AAAA,EAAA,CACjB;AAEK,QAAAC,cAAG,GAAG,QAAQ;AACrB;;"}
|