@angeloashmore/prismic-cli-poc 0.0.0-pr.6.9baab87 → 0.0.0-pr.8.b80fefa
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/dist/index.mjs +277 -432
- package/package.json +1 -1
- package/src/custom-type-add-field-boolean.ts +5 -12
- package/src/custom-type-add-field-color.ts +6 -12
- package/src/custom-type-add-field-date.ts +6 -12
- package/src/custom-type-add-field-embed.ts +6 -12
- package/src/custom-type-add-field-geo-point.ts +6 -12
- package/src/custom-type-add-field-image.ts +6 -12
- package/src/custom-type-add-field-key-text.ts +6 -12
- package/src/custom-type-add-field-link.ts +5 -12
- package/src/custom-type-add-field-number.ts +6 -12
- package/src/custom-type-add-field-rich-text.ts +5 -12
- package/src/custom-type-add-field-select.ts +5 -12
- package/src/custom-type-add-field-timestamp.ts +6 -12
- package/src/custom-type-add-field-uid.ts +6 -12
- package/src/custom-type-connect-slice.ts +6 -12
- package/src/custom-type-create.ts +6 -12
- package/src/custom-type-disconnect-slice.ts +6 -12
- package/src/custom-type-remove-field.ts +6 -12
- package/src/custom-type-remove.ts +6 -12
- package/src/custom-type-set-name.ts +6 -12
- package/src/docs.ts +149 -0
- package/src/index.ts +5 -0
- package/src/page-type-add-field-boolean.ts +5 -12
- package/src/page-type-add-field-color.ts +6 -12
- package/src/page-type-add-field-date.ts +6 -12
- package/src/page-type-add-field-embed.ts +6 -12
- package/src/page-type-add-field-geo-point.ts +6 -12
- package/src/page-type-add-field-image.ts +6 -12
- package/src/page-type-add-field-key-text.ts +6 -12
- package/src/page-type-add-field-link.ts +5 -12
- package/src/page-type-add-field-number.ts +6 -12
- package/src/page-type-add-field-rich-text.ts +5 -12
- package/src/page-type-add-field-select.ts +5 -12
- package/src/page-type-add-field-timestamp.ts +6 -12
- package/src/page-type-add-field-uid.ts +6 -12
- package/src/page-type-connect-slice.ts +6 -12
- package/src/page-type-create.ts +6 -12
- package/src/page-type-disconnect-slice.ts +6 -12
- package/src/page-type-remove-field.ts +6 -12
- package/src/page-type-remove.ts +6 -12
- package/src/page-type-set-name.ts +6 -12
- package/src/page-type-set-repeatable.ts +6 -12
- package/src/pull.ts +1 -6
- package/src/slice-add-field-boolean.ts +5 -12
- package/src/slice-add-field-color.ts +6 -12
- package/src/slice-add-field-date.ts +6 -12
- package/src/slice-add-field-embed.ts +6 -12
- package/src/slice-add-field-geo-point.ts +6 -12
- package/src/slice-add-field-image.ts +6 -12
- package/src/slice-add-field-key-text.ts +6 -12
- package/src/slice-add-field-link.ts +5 -12
- package/src/slice-add-field-number.ts +6 -12
- package/src/slice-add-field-rich-text.ts +5 -12
- package/src/slice-add-field-select.ts +5 -12
- package/src/slice-add-field-timestamp.ts +6 -12
- package/src/slice-add-variation.ts +6 -12
- package/src/slice-create.ts +6 -12
- package/src/slice-remove-field.ts +6 -12
- package/src/slice-remove-variation.ts +6 -12
- package/src/slice-remove.ts +6 -12
- package/src/slice-rename.ts +6 -12
- package/src/status.ts +113 -13
|
@@ -19,14 +19,11 @@ ARGUMENTS
|
|
|
19
19
|
type-id Custom type identifier (required)
|
|
20
20
|
field-id Field identifier (required)
|
|
21
21
|
|
|
22
|
-
Types are generated by default after changes. Use --no-types to skip.
|
|
23
|
-
|
|
24
22
|
FLAGS
|
|
25
23
|
-t, --tab string Target tab (default: first existing tab, or "Main")
|
|
26
24
|
-l, --label string Display label for the field (inferred from field-id if omitted)
|
|
27
25
|
-p, --placeholder string Placeholder text
|
|
28
26
|
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
29
|
-
--no-types Skip type generation
|
|
30
27
|
-h, --help Show help for command
|
|
31
28
|
|
|
32
29
|
EXAMPLES
|
|
@@ -46,7 +43,7 @@ const CustomTypeSchema = v.object({
|
|
|
46
43
|
|
|
47
44
|
export async function customTypeAddFieldUid(): Promise<void> {
|
|
48
45
|
const {
|
|
49
|
-
values: { help, tab, label, placeholder, types
|
|
46
|
+
values: { help, tab, label, placeholder, types },
|
|
50
47
|
positionals: [typeId, fieldId],
|
|
51
48
|
} = parseArgs({
|
|
52
49
|
args: process.argv.slice(5), // skip: node, script, "custom-type", "add-field", "uid"
|
|
@@ -55,7 +52,6 @@ export async function customTypeAddFieldUid(): Promise<void> {
|
|
|
55
52
|
label: { type: "string", short: "l" },
|
|
56
53
|
placeholder: { type: "string", short: "p" },
|
|
57
54
|
types: { type: "string" },
|
|
58
|
-
"no-types": { type: "boolean" },
|
|
59
55
|
help: { type: "boolean", short: "h" },
|
|
60
56
|
},
|
|
61
57
|
allowPositionals: true,
|
|
@@ -162,13 +158,11 @@ export async function customTypeAddFieldUid(): Promise<void> {
|
|
|
162
158
|
|
|
163
159
|
console.info(`Added field "${fieldId}" (UID) to "${targetTab}" tab in ${typeId}`);
|
|
164
160
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
171
|
-
}
|
|
161
|
+
try {
|
|
162
|
+
await buildTypes({ output: types });
|
|
163
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
172
166
|
}
|
|
173
167
|
|
|
174
168
|
console.info();
|
|
@@ -23,12 +23,9 @@ ARGUMENTS
|
|
|
23
23
|
type-id Custom type identifier (required)
|
|
24
24
|
slice-id Slice identifier (required)
|
|
25
25
|
|
|
26
|
-
Types are generated by default after changes. Use --no-types to skip.
|
|
27
|
-
|
|
28
26
|
FLAGS
|
|
29
27
|
-z, --slice-zone string Target slice zone field ID (default: "slices")
|
|
30
28
|
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
31
|
-
--no-types Skip type generation
|
|
32
29
|
-h, --help Show help for command
|
|
33
30
|
|
|
34
31
|
EXAMPLES
|
|
@@ -48,14 +45,13 @@ const CustomTypeSchema = v.object({
|
|
|
48
45
|
|
|
49
46
|
export async function customTypeConnectSlice(): Promise<void> {
|
|
50
47
|
const {
|
|
51
|
-
values: { help, "slice-zone": sliceZoneId, types
|
|
48
|
+
values: { help, "slice-zone": sliceZoneId, types },
|
|
52
49
|
positionals: [typeId, sliceId],
|
|
53
50
|
} = parseArgs({
|
|
54
51
|
args: process.argv.slice(4), // skip: node, script, "custom-type", "connect-slice"
|
|
55
52
|
options: {
|
|
56
53
|
"slice-zone": { type: "string", short: "z" },
|
|
57
54
|
types: { type: "string" },
|
|
58
|
-
"no-types": { type: "boolean" },
|
|
59
55
|
help: { type: "boolean", short: "h" },
|
|
60
56
|
},
|
|
61
57
|
allowPositionals: true,
|
|
@@ -209,12 +205,10 @@ export async function customTypeConnectSlice(): Promise<void> {
|
|
|
209
205
|
|
|
210
206
|
console.info(`Connected slice "${sliceId}" to slice zone "${sliceZoneFieldId}" in ${typeId}`);
|
|
211
207
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
218
|
-
}
|
|
208
|
+
try {
|
|
209
|
+
await buildTypes({ output: types });
|
|
210
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
211
|
+
} catch (error) {
|
|
212
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
219
213
|
}
|
|
220
214
|
}
|
|
@@ -16,13 +16,10 @@ USAGE
|
|
|
16
16
|
ARGUMENTS
|
|
17
17
|
id Custom type identifier (required)
|
|
18
18
|
|
|
19
|
-
Types are generated by default after changes. Use --no-types to skip.
|
|
20
|
-
|
|
21
19
|
FLAGS
|
|
22
20
|
-n, --name string Display name for the custom type
|
|
23
21
|
--single Create as a singleton (non-repeatable) type
|
|
24
22
|
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
25
|
-
--no-types Skip type generation
|
|
26
23
|
-h, --help Show help for command
|
|
27
24
|
|
|
28
25
|
LEARN MORE
|
|
@@ -31,7 +28,7 @@ LEARN MORE
|
|
|
31
28
|
|
|
32
29
|
export async function customTypeCreate(): Promise<void> {
|
|
33
30
|
const {
|
|
34
|
-
values: { help, name, single, types
|
|
31
|
+
values: { help, name, single, types },
|
|
35
32
|
positionals: [id],
|
|
36
33
|
} = parseArgs({
|
|
37
34
|
args: process.argv.slice(4), // skip: node, script, "custom-type", "create"
|
|
@@ -39,7 +36,6 @@ export async function customTypeCreate(): Promise<void> {
|
|
|
39
36
|
name: { type: "string", short: "n" },
|
|
40
37
|
single: { type: "boolean" },
|
|
41
38
|
types: { type: "string" },
|
|
42
|
-
"no-types": { type: "boolean" },
|
|
43
39
|
help: { type: "boolean", short: "h" },
|
|
44
40
|
},
|
|
45
41
|
allowPositionals: true,
|
|
@@ -100,13 +96,11 @@ export async function customTypeCreate(): Promise<void> {
|
|
|
100
96
|
|
|
101
97
|
console.info(`Created custom type at ${modelPath.href}`);
|
|
102
98
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
109
|
-
}
|
|
99
|
+
try {
|
|
100
|
+
await buildTypes({ output: types });
|
|
101
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
110
104
|
}
|
|
111
105
|
|
|
112
106
|
console.info();
|
|
@@ -18,12 +18,9 @@ ARGUMENTS
|
|
|
18
18
|
type-id Custom type identifier (required)
|
|
19
19
|
slice-id Slice identifier (required)
|
|
20
20
|
|
|
21
|
-
Types are generated by default after changes. Use --no-types to skip.
|
|
22
|
-
|
|
23
21
|
FLAGS
|
|
24
22
|
-z, --slice-zone string Target slice zone field ID (default: "slices")
|
|
25
23
|
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
26
|
-
--no-types Skip type generation
|
|
27
24
|
-h, --help Show help for command
|
|
28
25
|
|
|
29
26
|
EXAMPLES
|
|
@@ -43,14 +40,13 @@ const CustomTypeSchema = v.object({
|
|
|
43
40
|
|
|
44
41
|
export async function customTypeDisconnectSlice(): Promise<void> {
|
|
45
42
|
const {
|
|
46
|
-
values: { help, "slice-zone": sliceZoneId, types
|
|
43
|
+
values: { help, "slice-zone": sliceZoneId, types },
|
|
47
44
|
positionals: [typeId, sliceId],
|
|
48
45
|
} = parseArgs({
|
|
49
46
|
args: process.argv.slice(4), // skip: node, script, "custom-type", "disconnect-slice"
|
|
50
47
|
options: {
|
|
51
48
|
"slice-zone": { type: "string", short: "z" },
|
|
52
49
|
types: { type: "string" },
|
|
53
|
-
"no-types": { type: "boolean" },
|
|
54
50
|
help: { type: "boolean", short: "h" },
|
|
55
51
|
},
|
|
56
52
|
allowPositionals: true,
|
|
@@ -166,12 +162,10 @@ export async function customTypeDisconnectSlice(): Promise<void> {
|
|
|
166
162
|
`Disconnected slice "${sliceId}" from slice zone "${sliceZoneFieldId}" in ${typeId}`,
|
|
167
163
|
);
|
|
168
164
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
175
|
-
}
|
|
165
|
+
try {
|
|
166
|
+
await buildTypes({ output: types });
|
|
167
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
168
|
+
} catch (error) {
|
|
169
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
176
170
|
}
|
|
177
171
|
}
|
|
@@ -18,12 +18,9 @@ ARGUMENTS
|
|
|
18
18
|
type-id Custom type identifier (required)
|
|
19
19
|
field-id Field identifier (required)
|
|
20
20
|
|
|
21
|
-
Types are generated by default after changes. Use --no-types to skip.
|
|
22
|
-
|
|
23
21
|
FLAGS
|
|
24
22
|
--tab string Specific tab (searches all tabs if not specified)
|
|
25
23
|
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
26
|
-
--no-types Skip type generation
|
|
27
24
|
-h, --help Show help for command
|
|
28
25
|
|
|
29
26
|
EXAMPLES
|
|
@@ -42,14 +39,13 @@ const CustomTypeSchema = v.object({
|
|
|
42
39
|
|
|
43
40
|
export async function customTypeRemoveField(): Promise<void> {
|
|
44
41
|
const {
|
|
45
|
-
values: { help, tab, types
|
|
42
|
+
values: { help, tab, types },
|
|
46
43
|
positionals: [typeId, fieldId],
|
|
47
44
|
} = parseArgs({
|
|
48
45
|
args: process.argv.slice(4), // skip: node, script, "custom-type", "remove-field"
|
|
49
46
|
options: {
|
|
50
47
|
tab: { type: "string" },
|
|
51
48
|
types: { type: "string" },
|
|
52
|
-
"no-types": { type: "boolean" },
|
|
53
49
|
help: { type: "boolean", short: "h" },
|
|
54
50
|
},
|
|
55
51
|
allowPositionals: true,
|
|
@@ -166,12 +162,10 @@ export async function customTypeRemoveField(): Promise<void> {
|
|
|
166
162
|
|
|
167
163
|
console.info(`Removed field "${fieldId}" from tab "${foundTab}" in custom type "${typeId}"`);
|
|
168
164
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
175
|
-
}
|
|
165
|
+
try {
|
|
166
|
+
await buildTypes({ output: types });
|
|
167
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
168
|
+
} catch (error) {
|
|
169
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
176
170
|
}
|
|
177
171
|
}
|
|
@@ -16,12 +16,9 @@ USAGE
|
|
|
16
16
|
ARGUMENTS
|
|
17
17
|
type-id Custom type identifier (required)
|
|
18
18
|
|
|
19
|
-
Types are generated by default after changes. Use --no-types to skip.
|
|
20
|
-
|
|
21
19
|
FLAGS
|
|
22
20
|
-y Confirm removal
|
|
23
21
|
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
24
|
-
--no-types Skip type generation
|
|
25
22
|
-h, --help Show help for command
|
|
26
23
|
|
|
27
24
|
EXAMPLES
|
|
@@ -40,14 +37,13 @@ const CustomTypeSchema = v.object({
|
|
|
40
37
|
|
|
41
38
|
export async function customTypeRemove(): Promise<void> {
|
|
42
39
|
const {
|
|
43
|
-
values: { help, y, types
|
|
40
|
+
values: { help, y, types },
|
|
44
41
|
positionals: [typeId],
|
|
45
42
|
} = parseArgs({
|
|
46
43
|
args: process.argv.slice(4), // skip: node, script, "custom-type", "remove"
|
|
47
44
|
options: {
|
|
48
45
|
y: { type: "boolean", short: "y" },
|
|
49
46
|
types: { type: "string" },
|
|
50
|
-
"no-types": { type: "boolean" },
|
|
51
47
|
help: { type: "boolean", short: "h" },
|
|
52
48
|
},
|
|
53
49
|
allowPositionals: true,
|
|
@@ -133,12 +129,10 @@ export async function customTypeRemove(): Promise<void> {
|
|
|
133
129
|
|
|
134
130
|
console.info(`Removed custom type "${typeId}"`);
|
|
135
131
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
142
|
-
}
|
|
132
|
+
try {
|
|
133
|
+
await buildTypes({ output: types });
|
|
134
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
143
137
|
}
|
|
144
138
|
}
|
|
@@ -18,11 +18,8 @@ ARGUMENTS
|
|
|
18
18
|
type-id Custom type identifier (required)
|
|
19
19
|
new-name New display name (required)
|
|
20
20
|
|
|
21
|
-
Types are generated by default after changes. Use --no-types to skip.
|
|
22
|
-
|
|
23
21
|
FLAGS
|
|
24
22
|
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
25
|
-
--no-types Skip type generation
|
|
26
23
|
-h, --help Show help for command
|
|
27
24
|
|
|
28
25
|
EXAMPLES
|
|
@@ -41,13 +38,12 @@ const CustomTypeSchema = v.object({
|
|
|
41
38
|
|
|
42
39
|
export async function customTypeSetName(): Promise<void> {
|
|
43
40
|
const {
|
|
44
|
-
values: { help, types
|
|
41
|
+
values: { help, types },
|
|
45
42
|
positionals: [typeId, newName],
|
|
46
43
|
} = parseArgs({
|
|
47
44
|
args: process.argv.slice(4), // skip: node, script, "custom-type", "set-name"
|
|
48
45
|
options: {
|
|
49
46
|
types: { type: "string" },
|
|
50
|
-
"no-types": { type: "boolean" },
|
|
51
47
|
help: { type: "boolean", short: "h" },
|
|
52
48
|
},
|
|
53
49
|
allowPositionals: true,
|
|
@@ -133,12 +129,10 @@ export async function customTypeSetName(): Promise<void> {
|
|
|
133
129
|
|
|
134
130
|
console.info(`Renamed custom type "${typeId}" to "${newName}"`);
|
|
135
131
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
142
|
-
}
|
|
132
|
+
try {
|
|
133
|
+
await buildTypes({ output: types });
|
|
134
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
143
137
|
}
|
|
144
138
|
}
|
package/src/docs.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
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 <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 nextjs
|
|
17
|
+
prismic docs 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
|
+
// Each hyphen/space becomes a flexible match for hyphens or spaces
|
|
59
|
+
const pattern = anchor
|
|
60
|
+
.split("-")
|
|
61
|
+
.map((word) => word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
|
|
62
|
+
.join("[\\s-]+");
|
|
63
|
+
return new RegExp(`^(#{1,6})\\s+${pattern}\\s*$`, "im");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function extractSection(
|
|
67
|
+
markdown: string,
|
|
68
|
+
anchor: string,
|
|
69
|
+
): { ok: true; content: string } | { ok: false; error: string } {
|
|
70
|
+
const lines = markdown.split("\n");
|
|
71
|
+
const headingPattern = anchorToHeadingPattern(anchor);
|
|
72
|
+
|
|
73
|
+
let startIndex = -1;
|
|
74
|
+
let headingLevel = 0;
|
|
75
|
+
|
|
76
|
+
// Find the matching heading
|
|
77
|
+
for (let i = 0; i < lines.length; i++) {
|
|
78
|
+
const match = lines[i].match(headingPattern);
|
|
79
|
+
if (match) {
|
|
80
|
+
startIndex = i;
|
|
81
|
+
headingLevel = match[1].length;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (startIndex === -1) {
|
|
87
|
+
return { ok: false, error: `Anchor not found: #${anchor}` };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Find the end of this section (next heading of equal or lower level number)
|
|
91
|
+
let endIndex = lines.length;
|
|
92
|
+
for (let i = startIndex + 1; i < lines.length; i++) {
|
|
93
|
+
const headingMatch = lines[i].match(/^(#{1,6})\s/);
|
|
94
|
+
if (headingMatch && headingMatch[1].length <= headingLevel) {
|
|
95
|
+
endIndex = i;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const content = lines.slice(startIndex, endIndex).join("\n").trim();
|
|
101
|
+
return { ok: true, content };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function docs(): Promise<void> {
|
|
105
|
+
const {
|
|
106
|
+
positionals: [pathArg],
|
|
107
|
+
values: { help },
|
|
108
|
+
} = parseArgs({
|
|
109
|
+
args: process.argv.slice(3),
|
|
110
|
+
options: {
|
|
111
|
+
help: { type: "boolean", short: "h" },
|
|
112
|
+
},
|
|
113
|
+
allowPositionals: true,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
if (help) {
|
|
117
|
+
console.info(HELP);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!pathArg) {
|
|
122
|
+
console.info(HELP);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const { path, anchor } = parsePathAndAnchor(pathArg);
|
|
127
|
+
const url = `https://prismic.io/docs/${path}.md`;
|
|
128
|
+
|
|
129
|
+
const fetchResult = await fetchMarkdown(url);
|
|
130
|
+
if (!fetchResult.ok) {
|
|
131
|
+
console.error(fetchResult.error);
|
|
132
|
+
process.exitCode = 1;
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let output = fetchResult.content;
|
|
137
|
+
|
|
138
|
+
if (anchor) {
|
|
139
|
+
const extractResult = extractSection(output, anchor);
|
|
140
|
+
if (!extractResult.ok) {
|
|
141
|
+
console.error(extractResult.error);
|
|
142
|
+
process.exitCode = 1;
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
output = extractResult.content;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
console.info(output);
|
|
149
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { parseArgs } from "node:util";
|
|
|
5
5
|
import packageJson from "../package.json" with { type: "json" };
|
|
6
6
|
import { codegen } from "./codegen";
|
|
7
7
|
import { customType } from "./custom-type";
|
|
8
|
+
import { docs } from "./docs";
|
|
8
9
|
import { init } from "./init";
|
|
9
10
|
import { locale } from "./locale";
|
|
10
11
|
import { login } from "./login";
|
|
@@ -40,6 +41,7 @@ COMMANDS
|
|
|
40
41
|
pull Pull types and slices from Prismic
|
|
41
42
|
push Push types and slices to Prismic
|
|
42
43
|
codegen Generate code from Prismic models
|
|
44
|
+
docs Fetch documentation from Prismic
|
|
43
45
|
preview Manage preview configurations
|
|
44
46
|
token Manage API tokens in a repository
|
|
45
47
|
webhook Manage webhooks in a repository
|
|
@@ -107,6 +109,9 @@ if (version) {
|
|
|
107
109
|
case "codegen":
|
|
108
110
|
await codegen();
|
|
109
111
|
break;
|
|
112
|
+
case "docs":
|
|
113
|
+
await docs();
|
|
114
|
+
break;
|
|
110
115
|
case "preview":
|
|
111
116
|
await preview();
|
|
112
117
|
break;
|
|
@@ -19,8 +19,6 @@ ARGUMENTS
|
|
|
19
19
|
type-id Page type identifier (required)
|
|
20
20
|
field-id Field identifier (required)
|
|
21
21
|
|
|
22
|
-
Types are generated by default after changes. Use --no-types to skip.
|
|
23
|
-
|
|
24
22
|
FLAGS
|
|
25
23
|
-t, --tab string Target tab (default: first existing tab, or "Main")
|
|
26
24
|
-l, --label string Display label for the field (inferred from field-id if omitted)
|
|
@@ -28,7 +26,6 @@ FLAGS
|
|
|
28
26
|
--true-label string Label shown when toggle is on
|
|
29
27
|
--false-label string Label shown when toggle is off
|
|
30
28
|
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
31
|
-
--no-types Skip type generation
|
|
32
29
|
-h, --help Show help for command
|
|
33
30
|
|
|
34
31
|
EXAMPLES
|
|
@@ -56,7 +53,6 @@ export async function pageTypeAddFieldBoolean(): Promise<void> {
|
|
|
56
53
|
"true-label": trueLabel,
|
|
57
54
|
"false-label": falseLabel,
|
|
58
55
|
types,
|
|
59
|
-
"no-types": noTypes,
|
|
60
56
|
},
|
|
61
57
|
positionals: [typeId, fieldId],
|
|
62
58
|
} = parseArgs({
|
|
@@ -68,7 +64,6 @@ export async function pageTypeAddFieldBoolean(): Promise<void> {
|
|
|
68
64
|
"true-label": { type: "string" },
|
|
69
65
|
"false-label": { type: "string" },
|
|
70
66
|
types: { type: "string" },
|
|
71
|
-
"no-types": { type: "boolean" },
|
|
72
67
|
help: { type: "boolean", short: "h" },
|
|
73
68
|
},
|
|
74
69
|
allowPositionals: true,
|
|
@@ -177,13 +172,11 @@ export async function pageTypeAddFieldBoolean(): Promise<void> {
|
|
|
177
172
|
|
|
178
173
|
console.info(`Added field "${fieldId}" (Boolean) to "${targetTab}" tab in ${typeId}`);
|
|
179
174
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
186
|
-
}
|
|
175
|
+
try {
|
|
176
|
+
await buildTypes({ output: types });
|
|
177
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
187
180
|
}
|
|
188
181
|
|
|
189
182
|
console.info();
|
|
@@ -19,14 +19,11 @@ ARGUMENTS
|
|
|
19
19
|
type-id Page type identifier (required)
|
|
20
20
|
field-id Field identifier (required)
|
|
21
21
|
|
|
22
|
-
Types are generated by default after changes. Use --no-types to skip.
|
|
23
|
-
|
|
24
22
|
FLAGS
|
|
25
23
|
-t, --tab string Target tab (default: first existing tab, or "Main")
|
|
26
24
|
-l, --label string Display label for the field (inferred from field-id if omitted)
|
|
27
25
|
-p, --placeholder string Placeholder text
|
|
28
26
|
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
29
|
-
--no-types Skip type generation
|
|
30
27
|
-h, --help Show help for command
|
|
31
28
|
|
|
32
29
|
EXAMPLES
|
|
@@ -46,7 +43,7 @@ const CustomTypeSchema = v.object({
|
|
|
46
43
|
|
|
47
44
|
export async function pageTypeAddFieldColor(): Promise<void> {
|
|
48
45
|
const {
|
|
49
|
-
values: { help, tab, label, placeholder, types
|
|
46
|
+
values: { help, tab, label, placeholder, types },
|
|
50
47
|
positionals: [typeId, fieldId],
|
|
51
48
|
} = parseArgs({
|
|
52
49
|
args: process.argv.slice(5), // skip: node, script, "page-type", "add-field", "color"
|
|
@@ -55,7 +52,6 @@ export async function pageTypeAddFieldColor(): Promise<void> {
|
|
|
55
52
|
label: { type: "string", short: "l" },
|
|
56
53
|
placeholder: { type: "string", short: "p" },
|
|
57
54
|
types: { type: "string" },
|
|
58
|
-
"no-types": { type: "boolean" },
|
|
59
55
|
help: { type: "boolean", short: "h" },
|
|
60
56
|
},
|
|
61
57
|
allowPositionals: true,
|
|
@@ -162,13 +158,11 @@ export async function pageTypeAddFieldColor(): Promise<void> {
|
|
|
162
158
|
|
|
163
159
|
console.info(`Added field "${fieldId}" (Color) to "${targetTab}" tab in ${typeId}`);
|
|
164
160
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
171
|
-
}
|
|
161
|
+
try {
|
|
162
|
+
await buildTypes({ output: types });
|
|
163
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
172
166
|
}
|
|
173
167
|
|
|
174
168
|
console.info();
|
|
@@ -19,15 +19,12 @@ ARGUMENTS
|
|
|
19
19
|
type-id Page type identifier (required)
|
|
20
20
|
field-id Field identifier (required)
|
|
21
21
|
|
|
22
|
-
Types are generated by default after changes. Use --no-types to skip.
|
|
23
|
-
|
|
24
22
|
FLAGS
|
|
25
23
|
-t, --tab string Target tab (default: first existing tab, or "Main")
|
|
26
24
|
-l, --label string Display label for the field (inferred from field-id if omitted)
|
|
27
25
|
-p, --placeholder string Placeholder text
|
|
28
26
|
--default string Default date value (YYYY-MM-DD format)
|
|
29
27
|
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
30
|
-
--no-types Skip type generation
|
|
31
28
|
-h, --help Show help for command
|
|
32
29
|
|
|
33
30
|
EXAMPLES
|
|
@@ -47,7 +44,7 @@ const CustomTypeSchema = v.object({
|
|
|
47
44
|
|
|
48
45
|
export async function pageTypeAddFieldDate(): Promise<void> {
|
|
49
46
|
const {
|
|
50
|
-
values: { help, tab, label, placeholder, default: defaultValue, types
|
|
47
|
+
values: { help, tab, label, placeholder, default: defaultValue, types },
|
|
51
48
|
positionals: [typeId, fieldId],
|
|
52
49
|
} = parseArgs({
|
|
53
50
|
args: process.argv.slice(5), // skip: node, script, "page-type", "add-field", "date"
|
|
@@ -57,7 +54,6 @@ export async function pageTypeAddFieldDate(): Promise<void> {
|
|
|
57
54
|
placeholder: { type: "string", short: "p" },
|
|
58
55
|
default: { type: "string" },
|
|
59
56
|
types: { type: "string" },
|
|
60
|
-
"no-types": { type: "boolean" },
|
|
61
57
|
help: { type: "boolean", short: "h" },
|
|
62
58
|
},
|
|
63
59
|
allowPositionals: true,
|
|
@@ -165,13 +161,11 @@ export async function pageTypeAddFieldDate(): Promise<void> {
|
|
|
165
161
|
|
|
166
162
|
console.info(`Added field "${fieldId}" (Date) to "${targetTab}" tab in ${typeId}`);
|
|
167
163
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
174
|
-
}
|
|
164
|
+
try {
|
|
165
|
+
await buildTypes({ output: types });
|
|
166
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
175
169
|
}
|
|
176
170
|
|
|
177
171
|
console.info();
|