@angeloashmore/prismic-cli-poc 0.0.0-canary.d96e685 → 0.0.0-pr.3.219652e

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 (83) hide show
  1. package/dist/index.mjs +843 -271
  2. package/package.json +2 -1
  3. package/src/codegen-types.ts +82 -0
  4. package/src/codegen.ts +45 -0
  5. package/src/custom-type-add-field-boolean.ts +22 -5
  6. package/src/custom-type-add-field-color.ts +21 -6
  7. package/src/custom-type-add-field-date.ts +21 -6
  8. package/src/custom-type-add-field-embed.ts +21 -6
  9. package/src/custom-type-add-field-geo-point.ts +21 -6
  10. package/src/custom-type-add-field-image.ts +21 -6
  11. package/src/custom-type-add-field-key-text.ts +21 -6
  12. package/src/custom-type-add-field-link.ts +22 -5
  13. package/src/custom-type-add-field-number.ts +21 -6
  14. package/src/custom-type-add-field-rich-text.ts +22 -5
  15. package/src/custom-type-add-field-select.ts +30 -6
  16. package/src/custom-type-add-field-timestamp.ts +21 -6
  17. package/src/custom-type-add-field-uid.ts +21 -6
  18. package/src/custom-type-connect-slice.ts +24 -25
  19. package/src/custom-type-create.ts +17 -1
  20. package/src/custom-type-disconnect-slice.ts +24 -26
  21. package/src/custom-type-remove-field.ts +17 -1
  22. package/src/custom-type-remove.ts +20 -2
  23. package/src/custom-type-set-name.ts +17 -1
  24. package/src/index.ts +77 -45
  25. package/src/init.ts +3 -1
  26. package/src/lib/auth.ts +24 -1
  27. package/src/lib/custom-types-api.ts +438 -0
  28. package/src/lib/framework.ts +143 -0
  29. package/src/lib/slice.ts +5 -2
  30. package/src/lib/string.ts +6 -0
  31. package/src/login.ts +18 -9
  32. package/src/page-type-add-field-boolean.ts +22 -5
  33. package/src/page-type-add-field-color.ts +21 -6
  34. package/src/page-type-add-field-date.ts +21 -6
  35. package/src/page-type-add-field-embed.ts +21 -6
  36. package/src/page-type-add-field-geo-point.ts +21 -6
  37. package/src/page-type-add-field-image.ts +21 -6
  38. package/src/page-type-add-field-key-text.ts +21 -6
  39. package/src/page-type-add-field-link.ts +22 -5
  40. package/src/page-type-add-field-number.ts +21 -6
  41. package/src/page-type-add-field-rich-text.ts +22 -5
  42. package/src/page-type-add-field-select.ts +30 -6
  43. package/src/page-type-add-field-timestamp.ts +21 -6
  44. package/src/page-type-add-field-uid.ts +21 -6
  45. package/src/page-type-connect-slice.ts +24 -25
  46. package/src/page-type-create.ts +17 -1
  47. package/src/page-type-disconnect-slice.ts +24 -26
  48. package/src/page-type-remove-field.ts +17 -1
  49. package/src/page-type-remove.ts +20 -2
  50. package/src/page-type-set-name.ts +17 -1
  51. package/src/page-type-set-repeatable.ts +17 -1
  52. package/src/preview-get-simulator.ts +104 -0
  53. package/src/preview-remove-simulator.ts +80 -0
  54. package/src/preview-set-simulator.ts +116 -0
  55. package/src/preview.ts +19 -4
  56. package/src/pull.ts +247 -0
  57. package/src/push.ts +405 -0
  58. package/src/repo-get-access.ts +86 -0
  59. package/src/repo-set-access.ts +100 -0
  60. package/src/repo.ts +10 -0
  61. package/src/slice-add-field-boolean.ts +21 -2
  62. package/src/slice-add-field-color.ts +20 -3
  63. package/src/slice-add-field-date.ts +20 -3
  64. package/src/slice-add-field-embed.ts +20 -3
  65. package/src/slice-add-field-geo-point.ts +20 -3
  66. package/src/slice-add-field-image.ts +20 -3
  67. package/src/slice-add-field-key-text.ts +20 -3
  68. package/src/slice-add-field-link.ts +21 -2
  69. package/src/slice-add-field-number.ts +20 -3
  70. package/src/slice-add-field-rich-text.ts +21 -2
  71. package/src/slice-add-field-select.ts +29 -3
  72. package/src/slice-add-field-timestamp.ts +20 -3
  73. package/src/slice-add-variation.ts +21 -13
  74. package/src/slice-create.ts +17 -1
  75. package/src/slice-remove-field.ts +20 -9
  76. package/src/slice-remove-variation.ts +20 -10
  77. package/src/slice-remove.ts +17 -1
  78. package/src/slice-rename.ts +17 -1
  79. package/src/status.ts +588 -0
  80. package/src/token-create.ts +23 -5
  81. package/src/token-delete.ts +29 -8
  82. package/src/token-list.ts +14 -3
  83. package/src/token-set-name.ts +38 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angeloashmore/prismic-cli-poc",
3
- "version": "0.0.0-canary.d96e685",
3
+ "version": "0.0.0-pr.3.219652e",
4
4
  "description": "A proof-of-concept developer CLI for Prismic.",
5
5
  "keywords": [
6
6
  "prismic",
@@ -41,6 +41,7 @@
41
41
  "@vitest/coverage-v8": "4.0.17",
42
42
  "oxfmt": "^0.24.0",
43
43
  "oxlint": "1.39.0",
44
+ "prismic-ts-codegen": "^0.1.28",
44
45
  "tsdown": "0.19.0",
45
46
  "typescript": "5.9.3",
46
47
  "valibot": "^1.2.0",
@@ -0,0 +1,82 @@
1
+ import type { CustomTypeModel, SharedSliceModel } from "@prismicio/client";
2
+
3
+ import { writeFile } from "node:fs/promises";
4
+ import { parseArgs } from "node:util";
5
+ import { generateTypes, NON_EDITABLE_FILE_HEADER } from "prismic-ts-codegen";
6
+
7
+ import { readLocalCustomTypes, readLocalSlices } from "./lib/custom-types-api";
8
+
9
+ const HELP = `
10
+ Generate TypeScript types from local custom type and slice models.
11
+
12
+ USAGE
13
+ prismic codegen types [flags]
14
+
15
+ FLAGS
16
+ -o, --output string Output file path (default: "prismicio-types.d.ts")
17
+ -h, --help Show help for command
18
+
19
+ EXAMPLES
20
+ prismic codegen types
21
+ prismic codegen types --output custom.d.ts
22
+ `.trim();
23
+
24
+ export async function codegenTypes(): Promise<void> {
25
+ const {
26
+ values: { help, output },
27
+ } = parseArgs({
28
+ args: process.argv.slice(4), // skip: node, script, "codegen", "types"
29
+ options: {
30
+ output: { type: "string", short: "o" },
31
+ help: { type: "boolean", short: "h" },
32
+ },
33
+ allowPositionals: false,
34
+ });
35
+
36
+ if (help) {
37
+ console.info(HELP);
38
+ return;
39
+ }
40
+
41
+ try {
42
+ await buildTypes({ output });
43
+ console.info(`Generated types written to ${output ?? "prismicio-types.d.ts"}`);
44
+ } catch (error) {
45
+ console.error(error instanceof Error ? error.message : String(error));
46
+ process.exitCode = 1;
47
+ }
48
+ }
49
+
50
+ export async function buildTypes(args?: { output?: string }): Promise<void> {
51
+ const output = args?.output ?? "prismicio-types.d.ts";
52
+
53
+ const [customTypesResult, slicesResult] = await Promise.all([
54
+ readLocalCustomTypes(),
55
+ readLocalSlices(),
56
+ ]);
57
+
58
+ if (!customTypesResult.ok) {
59
+ throw new Error(`failed to read local custom types: ${customTypesResult.error}`);
60
+ }
61
+
62
+ if (!slicesResult.ok) {
63
+ throw new Error(`failed to read local slices: ${slicesResult.error}`);
64
+ }
65
+
66
+ const customTypes = customTypesResult.value as unknown as CustomTypeModel[];
67
+ const slices = slicesResult.value as unknown as SharedSliceModel[];
68
+
69
+ const types = generateTypes({
70
+ customTypeModels: customTypes,
71
+ sharedSliceModels: slices,
72
+ typesProvider: "@prismicio/client",
73
+ clientIntegration: {
74
+ includeCreateClientInterface: customTypes.length > 0 || slices.length > 0,
75
+ includeContentNamespace: true,
76
+ },
77
+ });
78
+
79
+ const content = NON_EDITABLE_FILE_HEADER + "\n\n" + types;
80
+
81
+ await writeFile(output, content);
82
+ }
package/src/codegen.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { parseArgs } from "node:util";
2
+
3
+ import { codegenTypes } from "./codegen-types";
4
+
5
+ const HELP = `
6
+ Generate code from Prismic models.
7
+
8
+ USAGE
9
+ prismic codegen <command> [flags]
10
+
11
+ COMMANDS
12
+ types Generate TypeScript types from models pushed to Prismic
13
+
14
+ FLAGS
15
+ -h, --help Show help for command
16
+
17
+ LEARN MORE
18
+ Use \`prismic codegen <command> --help\` for more information about a command.
19
+ `.trim();
20
+
21
+ export async function codegen(): Promise<void> {
22
+ const {
23
+ positionals: [subcommand],
24
+ } = parseArgs({
25
+ args: process.argv.slice(3), // skip: node, script, "codegen"
26
+ options: {
27
+ help: { type: "boolean", short: "h" },
28
+ },
29
+ allowPositionals: true,
30
+ strict: false,
31
+ });
32
+
33
+ switch (subcommand) {
34
+ case "types":
35
+ await codegenTypes();
36
+ break;
37
+ default: {
38
+ if (subcommand) {
39
+ console.error(`Unknown codegen subcommand: ${subcommand}\n`);
40
+ process.exitCode = 1;
41
+ }
42
+ console.info(HELP);
43
+ }
44
+ }
45
+ }
@@ -4,8 +4,10 @@ import { readFile, writeFile } from "node:fs/promises";
4
4
  import { parseArgs } from "node:util";
5
5
  import * as v from "valibot";
6
6
 
7
+ import { buildTypes } from "./codegen-types";
7
8
  import { findUpward } from "./lib/file";
8
9
  import { stringify } from "./lib/json";
10
+ import { humanReadable } from "./lib/string";
9
11
 
10
12
  const HELP = `
11
13
  Add a boolean (toggle) field to an existing custom type.
@@ -17,12 +19,16 @@ ARGUMENTS
17
19
  type-id Custom type identifier (required)
18
20
  field-id Field identifier (required)
19
21
 
22
+ Types are generated by default after changes. Use --no-types to skip.
23
+
20
24
  FLAGS
21
25
  -t, --tab string Target tab (default: first existing tab, or "Main")
22
- -l, --label string Display label for the field
26
+ -l, --label string Display label for the field (inferred from field-id if omitted)
23
27
  --default Set default value to true
24
28
  --true-label string Label shown when toggle is on
25
29
  --false-label string Label shown when toggle is off
30
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
31
+ --no-types Skip type generation
26
32
  -h, --help Show help for command
27
33
 
28
34
  EXAMPLES
@@ -49,6 +55,8 @@ export async function customTypeAddFieldBoolean(): Promise<void> {
49
55
  default: defaultValue,
50
56
  "true-label": trueLabel,
51
57
  "false-label": falseLabel,
58
+ types,
59
+ "no-types": noTypes,
52
60
  },
53
61
  positionals: [typeId, fieldId],
54
62
  } = parseArgs({
@@ -59,6 +67,8 @@ export async function customTypeAddFieldBoolean(): Promise<void> {
59
67
  default: { type: "boolean" },
60
68
  "true-label": { type: "string" },
61
69
  "false-label": { type: "string" },
70
+ types: { type: "string" },
71
+ "no-types": { type: "boolean" },
62
72
  help: { type: "boolean", short: "h" },
63
73
  },
64
74
  allowPositionals: true,
@@ -142,7 +152,7 @@ export async function customTypeAddFieldBoolean(): Promise<void> {
142
152
  const fieldDefinition: BooleanField = {
143
153
  type: "Boolean",
144
154
  config: {
145
- ...(label && { label }),
155
+ label: label ?? humanReadable(fieldId),
146
156
  ...(defaultValue && { default_value: true }),
147
157
  ...(trueLabel && { placeholder_true: trueLabel }),
148
158
  ...(falseLabel && { placeholder_false: falseLabel }),
@@ -165,7 +175,14 @@ export async function customTypeAddFieldBoolean(): Promise<void> {
165
175
  return;
166
176
  }
167
177
 
168
- console.info(
169
- `Added field "${fieldId}" (Boolean) to "${targetTab}" tab in ${typeId}`,
170
- );
178
+ console.info(`Added field "${fieldId}" (Boolean) to "${targetTab}" tab in ${typeId}`);
179
+
180
+ if (!noTypes) {
181
+ try {
182
+ await buildTypes({ output: types });
183
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
184
+ } catch (error) {
185
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
186
+ }
187
+ }
171
188
  }
@@ -4,8 +4,10 @@ import { readFile, writeFile } from "node:fs/promises";
4
4
  import { parseArgs } from "node:util";
5
5
  import * as v from "valibot";
6
6
 
7
+ import { buildTypes } from "./codegen-types";
7
8
  import { findUpward } from "./lib/file";
8
9
  import { stringify } from "./lib/json";
10
+ import { humanReadable } from "./lib/string";
9
11
 
10
12
  const HELP = `
11
13
  Add a color picker field to an existing custom type.
@@ -17,10 +19,14 @@ ARGUMENTS
17
19
  type-id Custom type identifier (required)
18
20
  field-id Field identifier (required)
19
21
 
22
+ Types are generated by default after changes. Use --no-types to skip.
23
+
20
24
  FLAGS
21
25
  -t, --tab string Target tab (default: first existing tab, or "Main")
22
- -l, --label string Display label for the field
26
+ -l, --label string Display label for the field (inferred from field-id if omitted)
23
27
  -p, --placeholder string Placeholder text
28
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
29
+ --no-types Skip type generation
24
30
  -h, --help Show help for command
25
31
 
26
32
  EXAMPLES
@@ -40,7 +46,7 @@ const CustomTypeSchema = v.object({
40
46
 
41
47
  export async function customTypeAddFieldColor(): Promise<void> {
42
48
  const {
43
- values: { help, tab, label, placeholder },
49
+ values: { help, tab, label, placeholder, types, "no-types": noTypes },
44
50
  positionals: [typeId, fieldId],
45
51
  } = parseArgs({
46
52
  args: process.argv.slice(5), // skip: node, script, "custom-type", "add-field", "color"
@@ -48,6 +54,8 @@ export async function customTypeAddFieldColor(): Promise<void> {
48
54
  tab: { type: "string", short: "t" },
49
55
  label: { type: "string", short: "l" },
50
56
  placeholder: { type: "string", short: "p" },
57
+ types: { type: "string" },
58
+ "no-types": { type: "boolean" },
51
59
  help: { type: "boolean", short: "h" },
52
60
  },
53
61
  allowPositionals: true,
@@ -131,7 +139,7 @@ export async function customTypeAddFieldColor(): Promise<void> {
131
139
  const fieldDefinition: Color = {
132
140
  type: "Color",
133
141
  config: {
134
- ...(label && { label }),
142
+ label: label ?? humanReadable(fieldId),
135
143
  ...(placeholder && { placeholder }),
136
144
  },
137
145
  };
@@ -152,7 +160,14 @@ export async function customTypeAddFieldColor(): Promise<void> {
152
160
  return;
153
161
  }
154
162
 
155
- console.info(
156
- `Added field "${fieldId}" (Color) to "${targetTab}" tab in ${typeId}`,
157
- );
163
+ console.info(`Added field "${fieldId}" (Color) to "${targetTab}" tab in ${typeId}`);
164
+
165
+ if (!noTypes) {
166
+ try {
167
+ await buildTypes({ output: types });
168
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
169
+ } catch (error) {
170
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
171
+ }
172
+ }
158
173
  }
@@ -4,8 +4,10 @@ import { readFile, writeFile } from "node:fs/promises";
4
4
  import { parseArgs } from "node:util";
5
5
  import * as v from "valibot";
6
6
 
7
+ import { buildTypes } from "./codegen-types";
7
8
  import { findUpward } from "./lib/file";
8
9
  import { stringify } from "./lib/json";
10
+ import { humanReadable } from "./lib/string";
9
11
 
10
12
  const HELP = `
11
13
  Add a date field to an existing custom type.
@@ -17,11 +19,15 @@ ARGUMENTS
17
19
  type-id Custom type identifier (required)
18
20
  field-id Field identifier (required)
19
21
 
22
+ Types are generated by default after changes. Use --no-types to skip.
23
+
20
24
  FLAGS
21
25
  -t, --tab string Target tab (default: first existing tab, or "Main")
22
- -l, --label string Display label for the field
26
+ -l, --label string Display label for the field (inferred from field-id if omitted)
23
27
  -p, --placeholder string Placeholder text
24
28
  --default string Default date value (YYYY-MM-DD format)
29
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
30
+ --no-types Skip type generation
25
31
  -h, --help Show help for command
26
32
 
27
33
  EXAMPLES
@@ -41,7 +47,7 @@ const CustomTypeSchema = v.object({
41
47
 
42
48
  export async function customTypeAddFieldDate(): Promise<void> {
43
49
  const {
44
- values: { help, tab, label, placeholder, default: defaultValue },
50
+ values: { help, tab, label, placeholder, default: defaultValue, types, "no-types": noTypes },
45
51
  positionals: [typeId, fieldId],
46
52
  } = parseArgs({
47
53
  args: process.argv.slice(5), // skip: node, script, "custom-type", "add-field", "date"
@@ -50,6 +56,8 @@ export async function customTypeAddFieldDate(): Promise<void> {
50
56
  label: { type: "string", short: "l" },
51
57
  placeholder: { type: "string", short: "p" },
52
58
  default: { type: "string" },
59
+ types: { type: "string" },
60
+ "no-types": { type: "boolean" },
53
61
  help: { type: "boolean", short: "h" },
54
62
  },
55
63
  allowPositionals: true,
@@ -133,7 +141,7 @@ export async function customTypeAddFieldDate(): Promise<void> {
133
141
  const fieldDefinition: DateField = {
134
142
  type: "Date",
135
143
  config: {
136
- ...(label && { label }),
144
+ label: label ?? humanReadable(fieldId),
137
145
  ...(placeholder && { placeholder }),
138
146
  ...(defaultValue && { default: defaultValue }),
139
147
  },
@@ -155,7 +163,14 @@ export async function customTypeAddFieldDate(): Promise<void> {
155
163
  return;
156
164
  }
157
165
 
158
- console.info(
159
- `Added field "${fieldId}" (Date) to "${targetTab}" tab in ${typeId}`,
160
- );
166
+ console.info(`Added field "${fieldId}" (Date) to "${targetTab}" tab in ${typeId}`);
167
+
168
+ if (!noTypes) {
169
+ try {
170
+ await buildTypes({ output: types });
171
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
172
+ } catch (error) {
173
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
174
+ }
175
+ }
161
176
  }
@@ -4,8 +4,10 @@ import { readFile, writeFile } from "node:fs/promises";
4
4
  import { parseArgs } from "node:util";
5
5
  import * as v from "valibot";
6
6
 
7
+ import { buildTypes } from "./codegen-types";
7
8
  import { findUpward } from "./lib/file";
8
9
  import { stringify } from "./lib/json";
10
+ import { humanReadable } from "./lib/string";
9
11
 
10
12
  const HELP = `
11
13
  Add an embed field to an existing custom type.
@@ -17,10 +19,14 @@ ARGUMENTS
17
19
  type-id Custom type identifier (required)
18
20
  field-id Field identifier (required)
19
21
 
22
+ Types are generated by default after changes. Use --no-types to skip.
23
+
20
24
  FLAGS
21
25
  -t, --tab string Target tab (default: first existing tab, or "Main")
22
- -l, --label string Display label for the field
26
+ -l, --label string Display label for the field (inferred from field-id if omitted)
23
27
  -p, --placeholder string Placeholder text
28
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
29
+ --no-types Skip type generation
24
30
  -h, --help Show help for command
25
31
 
26
32
  EXAMPLES
@@ -40,7 +46,7 @@ const CustomTypeSchema = v.object({
40
46
 
41
47
  export async function customTypeAddFieldEmbed(): Promise<void> {
42
48
  const {
43
- values: { help, tab, label, placeholder },
49
+ values: { help, tab, label, placeholder, types, "no-types": noTypes },
44
50
  positionals: [typeId, fieldId],
45
51
  } = parseArgs({
46
52
  args: process.argv.slice(5), // skip: node, script, "custom-type", "add-field", "embed"
@@ -48,6 +54,8 @@ export async function customTypeAddFieldEmbed(): Promise<void> {
48
54
  tab: { type: "string", short: "t" },
49
55
  label: { type: "string", short: "l" },
50
56
  placeholder: { type: "string", short: "p" },
57
+ types: { type: "string" },
58
+ "no-types": { type: "boolean" },
51
59
  help: { type: "boolean", short: "h" },
52
60
  },
53
61
  allowPositionals: true,
@@ -131,7 +139,7 @@ export async function customTypeAddFieldEmbed(): Promise<void> {
131
139
  const fieldDefinition: Embed = {
132
140
  type: "Embed",
133
141
  config: {
134
- ...(label && { label }),
142
+ label: label ?? humanReadable(fieldId),
135
143
  ...(placeholder && { placeholder }),
136
144
  },
137
145
  };
@@ -152,7 +160,14 @@ export async function customTypeAddFieldEmbed(): Promise<void> {
152
160
  return;
153
161
  }
154
162
 
155
- console.info(
156
- `Added field "${fieldId}" (Embed) to "${targetTab}" tab in ${typeId}`,
157
- );
163
+ console.info(`Added field "${fieldId}" (Embed) to "${targetTab}" tab in ${typeId}`);
164
+
165
+ if (!noTypes) {
166
+ try {
167
+ await buildTypes({ output: types });
168
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
169
+ } catch (error) {
170
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
171
+ }
172
+ }
158
173
  }
@@ -4,8 +4,10 @@ import { readFile, writeFile } from "node:fs/promises";
4
4
  import { parseArgs } from "node:util";
5
5
  import * as v from "valibot";
6
6
 
7
+ import { buildTypes } from "./codegen-types";
7
8
  import { findUpward } from "./lib/file";
8
9
  import { stringify } from "./lib/json";
10
+ import { humanReadable } from "./lib/string";
9
11
 
10
12
  const HELP = `
11
13
  Add a geo-point (location) field to an existing custom type.
@@ -17,9 +19,13 @@ ARGUMENTS
17
19
  type-id Custom type identifier (required)
18
20
  field-id Field identifier (required)
19
21
 
22
+ Types are generated by default after changes. Use --no-types to skip.
23
+
20
24
  FLAGS
21
25
  -t, --tab string Target tab (default: first existing tab, or "Main")
22
- -l, --label string Display label for the field
26
+ -l, --label string Display label for the field (inferred from field-id if omitted)
27
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
28
+ --no-types Skip type generation
23
29
  -h, --help Show help for command
24
30
 
25
31
  EXAMPLES
@@ -39,13 +45,15 @@ const CustomTypeSchema = v.object({
39
45
 
40
46
  export async function customTypeAddFieldGeoPoint(): Promise<void> {
41
47
  const {
42
- values: { help, tab, label },
48
+ values: { help, tab, label, types, "no-types": noTypes },
43
49
  positionals: [typeId, fieldId],
44
50
  } = parseArgs({
45
51
  args: process.argv.slice(5), // skip: node, script, "custom-type", "add-field", "geo-point"
46
52
  options: {
47
53
  tab: { type: "string", short: "t" },
48
54
  label: { type: "string", short: "l" },
55
+ types: { type: "string" },
56
+ "no-types": { type: "boolean" },
49
57
  help: { type: "boolean", short: "h" },
50
58
  },
51
59
  allowPositionals: true,
@@ -129,7 +137,7 @@ export async function customTypeAddFieldGeoPoint(): Promise<void> {
129
137
  const fieldDefinition: GeoPoint = {
130
138
  type: "GeoPoint",
131
139
  config: {
132
- ...(label && { label }),
140
+ label: label ?? humanReadable(fieldId),
133
141
  },
134
142
  };
135
143
 
@@ -149,7 +157,14 @@ export async function customTypeAddFieldGeoPoint(): Promise<void> {
149
157
  return;
150
158
  }
151
159
 
152
- console.info(
153
- `Added field "${fieldId}" (GeoPoint) to "${targetTab}" tab in ${typeId}`,
154
- );
160
+ console.info(`Added field "${fieldId}" (GeoPoint) to "${targetTab}" tab in ${typeId}`);
161
+
162
+ if (!noTypes) {
163
+ try {
164
+ await buildTypes({ output: types });
165
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
166
+ } catch (error) {
167
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
168
+ }
169
+ }
155
170
  }
@@ -4,8 +4,10 @@ import { readFile, writeFile } from "node:fs/promises";
4
4
  import { parseArgs } from "node:util";
5
5
  import * as v from "valibot";
6
6
 
7
+ import { buildTypes } from "./codegen-types";
7
8
  import { findUpward } from "./lib/file";
8
9
  import { stringify } from "./lib/json";
10
+ import { humanReadable } from "./lib/string";
9
11
 
10
12
  const HELP = `
11
13
  Add an image field to an existing custom type.
@@ -17,10 +19,14 @@ ARGUMENTS
17
19
  type-id Custom type identifier (required)
18
20
  field-id Field identifier (required)
19
21
 
22
+ Types are generated by default after changes. Use --no-types to skip.
23
+
20
24
  FLAGS
21
25
  -t, --tab string Target tab (default: first existing tab, or "Main")
22
- -l, --label string Display label for the field
26
+ -l, --label string Display label for the field (inferred from field-id if omitted)
23
27
  -p, --placeholder string Placeholder text
28
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
29
+ --no-types Skip type generation
24
30
  -h, --help Show help for command
25
31
 
26
32
  EXAMPLES
@@ -40,7 +46,7 @@ const CustomTypeSchema = v.object({
40
46
 
41
47
  export async function customTypeAddFieldImage(): Promise<void> {
42
48
  const {
43
- values: { help, tab, label, placeholder },
49
+ values: { help, tab, label, placeholder, types, "no-types": noTypes },
44
50
  positionals: [typeId, fieldId],
45
51
  } = parseArgs({
46
52
  args: process.argv.slice(5), // skip: node, script, "custom-type", "add-field", "image"
@@ -48,6 +54,8 @@ export async function customTypeAddFieldImage(): Promise<void> {
48
54
  tab: { type: "string", short: "t" },
49
55
  label: { type: "string", short: "l" },
50
56
  placeholder: { type: "string", short: "p" },
57
+ types: { type: "string" },
58
+ "no-types": { type: "boolean" },
51
59
  help: { type: "boolean", short: "h" },
52
60
  },
53
61
  allowPositionals: true,
@@ -131,7 +139,7 @@ export async function customTypeAddFieldImage(): Promise<void> {
131
139
  const fieldDefinition: Image = {
132
140
  type: "Image",
133
141
  config: {
134
- ...(label && { label }),
142
+ label: label ?? humanReadable(fieldId),
135
143
  ...(placeholder && { placeholder }),
136
144
  },
137
145
  };
@@ -152,7 +160,14 @@ export async function customTypeAddFieldImage(): Promise<void> {
152
160
  return;
153
161
  }
154
162
 
155
- console.info(
156
- `Added field "${fieldId}" (Image) to "${targetTab}" tab in ${typeId}`,
157
- );
163
+ console.info(`Added field "${fieldId}" (Image) to "${targetTab}" tab in ${typeId}`);
164
+
165
+ if (!noTypes) {
166
+ try {
167
+ await buildTypes({ output: types });
168
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
169
+ } catch (error) {
170
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
171
+ }
172
+ }
158
173
  }
@@ -4,8 +4,10 @@ import { readFile, writeFile } from "node:fs/promises";
4
4
  import { parseArgs } from "node:util";
5
5
  import * as v from "valibot";
6
6
 
7
+ import { buildTypes } from "./codegen-types";
7
8
  import { findUpward } from "./lib/file";
8
9
  import { stringify } from "./lib/json";
10
+ import { humanReadable } from "./lib/string";
9
11
 
10
12
  const HELP = `
11
13
  Add a key-text (single-line text) field to an existing custom type.
@@ -17,10 +19,14 @@ ARGUMENTS
17
19
  type-id Custom type identifier (required)
18
20
  field-id Field identifier (required)
19
21
 
22
+ Types are generated by default after changes. Use --no-types to skip.
23
+
20
24
  FLAGS
21
25
  -t, --tab string Target tab (default: first existing tab, or "Main")
22
- -l, --label string Display label for the field
26
+ -l, --label string Display label for the field (inferred from field-id if omitted)
23
27
  -p, --placeholder string Placeholder text
28
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
29
+ --no-types Skip type generation
24
30
  -h, --help Show help for command
25
31
 
26
32
  EXAMPLES
@@ -40,7 +46,7 @@ const CustomTypeSchema = v.object({
40
46
 
41
47
  export async function customTypeAddFieldKeyText(): Promise<void> {
42
48
  const {
43
- values: { help, tab, label, placeholder },
49
+ values: { help, tab, label, placeholder, types, "no-types": noTypes },
44
50
  positionals: [typeId, fieldId],
45
51
  } = parseArgs({
46
52
  args: process.argv.slice(5), // skip: node, script, "custom-type", "add-field", "key-text"
@@ -48,6 +54,8 @@ export async function customTypeAddFieldKeyText(): Promise<void> {
48
54
  tab: { type: "string", short: "t" },
49
55
  label: { type: "string", short: "l" },
50
56
  placeholder: { type: "string", short: "p" },
57
+ types: { type: "string" },
58
+ "no-types": { type: "boolean" },
51
59
  help: { type: "boolean", short: "h" },
52
60
  },
53
61
  allowPositionals: true,
@@ -131,7 +139,7 @@ export async function customTypeAddFieldKeyText(): Promise<void> {
131
139
  const fieldDefinition: Text = {
132
140
  type: "Text",
133
141
  config: {
134
- ...(label && { label }),
142
+ label: label ?? humanReadable(fieldId),
135
143
  ...(placeholder && { placeholder }),
136
144
  },
137
145
  };
@@ -152,7 +160,14 @@ export async function customTypeAddFieldKeyText(): Promise<void> {
152
160
  return;
153
161
  }
154
162
 
155
- console.info(
156
- `Added field "${fieldId}" (Text) to "${targetTab}" tab in ${typeId}`,
157
- );
163
+ console.info(`Added field "${fieldId}" (Text) to "${targetTab}" tab in ${typeId}`);
164
+
165
+ if (!noTypes) {
166
+ try {
167
+ await buildTypes({ output: types });
168
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
169
+ } catch (error) {
170
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
171
+ }
172
+ }
158
173
  }