@angeloashmore/prismic-cli-poc 0.0.0-canary.1d36cd8

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 (131) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +98 -0
  3. package/dist/index.mjs +2548 -0
  4. package/package.json +53 -0
  5. package/src/codegen-types.ts +82 -0
  6. package/src/codegen.ts +45 -0
  7. package/src/custom-type-add-field-boolean.ts +192 -0
  8. package/src/custom-type-add-field-color.ts +177 -0
  9. package/src/custom-type-add-field-date.ts +180 -0
  10. package/src/custom-type-add-field-embed.ts +177 -0
  11. package/src/custom-type-add-field-geo-point.ts +174 -0
  12. package/src/custom-type-add-field-image.ts +177 -0
  13. package/src/custom-type-add-field-key-text.ts +177 -0
  14. package/src/custom-type-add-field-link.ts +201 -0
  15. package/src/custom-type-add-field-number.ts +209 -0
  16. package/src/custom-type-add-field-rich-text.ts +202 -0
  17. package/src/custom-type-add-field-select.ts +192 -0
  18. package/src/custom-type-add-field-timestamp.ts +180 -0
  19. package/src/custom-type-add-field-uid.ts +177 -0
  20. package/src/custom-type-add-field.ts +111 -0
  21. package/src/custom-type-connect-slice.ts +220 -0
  22. package/src/custom-type-create.ts +118 -0
  23. package/src/custom-type-disconnect-slice.ts +177 -0
  24. package/src/custom-type-list.ts +110 -0
  25. package/src/custom-type-remove-field.ts +177 -0
  26. package/src/custom-type-remove.ts +144 -0
  27. package/src/custom-type-set-name.ts +144 -0
  28. package/src/custom-type-view.ts +118 -0
  29. package/src/custom-type.ts +85 -0
  30. package/src/index.ts +127 -0
  31. package/src/init.ts +64 -0
  32. package/src/lib/auth.ts +83 -0
  33. package/src/lib/config.ts +111 -0
  34. package/src/lib/custom-types-api.ts +438 -0
  35. package/src/lib/file.ts +49 -0
  36. package/src/lib/framework.ts +143 -0
  37. package/src/lib/json.ts +3 -0
  38. package/src/lib/request.ts +116 -0
  39. package/src/lib/slice.ts +115 -0
  40. package/src/lib/string.ts +6 -0
  41. package/src/lib/url.ts +25 -0
  42. package/src/locale-add.ts +116 -0
  43. package/src/locale-list.ts +107 -0
  44. package/src/locale-remove.ts +88 -0
  45. package/src/locale-set-default.ts +131 -0
  46. package/src/locale.ts +60 -0
  47. package/src/login.ts +152 -0
  48. package/src/logout.ts +36 -0
  49. package/src/page-type-add-field-boolean.ts +192 -0
  50. package/src/page-type-add-field-color.ts +177 -0
  51. package/src/page-type-add-field-date.ts +180 -0
  52. package/src/page-type-add-field-embed.ts +177 -0
  53. package/src/page-type-add-field-geo-point.ts +174 -0
  54. package/src/page-type-add-field-image.ts +177 -0
  55. package/src/page-type-add-field-key-text.ts +177 -0
  56. package/src/page-type-add-field-link.ts +201 -0
  57. package/src/page-type-add-field-number.ts +209 -0
  58. package/src/page-type-add-field-rich-text.ts +202 -0
  59. package/src/page-type-add-field-select.ts +192 -0
  60. package/src/page-type-add-field-timestamp.ts +180 -0
  61. package/src/page-type-add-field-uid.ts +177 -0
  62. package/src/page-type-add-field.ts +111 -0
  63. package/src/page-type-connect-slice.ts +220 -0
  64. package/src/page-type-create.ts +142 -0
  65. package/src/page-type-disconnect-slice.ts +177 -0
  66. package/src/page-type-list.ts +109 -0
  67. package/src/page-type-remove-field.ts +177 -0
  68. package/src/page-type-remove.ts +144 -0
  69. package/src/page-type-set-name.ts +144 -0
  70. package/src/page-type-set-repeatable.ts +153 -0
  71. package/src/page-type-view.ts +118 -0
  72. package/src/page-type.ts +90 -0
  73. package/src/preview-add.ts +126 -0
  74. package/src/preview-get-simulator.ts +104 -0
  75. package/src/preview-list.ts +106 -0
  76. package/src/preview-remove-simulator.ts +80 -0
  77. package/src/preview-remove.ts +109 -0
  78. package/src/preview-set-name.ts +137 -0
  79. package/src/preview-set-simulator.ts +116 -0
  80. package/src/preview.ts +75 -0
  81. package/src/pull.ts +247 -0
  82. package/src/push.ts +405 -0
  83. package/src/repo-create.ts +136 -0
  84. package/src/repo-get-access.ts +86 -0
  85. package/src/repo-list.ts +100 -0
  86. package/src/repo-set-access.ts +100 -0
  87. package/src/repo-set-name.ts +102 -0
  88. package/src/repo-view.ts +113 -0
  89. package/src/repo.ts +70 -0
  90. package/src/slice-add-field-boolean.ts +173 -0
  91. package/src/slice-add-field-color.ts +158 -0
  92. package/src/slice-add-field-date.ts +158 -0
  93. package/src/slice-add-field-embed.ts +158 -0
  94. package/src/slice-add-field-geo-point.ts +155 -0
  95. package/src/slice-add-field-image.ts +155 -0
  96. package/src/slice-add-field-key-text.ts +158 -0
  97. package/src/slice-add-field-link.ts +178 -0
  98. package/src/slice-add-field-number.ts +158 -0
  99. package/src/slice-add-field-rich-text.ts +183 -0
  100. package/src/slice-add-field-select.ts +173 -0
  101. package/src/slice-add-field-timestamp.ts +158 -0
  102. package/src/slice-add-field.ts +106 -0
  103. package/src/slice-add-variation.ts +145 -0
  104. package/src/slice-create.ts +148 -0
  105. package/src/slice-list-variations.ts +67 -0
  106. package/src/slice-list.ts +88 -0
  107. package/src/slice-remove-field.ts +128 -0
  108. package/src/slice-remove-variation.ts +118 -0
  109. package/src/slice-remove.ts +97 -0
  110. package/src/slice-rename.ts +128 -0
  111. package/src/slice-view.ts +77 -0
  112. package/src/slice.ts +90 -0
  113. package/src/status.ts +733 -0
  114. package/src/token-create.ts +203 -0
  115. package/src/token-delete.ts +182 -0
  116. package/src/token-list.ts +223 -0
  117. package/src/token-set-name.ts +193 -0
  118. package/src/token.ts +60 -0
  119. package/src/webhook-add-header.ts +118 -0
  120. package/src/webhook-create.ts +152 -0
  121. package/src/webhook-disable.ts +109 -0
  122. package/src/webhook-enable.ts +132 -0
  123. package/src/webhook-list.ts +93 -0
  124. package/src/webhook-remove-header.ts +117 -0
  125. package/src/webhook-remove.ts +106 -0
  126. package/src/webhook-set-triggers.ts +148 -0
  127. package/src/webhook-status.ts +90 -0
  128. package/src/webhook-test.ts +106 -0
  129. package/src/webhook-view.ts +147 -0
  130. package/src/webhook.ts +95 -0
  131. package/src/whoami.ts +62 -0
@@ -0,0 +1,183 @@
1
+ import type { RichText, SharedSlice } from "@prismicio/types-internal/lib/customtypes";
2
+
3
+ import { writeFile } from "node:fs/promises";
4
+ import { parseArgs } from "node:util";
5
+
6
+ import { buildTypes } from "./codegen-types";
7
+ import { stringify } from "./lib/json";
8
+ import { findSliceModel } from "./lib/slice";
9
+ import { humanReadable } from "./lib/string";
10
+
11
+ const HELP = `
12
+ Add a rich text field to an existing slice.
13
+
14
+ USAGE
15
+ prismic slice add-field rich-text <slice-id> <field-id> [flags]
16
+
17
+ ARGUMENTS
18
+ slice-id Slice identifier (required)
19
+ field-id Field identifier (required)
20
+
21
+ Types are generated by default after changes. Use --no-types to skip.
22
+
23
+ FLAGS
24
+ -v, --variation string Target variation (default: first variation)
25
+ -l, --label string Display label for the field (inferred from field-id if omitted)
26
+ -p, --placeholder string Placeholder text
27
+ --single string Allowed block types for single-line (comma-separated)
28
+ --multi string Allowed block types for multi-line (comma-separated)
29
+ --allow-target-blank Allow opening links in new tab
30
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
31
+ --no-types Skip type generation
32
+ -h, --help Show help for command
33
+
34
+ BLOCK TYPES
35
+ heading1, heading2, heading3, heading4, heading5, heading6,
36
+ paragraph, strong, em, preformatted, hyperlink, image, embed,
37
+ list-item, o-list-item, rtl
38
+
39
+ EXAMPLES
40
+ prismic slice add-field rich-text my_slice body
41
+ prismic slice add-field rich-text article content --multi "paragraph,heading2,heading3,strong,em,hyperlink"
42
+ prismic slice add-field rich-text hero tagline --single "heading1"
43
+ prismic slice add-field rich-text blog post --multi "paragraph,strong,em,hyperlink" --allow-target-blank
44
+ `.trim();
45
+
46
+ export async function sliceAddFieldRichText(): Promise<void> {
47
+ const {
48
+ values: {
49
+ help,
50
+ variation,
51
+ label,
52
+ placeholder,
53
+ single,
54
+ multi,
55
+ "allow-target-blank": allowTargetBlank,
56
+ types,
57
+ "no-types": noTypes,
58
+ },
59
+ positionals: [sliceId, fieldId],
60
+ } = parseArgs({
61
+ args: process.argv.slice(5), // skip: node, script, "slice", "add-field", "rich-text"
62
+ options: {
63
+ variation: { type: "string", short: "v" },
64
+ label: { type: "string", short: "l" },
65
+ placeholder: { type: "string", short: "p" },
66
+ single: { type: "string" },
67
+ multi: { type: "string" },
68
+ "allow-target-blank": { type: "boolean" },
69
+ types: { type: "string" },
70
+ "no-types": { type: "boolean" },
71
+ help: { type: "boolean", short: "h" },
72
+ },
73
+ allowPositionals: true,
74
+ });
75
+
76
+ if (help) {
77
+ console.info(HELP);
78
+ return;
79
+ }
80
+
81
+ if (!sliceId) {
82
+ console.error("Missing required argument: slice-id\n");
83
+ console.error("Usage: prismic slice add-field rich-text <slice-id> <field-id>");
84
+ process.exitCode = 1;
85
+ return;
86
+ }
87
+
88
+ if (!fieldId) {
89
+ console.error("Missing required argument: field-id\n");
90
+ console.error("Usage: prismic slice add-field rich-text <slice-id> <field-id>");
91
+ process.exitCode = 1;
92
+ return;
93
+ }
94
+
95
+ // Find the slice model
96
+ const result = await findSliceModel(sliceId);
97
+ if (!result.ok) {
98
+ console.error(result.error);
99
+ process.exitCode = 1;
100
+ return;
101
+ }
102
+
103
+ const { model, modelPath } = result;
104
+
105
+ // Check for variations
106
+ if (model.variations.length === 0) {
107
+ console.error(`Slice "${sliceId}" has no variations.\n`);
108
+ console.error("Add a variation first before adding fields.");
109
+ process.exitCode = 1;
110
+ return;
111
+ }
112
+
113
+ // Find target variation
114
+ const targetVariation = variation
115
+ ? model.variations.find((v) => v.id === variation)
116
+ : model.variations[0];
117
+
118
+ if (!targetVariation) {
119
+ console.error(`Variation "${variation}" not found in slice "${sliceId}"\n`);
120
+ console.error(`Available variations: ${model.variations.map((v) => v.id).join(", ")}`);
121
+ process.exitCode = 1;
122
+ return;
123
+ }
124
+
125
+ // Initialize primary if it doesn't exist
126
+ if (!targetVariation.primary) {
127
+ targetVariation.primary = {};
128
+ }
129
+
130
+ // Check if field already exists in any variation
131
+ for (const v of model.variations) {
132
+ if (v.primary?.[fieldId]) {
133
+ console.error(`Field "${fieldId}" already exists in variation "${v.id}"`);
134
+ process.exitCode = 1;
135
+ return;
136
+ }
137
+ }
138
+
139
+ // Build field definition
140
+ const fieldDefinition: RichText = {
141
+ type: "StructuredText",
142
+ config: {
143
+ label: label ?? humanReadable(fieldId),
144
+ ...(placeholder && { placeholder }),
145
+ ...(single && { single }),
146
+ ...(multi && { multi }),
147
+ ...(allowTargetBlank && { allowTargetBlank: true }),
148
+ },
149
+ };
150
+
151
+ // Add field to variation
152
+ targetVariation.primary[fieldId] = fieldDefinition;
153
+
154
+ // Write updated model
155
+ try {
156
+ await writeFile(modelPath, stringify(model as SharedSlice));
157
+ } catch (error) {
158
+ if (error instanceof Error) {
159
+ console.error(`Failed to update slice: ${error.message}`);
160
+ } else {
161
+ console.error("Failed to update slice");
162
+ }
163
+ process.exitCode = 1;
164
+ return;
165
+ }
166
+
167
+ console.info(
168
+ `Added field "${fieldId}" (StructuredText) to "${targetVariation.id}" variation in ${sliceId}`,
169
+ );
170
+
171
+ if (!noTypes) {
172
+ try {
173
+ await buildTypes({ output: types });
174
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
175
+ } catch (error) {
176
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
177
+ }
178
+ }
179
+
180
+ console.info();
181
+ console.info("Next: Add more fields with `prismic slice add-field`");
182
+ console.info(" Run `prismic status` when done to find next steps");
183
+ }
@@ -0,0 +1,173 @@
1
+ import type { Select, SharedSlice } from "@prismicio/types-internal/lib/customtypes";
2
+
3
+ import { writeFile } from "node:fs/promises";
4
+ import { parseArgs } from "node:util";
5
+
6
+ import { buildTypes } from "./codegen-types";
7
+ import { stringify } from "./lib/json";
8
+ import { findSliceModel } from "./lib/slice";
9
+ import { humanReadable } from "./lib/string";
10
+
11
+ const HELP = `
12
+ Add a select (dropdown) field to an existing slice.
13
+
14
+ USAGE
15
+ prismic slice add-field select <slice-id> <field-id> [flags]
16
+
17
+ ARGUMENTS
18
+ slice-id Slice identifier (required)
19
+ field-id Field identifier (required)
20
+
21
+ Types are generated by default after changes. Use --no-types to skip.
22
+
23
+ FLAGS
24
+ -v, --variation string Target variation (default: first variation)
25
+ -l, --label string Display label for the field (inferred from field-id if omitted)
26
+ -p, --placeholder string Placeholder text
27
+ --option string Add an option (can be used multiple times)
28
+ --default string Default selected value
29
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
30
+ --no-types Skip type generation
31
+ -h, --help Show help for command
32
+
33
+ EXAMPLES
34
+ prismic slice add-field select my_slice layout --option "full" --option "sidebar"
35
+ prismic slice add-field select hero style --option "light" --option "dark" --default "light"
36
+ prismic slice add-field select product size --option "small" --option "medium" --option "large" --label "Size"
37
+ `.trim();
38
+
39
+ export async function sliceAddFieldSelect(): Promise<void> {
40
+ const {
41
+ values: {
42
+ help,
43
+ variation,
44
+ label,
45
+ placeholder,
46
+ option,
47
+ default: defaultValue,
48
+ types,
49
+ "no-types": noTypes,
50
+ },
51
+ positionals: [sliceId, fieldId],
52
+ } = parseArgs({
53
+ args: process.argv.slice(5), // skip: node, script, "slice", "add-field", "select"
54
+ options: {
55
+ variation: { type: "string", short: "v" },
56
+ label: { type: "string", short: "l" },
57
+ placeholder: { type: "string", short: "p" },
58
+ option: { type: "string", multiple: true },
59
+ default: { type: "string" },
60
+ types: { type: "string" },
61
+ "no-types": { type: "boolean" },
62
+ help: { type: "boolean", short: "h" },
63
+ },
64
+ allowPositionals: true,
65
+ });
66
+
67
+ if (help) {
68
+ console.info(HELP);
69
+ return;
70
+ }
71
+
72
+ if (!sliceId) {
73
+ console.error("Missing required argument: slice-id\n");
74
+ console.error("Usage: prismic slice add-field select <slice-id> <field-id>");
75
+ process.exitCode = 1;
76
+ return;
77
+ }
78
+
79
+ if (!fieldId) {
80
+ console.error("Missing required argument: field-id\n");
81
+ console.error("Usage: prismic slice add-field select <slice-id> <field-id>");
82
+ process.exitCode = 1;
83
+ return;
84
+ }
85
+
86
+ // Find the slice model
87
+ const result = await findSliceModel(sliceId);
88
+ if (!result.ok) {
89
+ console.error(result.error);
90
+ process.exitCode = 1;
91
+ return;
92
+ }
93
+
94
+ const { model, modelPath } = result;
95
+
96
+ // Check for variations
97
+ if (model.variations.length === 0) {
98
+ console.error(`Slice "${sliceId}" has no variations.\n`);
99
+ console.error("Add a variation first before adding fields.");
100
+ process.exitCode = 1;
101
+ return;
102
+ }
103
+
104
+ // Find target variation
105
+ const targetVariation = variation
106
+ ? model.variations.find((v) => v.id === variation)
107
+ : model.variations[0];
108
+
109
+ if (!targetVariation) {
110
+ console.error(`Variation "${variation}" not found in slice "${sliceId}"\n`);
111
+ console.error(`Available variations: ${model.variations.map((v) => v.id).join(", ")}`);
112
+ process.exitCode = 1;
113
+ return;
114
+ }
115
+
116
+ // Initialize primary if it doesn't exist
117
+ if (!targetVariation.primary) {
118
+ targetVariation.primary = {};
119
+ }
120
+
121
+ // Check if field already exists in any variation
122
+ for (const v of model.variations) {
123
+ if (v.primary?.[fieldId]) {
124
+ console.error(`Field "${fieldId}" already exists in variation "${v.id}"`);
125
+ process.exitCode = 1;
126
+ return;
127
+ }
128
+ }
129
+
130
+ // Build field definition
131
+ const fieldDefinition: Select = {
132
+ type: "Select",
133
+ config: {
134
+ label: label ?? humanReadable(fieldId),
135
+ ...(placeholder && { placeholder }),
136
+ ...(option && option.length > 0 && { options: option }),
137
+ ...(defaultValue && { default_value: defaultValue }),
138
+ },
139
+ };
140
+
141
+ // Add field to variation
142
+ targetVariation.primary[fieldId] = fieldDefinition;
143
+
144
+ // Write updated model
145
+ try {
146
+ await writeFile(modelPath, stringify(model as SharedSlice));
147
+ } catch (error) {
148
+ if (error instanceof Error) {
149
+ console.error(`Failed to update slice: ${error.message}`);
150
+ } else {
151
+ console.error("Failed to update slice");
152
+ }
153
+ process.exitCode = 1;
154
+ return;
155
+ }
156
+
157
+ console.info(
158
+ `Added field "${fieldId}" (Select) to "${targetVariation.id}" variation in ${sliceId}`,
159
+ );
160
+
161
+ if (!noTypes) {
162
+ try {
163
+ await buildTypes({ output: types });
164
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
165
+ } catch (error) {
166
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
167
+ }
168
+ }
169
+
170
+ console.info();
171
+ console.info("Next: Add more fields with `prismic slice add-field`");
172
+ console.info(" Run `prismic status` when done to find next steps");
173
+ }
@@ -0,0 +1,158 @@
1
+ import type { SharedSlice, Timestamp } from "@prismicio/types-internal/lib/customtypes";
2
+
3
+ import { writeFile } from "node:fs/promises";
4
+ import { parseArgs } from "node:util";
5
+
6
+ import { buildTypes } from "./codegen-types";
7
+ import { stringify } from "./lib/json";
8
+ import { findSliceModel } from "./lib/slice";
9
+ import { humanReadable } from "./lib/string";
10
+
11
+ const HELP = `
12
+ Add a timestamp (date and time) field to an existing slice.
13
+
14
+ USAGE
15
+ prismic slice add-field timestamp <slice-id> <field-id> [flags]
16
+
17
+ ARGUMENTS
18
+ slice-id Slice identifier (required)
19
+ field-id Field identifier (required)
20
+
21
+ Types are generated by default after changes. Use --no-types to skip.
22
+
23
+ FLAGS
24
+ -v, --variation string Target variation (default: first variation)
25
+ -l, --label string Display label for the field (inferred from field-id if omitted)
26
+ -p, --placeholder string Placeholder text
27
+ --types string Output file for generated types (default: "prismicio-types.d.ts")
28
+ --no-types Skip type generation
29
+ -h, --help Show help for command
30
+
31
+ EXAMPLES
32
+ prismic slice add-field timestamp my_slice created_at
33
+ prismic slice add-field timestamp event start_time --label "Event Start"
34
+ prismic slice add-field timestamp schedule meeting_time --variation "detailed"
35
+ `.trim();
36
+
37
+ export async function sliceAddFieldTimestamp(): Promise<void> {
38
+ const {
39
+ values: { help, variation, label, placeholder, types, "no-types": noTypes },
40
+ positionals: [sliceId, fieldId],
41
+ } = parseArgs({
42
+ args: process.argv.slice(5), // skip: node, script, "slice", "add-field", "timestamp"
43
+ options: {
44
+ variation: { type: "string", short: "v" },
45
+ label: { type: "string", short: "l" },
46
+ placeholder: { type: "string", short: "p" },
47
+ types: { type: "string" },
48
+ "no-types": { type: "boolean" },
49
+ help: { type: "boolean", short: "h" },
50
+ },
51
+ allowPositionals: true,
52
+ });
53
+
54
+ if (help) {
55
+ console.info(HELP);
56
+ return;
57
+ }
58
+
59
+ if (!sliceId) {
60
+ console.error("Missing required argument: slice-id\n");
61
+ console.error("Usage: prismic slice add-field timestamp <slice-id> <field-id>");
62
+ process.exitCode = 1;
63
+ return;
64
+ }
65
+
66
+ if (!fieldId) {
67
+ console.error("Missing required argument: field-id\n");
68
+ console.error("Usage: prismic slice add-field timestamp <slice-id> <field-id>");
69
+ process.exitCode = 1;
70
+ return;
71
+ }
72
+
73
+ // Find the slice model
74
+ const result = await findSliceModel(sliceId);
75
+ if (!result.ok) {
76
+ console.error(result.error);
77
+ process.exitCode = 1;
78
+ return;
79
+ }
80
+
81
+ const { model, modelPath } = result;
82
+
83
+ // Check for variations
84
+ if (model.variations.length === 0) {
85
+ console.error(`Slice "${sliceId}" has no variations.\n`);
86
+ console.error("Add a variation first before adding fields.");
87
+ process.exitCode = 1;
88
+ return;
89
+ }
90
+
91
+ // Find target variation
92
+ const targetVariation = variation
93
+ ? model.variations.find((v) => v.id === variation)
94
+ : model.variations[0];
95
+
96
+ if (!targetVariation) {
97
+ console.error(`Variation "${variation}" not found in slice "${sliceId}"\n`);
98
+ console.error(`Available variations: ${model.variations.map((v) => v.id).join(", ")}`);
99
+ process.exitCode = 1;
100
+ return;
101
+ }
102
+
103
+ // Initialize primary if it doesn't exist
104
+ if (!targetVariation.primary) {
105
+ targetVariation.primary = {};
106
+ }
107
+
108
+ // Check if field already exists in any variation
109
+ for (const v of model.variations) {
110
+ if (v.primary?.[fieldId]) {
111
+ console.error(`Field "${fieldId}" already exists in variation "${v.id}"`);
112
+ process.exitCode = 1;
113
+ return;
114
+ }
115
+ }
116
+
117
+ // Build field definition
118
+ const fieldDefinition: Timestamp = {
119
+ type: "Timestamp",
120
+ config: {
121
+ label: label ?? humanReadable(fieldId),
122
+ ...(placeholder && { placeholder }),
123
+ },
124
+ };
125
+
126
+ // Add field to variation
127
+ targetVariation.primary[fieldId] = fieldDefinition;
128
+
129
+ // Write updated model
130
+ try {
131
+ await writeFile(modelPath, stringify(model as SharedSlice));
132
+ } catch (error) {
133
+ if (error instanceof Error) {
134
+ console.error(`Failed to update slice: ${error.message}`);
135
+ } else {
136
+ console.error("Failed to update slice");
137
+ }
138
+ process.exitCode = 1;
139
+ return;
140
+ }
141
+
142
+ console.info(
143
+ `Added field "${fieldId}" (Timestamp) to "${targetVariation.id}" variation in ${sliceId}`,
144
+ );
145
+
146
+ if (!noTypes) {
147
+ try {
148
+ await buildTypes({ output: types });
149
+ console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
150
+ } catch (error) {
151
+ console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
152
+ }
153
+ }
154
+
155
+ console.info();
156
+ console.info("Next: Add more fields with `prismic slice add-field`");
157
+ console.info(" Run `prismic status` when done to find next steps");
158
+ }
@@ -0,0 +1,106 @@
1
+ import { parseArgs } from "node:util";
2
+
3
+ import { sliceAddFieldBoolean } from "./slice-add-field-boolean";
4
+ import { sliceAddFieldColor } from "./slice-add-field-color";
5
+ import { sliceAddFieldDate } from "./slice-add-field-date";
6
+ import { sliceAddFieldEmbed } from "./slice-add-field-embed";
7
+ import { sliceAddFieldGeoPoint } from "./slice-add-field-geo-point";
8
+ import { sliceAddFieldImage } from "./slice-add-field-image";
9
+ import { sliceAddFieldKeyText } from "./slice-add-field-key-text";
10
+ import { sliceAddFieldLink } from "./slice-add-field-link";
11
+ import { sliceAddFieldNumber } from "./slice-add-field-number";
12
+ import { sliceAddFieldRichText } from "./slice-add-field-rich-text";
13
+ import { sliceAddFieldSelect } from "./slice-add-field-select";
14
+ import { sliceAddFieldTimestamp } from "./slice-add-field-timestamp";
15
+
16
+ const HELP = `
17
+ Add a field to an existing slice.
18
+
19
+ USAGE
20
+ prismic slice add-field <field-type> <slice-id> <field-id> [flags]
21
+
22
+ FIELD TYPES
23
+ boolean Boolean toggle
24
+ color Color picker
25
+ date Date picker
26
+ embed Embed (oEmbed)
27
+ geo-point Geographic coordinates
28
+ image Image
29
+ key-text Single-line text
30
+ link Any link type
31
+ number Number
32
+ rich-text Rich text editor
33
+ select Dropdown select
34
+ timestamp Date and time
35
+
36
+ FLAGS
37
+ -h, --help Show help for command
38
+
39
+ LEARN MORE
40
+ Use \`prismic slice add-field <field-type> --help\` for more information.
41
+
42
+ EXAMPLES
43
+ prismic slice add-field key-text my_slice title --label "Title"
44
+ prismic slice add-field link my_slice cta --allow-text
45
+ prismic slice add-field rich-text my_slice body --multi "paragraph,heading2,strong,em"
46
+ prismic slice add-field select my_slice layout --option "full" --option "sidebar"
47
+ `.trim();
48
+
49
+ export async function sliceAddField(): Promise<void> {
50
+ const {
51
+ positionals: [fieldType],
52
+ } = parseArgs({
53
+ args: process.argv.slice(4), // skip: node, script, "slice", "add-field"
54
+ options: {
55
+ help: { type: "boolean", short: "h" },
56
+ },
57
+ allowPositionals: true,
58
+ strict: false,
59
+ });
60
+
61
+ switch (fieldType) {
62
+ case "boolean":
63
+ await sliceAddFieldBoolean();
64
+ break;
65
+ case "color":
66
+ await sliceAddFieldColor();
67
+ break;
68
+ case "date":
69
+ await sliceAddFieldDate();
70
+ break;
71
+ case "embed":
72
+ await sliceAddFieldEmbed();
73
+ break;
74
+ case "geo-point":
75
+ await sliceAddFieldGeoPoint();
76
+ break;
77
+ case "image":
78
+ await sliceAddFieldImage();
79
+ break;
80
+ case "key-text":
81
+ await sliceAddFieldKeyText();
82
+ break;
83
+ case "link":
84
+ await sliceAddFieldLink();
85
+ break;
86
+ case "number":
87
+ await sliceAddFieldNumber();
88
+ break;
89
+ case "rich-text":
90
+ await sliceAddFieldRichText();
91
+ break;
92
+ case "select":
93
+ await sliceAddFieldSelect();
94
+ break;
95
+ case "timestamp":
96
+ await sliceAddFieldTimestamp();
97
+ break;
98
+ default: {
99
+ if (fieldType) {
100
+ console.error(`Unknown field type: ${fieldType}\n`);
101
+ process.exitCode = 1;
102
+ }
103
+ console.info(HELP);
104
+ }
105
+ }
106
+ }