@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.
Files changed (207) hide show
  1. package/dist/hooks/documentation-read.cjs.map +1 -1
  2. package/dist/hooks/documentation-read.js.map +1 -1
  3. package/dist/hooks/project-init.cjs +51 -52
  4. package/dist/hooks/project-init.cjs.map +1 -1
  5. package/dist/hooks/project-init.js +51 -51
  6. package/dist/hooks/project-init.js.map +1 -1
  7. package/dist/hooks/slice-create.cjs +29 -44
  8. package/dist/hooks/slice-create.cjs.map +1 -1
  9. package/dist/hooks/slice-create.js +29 -26
  10. package/dist/hooks/slice-create.js.map +1 -1
  11. package/dist/lib/checkHasAppRouter.cjs +23 -2
  12. package/dist/lib/checkHasAppRouter.cjs.map +1 -1
  13. package/dist/lib/checkHasAppRouter.js +6 -2
  14. package/dist/lib/checkHasAppRouter.js.map +1 -1
  15. package/dist/lib/checkHasSrcDirectory.cjs +5 -2
  16. package/dist/lib/checkHasSrcDirectory.cjs.map +1 -1
  17. package/dist/lib/checkHasSrcDirectory.js +5 -2
  18. package/dist/lib/checkHasSrcDirectory.js.map +1 -1
  19. package/dist/lib/checkIsTypeScriptProject.cjs +2 -3
  20. package/dist/lib/checkIsTypeScriptProject.cjs.map +1 -1
  21. package/dist/lib/checkIsTypeScriptProject.js +2 -3
  22. package/dist/lib/checkIsTypeScriptProject.js.map +1 -1
  23. package/dist/lib/upsertSliceLibraryIndexFile.cjs +29 -21
  24. package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -1
  25. package/dist/lib/upsertSliceLibraryIndexFile.js +29 -20
  26. package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -1
  27. package/dist/plugin.cjs +178 -36
  28. package/dist/plugin.cjs.map +1 -1
  29. package/dist/plugin.js +178 -36
  30. package/dist/plugin.js.map +1 -1
  31. package/package.json +4 -6
  32. package/src/hooks/documentation-read.ts +2 -1
  33. package/src/hooks/project-init.ts +58 -63
  34. package/src/hooks/slice-create.ts +39 -31
  35. package/src/lib/checkHasAppRouter.ts +6 -6
  36. package/src/lib/checkHasSrcDirectory.ts +5 -2
  37. package/src/lib/checkIsTypeScriptProject.ts +5 -4
  38. package/src/lib/upsertSliceLibraryIndexFile.ts +53 -33
  39. package/src/plugin.ts +245 -37
  40. package/dist/hooks/customType-asset-delete.cjs +0 -31
  41. package/dist/hooks/customType-asset-delete.cjs.map +0 -1
  42. package/dist/hooks/customType-asset-delete.d.ts +0 -3
  43. package/dist/hooks/customType-asset-delete.js +0 -14
  44. package/dist/hooks/customType-asset-delete.js.map +0 -1
  45. package/dist/hooks/customType-asset-read.cjs +0 -34
  46. package/dist/hooks/customType-asset-read.cjs.map +0 -1
  47. package/dist/hooks/customType-asset-read.d.ts +0 -3
  48. package/dist/hooks/customType-asset-read.js +0 -17
  49. package/dist/hooks/customType-asset-read.js.map +0 -1
  50. package/dist/hooks/customType-asset-update.cjs +0 -34
  51. package/dist/hooks/customType-asset-update.cjs.map +0 -1
  52. package/dist/hooks/customType-asset-update.d.ts +0 -3
  53. package/dist/hooks/customType-asset-update.js +0 -16
  54. package/dist/hooks/customType-asset-update.js.map +0 -1
  55. package/dist/hooks/customType-create.cjs +0 -43
  56. package/dist/hooks/customType-create.cjs.map +0 -1
  57. package/dist/hooks/customType-create.d.ts +0 -3
  58. package/dist/hooks/customType-create.js +0 -25
  59. package/dist/hooks/customType-create.js.map +0 -1
  60. package/dist/hooks/customType-delete.cjs +0 -32
  61. package/dist/hooks/customType-delete.cjs.map +0 -1
  62. package/dist/hooks/customType-delete.d.ts +0 -3
  63. package/dist/hooks/customType-delete.js +0 -15
  64. package/dist/hooks/customType-delete.js.map +0 -1
  65. package/dist/hooks/customType-read.cjs +0 -31
  66. package/dist/hooks/customType-read.cjs.map +0 -1
  67. package/dist/hooks/customType-read.d.ts +0 -3
  68. package/dist/hooks/customType-read.js +0 -14
  69. package/dist/hooks/customType-read.js.map +0 -1
  70. package/dist/hooks/customType-rename.cjs +0 -6
  71. package/dist/hooks/customType-rename.cjs.map +0 -1
  72. package/dist/hooks/customType-rename.d.ts +0 -1
  73. package/dist/hooks/customType-rename.js +0 -6
  74. package/dist/hooks/customType-rename.js.map +0 -1
  75. package/dist/hooks/customType-update.cjs +0 -6
  76. package/dist/hooks/customType-update.cjs.map +0 -1
  77. package/dist/hooks/customType-update.d.ts +0 -1
  78. package/dist/hooks/customType-update.js +0 -6
  79. package/dist/hooks/customType-update.js.map +0 -1
  80. package/dist/hooks/customTypeLibrary-read.cjs +0 -55
  81. package/dist/hooks/customTypeLibrary-read.cjs.map +0 -1
  82. package/dist/hooks/customTypeLibrary-read.d.ts +0 -3
  83. package/dist/hooks/customTypeLibrary-read.js +0 -37
  84. package/dist/hooks/customTypeLibrary-read.js.map +0 -1
  85. package/dist/hooks/slice-asset-delete.cjs +0 -33
  86. package/dist/hooks/slice-asset-delete.cjs.map +0 -1
  87. package/dist/hooks/slice-asset-delete.d.ts +0 -3
  88. package/dist/hooks/slice-asset-delete.js +0 -16
  89. package/dist/hooks/slice-asset-delete.js.map +0 -1
  90. package/dist/hooks/slice-asset-read.cjs +0 -36
  91. package/dist/hooks/slice-asset-read.cjs.map +0 -1
  92. package/dist/hooks/slice-asset-read.d.ts +0 -3
  93. package/dist/hooks/slice-asset-read.js +0 -19
  94. package/dist/hooks/slice-asset-read.js.map +0 -1
  95. package/dist/hooks/slice-asset-update.cjs +0 -36
  96. package/dist/hooks/slice-asset-update.cjs.map +0 -1
  97. package/dist/hooks/slice-asset-update.d.ts +0 -3
  98. package/dist/hooks/slice-asset-update.js +0 -18
  99. package/dist/hooks/slice-asset-update.js.map +0 -1
  100. package/dist/hooks/slice-delete.cjs +0 -41
  101. package/dist/hooks/slice-delete.cjs.map +0 -1
  102. package/dist/hooks/slice-delete.d.ts +0 -3
  103. package/dist/hooks/slice-delete.js +0 -24
  104. package/dist/hooks/slice-delete.js.map +0 -1
  105. package/dist/hooks/slice-read.cjs +0 -62
  106. package/dist/hooks/slice-read.cjs.map +0 -1
  107. package/dist/hooks/slice-read.d.ts +0 -3
  108. package/dist/hooks/slice-read.js +0 -44
  109. package/dist/hooks/slice-read.js.map +0 -1
  110. package/dist/hooks/slice-rename.cjs +0 -51
  111. package/dist/hooks/slice-rename.cjs.map +0 -1
  112. package/dist/hooks/slice-rename.d.ts +0 -3
  113. package/dist/hooks/slice-rename.js +0 -34
  114. package/dist/hooks/slice-rename.js.map +0 -1
  115. package/dist/hooks/slice-update.cjs +0 -14
  116. package/dist/hooks/slice-update.cjs.map +0 -1
  117. package/dist/hooks/slice-update.d.ts +0 -3
  118. package/dist/hooks/slice-update.js +0 -14
  119. package/dist/hooks/slice-update.js.map +0 -1
  120. package/dist/hooks/sliceLibrary-read.cjs +0 -52
  121. package/dist/hooks/sliceLibrary-read.cjs.map +0 -1
  122. package/dist/hooks/sliceLibrary-read.d.ts +0 -3
  123. package/dist/hooks/sliceLibrary-read.js +0 -34
  124. package/dist/hooks/sliceLibrary-read.js.map +0 -1
  125. package/dist/lib/buildCustomTypeAssetPath.cjs +0 -29
  126. package/dist/lib/buildCustomTypeAssetPath.cjs.map +0 -1
  127. package/dist/lib/buildCustomTypeAssetPath.d.ts +0 -9
  128. package/dist/lib/buildCustomTypeAssetPath.js +0 -12
  129. package/dist/lib/buildCustomTypeAssetPath.js.map +0 -1
  130. package/dist/lib/buildCustomTypeDirectoryPath.cjs +0 -26
  131. package/dist/lib/buildCustomTypeDirectoryPath.cjs.map +0 -1
  132. package/dist/lib/buildCustomTypeDirectoryPath.d.ts +0 -8
  133. package/dist/lib/buildCustomTypeDirectoryPath.js +0 -9
  134. package/dist/lib/buildCustomTypeDirectoryPath.js.map +0 -1
  135. package/dist/lib/buildCustomTypeLibraryDirectoryPath.cjs +0 -7
  136. package/dist/lib/buildCustomTypeLibraryDirectoryPath.cjs.map +0 -1
  137. package/dist/lib/buildCustomTypeLibraryDirectoryPath.d.ts +0 -7
  138. package/dist/lib/buildCustomTypeLibraryDirectoryPath.js +0 -7
  139. package/dist/lib/buildCustomTypeLibraryDirectoryPath.js.map +0 -1
  140. package/dist/lib/buildSliceAssetPath.cjs +0 -34
  141. package/dist/lib/buildSliceAssetPath.cjs.map +0 -1
  142. package/dist/lib/buildSliceAssetPath.d.ts +0 -11
  143. package/dist/lib/buildSliceAssetPath.js +0 -17
  144. package/dist/lib/buildSliceAssetPath.js.map +0 -1
  145. package/dist/lib/buildSliceDirectoryPath.cjs +0 -30
  146. package/dist/lib/buildSliceDirectoryPath.cjs.map +0 -1
  147. package/dist/lib/buildSliceDirectoryPath.d.ts +0 -10
  148. package/dist/lib/buildSliceDirectoryPath.js +0 -13
  149. package/dist/lib/buildSliceDirectoryPath.js.map +0 -1
  150. package/dist/lib/buildSliceLibraryDirectoryPath.cjs +0 -7
  151. package/dist/lib/buildSliceLibraryDirectoryPath.cjs.map +0 -1
  152. package/dist/lib/buildSliceLibraryDirectoryPath.d.ts +0 -8
  153. package/dist/lib/buildSliceLibraryDirectoryPath.js +0 -7
  154. package/dist/lib/buildSliceLibraryDirectoryPath.js.map +0 -1
  155. package/dist/lib/checkPathExists.cjs +0 -30
  156. package/dist/lib/checkPathExists.cjs.map +0 -1
  157. package/dist/lib/checkPathExists.d.ts +0 -2
  158. package/dist/lib/checkPathExists.js +0 -13
  159. package/dist/lib/checkPathExists.js.map +0 -1
  160. package/dist/lib/isSharedSliceModel.cjs +0 -7
  161. package/dist/lib/isSharedSliceModel.cjs.map +0 -1
  162. package/dist/lib/isSharedSliceModel.d.ts +0 -335
  163. package/dist/lib/isSharedSliceModel.js +0 -7
  164. package/dist/lib/isSharedSliceModel.js.map +0 -1
  165. package/dist/lib/readJSONFile.cjs +0 -26
  166. package/dist/lib/readJSONFile.cjs.map +0 -1
  167. package/dist/lib/readJSONFile.d.ts +0 -1
  168. package/dist/lib/readJSONFile.js +0 -9
  169. package/dist/lib/readJSONFile.js.map +0 -1
  170. package/dist/lib/updateSliceModelFile.cjs +0 -33
  171. package/dist/lib/updateSliceModelFile.cjs.map +0 -1
  172. package/dist/lib/updateSliceModelFile.d.ts +0 -9
  173. package/dist/lib/updateSliceModelFile.js +0 -15
  174. package/dist/lib/updateSliceModelFile.js.map +0 -1
  175. package/dist/lib/upsertGlobalContentTypes.cjs +0 -56
  176. package/dist/lib/upsertGlobalContentTypes.cjs.map +0 -1
  177. package/dist/lib/upsertGlobalContentTypes.d.ts +0 -12
  178. package/dist/lib/upsertGlobalContentTypes.js +0 -38
  179. package/dist/lib/upsertGlobalContentTypes.js.map +0 -1
  180. package/src/hooks/customType-asset-delete.ts +0 -18
  181. package/src/hooks/customType-asset-read.ts +0 -22
  182. package/src/hooks/customType-asset-update.ts +0 -20
  183. package/src/hooks/customType-create.ts +0 -45
  184. package/src/hooks/customType-delete.ts +0 -21
  185. package/src/hooks/customType-read.ts +0 -24
  186. package/src/hooks/customType-rename.ts +0 -3
  187. package/src/hooks/customType-update.ts +0 -3
  188. package/src/hooks/customTypeLibrary-read.ts +0 -58
  189. package/src/hooks/slice-asset-delete.ts +0 -21
  190. package/src/hooks/slice-asset-read.ts +0 -25
  191. package/src/hooks/slice-asset-update.ts +0 -23
  192. package/src/hooks/slice-delete.ts +0 -41
  193. package/src/hooks/slice-read.ts +0 -69
  194. package/src/hooks/slice-rename.ts +0 -46
  195. package/src/hooks/slice-update.ts +0 -19
  196. package/src/hooks/sliceLibrary-read.ts +0 -48
  197. package/src/lib/buildCustomTypeAssetPath.ts +0 -24
  198. package/src/lib/buildCustomTypeDirectoryPath.ts +0 -20
  199. package/src/lib/buildCustomTypeLibraryDirectoryPath.ts +0 -13
  200. package/src/lib/buildSliceAssetPath.ts +0 -32
  201. package/src/lib/buildSliceDirectoryPath.ts +0 -26
  202. package/src/lib/buildSliceLibraryDirectoryPath.ts +0 -14
  203. package/src/lib/checkPathExists.ts +0 -12
  204. package/src/lib/isSharedSliceModel.ts +0 -14
  205. package/src/lib/readJSONFile.ts +0 -7
  206. package/src/lib/updateSliceModelFile.ts +0 -33
  207. 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 ({ dir, data, helpers, options }: Args) => {
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 filePath = path.join(dir, `index.${extension}`);
29
- const model = data.model;
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
- if (options.format) {
88
- contents = await helpers.format(contents, filePath);
89
- }
90
-
91
- await fs.writeFile(filePath, contents);
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
- updateSliceModelFile({
107
+ writeSliceModel({
109
108
  libraryID: data.libraryID,
110
109
  model: data.model,
111
- ...context,
110
+ format: context.options.format,
111
+ helpers: context.helpers,
112
112
  }),
113
- createComponentFile({ dir, data, ...context }),
113
+ createComponentFile({ data, ...context }),
114
114
  ]),
115
115
  );
116
116
 
117
117
  rejectIfNecessary(
118
118
  await Promise.allSettled([
119
- upsertGlobalContentTypes(context),
120
- upsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context }),
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 checkPathExists(
18
- hasSrcDirectory
19
- ? args.helpers.joinPathFromRoot("src", "app")
20
- : args.helpers.joinPathFromRoot("app"),
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 checkPathExists(args.helpers.joinPathFromRoot("src"));
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
- const tsConfigPath = args.helpers.joinPathFromRoot("tsconfig.json");
15
-
16
- return args.options.typescript ?? (await checkPathExists(tsConfigPath));
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
- ${slices
46
- .map((slice) => {
47
- const id = slice.model.id;
48
- const dirName = pascalCase(slice.model.name);
49
-
50
- return `${id}: dynamic(() => import('./${dirName}'))`;
51
- })
52
- .join(",\n")}
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
- ${slices
60
- .map((slice) => {
61
- const componentName = pascalCase(slice.model.name);
62
- const dirName = pascalCase(slice.model.name);
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
- return `import ${componentName} from "./${dirName}";`;
65
- })
66
- .join("\n")}
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
- if (args.options.format) {
82
- contents = await args.helpers.format(contents, filePath);
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 fs.writeFile(filePath, contents);
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", sliceUpdate);
42
- hook("slice:rename", sliceRename);
43
- hook("slice:delete", sliceDelete);
44
- hook("slice:read", sliceRead);
45
- hook("slice:asset:update", sliceAssetUpdate);
46
- hook("slice:asset:delete", sliceAssetDelete);
47
- hook("slice:asset:read", sliceAssetRead);
48
- hook("slice-library:read", sliceLibraryRead);
49
-
50
- hook("custom-type:create", customTypeCreate);
51
- hook("custom-type:update", customTypeUpdate);
52
- hook("custom-type:rename", customTypeRename);
53
- hook("custom-type:delete", customTypeDelete);
54
- hook("custom-type:read", customTypeRead);
55
- hook("custom-type:asset:update", customTypeAssetUpdate);
56
- hook("custom-type:asset:delete", customTypeAssetDelete);
57
- hook("custom-type:asset:read", customTypeAssetRead);
58
- hook("custom-type-library:read", customTypeLibraryRead);
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;;"}
@@ -1,3 +0,0 @@
1
- import type { CustomTypeAssetDeleteHook } from "@slicemachine/plugin-kit";
2
- import type { PluginOptions } from "../types";
3
- export declare const customTypeAssetDelete: CustomTypeAssetDeleteHook<PluginOptions>;