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,128 @@
|
|
|
1
|
+
import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
+
|
|
3
|
+
import { pascalCase } from "change-case";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
|
|
6
|
+
import { buildTypes } from "./codegen-types";
|
|
7
|
+
import { getDocsPath, requireFramework } from "./framework";
|
|
8
|
+
|
|
9
|
+
const HELP = `
|
|
10
|
+
Create a new page type in a Prismic repository.
|
|
11
|
+
|
|
12
|
+
USAGE
|
|
13
|
+
prismic page-type create <id> [flags]
|
|
14
|
+
|
|
15
|
+
ARGUMENTS
|
|
16
|
+
id Page type identifier (required)
|
|
17
|
+
|
|
18
|
+
FLAGS
|
|
19
|
+
-n, --name string Display name for the page type
|
|
20
|
+
--single Create as a singleton (non-repeatable) type
|
|
21
|
+
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
22
|
+
-h, --help Show help for command
|
|
23
|
+
|
|
24
|
+
LEARN MORE
|
|
25
|
+
Use \`prismic page-type <command> --help\` for more information about a command.
|
|
26
|
+
`.trim();
|
|
27
|
+
|
|
28
|
+
export async function pageTypeCreate(): Promise<void> {
|
|
29
|
+
const {
|
|
30
|
+
values: { help, name, single, types },
|
|
31
|
+
positionals: [id],
|
|
32
|
+
} = parseArgs({
|
|
33
|
+
args: process.argv.slice(4), // skip: node, script, "page-type", "create"
|
|
34
|
+
options: {
|
|
35
|
+
name: { type: "string", short: "n" },
|
|
36
|
+
single: { type: "boolean" },
|
|
37
|
+
types: { type: "string" },
|
|
38
|
+
help: { type: "boolean", short: "h" },
|
|
39
|
+
},
|
|
40
|
+
allowPositionals: true,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (help) {
|
|
44
|
+
console.info(HELP);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!id) {
|
|
49
|
+
console.error("Missing required argument: id");
|
|
50
|
+
process.exitCode = 1;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const framework = await requireFramework();
|
|
55
|
+
if (!framework) return;
|
|
56
|
+
|
|
57
|
+
const model = {
|
|
58
|
+
id,
|
|
59
|
+
label: name ?? pascalCase(id),
|
|
60
|
+
repeatable: !single,
|
|
61
|
+
status: true,
|
|
62
|
+
format: "page",
|
|
63
|
+
json: {
|
|
64
|
+
Main: single
|
|
65
|
+
? {}
|
|
66
|
+
: {
|
|
67
|
+
uid: {
|
|
68
|
+
type: "UID",
|
|
69
|
+
config: { label: "UID", placeholder: "" },
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
"SEO & Metadata": {
|
|
73
|
+
meta_title: {
|
|
74
|
+
type: "Text",
|
|
75
|
+
config: {
|
|
76
|
+
label: "Meta Title",
|
|
77
|
+
placeholder: "A title of the page used for social media and search engines",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
meta_description: {
|
|
81
|
+
type: "Text",
|
|
82
|
+
config: {
|
|
83
|
+
label: "Meta Description",
|
|
84
|
+
placeholder: "A brief summary of the page",
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
meta_image: {
|
|
88
|
+
type: "Image",
|
|
89
|
+
config: {
|
|
90
|
+
label: "Meta Image",
|
|
91
|
+
constraint: { width: 2400, height: 1260 },
|
|
92
|
+
thumbnails: [],
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const { modelPath } = await framework.createCustomType(model as CustomType);
|
|
101
|
+
console.info(`Created page type at ${modelPath.href}`);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (error instanceof Error) {
|
|
104
|
+
console.error(`Failed to create page type: ${error.message}`);
|
|
105
|
+
} else {
|
|
106
|
+
console.error(`Failed to create page type`);
|
|
107
|
+
}
|
|
108
|
+
process.exitCode = 1;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
await buildTypes({ output: types });
|
|
114
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
console.info();
|
|
120
|
+
console.info("Next: Add fields with `prismic page-type add-field`");
|
|
121
|
+
|
|
122
|
+
if (framework) {
|
|
123
|
+
const docsPath = getDocsPath(framework.id);
|
|
124
|
+
console.info(
|
|
125
|
+
` Run \`prismic docs fetch ${docsPath}#write-page-components\` to learn how to implement a page file`,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { CustomType, DynamicSlices } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
+
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
|
|
5
|
+
import { buildTypes } from "./codegen-types";
|
|
6
|
+
import { requireFramework } from "./framework";
|
|
7
|
+
|
|
8
|
+
const HELP = `
|
|
9
|
+
Disconnect a shared slice from a page type's slice zone.
|
|
10
|
+
|
|
11
|
+
USAGE
|
|
12
|
+
prismic page-type disconnect-slice <type-id> <slice-id> [flags]
|
|
13
|
+
|
|
14
|
+
ARGUMENTS
|
|
15
|
+
type-id Page type identifier (required)
|
|
16
|
+
slice-id Slice identifier (required)
|
|
17
|
+
|
|
18
|
+
FLAGS
|
|
19
|
+
-z, --slice-zone string Target slice zone field ID (default: "slices")
|
|
20
|
+
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
21
|
+
-h, --help Show help for command
|
|
22
|
+
|
|
23
|
+
EXAMPLES
|
|
24
|
+
prismic page-type disconnect-slice homepage CallToAction
|
|
25
|
+
prismic page-type disconnect-slice homepage CallToAction --slice-zone slices
|
|
26
|
+
prismic page-type disconnect-slice article HeroSection -z body
|
|
27
|
+
`.trim();
|
|
28
|
+
|
|
29
|
+
export async function pageTypeDisconnectSlice(): Promise<void> {
|
|
30
|
+
const {
|
|
31
|
+
values: { help, "slice-zone": sliceZoneId, types },
|
|
32
|
+
positionals: [typeId, sliceId],
|
|
33
|
+
} = parseArgs({
|
|
34
|
+
args: process.argv.slice(4), // skip: node, script, "page-type", "disconnect-slice"
|
|
35
|
+
options: {
|
|
36
|
+
"slice-zone": { type: "string", short: "z" },
|
|
37
|
+
types: { type: "string" },
|
|
38
|
+
help: { type: "boolean", short: "h" },
|
|
39
|
+
},
|
|
40
|
+
allowPositionals: true,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (help) {
|
|
44
|
+
console.info(HELP);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!typeId) {
|
|
49
|
+
console.error("Missing required argument: type-id\n");
|
|
50
|
+
console.error("Usage: prismic page-type disconnect-slice <type-id> <slice-id>");
|
|
51
|
+
process.exitCode = 1;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!sliceId) {
|
|
56
|
+
console.error("Missing required argument: slice-id\n");
|
|
57
|
+
console.error("Usage: prismic page-type disconnect-slice <type-id> <slice-id>");
|
|
58
|
+
process.exitCode = 1;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const framework = await requireFramework();
|
|
63
|
+
if (!framework) return;
|
|
64
|
+
|
|
65
|
+
let model: CustomType;
|
|
66
|
+
try {
|
|
67
|
+
model = await framework.readCustomType(typeId);
|
|
68
|
+
} catch {
|
|
69
|
+
console.error(`Page type not found: ${typeId}\n\nCreate it first with: prismic page-type create ${typeId}`);
|
|
70
|
+
process.exitCode = 1;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const targetSliceZoneId = sliceZoneId ?? "slices";
|
|
75
|
+
|
|
76
|
+
// Find existing slice zone
|
|
77
|
+
let sliceZone: DynamicSlices | undefined;
|
|
78
|
+
let sliceZoneFieldId: string | undefined;
|
|
79
|
+
|
|
80
|
+
// Search all tabs for a Slices field matching the target ID
|
|
81
|
+
for (const [, tabFields] of Object.entries(model.json)) {
|
|
82
|
+
for (const [fieldId, field] of Object.entries(tabFields)) {
|
|
83
|
+
if ((field as { type?: string }).type === "Slices" && fieldId === targetSliceZoneId) {
|
|
84
|
+
sliceZone = field as DynamicSlices;
|
|
85
|
+
sliceZoneFieldId = fieldId;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (sliceZone) break;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Slice zone must exist for disconnect
|
|
93
|
+
if (!sliceZone) {
|
|
94
|
+
console.error(`Slice zone "${targetSliceZoneId}" not found in page type "${typeId}"`);
|
|
95
|
+
process.exitCode = 1;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Check if slice is connected
|
|
100
|
+
if (!sliceZone.config?.choices || !(sliceId in sliceZone.config.choices)) {
|
|
101
|
+
console.error(
|
|
102
|
+
`Slice "${sliceId}" is not connected to slice zone "${sliceZoneFieldId}" in ${typeId}`,
|
|
103
|
+
);
|
|
104
|
+
process.exitCode = 1;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Remove the slice reference
|
|
109
|
+
delete sliceZone.config.choices[sliceId];
|
|
110
|
+
|
|
111
|
+
// Write updated model
|
|
112
|
+
try {
|
|
113
|
+
await framework.updateCustomType(model);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (error instanceof Error) {
|
|
116
|
+
console.error(`Failed to update page type: ${error.message}`);
|
|
117
|
+
} else {
|
|
118
|
+
console.error("Failed to update page type");
|
|
119
|
+
}
|
|
120
|
+
process.exitCode = 1;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
console.info(
|
|
125
|
+
`Disconnected slice "${sliceId}" from slice zone "${sliceZoneFieldId}" in ${typeId}`,
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
await buildTypes({ output: types });
|
|
130
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
|
|
5
|
+
import { findUpward } from "./lib/file";
|
|
6
|
+
|
|
7
|
+
const HELP = `
|
|
8
|
+
List all page types in a Prismic project.
|
|
9
|
+
|
|
10
|
+
USAGE
|
|
11
|
+
prismic page-type list [flags]
|
|
12
|
+
|
|
13
|
+
FLAGS
|
|
14
|
+
--json Output as JSON
|
|
15
|
+
-h, --help Show help for command
|
|
16
|
+
|
|
17
|
+
EXAMPLES
|
|
18
|
+
prismic page-type list
|
|
19
|
+
prismic page-type list --json
|
|
20
|
+
`.trim();
|
|
21
|
+
|
|
22
|
+
const CustomTypeSchema = v.object({
|
|
23
|
+
id: v.string(),
|
|
24
|
+
label: v.string(),
|
|
25
|
+
repeatable: v.boolean(),
|
|
26
|
+
status: v.boolean(),
|
|
27
|
+
format: v.optional(v.string()),
|
|
28
|
+
json: v.record(v.string(), v.record(v.string(), v.unknown())),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export async function pageTypeList(): Promise<void> {
|
|
32
|
+
const {
|
|
33
|
+
values: { help, json },
|
|
34
|
+
} = parseArgs({
|
|
35
|
+
args: process.argv.slice(4), // skip: node, script, "page-type", "list"
|
|
36
|
+
options: {
|
|
37
|
+
json: { type: "boolean" },
|
|
38
|
+
help: { type: "boolean", short: "h" },
|
|
39
|
+
},
|
|
40
|
+
allowPositionals: true,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (help) {
|
|
44
|
+
console.info(HELP);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const projectRoot = await findUpward("package.json");
|
|
49
|
+
if (!projectRoot) {
|
|
50
|
+
console.error("Could not find project root (no package.json found)");
|
|
51
|
+
process.exitCode = 1;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const customTypesDirectory = new URL("customtypes/", projectRoot);
|
|
56
|
+
|
|
57
|
+
let entries: string[];
|
|
58
|
+
try {
|
|
59
|
+
entries = (await readdir(customTypesDirectory, {
|
|
60
|
+
withFileTypes: false,
|
|
61
|
+
})) as unknown as string[];
|
|
62
|
+
} catch {
|
|
63
|
+
if (json) {
|
|
64
|
+
console.info(JSON.stringify([]));
|
|
65
|
+
} else {
|
|
66
|
+
console.info("No page types found.");
|
|
67
|
+
}
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const pageTypes: { id: string; label: string; repeatable: boolean }[] = [];
|
|
72
|
+
|
|
73
|
+
for (const entry of entries) {
|
|
74
|
+
const modelPath = new URL(`${entry}/index.json`, customTypesDirectory);
|
|
75
|
+
try {
|
|
76
|
+
const contents = await readFile(modelPath, "utf8");
|
|
77
|
+
const parsed = JSON.parse(contents);
|
|
78
|
+
const result = v.safeParse(CustomTypeSchema, parsed);
|
|
79
|
+
if (result.success && result.output.format === "page") {
|
|
80
|
+
pageTypes.push({
|
|
81
|
+
id: result.output.id,
|
|
82
|
+
label: result.output.label,
|
|
83
|
+
repeatable: result.output.repeatable,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
} catch {
|
|
87
|
+
// Skip directories without valid index.json
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (pageTypes.length === 0) {
|
|
92
|
+
if (json) {
|
|
93
|
+
console.info(JSON.stringify([]));
|
|
94
|
+
} else {
|
|
95
|
+
console.info("No page types found.");
|
|
96
|
+
}
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (json) {
|
|
101
|
+
console.info(JSON.stringify(pageTypes, null, 2));
|
|
102
|
+
} else {
|
|
103
|
+
console.info("ID\tLABEL\tTYPE");
|
|
104
|
+
for (const pageType of pageTypes) {
|
|
105
|
+
const typeLabel = pageType.repeatable ? "repeatable" : "singleton";
|
|
106
|
+
console.info(`${pageType.id}\t${pageType.label}\t${typeLabel}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
+
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
|
|
5
|
+
import { buildTypes } from "./codegen-types";
|
|
6
|
+
import { requireFramework } from "./framework";
|
|
7
|
+
|
|
8
|
+
const HELP = `
|
|
9
|
+
Remove a field from a page type.
|
|
10
|
+
|
|
11
|
+
USAGE
|
|
12
|
+
prismic page-type remove-field <type-id> <field-id> [flags]
|
|
13
|
+
|
|
14
|
+
ARGUMENTS
|
|
15
|
+
type-id Page type identifier (required)
|
|
16
|
+
field-id Field identifier (required)
|
|
17
|
+
|
|
18
|
+
FLAGS
|
|
19
|
+
--tab string Specific tab (searches all tabs if not specified)
|
|
20
|
+
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
21
|
+
-h, --help Show help for command
|
|
22
|
+
|
|
23
|
+
EXAMPLES
|
|
24
|
+
prismic page-type remove-field homepage title
|
|
25
|
+
prismic page-type remove-field homepage meta_title --tab "SEO & Metadata"
|
|
26
|
+
`.trim();
|
|
27
|
+
|
|
28
|
+
export async function pageTypeRemoveField(): Promise<void> {
|
|
29
|
+
const {
|
|
30
|
+
values: { help, tab, types },
|
|
31
|
+
positionals: [typeId, fieldId],
|
|
32
|
+
} = parseArgs({
|
|
33
|
+
args: process.argv.slice(4), // skip: node, script, "page-type", "remove-field"
|
|
34
|
+
options: {
|
|
35
|
+
tab: { type: "string" },
|
|
36
|
+
types: { type: "string" },
|
|
37
|
+
help: { type: "boolean", short: "h" },
|
|
38
|
+
},
|
|
39
|
+
allowPositionals: true,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (help) {
|
|
43
|
+
console.info(HELP);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!typeId) {
|
|
48
|
+
console.error("Missing required argument: type-id\n");
|
|
49
|
+
console.error("Usage: prismic page-type remove-field <type-id> <field-id>");
|
|
50
|
+
process.exitCode = 1;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!fieldId) {
|
|
55
|
+
console.error("Missing required argument: field-id\n");
|
|
56
|
+
console.error("Usage: prismic page-type remove-field <type-id> <field-id>");
|
|
57
|
+
process.exitCode = 1;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const framework = await requireFramework();
|
|
62
|
+
if (!framework) return;
|
|
63
|
+
|
|
64
|
+
let model: CustomType;
|
|
65
|
+
try {
|
|
66
|
+
model = await framework.readCustomType(typeId);
|
|
67
|
+
} catch {
|
|
68
|
+
console.error(`Page type not found: ${typeId}\n\nCreate it first with: prismic page-type create ${typeId}`);
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Check if this is actually a page type
|
|
74
|
+
if (model.format !== "page") {
|
|
75
|
+
console.error(`"${typeId}" is not a page type (format: ${model.format ?? "custom"})`);
|
|
76
|
+
process.exitCode = 1;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Find and remove the field
|
|
81
|
+
let foundTab: string | undefined;
|
|
82
|
+
|
|
83
|
+
if (tab) {
|
|
84
|
+
// Look in specific tab
|
|
85
|
+
if (!model.json[tab]) {
|
|
86
|
+
console.error(`Tab "${tab}" not found in page type "${typeId}"`);
|
|
87
|
+
console.error(`Available tabs: ${Object.keys(model.json).join(", ")}`);
|
|
88
|
+
process.exitCode = 1;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (!(fieldId in model.json[tab])) {
|
|
92
|
+
console.error(`Field "${fieldId}" not found in tab "${tab}"`);
|
|
93
|
+
process.exitCode = 1;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
delete model.json[tab][fieldId];
|
|
97
|
+
foundTab = tab;
|
|
98
|
+
} else {
|
|
99
|
+
// Search all tabs
|
|
100
|
+
for (const [tabName, tabFields] of Object.entries(model.json)) {
|
|
101
|
+
if (fieldId in tabFields) {
|
|
102
|
+
delete tabFields[fieldId];
|
|
103
|
+
foundTab = tabName;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (!foundTab) {
|
|
108
|
+
console.error(`Field "${fieldId}" not found in any tab of page type "${typeId}"`);
|
|
109
|
+
process.exitCode = 1;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Write updated model
|
|
115
|
+
try {
|
|
116
|
+
await framework.updateCustomType(model);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
if (error instanceof Error) {
|
|
119
|
+
console.error(`Failed to update page type: ${error.message}`);
|
|
120
|
+
} else {
|
|
121
|
+
console.error("Failed to update page type");
|
|
122
|
+
}
|
|
123
|
+
process.exitCode = 1;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
console.info(`Removed field "${fieldId}" from tab "${foundTab}" in page type "${typeId}"`);
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
await buildTypes({ output: types });
|
|
131
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
+
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
|
|
5
|
+
import { buildTypes } from "./codegen-types";
|
|
6
|
+
import { requireFramework } from "./framework";
|
|
7
|
+
|
|
8
|
+
const HELP = `
|
|
9
|
+
Remove a page type from the project.
|
|
10
|
+
|
|
11
|
+
USAGE
|
|
12
|
+
prismic page-type remove <type-id> [flags]
|
|
13
|
+
|
|
14
|
+
ARGUMENTS
|
|
15
|
+
type-id Page type identifier (required)
|
|
16
|
+
|
|
17
|
+
FLAGS
|
|
18
|
+
-y Confirm removal
|
|
19
|
+
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
20
|
+
-h, --help Show help for command
|
|
21
|
+
|
|
22
|
+
EXAMPLES
|
|
23
|
+
prismic page-type remove homepage
|
|
24
|
+
prismic page-type remove homepage -y
|
|
25
|
+
`.trim();
|
|
26
|
+
|
|
27
|
+
export async function pageTypeRemove(): Promise<void> {
|
|
28
|
+
const {
|
|
29
|
+
values: { help, y, types },
|
|
30
|
+
positionals: [typeId],
|
|
31
|
+
} = parseArgs({
|
|
32
|
+
args: process.argv.slice(4), // skip: node, script, "page-type", "remove"
|
|
33
|
+
options: {
|
|
34
|
+
y: { type: "boolean", short: "y" },
|
|
35
|
+
types: { type: "string" },
|
|
36
|
+
help: { type: "boolean", short: "h" },
|
|
37
|
+
},
|
|
38
|
+
allowPositionals: true,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (help) {
|
|
42
|
+
console.info(HELP);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!typeId) {
|
|
47
|
+
console.error("Missing required argument: type-id\n");
|
|
48
|
+
console.error("Usage: prismic page-type remove <type-id>");
|
|
49
|
+
process.exitCode = 1;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const framework = await requireFramework();
|
|
54
|
+
if (!framework) return;
|
|
55
|
+
|
|
56
|
+
let model: CustomType;
|
|
57
|
+
try {
|
|
58
|
+
model = await framework.readCustomType(typeId);
|
|
59
|
+
} catch {
|
|
60
|
+
console.error(`Page type not found: ${typeId}\n\nCreate it first with: prismic page-type create ${typeId}`);
|
|
61
|
+
process.exitCode = 1;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Check if this is actually a page type
|
|
66
|
+
if (model.format !== "page") {
|
|
67
|
+
console.error(`"${typeId}" is not a page type (format: ${model.format ?? "custom"})`);
|
|
68
|
+
process.exitCode = 1;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Require -y flag to confirm deletion
|
|
73
|
+
if (!y) {
|
|
74
|
+
console.error(
|
|
75
|
+
`Refusing to remove page type "${typeId}" (this will delete the entire directory).`,
|
|
76
|
+
);
|
|
77
|
+
console.error("Re-run with -y to confirm.");
|
|
78
|
+
process.exitCode = 1;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Delete the page type directory
|
|
83
|
+
try {
|
|
84
|
+
await framework.deleteCustomType(typeId);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (error instanceof Error) {
|
|
87
|
+
console.error(`Failed to remove page type: ${error.message}`);
|
|
88
|
+
} else {
|
|
89
|
+
console.error("Failed to remove page type");
|
|
90
|
+
}
|
|
91
|
+
process.exitCode = 1;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
console.info(`Removed page type "${typeId}"`);
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
await buildTypes({ output: types });
|
|
99
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
+
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
|
|
5
|
+
import { buildTypes } from "./codegen-types";
|
|
6
|
+
import { requireFramework } from "./framework";
|
|
7
|
+
|
|
8
|
+
const HELP = `
|
|
9
|
+
Change a page type's display name (label).
|
|
10
|
+
|
|
11
|
+
USAGE
|
|
12
|
+
prismic page-type set-name <type-id> <new-name> [flags]
|
|
13
|
+
|
|
14
|
+
ARGUMENTS
|
|
15
|
+
type-id Page type identifier (required)
|
|
16
|
+
new-name New display name (required)
|
|
17
|
+
|
|
18
|
+
FLAGS
|
|
19
|
+
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
20
|
+
-h, --help Show help for command
|
|
21
|
+
|
|
22
|
+
EXAMPLES
|
|
23
|
+
prismic page-type set-name homepage "Home Page"
|
|
24
|
+
prismic page-type set-name blog_post "Blog Post"
|
|
25
|
+
`.trim();
|
|
26
|
+
|
|
27
|
+
export async function pageTypeSetName(): Promise<void> {
|
|
28
|
+
const {
|
|
29
|
+
values: { help, types },
|
|
30
|
+
positionals: [typeId, newName],
|
|
31
|
+
} = parseArgs({
|
|
32
|
+
args: process.argv.slice(4), // skip: node, script, "page-type", "set-name"
|
|
33
|
+
options: {
|
|
34
|
+
types: { type: "string" },
|
|
35
|
+
help: { type: "boolean", short: "h" },
|
|
36
|
+
},
|
|
37
|
+
allowPositionals: true,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (help) {
|
|
41
|
+
console.info(HELP);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!typeId) {
|
|
46
|
+
console.error("Missing required argument: type-id\n");
|
|
47
|
+
console.error("Usage: prismic page-type set-name <type-id> <new-name>");
|
|
48
|
+
process.exitCode = 1;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!newName) {
|
|
53
|
+
console.error("Missing required argument: new-name\n");
|
|
54
|
+
console.error("Usage: prismic page-type set-name <type-id> <new-name>");
|
|
55
|
+
process.exitCode = 1;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const framework = await requireFramework();
|
|
60
|
+
if (!framework) return;
|
|
61
|
+
|
|
62
|
+
let model: CustomType;
|
|
63
|
+
try {
|
|
64
|
+
model = await framework.readCustomType(typeId);
|
|
65
|
+
} catch {
|
|
66
|
+
console.error(`Page type not found: ${typeId}\n\nCreate it first with: prismic page-type create ${typeId}`);
|
|
67
|
+
process.exitCode = 1;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Check if this is actually a page type
|
|
72
|
+
if (model.format !== "page") {
|
|
73
|
+
console.error(`"${typeId}" is not a page type (format: ${model.format ?? "custom"})`);
|
|
74
|
+
process.exitCode = 1;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Update the model
|
|
79
|
+
model.label = newName;
|
|
80
|
+
|
|
81
|
+
// Write updated model
|
|
82
|
+
try {
|
|
83
|
+
await framework.updateCustomType(model);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error instanceof Error) {
|
|
86
|
+
console.error(`Failed to update page type: ${error.message}`);
|
|
87
|
+
} else {
|
|
88
|
+
console.error("Failed to update page type");
|
|
89
|
+
}
|
|
90
|
+
process.exitCode = 1;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
console.info(`Renamed page type "${typeId}" to "${newName}"`);
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
await buildTypes({ output: types });
|
|
98
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
101
|
+
}
|
|
102
|
+
}
|