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,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 custom type.
|
|
10
|
+
|
|
11
|
+
USAGE
|
|
12
|
+
prismic custom-type remove-field <type-id> <field-id> [flags]
|
|
13
|
+
|
|
14
|
+
ARGUMENTS
|
|
15
|
+
type-id Custom 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 custom-type remove-field settings title
|
|
25
|
+
prismic custom-type remove-field settings description --tab "Content"
|
|
26
|
+
`.trim();
|
|
27
|
+
|
|
28
|
+
export async function customTypeRemoveField(): Promise<void> {
|
|
29
|
+
const {
|
|
30
|
+
values: { help, tab, types },
|
|
31
|
+
positionals: [typeId, fieldId],
|
|
32
|
+
} = parseArgs({
|
|
33
|
+
args: process.argv.slice(4), // skip: node, script, "custom-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 custom-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 custom-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(`Custom type not found: ${typeId}\n\nCreate it first with: prismic custom-type create ${typeId}`);
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Check if this is actually a custom type (not a page type)
|
|
74
|
+
if (model.format === "page") {
|
|
75
|
+
console.error(`"${typeId}" is not a custom type (format: page)`);
|
|
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 custom 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 custom 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 custom type: ${error.message}`);
|
|
120
|
+
} else {
|
|
121
|
+
console.error("Failed to update custom type");
|
|
122
|
+
}
|
|
123
|
+
process.exitCode = 1;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
console.info(`Removed field "${fieldId}" from tab "${foundTab}" in custom 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 custom type from the project.
|
|
10
|
+
|
|
11
|
+
USAGE
|
|
12
|
+
prismic custom-type remove <type-id> [flags]
|
|
13
|
+
|
|
14
|
+
ARGUMENTS
|
|
15
|
+
type-id Custom 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 custom-type remove settings
|
|
24
|
+
prismic custom-type remove settings -y
|
|
25
|
+
`.trim();
|
|
26
|
+
|
|
27
|
+
export async function customTypeRemove(): Promise<void> {
|
|
28
|
+
const {
|
|
29
|
+
values: { help, y, types },
|
|
30
|
+
positionals: [typeId],
|
|
31
|
+
} = parseArgs({
|
|
32
|
+
args: process.argv.slice(4), // skip: node, script, "custom-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 custom-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(`Custom type not found: ${typeId}\n\nCreate it first with: prismic custom-type create ${typeId}`);
|
|
61
|
+
process.exitCode = 1;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Check if this is actually a custom type (not a page type)
|
|
66
|
+
if (model.format === "page") {
|
|
67
|
+
console.error(`"${typeId}" is not a custom type (format: page)`);
|
|
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 custom 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 custom type directory
|
|
83
|
+
try {
|
|
84
|
+
await framework.deleteCustomType(typeId);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (error instanceof Error) {
|
|
87
|
+
console.error(`Failed to remove custom type: ${error.message}`);
|
|
88
|
+
} else {
|
|
89
|
+
console.error("Failed to remove custom type");
|
|
90
|
+
}
|
|
91
|
+
process.exitCode = 1;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
console.info(`Removed custom 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 custom type's display name (label).
|
|
10
|
+
|
|
11
|
+
USAGE
|
|
12
|
+
prismic custom-type set-name <type-id> <new-name> [flags]
|
|
13
|
+
|
|
14
|
+
ARGUMENTS
|
|
15
|
+
type-id Custom 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 custom-type set-name settings "Site Settings"
|
|
24
|
+
prismic custom-type set-name menu "Navigation Menu"
|
|
25
|
+
`.trim();
|
|
26
|
+
|
|
27
|
+
export async function customTypeSetName(): Promise<void> {
|
|
28
|
+
const {
|
|
29
|
+
values: { help, types },
|
|
30
|
+
positionals: [typeId, newName],
|
|
31
|
+
} = parseArgs({
|
|
32
|
+
args: process.argv.slice(4), // skip: node, script, "custom-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 custom-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 custom-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(`Custom type not found: ${typeId}\n\nCreate it first with: prismic custom-type create ${typeId}`);
|
|
67
|
+
process.exitCode = 1;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Check if this is actually a custom type (not a page type)
|
|
72
|
+
if (model.format === "page") {
|
|
73
|
+
console.error(`"${typeId}" is not a custom type (format: page)`);
|
|
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 custom type: ${error.message}`);
|
|
87
|
+
} else {
|
|
88
|
+
console.error("Failed to update custom type");
|
|
89
|
+
}
|
|
90
|
+
process.exitCode = 1;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
console.info(`Renamed custom 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
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
+
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import * as v from "valibot";
|
|
6
|
+
|
|
7
|
+
import { findUpward } from "./lib/file";
|
|
8
|
+
|
|
9
|
+
const HELP = `
|
|
10
|
+
View details of a specific custom type.
|
|
11
|
+
|
|
12
|
+
USAGE
|
|
13
|
+
prismic custom-type view <type-id> [flags]
|
|
14
|
+
|
|
15
|
+
ARGUMENTS
|
|
16
|
+
type-id Custom type identifier (required)
|
|
17
|
+
|
|
18
|
+
FLAGS
|
|
19
|
+
--json Output as JSON
|
|
20
|
+
-h, --help Show help for command
|
|
21
|
+
|
|
22
|
+
EXAMPLES
|
|
23
|
+
prismic custom-type view settings
|
|
24
|
+
prismic custom-type view settings --json
|
|
25
|
+
`.trim();
|
|
26
|
+
|
|
27
|
+
const CustomTypeSchema = v.object({
|
|
28
|
+
id: v.string(),
|
|
29
|
+
label: v.string(),
|
|
30
|
+
repeatable: v.boolean(),
|
|
31
|
+
status: v.boolean(),
|
|
32
|
+
format: v.optional(v.string()),
|
|
33
|
+
json: v.record(v.string(), v.record(v.string(), v.unknown())),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export async function customTypeView(): Promise<void> {
|
|
37
|
+
const {
|
|
38
|
+
values: { help, json },
|
|
39
|
+
positionals: [typeId],
|
|
40
|
+
} = parseArgs({
|
|
41
|
+
args: process.argv.slice(4), // skip: node, script, "custom-type", "view"
|
|
42
|
+
options: {
|
|
43
|
+
json: { type: "boolean" },
|
|
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 custom-type view <type-id>");
|
|
57
|
+
process.exitCode = 1;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const projectRoot = await findUpward("package.json");
|
|
62
|
+
if (!projectRoot) {
|
|
63
|
+
console.error("Could not find project root (no package.json found)");
|
|
64
|
+
process.exitCode = 1;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const modelPath = new URL(`customtypes/${typeId}/index.json`, projectRoot);
|
|
69
|
+
|
|
70
|
+
let model: CustomType;
|
|
71
|
+
try {
|
|
72
|
+
const contents = await readFile(modelPath, "utf8");
|
|
73
|
+
const result = v.safeParse(CustomTypeSchema, JSON.parse(contents));
|
|
74
|
+
if (!result.success) {
|
|
75
|
+
console.error(`Invalid custom type model: ${modelPath.href}`);
|
|
76
|
+
process.exitCode = 1;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
model = result.output as CustomType;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
82
|
+
console.error(`Custom type not found: ${typeId}\n`);
|
|
83
|
+
console.error(`Create it first with: prismic custom-type create ${typeId}`);
|
|
84
|
+
process.exitCode = 1;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (error instanceof Error) {
|
|
88
|
+
console.error(`Failed to read custom type: ${error.message}`);
|
|
89
|
+
} else {
|
|
90
|
+
console.error("Failed to read custom type");
|
|
91
|
+
}
|
|
92
|
+
process.exitCode = 1;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Check if this is actually a custom type (not a page type)
|
|
97
|
+
if (model.format === "page") {
|
|
98
|
+
console.error(`"${typeId}" is not a custom type (format: page)`);
|
|
99
|
+
process.exitCode = 1;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (json) {
|
|
104
|
+
console.info(JSON.stringify(model, null, 2));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
console.info(`ID: ${model.id}`);
|
|
109
|
+
console.info(`Label: ${model.label}`);
|
|
110
|
+
console.info(`Repeatable: ${model.repeatable}`);
|
|
111
|
+
|
|
112
|
+
const tabs = Object.entries(model.json);
|
|
113
|
+
console.info(`\nTabs (${tabs.length}):`);
|
|
114
|
+
for (const [tabName, tabFields] of tabs) {
|
|
115
|
+
const fieldCount = Object.keys(tabFields).length;
|
|
116
|
+
console.info(` - ${tabName}: ${fieldCount} fields`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
|
|
3
|
+
import { customTypeAddField } from "./custom-type-add-field";
|
|
4
|
+
import { customTypeConnectSlice } from "./custom-type-connect-slice";
|
|
5
|
+
import { customTypeCreate } from "./custom-type-create";
|
|
6
|
+
import { customTypeDisconnectSlice } from "./custom-type-disconnect-slice";
|
|
7
|
+
import { customTypeList } from "./custom-type-list";
|
|
8
|
+
import { customTypeRemove } from "./custom-type-remove";
|
|
9
|
+
import { customTypeRemoveField } from "./custom-type-remove-field";
|
|
10
|
+
import { customTypeSetName } from "./custom-type-set-name";
|
|
11
|
+
import { customTypeView } from "./custom-type-view";
|
|
12
|
+
|
|
13
|
+
const HELP = `
|
|
14
|
+
Manage custom types in a Prismic repository.
|
|
15
|
+
|
|
16
|
+
USAGE
|
|
17
|
+
prismic custom-type <command> [flags]
|
|
18
|
+
|
|
19
|
+
COMMANDS
|
|
20
|
+
create Create a new custom type
|
|
21
|
+
list List all custom types
|
|
22
|
+
view View details of a custom type
|
|
23
|
+
remove Remove a custom type
|
|
24
|
+
set-name Change a custom type's display name
|
|
25
|
+
add-field Add a field to a custom type
|
|
26
|
+
remove-field Remove a field from a custom type
|
|
27
|
+
connect-slice Connect a shared slice to a custom type
|
|
28
|
+
disconnect-slice Disconnect a shared slice from a custom type
|
|
29
|
+
|
|
30
|
+
FLAGS
|
|
31
|
+
-h, --help Show help for command
|
|
32
|
+
|
|
33
|
+
LEARN MORE
|
|
34
|
+
Use \`prismic custom-type <command> --help\` for more information about a command.
|
|
35
|
+
`.trim();
|
|
36
|
+
|
|
37
|
+
export async function customType(): Promise<void> {
|
|
38
|
+
const {
|
|
39
|
+
positionals: [subcommand],
|
|
40
|
+
} = parseArgs({
|
|
41
|
+
args: process.argv.slice(3), // skip: node, script, "custom-type"
|
|
42
|
+
options: {
|
|
43
|
+
help: { type: "boolean", short: "h" },
|
|
44
|
+
},
|
|
45
|
+
allowPositionals: true,
|
|
46
|
+
strict: false,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
switch (subcommand) {
|
|
50
|
+
case "create":
|
|
51
|
+
await customTypeCreate();
|
|
52
|
+
break;
|
|
53
|
+
case "list":
|
|
54
|
+
await customTypeList();
|
|
55
|
+
break;
|
|
56
|
+
case "view":
|
|
57
|
+
await customTypeView();
|
|
58
|
+
break;
|
|
59
|
+
case "remove":
|
|
60
|
+
await customTypeRemove();
|
|
61
|
+
break;
|
|
62
|
+
case "set-name":
|
|
63
|
+
await customTypeSetName();
|
|
64
|
+
break;
|
|
65
|
+
case "add-field":
|
|
66
|
+
await customTypeAddField();
|
|
67
|
+
break;
|
|
68
|
+
case "remove-field":
|
|
69
|
+
await customTypeRemoveField();
|
|
70
|
+
break;
|
|
71
|
+
case "connect-slice":
|
|
72
|
+
await customTypeConnectSlice();
|
|
73
|
+
break;
|
|
74
|
+
case "disconnect-slice":
|
|
75
|
+
await customTypeDisconnectSlice();
|
|
76
|
+
break;
|
|
77
|
+
default: {
|
|
78
|
+
if (subcommand) {
|
|
79
|
+
console.error(`Unknown custom-type subcommand: ${subcommand}\n`);
|
|
80
|
+
process.exitCode = 1;
|
|
81
|
+
}
|
|
82
|
+
console.info(HELP);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
|
|
3
|
+
const HELP = `
|
|
4
|
+
Fetch and display documentation from Prismic's docs site.
|
|
5
|
+
|
|
6
|
+
USAGE
|
|
7
|
+
prismic docs fetch <path> [flags]
|
|
8
|
+
|
|
9
|
+
ARGUMENTS
|
|
10
|
+
path Documentation path with optional anchor (e.g., "nextjs" or "nextjs#set-up-a-prismic-client")
|
|
11
|
+
|
|
12
|
+
FLAGS
|
|
13
|
+
-h, --help Show help for command
|
|
14
|
+
|
|
15
|
+
EXAMPLES
|
|
16
|
+
prismic docs fetch nextjs
|
|
17
|
+
prismic docs fetch nextjs#set-up-a-prismic-client
|
|
18
|
+
|
|
19
|
+
LEARN MORE
|
|
20
|
+
Visit https://prismic.io/docs for the full documentation.
|
|
21
|
+
`.trim();
|
|
22
|
+
|
|
23
|
+
function parsePathAndAnchor(input: string): { path: string; anchor?: string } {
|
|
24
|
+
const hashIndex = input.indexOf("#");
|
|
25
|
+
if (hashIndex === -1) {
|
|
26
|
+
return { path: input };
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
path: input.slice(0, hashIndex),
|
|
30
|
+
anchor: input.slice(hashIndex + 1),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function fetchMarkdown(
|
|
35
|
+
url: string,
|
|
36
|
+
): Promise<{ ok: true; content: string } | { ok: false; error: string }> {
|
|
37
|
+
try {
|
|
38
|
+
const response = await fetch(url);
|
|
39
|
+
if (response.status === 404) {
|
|
40
|
+
return { ok: false, error: `Documentation not found: ${url}` };
|
|
41
|
+
}
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
return {
|
|
44
|
+
ok: false,
|
|
45
|
+
error: `Failed to fetch documentation: ${response.status}`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const content = await response.text();
|
|
49
|
+
return { ok: true, content };
|
|
50
|
+
} catch (error) {
|
|
51
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
52
|
+
return { ok: false, error: `Network error: ${message}` };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function anchorToHeadingPattern(anchor: string): RegExp {
|
|
57
|
+
// Convert kebab-case anchor to a pattern that matches the heading text.
|
|
58
|
+
const pattern = anchor
|
|
59
|
+
.split("-")
|
|
60
|
+
.map((word) => word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
|
|
61
|
+
.join("[\\s-]+");
|
|
62
|
+
return new RegExp(`^(#{1,6})\\s+${pattern}\\s*$`, "im");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function extractSection(
|
|
66
|
+
markdown: string,
|
|
67
|
+
anchor: string,
|
|
68
|
+
): { ok: true; content: string } | { ok: false; error: string } {
|
|
69
|
+
const lines = markdown.split("\n");
|
|
70
|
+
const headingPattern = anchorToHeadingPattern(anchor);
|
|
71
|
+
|
|
72
|
+
let startIndex = -1;
|
|
73
|
+
let headingLevel = 0;
|
|
74
|
+
|
|
75
|
+
for (let i = 0; i < lines.length; i++) {
|
|
76
|
+
const match = lines[i].match(headingPattern);
|
|
77
|
+
if (match) {
|
|
78
|
+
startIndex = i;
|
|
79
|
+
headingLevel = match[1].length;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (startIndex === -1) {
|
|
85
|
+
return { ok: false, error: `Anchor not found: #${anchor}` };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let endIndex = lines.length;
|
|
89
|
+
for (let i = startIndex + 1; i < lines.length; i++) {
|
|
90
|
+
const headingMatch = lines[i].match(/^(#{1,6})\s/);
|
|
91
|
+
if (headingMatch && headingMatch[1].length <= headingLevel) {
|
|
92
|
+
endIndex = i;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const content = lines.slice(startIndex, endIndex).join("\n").trim();
|
|
98
|
+
return { ok: true, content };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function docsFetch(): Promise<void> {
|
|
102
|
+
const {
|
|
103
|
+
positionals: [pathArg],
|
|
104
|
+
values: { help },
|
|
105
|
+
} = parseArgs({
|
|
106
|
+
args: process.argv.slice(4),
|
|
107
|
+
options: {
|
|
108
|
+
help: { type: "boolean", short: "h" },
|
|
109
|
+
},
|
|
110
|
+
allowPositionals: true,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
if (help) {
|
|
114
|
+
console.info(HELP);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (!pathArg) {
|
|
119
|
+
console.info(HELP);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const { path, anchor } = parsePathAndAnchor(pathArg);
|
|
124
|
+
const url = `https://prismic.io/docs/${path}.md`;
|
|
125
|
+
|
|
126
|
+
const fetchResult = await fetchMarkdown(url);
|
|
127
|
+
if (!fetchResult.ok) {
|
|
128
|
+
console.error(fetchResult.error);
|
|
129
|
+
process.exitCode = 1;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let output = fetchResult.content;
|
|
134
|
+
|
|
135
|
+
if (anchor) {
|
|
136
|
+
const extractResult = extractSection(output, anchor);
|
|
137
|
+
if (!extractResult.ok) {
|
|
138
|
+
console.error(extractResult.error);
|
|
139
|
+
process.exitCode = 1;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
output = extractResult.content;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
console.info(output);
|
|
146
|
+
}
|