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