@prismicio/adapter-sveltekit 0.0.1

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 (61) hide show
  1. package/dist/constants.d.ts +4 -0
  2. package/dist/constants.js +5 -0
  3. package/dist/constants.js.map +1 -0
  4. package/dist/hooks/project-init.d.ts +3 -0
  5. package/dist/hooks/project-init.js +195 -0
  6. package/dist/hooks/project-init.js.map +1 -0
  7. package/dist/hooks/project-init.templates.d.ts +9 -0
  8. package/dist/hooks/project-init.templates.js +171 -0
  9. package/dist/hooks/project-init.templates.js.map +1 -0
  10. package/dist/hooks/slice-create.d.ts +3 -0
  11. package/dist/hooks/slice-create.js +53 -0
  12. package/dist/hooks/slice-create.js.map +1 -0
  13. package/dist/hooks/slice-create.templates.d.ts +6 -0
  14. package/dist/hooks/slice-create.templates.js +40 -0
  15. package/dist/hooks/slice-create.templates.js.map +1 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.js +5 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/lib/checkIsTypeScriptProject.d.ts +8 -0
  20. package/dist/lib/checkIsTypeScriptProject.js +8 -0
  21. package/dist/lib/checkIsTypeScriptProject.js.map +1 -0
  22. package/dist/lib/getJSFileExtension.d.ts +5 -0
  23. package/dist/lib/getJSFileExtension.js +12 -0
  24. package/dist/lib/getJSFileExtension.js.map +1 -0
  25. package/dist/lib/getSvelteMajor.d.ts +1 -0
  26. package/dist/lib/getSvelteMajor.js +16 -0
  27. package/dist/lib/getSvelteMajor.js.map +1 -0
  28. package/dist/lib/pascalCase.d.ts +8 -0
  29. package/dist/lib/pascalCase.js +8 -0
  30. package/dist/lib/pascalCase.js.map +1 -0
  31. package/dist/lib/rejectIfNecessary.d.ts +1 -0
  32. package/dist/lib/rejectIfNecessary.js +10 -0
  33. package/dist/lib/rejectIfNecessary.js.map +1 -0
  34. package/dist/lib/requireResolve.d.ts +10 -0
  35. package/dist/lib/requireResolve.js +16 -0
  36. package/dist/lib/requireResolve.js.map +1 -0
  37. package/dist/lib/upsertSliceLibraryIndexFile.d.ts +7 -0
  38. package/dist/lib/upsertSliceLibraryIndexFile.js +50 -0
  39. package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -0
  40. package/dist/package.json.js +5 -0
  41. package/dist/package.json.js.map +1 -0
  42. package/dist/plugin.d.ts +2 -0
  43. package/dist/plugin.js +144 -0
  44. package/dist/plugin.js.map +1 -0
  45. package/dist/types.d.ts +28 -0
  46. package/package.json +95 -0
  47. package/src/constants.ts +5 -0
  48. package/src/hooks/project-init.templates.ts +173 -0
  49. package/src/hooks/project-init.ts +315 -0
  50. package/src/hooks/slice-create.templates.ts +82 -0
  51. package/src/hooks/slice-create.ts +84 -0
  52. package/src/index.ts +3 -0
  53. package/src/lib/checkIsTypeScriptProject.ts +18 -0
  54. package/src/lib/getJSFileExtension.ts +22 -0
  55. package/src/lib/getSvelteMajor.ts +23 -0
  56. package/src/lib/pascalCase.ts +12 -0
  57. package/src/lib/rejectIfNecessary.ts +16 -0
  58. package/src/lib/requireResolve.ts +30 -0
  59. package/src/lib/upsertSliceLibraryIndexFile.ts +78 -0
  60. package/src/plugin.ts +190 -0
  61. package/src/types.ts +31 -0
package/src/plugin.ts ADDED
@@ -0,0 +1,190 @@
1
+ import { definePlugin } from "@prismicio/plugin-kit";
2
+ import {
3
+ deleteCustomTypeDirectory,
4
+ deleteSliceDirectory,
5
+ readCustomTypeLibrary,
6
+ readCustomTypeModel,
7
+ readSliceLibrary,
8
+ readSliceModel,
9
+ renameSlice,
10
+ upsertGlobalTypeScriptTypes,
11
+ writeCustomTypeModel,
12
+ writeSliceModel,
13
+ } from "@prismicio/plugin-kit/fs";
14
+
15
+ import { name as pkgName } from "../package.json";
16
+
17
+ import { projectInit } from "./hooks/project-init";
18
+ import { sliceCreate } from "./hooks/slice-create";
19
+ import { rejectIfNecessary } from "./lib/rejectIfNecessary";
20
+ import { upsertSliceLibraryIndexFile } from "./lib/upsertSliceLibraryIndexFile";
21
+ import { PluginOptions } from "./types";
22
+
23
+ export const plugin = definePlugin<PluginOptions>({
24
+ meta: {
25
+ name: pkgName,
26
+ },
27
+ defaultOptions: {
28
+ format: true,
29
+ generatedTypesFilePath: "./src/prismicio-types.d.ts",
30
+ },
31
+ setup({ hook }) {
32
+ ////////////////////////////////////////////////////////////////
33
+ // project:*
34
+ ////////////////////////////////////////////////////////////////
35
+
36
+ hook("project:init", projectInit);
37
+
38
+ ////////////////////////////////////////////////////////////////
39
+ // slice:*
40
+ ////////////////////////////////////////////////////////////////
41
+
42
+ hook("slice:create", sliceCreate);
43
+ hook("slice:update", async (data, context) => {
44
+ await writeSliceModel({
45
+ libraryID: data.libraryID,
46
+ model: data.model,
47
+ ...context,
48
+ });
49
+
50
+ await upsertGlobalTypeScriptTypes({
51
+ filename: context.options.generatedTypesFilePath,
52
+ format: context.options.format,
53
+ ...context,
54
+ });
55
+ });
56
+ hook("slice:rename", async (data, context) => {
57
+ await renameSlice({
58
+ libraryID: data.libraryID,
59
+ model: data.model,
60
+ format: context.options.format,
61
+ ...context,
62
+ });
63
+
64
+ rejectIfNecessary(
65
+ await Promise.allSettled([
66
+ upsertSliceLibraryIndexFile({
67
+ libraryID: data.libraryID,
68
+ ...context,
69
+ }),
70
+ upsertGlobalTypeScriptTypes({
71
+ filename: context.options.generatedTypesFilePath,
72
+ format: context.options.format,
73
+ ...context,
74
+ }),
75
+ ]),
76
+ );
77
+ });
78
+ hook("slice:delete", async (data, context) => {
79
+ await deleteSliceDirectory({
80
+ libraryID: data.libraryID,
81
+ model: data.model,
82
+ ...context,
83
+ });
84
+
85
+ rejectIfNecessary(
86
+ await Promise.allSettled([
87
+ upsertSliceLibraryIndexFile({
88
+ libraryID: data.libraryID,
89
+ ...context,
90
+ }),
91
+ upsertGlobalTypeScriptTypes({
92
+ filename: context.options.generatedTypesFilePath,
93
+ format: context.options.format,
94
+ ...context,
95
+ }),
96
+ ]),
97
+ );
98
+ });
99
+ hook("slice:read", async (data, context) => {
100
+ return await readSliceModel({
101
+ libraryID: data.libraryID,
102
+ sliceID: data.sliceID,
103
+ ...context,
104
+ });
105
+ });
106
+
107
+ ////////////////////////////////////////////////////////////////
108
+ // slice-library:*
109
+ ////////////////////////////////////////////////////////////////
110
+
111
+ hook("slice-library:read", async (data, context) => {
112
+ return await readSliceLibrary({
113
+ libraryID: data.libraryID,
114
+ ...context,
115
+ });
116
+ });
117
+
118
+ ////////////////////////////////////////////////////////////////
119
+ // custom-type:*
120
+ ////////////////////////////////////////////////////////////////
121
+
122
+ hook("custom-type:create", async (data, context) => {
123
+ await writeCustomTypeModel({
124
+ model: data.model,
125
+ format: context.options.format,
126
+ ...context,
127
+ });
128
+
129
+ await upsertGlobalTypeScriptTypes({
130
+ filename: context.options.generatedTypesFilePath,
131
+ format: context.options.format,
132
+ ...context,
133
+ });
134
+ });
135
+ hook("custom-type:update", async (data, context) => {
136
+ await writeCustomTypeModel({
137
+ model: data.model,
138
+ format: context.options.format,
139
+ ...context,
140
+ });
141
+
142
+ await upsertGlobalTypeScriptTypes({
143
+ filename: context.options.generatedTypesFilePath,
144
+ format: context.options.format,
145
+ ...context,
146
+ });
147
+ });
148
+ hook("custom-type:rename", async (data, context) => {
149
+ await writeCustomTypeModel({
150
+ model: data.model,
151
+ format: context.options.format,
152
+ ...context,
153
+ });
154
+
155
+ await upsertGlobalTypeScriptTypes({
156
+ filename: context.options.generatedTypesFilePath,
157
+ format: context.options.format,
158
+ ...context,
159
+ });
160
+ });
161
+ hook("custom-type:delete", async (data, context) => {
162
+ await deleteCustomTypeDirectory({
163
+ customTypeID: data.model.id,
164
+ ...context,
165
+ });
166
+
167
+ await upsertGlobalTypeScriptTypes({
168
+ filename: context.options.generatedTypesFilePath,
169
+ format: context.options.format,
170
+ ...context,
171
+ });
172
+ });
173
+ hook("custom-type:read", async (data, context) => {
174
+ return await readCustomTypeModel({
175
+ customTypeID: data.id,
176
+ ...context,
177
+ });
178
+ });
179
+
180
+ ////////////////////////////////////////////////////////////////
181
+ // custom-type-library:*
182
+ ////////////////////////////////////////////////////////////////
183
+
184
+ hook("custom-type-library:read", async (_data, context) => {
185
+ return await readCustomTypeLibrary({
186
+ helpers: context.helpers,
187
+ });
188
+ });
189
+ },
190
+ });
package/src/types.ts ADDED
@@ -0,0 +1,31 @@
1
+ export type PluginOptions = {
2
+ /**
3
+ * Determines if generated files should be formatted using Prettier.
4
+ *
5
+ * @defaultValue `true`
6
+ */
7
+ format?: boolean;
8
+
9
+ /**
10
+ * The filepath at which generated TypeScript types will be saved.
11
+ *
12
+ * @defaultValue `prismicio-types.d.ts`
13
+ */
14
+ generatedTypesFilePath?: string;
15
+
16
+ /**
17
+ * Determines if generated files should be written in TypeScript or
18
+ * JavaScript.
19
+ *
20
+ * @defaultValue `true` if the project contains a `tsconfig.json`, `false` otherwise.
21
+ */
22
+ typescript?: boolean;
23
+
24
+ /**
25
+ * The filepath at which the active Prismic environment is stored as an
26
+ * environment variable.
27
+ *
28
+ * @defaultValue `.env.local`
29
+ */
30
+ environmentVariableFilePath?: string;
31
+ };