prismic 0.0.0-pr.28.59bf330

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 (158) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +69 -0
  3. package/dist/builders-hKD4IrLX-DsO7BUQw.mjs +97 -0
  4. package/dist/dist-B11B2hHn.mjs +1 -0
  5. package/dist/dist-DT8CtumB.mjs +1 -0
  6. package/dist/framework-CfjEoVk0.mjs +17 -0
  7. package/dist/index.mjs +2537 -0
  8. package/dist/nextjs-9z7YrSnS.mjs +312 -0
  9. package/dist/nuxt-KoJ61G2q.mjs +59 -0
  10. package/dist/sveltekit-DjXKCG78.mjs +226 -0
  11. package/package.json +58 -0
  12. package/src/codegen-types.ts +82 -0
  13. package/src/codegen.ts +45 -0
  14. package/src/custom-type-add-field-boolean.ts +185 -0
  15. package/src/custom-type-add-field-color.ts +168 -0
  16. package/src/custom-type-add-field-date.ts +171 -0
  17. package/src/custom-type-add-field-embed.ts +168 -0
  18. package/src/custom-type-add-field-geo-point.ts +165 -0
  19. package/src/custom-type-add-field-group.ts +142 -0
  20. package/src/custom-type-add-field-image.ts +168 -0
  21. package/src/custom-type-add-field-key-text.ts +168 -0
  22. package/src/custom-type-add-field-link.ts +191 -0
  23. package/src/custom-type-add-field-number.ts +200 -0
  24. package/src/custom-type-add-field-rich-text.ts +192 -0
  25. package/src/custom-type-add-field-select.ts +174 -0
  26. package/src/custom-type-add-field-timestamp.ts +171 -0
  27. package/src/custom-type-add-field-uid.ts +151 -0
  28. package/src/custom-type-add-field.ts +116 -0
  29. package/src/custom-type-connect-slice.ts +178 -0
  30. package/src/custom-type-create.ts +98 -0
  31. package/src/custom-type-disconnect-slice.ts +134 -0
  32. package/src/custom-type-list.ts +110 -0
  33. package/src/custom-type-remove-field.ts +135 -0
  34. package/src/custom-type-remove.ts +103 -0
  35. package/src/custom-type-set-name.ts +102 -0
  36. package/src/custom-type-view.ts +118 -0
  37. package/src/custom-type.ts +85 -0
  38. package/src/docs-fetch.ts +146 -0
  39. package/src/docs-list.ts +131 -0
  40. package/src/docs.ts +54 -0
  41. package/src/env.d.ts +12 -0
  42. package/src/framework/index.ts +399 -0
  43. package/src/framework/nextjs.templates.ts +426 -0
  44. package/src/framework/nextjs.ts +216 -0
  45. package/src/framework/nuxt.templates.ts +74 -0
  46. package/src/framework/nuxt.ts +250 -0
  47. package/src/framework/sveltekit.templates.ts +278 -0
  48. package/src/framework/sveltekit.ts +241 -0
  49. package/src/index.ts +155 -0
  50. package/src/init.ts +173 -0
  51. package/src/lib/auth.ts +200 -0
  52. package/src/lib/browser.ts +11 -0
  53. package/src/lib/config.ts +111 -0
  54. package/src/lib/custom-types-api.ts +385 -0
  55. package/src/lib/field-path.ts +81 -0
  56. package/src/lib/file.ts +49 -0
  57. package/src/lib/json.ts +3 -0
  58. package/src/lib/packageJson.ts +35 -0
  59. package/src/lib/profile.ts +39 -0
  60. package/src/lib/request.ts +116 -0
  61. package/src/lib/segment.ts +145 -0
  62. package/src/lib/sentry.ts +63 -0
  63. package/src/lib/string.ts +10 -0
  64. package/src/lib/url.ts +31 -0
  65. package/src/locale-add.ts +116 -0
  66. package/src/locale-list.ts +107 -0
  67. package/src/locale-remove.ts +88 -0
  68. package/src/locale-set-default.ts +131 -0
  69. package/src/locale.ts +60 -0
  70. package/src/login.ts +45 -0
  71. package/src/logout.ts +36 -0
  72. package/src/page-type-add-field-boolean.ts +179 -0
  73. package/src/page-type-add-field-color.ts +165 -0
  74. package/src/page-type-add-field-date.ts +168 -0
  75. package/src/page-type-add-field-embed.ts +165 -0
  76. package/src/page-type-add-field-geo-point.ts +162 -0
  77. package/src/page-type-add-field-group.ts +139 -0
  78. package/src/page-type-add-field-image.ts +165 -0
  79. package/src/page-type-add-field-key-text.ts +165 -0
  80. package/src/page-type-add-field-link.ts +188 -0
  81. package/src/page-type-add-field-number.ts +197 -0
  82. package/src/page-type-add-field-rich-text.ts +189 -0
  83. package/src/page-type-add-field-select.ts +171 -0
  84. package/src/page-type-add-field-timestamp.ts +168 -0
  85. package/src/page-type-add-field-uid.ts +148 -0
  86. package/src/page-type-add-field.ts +116 -0
  87. package/src/page-type-connect-slice.ts +178 -0
  88. package/src/page-type-create.ts +128 -0
  89. package/src/page-type-disconnect-slice.ts +134 -0
  90. package/src/page-type-list.ts +109 -0
  91. package/src/page-type-remove-field.ts +135 -0
  92. package/src/page-type-remove.ts +103 -0
  93. package/src/page-type-set-name.ts +102 -0
  94. package/src/page-type-set-repeatable.ts +111 -0
  95. package/src/page-type-view.ts +118 -0
  96. package/src/page-type.ts +90 -0
  97. package/src/preview-add.ts +126 -0
  98. package/src/preview-get-simulator.ts +104 -0
  99. package/src/preview-list.ts +106 -0
  100. package/src/preview-remove-simulator.ts +80 -0
  101. package/src/preview-remove.ts +109 -0
  102. package/src/preview-set-name.ts +137 -0
  103. package/src/preview-set-simulator.ts +116 -0
  104. package/src/preview.ts +75 -0
  105. package/src/pull.ts +236 -0
  106. package/src/push.ts +409 -0
  107. package/src/repo-create.ts +175 -0
  108. package/src/repo-get-access.ts +86 -0
  109. package/src/repo-list.ts +100 -0
  110. package/src/repo-set-access.ts +100 -0
  111. package/src/repo-set-name.ts +102 -0
  112. package/src/repo-view.ts +113 -0
  113. package/src/repo.ts +70 -0
  114. package/src/slice-add-field-boolean.ts +219 -0
  115. package/src/slice-add-field-color.ts +205 -0
  116. package/src/slice-add-field-date.ts +205 -0
  117. package/src/slice-add-field-embed.ts +205 -0
  118. package/src/slice-add-field-geo-point.ts +202 -0
  119. package/src/slice-add-field-group.ts +170 -0
  120. package/src/slice-add-field-image.ts +202 -0
  121. package/src/slice-add-field-key-text.ts +205 -0
  122. package/src/slice-add-field-link.ts +224 -0
  123. package/src/slice-add-field-number.ts +205 -0
  124. package/src/slice-add-field-rich-text.ts +229 -0
  125. package/src/slice-add-field-select.ts +211 -0
  126. package/src/slice-add-field-timestamp.ts +205 -0
  127. package/src/slice-add-field.ts +111 -0
  128. package/src/slice-add-variation.ts +142 -0
  129. package/src/slice-create.ts +164 -0
  130. package/src/slice-list-variations.ts +71 -0
  131. package/src/slice-list.ts +60 -0
  132. package/src/slice-remove-field.ts +125 -0
  133. package/src/slice-remove-variation.ts +113 -0
  134. package/src/slice-remove.ts +92 -0
  135. package/src/slice-rename.ts +104 -0
  136. package/src/slice-set-screenshot.ts +239 -0
  137. package/src/slice-view.ts +83 -0
  138. package/src/slice.ts +95 -0
  139. package/src/status.ts +834 -0
  140. package/src/sync.ts +259 -0
  141. package/src/token-create.ts +203 -0
  142. package/src/token-delete.ts +182 -0
  143. package/src/token-list.ts +223 -0
  144. package/src/token-set-name.ts +193 -0
  145. package/src/token.ts +60 -0
  146. package/src/webhook-add-header.ts +118 -0
  147. package/src/webhook-create.ts +152 -0
  148. package/src/webhook-disable.ts +109 -0
  149. package/src/webhook-enable.ts +132 -0
  150. package/src/webhook-list.ts +93 -0
  151. package/src/webhook-remove-header.ts +117 -0
  152. package/src/webhook-remove.ts +106 -0
  153. package/src/webhook-set-triggers.ts +148 -0
  154. package/src/webhook-status.ts +90 -0
  155. package/src/webhook-test.ts +106 -0
  156. package/src/webhook-view.ts +147 -0
  157. package/src/webhook.ts +95 -0
  158. package/src/whoami.ts +62 -0
@@ -0,0 +1,165 @@
1
+ import type { Color, CustomType } from "@prismicio/types-internal/lib/customtypes";
2
+
3
+ import { parseArgs } from "node:util";
4
+
5
+ import { buildTypes } from "./codegen-types";
6
+ import { findGroupInTab, isGroupField, parseFieldPath, validateNestedFieldPath } from "./lib/field-path";
7
+ import { getDocsPath, requireFramework } from "./framework";
8
+ import { humanReadable } from "./lib/string";
9
+
10
+ const HELP = `
11
+ Add a color picker field to an existing page type.
12
+
13
+ USAGE
14
+ prismic page-type add-field color <type-id> <field-id> [flags]
15
+
16
+ ARGUMENTS
17
+ type-id Page type identifier (required)
18
+ field-id Field identifier (required)
19
+
20
+ FLAGS
21
+ -t, --tab string Target tab (default: first existing tab, or "Main")
22
+ -l, --label string Display label for the field (inferred from field-id if omitted)
23
+ -p, --placeholder string Placeholder text
24
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
25
+ -h, --help Show help for command
26
+
27
+ EXAMPLES
28
+ prismic page-type add-field color homepage bg_color
29
+ prismic page-type add-field color homepage accent --tab "Design"
30
+ prismic page-type add-field color homepage text_color --label "Text Color"
31
+ `.trim();
32
+
33
+
34
+ export async function pageTypeAddFieldColor(): Promise<void> {
35
+ const {
36
+ values: { help, tab, label, placeholder, types },
37
+ positionals: [typeId, fieldId],
38
+ } = parseArgs({
39
+ args: process.argv.slice(5), // skip: node, script, "page-type", "add-field", "color"
40
+ options: {
41
+ tab: { type: "string", short: "t" },
42
+ label: { type: "string", short: "l" },
43
+ placeholder: { type: "string", short: "p" },
44
+ types: { type: "string" },
45
+ help: { type: "boolean", short: "h" },
46
+ },
47
+ allowPositionals: true,
48
+ });
49
+
50
+ if (help) {
51
+ console.info(HELP);
52
+ return;
53
+ }
54
+
55
+ if (!typeId) {
56
+ console.error("Missing required argument: type-id\n");
57
+ console.error("Usage: prismic page-type add-field color <type-id> <field-id>");
58
+ process.exitCode = 1;
59
+ return;
60
+ }
61
+
62
+ if (!fieldId) {
63
+ console.error("Missing required argument: field-id\n");
64
+ console.error("Usage: prismic page-type add-field color <type-id> <field-id>");
65
+ process.exitCode = 1;
66
+ return;
67
+ }
68
+
69
+ // Parse and validate field path
70
+ const fieldPath = parseFieldPath(fieldId);
71
+ const pathValidation = validateNestedFieldPath(fieldPath);
72
+ if (!pathValidation.ok) {
73
+ console.error(pathValidation.error);
74
+ process.exitCode = 1;
75
+ return;
76
+ }
77
+
78
+ const framework = await requireFramework();
79
+ if (!framework) return;
80
+
81
+ let model: CustomType;
82
+ try {
83
+ model = await framework.readCustomType(typeId);
84
+ } catch {
85
+ console.error(`Page type not found: ${typeId}\n\nCreate it first with: prismic page-type create ${typeId}`);
86
+ process.exitCode = 1;
87
+ return;
88
+ }
89
+
90
+ // Determine target tab
91
+ const existingTabs = Object.keys(model.json);
92
+ const targetTab = tab ?? existingTabs[0] ?? "Main";
93
+
94
+ // Initialize tab if it doesn't exist
95
+ if (!model.json[targetTab]) {
96
+ model.json[targetTab] = {};
97
+ }
98
+
99
+ // Build field definition
100
+ const fieldDefinition: Color = {
101
+ type: "Color",
102
+ config: {
103
+ label: label ?? humanReadable(fieldPath.type === "nested" ? fieldPath.nestedFieldId : fieldId),
104
+ ...(placeholder && { placeholder }),
105
+ },
106
+ };
107
+
108
+ // Add field to model
109
+ if (fieldPath.type === "nested") {
110
+ const groupResult = findGroupInTab(model.json[targetTab], fieldPath.groupId, targetTab);
111
+ if (!groupResult.ok) {
112
+ console.error(groupResult.error);
113
+ process.exitCode = 1;
114
+ return;
115
+ }
116
+ if (groupResult.group.config.fields[fieldPath.nestedFieldId]) {
117
+ console.error(`Field "${fieldPath.nestedFieldId}" already exists in group "${fieldPath.groupId}"`);
118
+ process.exitCode = 1;
119
+ return;
120
+ }
121
+ groupResult.group.config.fields[fieldPath.nestedFieldId] = fieldDefinition;
122
+ } else {
123
+ for (const [tabName, tabFields] of Object.entries(model.json)) {
124
+ if (tabFields[fieldId]) {
125
+ console.error(`Field "${fieldId}" already exists in tab "${tabName}"`);
126
+ process.exitCode = 1;
127
+ return;
128
+ }
129
+ for (const [groupFieldId, groupField] of Object.entries(tabFields)) {
130
+ if (isGroupField(groupField) && groupField.config.fields[fieldId]) {
131
+ console.error(`Field "${fieldId}" already exists in group "${groupFieldId}" in tab "${tabName}"`);
132
+ process.exitCode = 1;
133
+ return;
134
+ }
135
+ }
136
+ }
137
+ model.json[targetTab][fieldId] = fieldDefinition;
138
+ }
139
+
140
+ // Write updated model
141
+ await framework.updateCustomType(model);
142
+
143
+ if (fieldPath.type === "nested") {
144
+ console.info(`Added field "${fieldPath.nestedFieldId}" (Color) to group "${fieldPath.groupId}" in ${typeId}`);
145
+ } else {
146
+ console.info(`Added field "${fieldId}" (Color) to "${targetTab}" tab in ${typeId}`);
147
+ }
148
+
149
+ try {
150
+ await buildTypes({ output: types });
151
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
152
+ } catch (error) {
153
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
154
+ }
155
+
156
+ console.info();
157
+ console.info("Next: Add more fields with `prismic page-type add-field`");
158
+
159
+ if (framework) {
160
+ const docsPath = getDocsPath(framework.id);
161
+ console.info(
162
+ ` Run \`prismic docs fetch ${docsPath}#write-page-components\` to learn how to implement a page file`,
163
+ );
164
+ }
165
+ }
@@ -0,0 +1,168 @@
1
+ import type { CustomType, Date as DateField } from "@prismicio/types-internal/lib/customtypes";
2
+
3
+ import { parseArgs } from "node:util";
4
+
5
+ import { buildTypes } from "./codegen-types";
6
+ import { findGroupInTab, isGroupField, parseFieldPath, validateNestedFieldPath } from "./lib/field-path";
7
+ import { getDocsPath, requireFramework } from "./framework";
8
+ import { humanReadable } from "./lib/string";
9
+
10
+ const HELP = `
11
+ Add a date field to an existing page type.
12
+
13
+ USAGE
14
+ prismic page-type add-field date <type-id> <field-id> [flags]
15
+
16
+ ARGUMENTS
17
+ type-id Page type identifier (required)
18
+ field-id Field identifier (required)
19
+
20
+ FLAGS
21
+ -t, --tab string Target tab (default: first existing tab, or "Main")
22
+ -l, --label string Display label for the field (inferred from field-id if omitted)
23
+ -p, --placeholder string Placeholder text
24
+ --default string Default date value (YYYY-MM-DD format)
25
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
26
+ -h, --help Show help for command
27
+
28
+ EXAMPLES
29
+ prismic page-type add-field date homepage publish_date
30
+ prismic page-type add-field date event start_date --tab "Schedule"
31
+ prismic page-type add-field date article date --label "Publication Date" --default "2024-01-01"
32
+ `.trim();
33
+
34
+
35
+ export async function pageTypeAddFieldDate(): Promise<void> {
36
+ const {
37
+ values: { help, tab, label, placeholder, default: defaultValue, types },
38
+ positionals: [typeId, fieldId],
39
+ } = parseArgs({
40
+ args: process.argv.slice(5), // skip: node, script, "page-type", "add-field", "date"
41
+ options: {
42
+ tab: { type: "string", short: "t" },
43
+ label: { type: "string", short: "l" },
44
+ placeholder: { type: "string", short: "p" },
45
+ default: { type: "string" },
46
+ types: { type: "string" },
47
+ help: { type: "boolean", short: "h" },
48
+ },
49
+ allowPositionals: true,
50
+ });
51
+
52
+ if (help) {
53
+ console.info(HELP);
54
+ return;
55
+ }
56
+
57
+ if (!typeId) {
58
+ console.error("Missing required argument: type-id\n");
59
+ console.error("Usage: prismic page-type add-field date <type-id> <field-id>");
60
+ process.exitCode = 1;
61
+ return;
62
+ }
63
+
64
+ if (!fieldId) {
65
+ console.error("Missing required argument: field-id\n");
66
+ console.error("Usage: prismic page-type add-field date <type-id> <field-id>");
67
+ process.exitCode = 1;
68
+ return;
69
+ }
70
+
71
+ // Parse and validate field path
72
+ const fieldPath = parseFieldPath(fieldId);
73
+ const pathValidation = validateNestedFieldPath(fieldPath);
74
+ if (!pathValidation.ok) {
75
+ console.error(pathValidation.error);
76
+ process.exitCode = 1;
77
+ return;
78
+ }
79
+
80
+ const framework = await requireFramework();
81
+ if (!framework) return;
82
+
83
+ let model: CustomType;
84
+ try {
85
+ model = await framework.readCustomType(typeId);
86
+ } catch {
87
+ console.error(`Page type not found: ${typeId}\n\nCreate it first with: prismic page-type create ${typeId}`);
88
+ process.exitCode = 1;
89
+ return;
90
+ }
91
+
92
+ // Determine target tab
93
+ const existingTabs = Object.keys(model.json);
94
+ const targetTab = tab ?? existingTabs[0] ?? "Main";
95
+
96
+ // Initialize tab if it doesn't exist
97
+ if (!model.json[targetTab]) {
98
+ model.json[targetTab] = {};
99
+ }
100
+
101
+ // Build field definition
102
+ const fieldDefinition: DateField = {
103
+ type: "Date",
104
+ config: {
105
+ label: label ?? humanReadable(fieldPath.type === "nested" ? fieldPath.nestedFieldId : fieldId),
106
+ ...(placeholder && { placeholder }),
107
+ ...(defaultValue && { default: defaultValue }),
108
+ },
109
+ };
110
+
111
+ // Add field to model
112
+ if (fieldPath.type === "nested") {
113
+ const groupResult = findGroupInTab(model.json[targetTab], fieldPath.groupId, targetTab);
114
+ if (!groupResult.ok) {
115
+ console.error(groupResult.error);
116
+ process.exitCode = 1;
117
+ return;
118
+ }
119
+ if (groupResult.group.config.fields[fieldPath.nestedFieldId]) {
120
+ console.error(`Field "${fieldPath.nestedFieldId}" already exists in group "${fieldPath.groupId}"`);
121
+ process.exitCode = 1;
122
+ return;
123
+ }
124
+ groupResult.group.config.fields[fieldPath.nestedFieldId] = fieldDefinition;
125
+ } else {
126
+ for (const [tabName, tabFields] of Object.entries(model.json)) {
127
+ if (tabFields[fieldId]) {
128
+ console.error(`Field "${fieldId}" already exists in tab "${tabName}"`);
129
+ process.exitCode = 1;
130
+ return;
131
+ }
132
+ for (const [groupFieldId, groupField] of Object.entries(tabFields)) {
133
+ if (isGroupField(groupField) && groupField.config.fields[fieldId]) {
134
+ console.error(`Field "${fieldId}" already exists in group "${groupFieldId}" in tab "${tabName}"`);
135
+ process.exitCode = 1;
136
+ return;
137
+ }
138
+ }
139
+ }
140
+ model.json[targetTab][fieldId] = fieldDefinition;
141
+ }
142
+
143
+ // Write updated model
144
+ await framework.updateCustomType(model);
145
+
146
+ if (fieldPath.type === "nested") {
147
+ console.info(`Added field "${fieldPath.nestedFieldId}" (Date) to group "${fieldPath.groupId}" in ${typeId}`);
148
+ } else {
149
+ console.info(`Added field "${fieldId}" (Date) to "${targetTab}" tab in ${typeId}`);
150
+ }
151
+
152
+ try {
153
+ await buildTypes({ output: types });
154
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
155
+ } catch (error) {
156
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
157
+ }
158
+
159
+ console.info();
160
+ console.info("Next: Add more fields with `prismic page-type add-field`");
161
+
162
+ if (framework) {
163
+ const docsPath = getDocsPath(framework.id);
164
+ console.info(
165
+ ` Run \`prismic docs fetch ${docsPath}#write-page-components\` to learn how to implement a page file`,
166
+ );
167
+ }
168
+ }
@@ -0,0 +1,165 @@
1
+ import type { CustomType, Embed } from "@prismicio/types-internal/lib/customtypes";
2
+
3
+ import { parseArgs } from "node:util";
4
+
5
+ import { buildTypes } from "./codegen-types";
6
+ import { findGroupInTab, isGroupField, parseFieldPath, validateNestedFieldPath } from "./lib/field-path";
7
+ import { getDocsPath, requireFramework } from "./framework";
8
+ import { humanReadable } from "./lib/string";
9
+
10
+ const HELP = `
11
+ Add an embed field to an existing page type.
12
+
13
+ USAGE
14
+ prismic page-type add-field embed <type-id> <field-id> [flags]
15
+
16
+ ARGUMENTS
17
+ type-id Page type identifier (required)
18
+ field-id Field identifier (required)
19
+
20
+ FLAGS
21
+ -t, --tab string Target tab (default: first existing tab, or "Main")
22
+ -l, --label string Display label for the field (inferred from field-id if omitted)
23
+ -p, --placeholder string Placeholder text
24
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
25
+ -h, --help Show help for command
26
+
27
+ EXAMPLES
28
+ prismic page-type add-field embed homepage video
29
+ prismic page-type add-field embed homepage youtube --tab "Media"
30
+ prismic page-type add-field embed homepage media --label "Media Embed"
31
+ `.trim();
32
+
33
+
34
+ export async function pageTypeAddFieldEmbed(): Promise<void> {
35
+ const {
36
+ values: { help, tab, label, placeholder, types },
37
+ positionals: [typeId, fieldId],
38
+ } = parseArgs({
39
+ args: process.argv.slice(5), // skip: node, script, "page-type", "add-field", "embed"
40
+ options: {
41
+ tab: { type: "string", short: "t" },
42
+ label: { type: "string", short: "l" },
43
+ placeholder: { type: "string", short: "p" },
44
+ types: { type: "string" },
45
+ help: { type: "boolean", short: "h" },
46
+ },
47
+ allowPositionals: true,
48
+ });
49
+
50
+ if (help) {
51
+ console.info(HELP);
52
+ return;
53
+ }
54
+
55
+ if (!typeId) {
56
+ console.error("Missing required argument: type-id\n");
57
+ console.error("Usage: prismic page-type add-field embed <type-id> <field-id>");
58
+ process.exitCode = 1;
59
+ return;
60
+ }
61
+
62
+ if (!fieldId) {
63
+ console.error("Missing required argument: field-id\n");
64
+ console.error("Usage: prismic page-type add-field embed <type-id> <field-id>");
65
+ process.exitCode = 1;
66
+ return;
67
+ }
68
+
69
+ // Parse and validate field path
70
+ const fieldPath = parseFieldPath(fieldId);
71
+ const pathValidation = validateNestedFieldPath(fieldPath);
72
+ if (!pathValidation.ok) {
73
+ console.error(pathValidation.error);
74
+ process.exitCode = 1;
75
+ return;
76
+ }
77
+
78
+ const framework = await requireFramework();
79
+ if (!framework) return;
80
+
81
+ let model: CustomType;
82
+ try {
83
+ model = await framework.readCustomType(typeId);
84
+ } catch {
85
+ console.error(`Page type not found: ${typeId}\n\nCreate it first with: prismic page-type create ${typeId}`);
86
+ process.exitCode = 1;
87
+ return;
88
+ }
89
+
90
+ // Determine target tab
91
+ const existingTabs = Object.keys(model.json);
92
+ const targetTab = tab ?? existingTabs[0] ?? "Main";
93
+
94
+ // Initialize tab if it doesn't exist
95
+ if (!model.json[targetTab]) {
96
+ model.json[targetTab] = {};
97
+ }
98
+
99
+ // Build field definition
100
+ const fieldDefinition: Embed = {
101
+ type: "Embed",
102
+ config: {
103
+ label: label ?? humanReadable(fieldPath.type === "nested" ? fieldPath.nestedFieldId : fieldId),
104
+ ...(placeholder && { placeholder }),
105
+ },
106
+ };
107
+
108
+ // Add field to model
109
+ if (fieldPath.type === "nested") {
110
+ const groupResult = findGroupInTab(model.json[targetTab], fieldPath.groupId, targetTab);
111
+ if (!groupResult.ok) {
112
+ console.error(groupResult.error);
113
+ process.exitCode = 1;
114
+ return;
115
+ }
116
+ if (groupResult.group.config.fields[fieldPath.nestedFieldId]) {
117
+ console.error(`Field "${fieldPath.nestedFieldId}" already exists in group "${fieldPath.groupId}"`);
118
+ process.exitCode = 1;
119
+ return;
120
+ }
121
+ groupResult.group.config.fields[fieldPath.nestedFieldId] = fieldDefinition;
122
+ } else {
123
+ for (const [tabName, tabFields] of Object.entries(model.json)) {
124
+ if (tabFields[fieldId]) {
125
+ console.error(`Field "${fieldId}" already exists in tab "${tabName}"`);
126
+ process.exitCode = 1;
127
+ return;
128
+ }
129
+ for (const [groupFieldId, groupField] of Object.entries(tabFields)) {
130
+ if (isGroupField(groupField) && groupField.config.fields[fieldId]) {
131
+ console.error(`Field "${fieldId}" already exists in group "${groupFieldId}" in tab "${tabName}"`);
132
+ process.exitCode = 1;
133
+ return;
134
+ }
135
+ }
136
+ }
137
+ model.json[targetTab][fieldId] = fieldDefinition;
138
+ }
139
+
140
+ // Write updated model
141
+ await framework.updateCustomType(model);
142
+
143
+ if (fieldPath.type === "nested") {
144
+ console.info(`Added field "${fieldPath.nestedFieldId}" (Embed) to group "${fieldPath.groupId}" in ${typeId}`);
145
+ } else {
146
+ console.info(`Added field "${fieldId}" (Embed) to "${targetTab}" tab in ${typeId}`);
147
+ }
148
+
149
+ try {
150
+ await buildTypes({ output: types });
151
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
152
+ } catch (error) {
153
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
154
+ }
155
+
156
+ console.info();
157
+ console.info("Next: Add more fields with `prismic page-type add-field`");
158
+
159
+ if (framework) {
160
+ const docsPath = getDocsPath(framework.id);
161
+ console.info(
162
+ ` Run \`prismic docs fetch ${docsPath}#write-page-components\` to learn how to implement a page file`,
163
+ );
164
+ }
165
+ }
@@ -0,0 +1,162 @@
1
+ import type { CustomType, GeoPoint } from "@prismicio/types-internal/lib/customtypes";
2
+
3
+ import { parseArgs } from "node:util";
4
+
5
+ import { buildTypes } from "./codegen-types";
6
+ import { findGroupInTab, isGroupField, parseFieldPath, validateNestedFieldPath } from "./lib/field-path";
7
+ import { getDocsPath, requireFramework } from "./framework";
8
+ import { humanReadable } from "./lib/string";
9
+
10
+ const HELP = `
11
+ Add a geo-point (location) field to an existing page type.
12
+
13
+ USAGE
14
+ prismic page-type add-field geo-point <type-id> <field-id> [flags]
15
+
16
+ ARGUMENTS
17
+ type-id Page type identifier (required)
18
+ field-id Field identifier (required)
19
+
20
+ FLAGS
21
+ -t, --tab string Target tab (default: first existing tab, or "Main")
22
+ -l, --label string Display label for the field (inferred from field-id if omitted)
23
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
24
+ -h, --help Show help for command
25
+
26
+ EXAMPLES
27
+ prismic page-type add-field geo-point homepage location
28
+ prismic page-type add-field geo-point store address --tab "Details"
29
+ prismic page-type add-field geo-point event venue --label "Event Venue"
30
+ `.trim();
31
+
32
+
33
+ export async function pageTypeAddFieldGeoPoint(): Promise<void> {
34
+ const {
35
+ values: { help, tab, label, types },
36
+ positionals: [typeId, fieldId],
37
+ } = parseArgs({
38
+ args: process.argv.slice(5), // skip: node, script, "page-type", "add-field", "geo-point"
39
+ options: {
40
+ tab: { type: "string", short: "t" },
41
+ label: { type: "string", short: "l" },
42
+ types: { type: "string" },
43
+ help: { type: "boolean", short: "h" },
44
+ },
45
+ allowPositionals: true,
46
+ });
47
+
48
+ if (help) {
49
+ console.info(HELP);
50
+ return;
51
+ }
52
+
53
+ if (!typeId) {
54
+ console.error("Missing required argument: type-id\n");
55
+ console.error("Usage: prismic page-type add-field geo-point <type-id> <field-id>");
56
+ process.exitCode = 1;
57
+ return;
58
+ }
59
+
60
+ if (!fieldId) {
61
+ console.error("Missing required argument: field-id\n");
62
+ console.error("Usage: prismic page-type add-field geo-point <type-id> <field-id>");
63
+ process.exitCode = 1;
64
+ return;
65
+ }
66
+
67
+ // Parse and validate field path
68
+ const fieldPath = parseFieldPath(fieldId);
69
+ const pathValidation = validateNestedFieldPath(fieldPath);
70
+ if (!pathValidation.ok) {
71
+ console.error(pathValidation.error);
72
+ process.exitCode = 1;
73
+ return;
74
+ }
75
+
76
+ const framework = await requireFramework();
77
+ if (!framework) return;
78
+
79
+ let model: CustomType;
80
+ try {
81
+ model = await framework.readCustomType(typeId);
82
+ } catch {
83
+ console.error(`Page type not found: ${typeId}\n\nCreate it first with: prismic page-type create ${typeId}`);
84
+ process.exitCode = 1;
85
+ return;
86
+ }
87
+
88
+ // Determine target tab
89
+ const existingTabs = Object.keys(model.json);
90
+ const targetTab = tab ?? existingTabs[0] ?? "Main";
91
+
92
+ // Initialize tab if it doesn't exist
93
+ if (!model.json[targetTab]) {
94
+ model.json[targetTab] = {};
95
+ }
96
+
97
+ // Build field definition
98
+ const fieldDefinition: GeoPoint = {
99
+ type: "GeoPoint",
100
+ config: {
101
+ label: label ?? humanReadable(fieldPath.type === "nested" ? fieldPath.nestedFieldId : fieldId),
102
+ },
103
+ };
104
+
105
+ // Add field to model
106
+ if (fieldPath.type === "nested") {
107
+ const groupResult = findGroupInTab(model.json[targetTab], fieldPath.groupId, targetTab);
108
+ if (!groupResult.ok) {
109
+ console.error(groupResult.error);
110
+ process.exitCode = 1;
111
+ return;
112
+ }
113
+ if (groupResult.group.config.fields[fieldPath.nestedFieldId]) {
114
+ console.error(`Field "${fieldPath.nestedFieldId}" already exists in group "${fieldPath.groupId}"`);
115
+ process.exitCode = 1;
116
+ return;
117
+ }
118
+ groupResult.group.config.fields[fieldPath.nestedFieldId] = fieldDefinition;
119
+ } else {
120
+ for (const [tabName, tabFields] of Object.entries(model.json)) {
121
+ if (tabFields[fieldId]) {
122
+ console.error(`Field "${fieldId}" already exists in tab "${tabName}"`);
123
+ process.exitCode = 1;
124
+ return;
125
+ }
126
+ for (const [groupFieldId, groupField] of Object.entries(tabFields)) {
127
+ if (isGroupField(groupField) && groupField.config.fields[fieldId]) {
128
+ console.error(`Field "${fieldId}" already exists in group "${groupFieldId}" in tab "${tabName}"`);
129
+ process.exitCode = 1;
130
+ return;
131
+ }
132
+ }
133
+ }
134
+ model.json[targetTab][fieldId] = fieldDefinition;
135
+ }
136
+
137
+ // Write updated model
138
+ await framework.updateCustomType(model);
139
+
140
+ if (fieldPath.type === "nested") {
141
+ console.info(`Added field "${fieldPath.nestedFieldId}" (GeoPoint) to group "${fieldPath.groupId}" in ${typeId}`);
142
+ } else {
143
+ console.info(`Added field "${fieldId}" (GeoPoint) to "${targetTab}" tab in ${typeId}`);
144
+ }
145
+
146
+ try {
147
+ await buildTypes({ output: types });
148
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
149
+ } catch (error) {
150
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
151
+ }
152
+
153
+ console.info();
154
+ console.info("Next: Add more fields with `prismic page-type add-field`");
155
+
156
+ if (framework) {
157
+ const docsPath = getDocsPath(framework.id);
158
+ console.info(
159
+ ` Run \`prismic docs fetch ${docsPath}#write-page-components\` to learn how to implement a page file`,
160
+ );
161
+ }
162
+ }