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,107 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
|
|
4
|
+
import { isAuthenticated } from "./lib/auth";
|
|
5
|
+
import { safeGetRepositoryFromConfig } from "./lib/config";
|
|
6
|
+
import { stringify } from "./lib/json";
|
|
7
|
+
import { ForbiddenRequestError, type ParsedRequestResponse, request } from "./lib/request";
|
|
8
|
+
import { getInternalApiUrl } from "./lib/url";
|
|
9
|
+
|
|
10
|
+
const HELP = `
|
|
11
|
+
List all locales in a Prismic repository.
|
|
12
|
+
|
|
13
|
+
By default, this command reads the repository from prismic.config.json at the
|
|
14
|
+
project root.
|
|
15
|
+
|
|
16
|
+
USAGE
|
|
17
|
+
prismic locale list [flags]
|
|
18
|
+
|
|
19
|
+
FLAGS
|
|
20
|
+
--json Output as JSON
|
|
21
|
+
-r, --repo string Repository domain
|
|
22
|
+
-h, --help Show help for command
|
|
23
|
+
|
|
24
|
+
LEARN MORE
|
|
25
|
+
Use \`prismic <command> <subcommand> --help\` for more information about a command.
|
|
26
|
+
`.trim();
|
|
27
|
+
|
|
28
|
+
export async function localeList(): Promise<void> {
|
|
29
|
+
const {
|
|
30
|
+
values: { help, repo = await safeGetRepositoryFromConfig(), json },
|
|
31
|
+
} = parseArgs({
|
|
32
|
+
args: process.argv.slice(4), // skip: node, script, "locale", "list"
|
|
33
|
+
options: {
|
|
34
|
+
json: { type: "boolean" },
|
|
35
|
+
repo: { type: "string", short: "r" },
|
|
36
|
+
help: { type: "boolean", short: "h" },
|
|
37
|
+
},
|
|
38
|
+
allowPositionals: false,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (help) {
|
|
42
|
+
console.info(HELP);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!repo) {
|
|
47
|
+
console.error("Missing prismic.config.json or --repo option");
|
|
48
|
+
process.exitCode = 1;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const authenticated = await isAuthenticated();
|
|
53
|
+
if (!authenticated) {
|
|
54
|
+
handleUnauthenticated();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const response = await getLocales(repo);
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
if (response.error instanceof ForbiddenRequestError) {
|
|
61
|
+
handleUnauthenticated();
|
|
62
|
+
} else if (v.isValiError(response.error)) {
|
|
63
|
+
console.error(
|
|
64
|
+
`Failed to list locales: Invalid response: ${stringify(response.error.issues)}`,
|
|
65
|
+
);
|
|
66
|
+
process.exitCode = 1;
|
|
67
|
+
} else {
|
|
68
|
+
console.error(`Failed to list locales: ${stringify(response.value)}`);
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const locales = response.value.results;
|
|
75
|
+
if (json) {
|
|
76
|
+
console.info(stringify(locales));
|
|
77
|
+
} else {
|
|
78
|
+
for (const locale of locales) {
|
|
79
|
+
const defaultLabel = locale.isMaster ? " (default)" : "";
|
|
80
|
+
console.info(`${locale.id} ${locale.label}${defaultLabel}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const LocaleSchema = v.object({
|
|
86
|
+
id: v.string(),
|
|
87
|
+
label: v.string(),
|
|
88
|
+
customName: v.nullable(v.string()),
|
|
89
|
+
isMaster: v.boolean(),
|
|
90
|
+
});
|
|
91
|
+
export type Locale = v.InferOutput<typeof LocaleSchema>;
|
|
92
|
+
|
|
93
|
+
const GetLocalesResponseSchema = v.object({
|
|
94
|
+
results: v.array(LocaleSchema),
|
|
95
|
+
});
|
|
96
|
+
type GetLocalesResponse = v.InferOutput<typeof GetLocalesResponseSchema>;
|
|
97
|
+
|
|
98
|
+
export async function getLocales(repo: string): Promise<ParsedRequestResponse<GetLocalesResponse>> {
|
|
99
|
+
const url = new URL("/locale/repository/locales", await getInternalApiUrl());
|
|
100
|
+
url.searchParams.set("repository", repo);
|
|
101
|
+
return await request(url, { schema: GetLocalesResponseSchema });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function handleUnauthenticated() {
|
|
105
|
+
console.error("Not logged in. Run `prismic login` first.");
|
|
106
|
+
process.exitCode = 1;
|
|
107
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
|
|
3
|
+
import { isAuthenticated } from "./lib/auth";
|
|
4
|
+
import { safeGetRepositoryFromConfig } from "./lib/config";
|
|
5
|
+
import { stringify } from "./lib/json";
|
|
6
|
+
import { ForbiddenRequestError, request } from "./lib/request";
|
|
7
|
+
import { getInternalApiUrl } from "./lib/url";
|
|
8
|
+
|
|
9
|
+
const HELP = `
|
|
10
|
+
Remove a locale from a Prismic repository.
|
|
11
|
+
|
|
12
|
+
By default, this command reads the repository from prismic.config.json at the
|
|
13
|
+
project root.
|
|
14
|
+
|
|
15
|
+
USAGE
|
|
16
|
+
prismic locale remove <code> [flags]
|
|
17
|
+
|
|
18
|
+
ARGUMENTS
|
|
19
|
+
<code> Locale code (e.g. en-us, fr-fr)
|
|
20
|
+
|
|
21
|
+
FLAGS
|
|
22
|
+
-r, --repo string Repository domain
|
|
23
|
+
-h, --help Show help for command
|
|
24
|
+
|
|
25
|
+
LEARN MORE
|
|
26
|
+
Use \`prismic <command> <subcommand> --help\` for more information about a command.
|
|
27
|
+
`.trim();
|
|
28
|
+
|
|
29
|
+
export async function localeRemove(): Promise<void> {
|
|
30
|
+
const {
|
|
31
|
+
values: { repo = await safeGetRepositoryFromConfig(), help },
|
|
32
|
+
positionals: [code],
|
|
33
|
+
} = parseArgs({
|
|
34
|
+
args: process.argv.slice(4), // skip: node, script, "locale", "remove"
|
|
35
|
+
options: {
|
|
36
|
+
repo: { type: "string", short: "r" },
|
|
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 (!code) {
|
|
48
|
+
console.error("Missing required argument: <code>");
|
|
49
|
+
process.exitCode = 1;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!repo) {
|
|
54
|
+
console.error("Missing prismic.config.json or --repo option");
|
|
55
|
+
process.exitCode = 1;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const authenticated = await isAuthenticated();
|
|
60
|
+
if (!authenticated) {
|
|
61
|
+
handleUnauthenticated();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const response = await removeLocale(repo, code);
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
if (response.error instanceof ForbiddenRequestError) {
|
|
68
|
+
handleUnauthenticated();
|
|
69
|
+
} else {
|
|
70
|
+
console.error(`Failed to remove locale: ${stringify(response.value)}`);
|
|
71
|
+
process.exitCode = 1;
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
console.info(`Removed locale: ${code}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function removeLocale(repository: string, code: string) {
|
|
80
|
+
const url = new URL(`/locale/repository/locales/${code}`, await getInternalApiUrl());
|
|
81
|
+
url.searchParams.set("repository", repository);
|
|
82
|
+
return await request(url, { method: "DELETE" });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function handleUnauthenticated() {
|
|
86
|
+
console.error("Not logged in. Run `prismic login` first.");
|
|
87
|
+
process.exitCode = 1;
|
|
88
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
|
|
4
|
+
import { isAuthenticated } from "./lib/auth";
|
|
5
|
+
import { safeGetRepositoryFromConfig } from "./lib/config";
|
|
6
|
+
import { stringify } from "./lib/json";
|
|
7
|
+
import { ForbiddenRequestError, request } from "./lib/request";
|
|
8
|
+
import { getInternalApiUrl } from "./lib/url";
|
|
9
|
+
import { type Locale, getLocales } from "./locale-list";
|
|
10
|
+
|
|
11
|
+
const HELP = `
|
|
12
|
+
Set the default locale for a Prismic repository.
|
|
13
|
+
|
|
14
|
+
By default, this command reads the repository from prismic.config.json at the
|
|
15
|
+
project root.
|
|
16
|
+
|
|
17
|
+
USAGE
|
|
18
|
+
prismic locale set-default <code> [flags]
|
|
19
|
+
|
|
20
|
+
ARGUMENTS
|
|
21
|
+
<code> Locale code (e.g. en-us, fr-fr)
|
|
22
|
+
|
|
23
|
+
FLAGS
|
|
24
|
+
-r, --repo string Repository domain
|
|
25
|
+
-h, --help Show help for command
|
|
26
|
+
|
|
27
|
+
LEARN MORE
|
|
28
|
+
Use \`prismic <command> <subcommand> --help\` for more information about a command.
|
|
29
|
+
`.trim();
|
|
30
|
+
|
|
31
|
+
export async function localeSetDefault(): Promise<void> {
|
|
32
|
+
const {
|
|
33
|
+
values: { help, repo = await safeGetRepositoryFromConfig() },
|
|
34
|
+
positionals: [code],
|
|
35
|
+
} = parseArgs({
|
|
36
|
+
args: process.argv.slice(4), // skip: node, script, "locale", "set-default"
|
|
37
|
+
options: {
|
|
38
|
+
repo: { type: "string", short: "r" },
|
|
39
|
+
help: { type: "boolean", short: "h" },
|
|
40
|
+
},
|
|
41
|
+
allowPositionals: true,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (help) {
|
|
45
|
+
console.info(HELP);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!code) {
|
|
50
|
+
console.error("Missing required argument: <code>");
|
|
51
|
+
process.exitCode = 1;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!repo) {
|
|
56
|
+
console.error("Missing prismic.config.json or --repo option");
|
|
57
|
+
process.exitCode = 1;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const authenticated = await isAuthenticated();
|
|
62
|
+
if (!authenticated) {
|
|
63
|
+
handleUnauthenticated();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const localesResponse = await getLocales(repo);
|
|
68
|
+
if (!localesResponse.ok) {
|
|
69
|
+
if (localesResponse.error instanceof ForbiddenRequestError) {
|
|
70
|
+
handleUnauthenticated();
|
|
71
|
+
} else if (v.isValiError(localesResponse.error)) {
|
|
72
|
+
console.error(
|
|
73
|
+
`Failed to set default locale: Invalid response: ${stringify(localesResponse.error.issues)}`,
|
|
74
|
+
);
|
|
75
|
+
process.exitCode = 1;
|
|
76
|
+
} else {
|
|
77
|
+
console.error(`Failed to set default locale: ${stringify(localesResponse.value)}`);
|
|
78
|
+
process.exitCode = 1;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const locales = localesResponse.value.results;
|
|
85
|
+
const locale = locales.find((l) => l.id === code);
|
|
86
|
+
if (!locale) {
|
|
87
|
+
console.error(
|
|
88
|
+
`Locale "${code}" not found in repository. Available locales: ${locales.map((l) => l.id).join(", ")}`,
|
|
89
|
+
);
|
|
90
|
+
process.exitCode = 1;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (locale.isMaster) {
|
|
95
|
+
console.error(`Locale "${code}" is already the default.`);
|
|
96
|
+
process.exitCode = 1;
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const response = await setDefaultLocale(repo, locale);
|
|
101
|
+
if (!response.ok) {
|
|
102
|
+
if (response.error instanceof ForbiddenRequestError) {
|
|
103
|
+
handleUnauthenticated();
|
|
104
|
+
} else {
|
|
105
|
+
console.error(`Failed to set default locale: ${stringify(response.value)}`);
|
|
106
|
+
process.exitCode = 1;
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
console.info(`Default locale set: ${code}`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function setDefaultLocale(repo: string, locale: Locale) {
|
|
115
|
+
const url = new URL("/locale/repository/locales", await getInternalApiUrl());
|
|
116
|
+
url.searchParams.set("repository", repo);
|
|
117
|
+
return await request(url, {
|
|
118
|
+
method: "POST",
|
|
119
|
+
body: {
|
|
120
|
+
id: locale.id,
|
|
121
|
+
label: locale.label,
|
|
122
|
+
customName: locale.customName,
|
|
123
|
+
isMaster: true,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function handleUnauthenticated() {
|
|
129
|
+
console.error("Not logged in. Run `prismic login` first.");
|
|
130
|
+
process.exitCode = 1;
|
|
131
|
+
}
|
package/src/locale.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
|
|
3
|
+
import { localeAdd } from "./locale-add";
|
|
4
|
+
import { localeList } from "./locale-list";
|
|
5
|
+
import { localeRemove } from "./locale-remove";
|
|
6
|
+
import { localeSetDefault } from "./locale-set-default";
|
|
7
|
+
|
|
8
|
+
const HELP = `
|
|
9
|
+
Manage locales in a Prismic repository.
|
|
10
|
+
|
|
11
|
+
USAGE
|
|
12
|
+
prismic locale <command> [flags]
|
|
13
|
+
|
|
14
|
+
COMMANDS
|
|
15
|
+
add Add a locale to a repository
|
|
16
|
+
list List locales in a repository
|
|
17
|
+
remove Remove a locale from a repository
|
|
18
|
+
set-default Set the default locale for a repository
|
|
19
|
+
|
|
20
|
+
FLAGS
|
|
21
|
+
-h, --help Show help for command
|
|
22
|
+
|
|
23
|
+
LEARN MORE
|
|
24
|
+
Use \`prismic locale <command> --help\` for more information about a command.
|
|
25
|
+
`.trim();
|
|
26
|
+
|
|
27
|
+
export async function locale(): Promise<void> {
|
|
28
|
+
const {
|
|
29
|
+
positionals: [subcommand],
|
|
30
|
+
} = parseArgs({
|
|
31
|
+
args: process.argv.slice(3), // skip: node, script, "locale"
|
|
32
|
+
options: {
|
|
33
|
+
help: { type: "boolean", short: "h" },
|
|
34
|
+
},
|
|
35
|
+
allowPositionals: true,
|
|
36
|
+
strict: false,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
switch (subcommand) {
|
|
40
|
+
case "add":
|
|
41
|
+
await localeAdd();
|
|
42
|
+
break;
|
|
43
|
+
case "list":
|
|
44
|
+
await localeList();
|
|
45
|
+
break;
|
|
46
|
+
case "remove":
|
|
47
|
+
await localeRemove();
|
|
48
|
+
break;
|
|
49
|
+
case "set-default":
|
|
50
|
+
await localeSetDefault();
|
|
51
|
+
break;
|
|
52
|
+
default: {
|
|
53
|
+
if (subcommand) {
|
|
54
|
+
console.error(`Unknown locale subcommand: ${subcommand}\n`);
|
|
55
|
+
process.exitCode = 1;
|
|
56
|
+
}
|
|
57
|
+
console.info(HELP);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
package/src/login.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { exec } from "node:child_process";
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
|
|
4
|
+
import { createLoginSession } from "./lib/auth";
|
|
5
|
+
|
|
6
|
+
const HELP = `
|
|
7
|
+
Log in to Prismic via browser.
|
|
8
|
+
|
|
9
|
+
USAGE
|
|
10
|
+
prismic login [flags]
|
|
11
|
+
|
|
12
|
+
FLAGS
|
|
13
|
+
-h, --help Show help for command
|
|
14
|
+
|
|
15
|
+
LEARN MORE
|
|
16
|
+
Use \`prismic <command> --help\` for more information about a command.
|
|
17
|
+
`.trim();
|
|
18
|
+
|
|
19
|
+
export async function login(): Promise<void> {
|
|
20
|
+
const { values } = parseArgs({
|
|
21
|
+
args: process.argv.slice(3),
|
|
22
|
+
options: { help: { type: "boolean", short: "h" } },
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (values.help) {
|
|
26
|
+
console.info(HELP);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const { email } = await createLoginSession({
|
|
31
|
+
onReady: (url) => {
|
|
32
|
+
console.info("Opening browser to complete login...");
|
|
33
|
+
console.info(`If the browser doesn't open, visit: ${url}`);
|
|
34
|
+
openBrowser(url);
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
console.info(`Logged in to Prismic as ${email}`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function openBrowser(url: URL): void {
|
|
42
|
+
const cmd =
|
|
43
|
+
process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
44
|
+
exec(`${cmd} "${url.toString()}"`);
|
|
45
|
+
}
|
package/src/logout.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
|
|
3
|
+
import { removeToken } from "./lib/auth";
|
|
4
|
+
|
|
5
|
+
const HELP = `
|
|
6
|
+
Log out of Prismic.
|
|
7
|
+
|
|
8
|
+
USAGE
|
|
9
|
+
prismic logout [flags]
|
|
10
|
+
|
|
11
|
+
FLAGS
|
|
12
|
+
-h, --help Show help for command
|
|
13
|
+
|
|
14
|
+
LEARN MORE
|
|
15
|
+
Use \`prismic <command> --help\` for more information about a command.
|
|
16
|
+
`.trim();
|
|
17
|
+
|
|
18
|
+
export async function logout(): Promise<void> {
|
|
19
|
+
const { values } = parseArgs({
|
|
20
|
+
args: process.argv.slice(3),
|
|
21
|
+
options: { help: { type: "boolean", short: "h" } },
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
if (values.help) {
|
|
25
|
+
console.info(HELP);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const ok = await removeToken();
|
|
30
|
+
if (ok) {
|
|
31
|
+
console.info("Logged out of Prismic");
|
|
32
|
+
} else {
|
|
33
|
+
console.error("Logout failed. You can log out manually by deleting the file.");
|
|
34
|
+
process.exitCode = 1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { BooleanField, CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
+
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
|
|
5
|
+
import { buildTypes } from "./codegen-types";
|
|
6
|
+
import { findGroupInTab, isGroupField, parseFieldPath, validateNestedFieldPath } from "./lib/field-path";
|
|
7
|
+
import { getDocsPath, requireFramework } from "./framework";
|
|
8
|
+
import { humanReadable } from "./lib/string";
|
|
9
|
+
|
|
10
|
+
const HELP = `
|
|
11
|
+
Add a boolean (toggle) field to an existing page type.
|
|
12
|
+
|
|
13
|
+
USAGE
|
|
14
|
+
prismic page-type add-field boolean <type-id> <field-id> [flags]
|
|
15
|
+
|
|
16
|
+
ARGUMENTS
|
|
17
|
+
type-id Page type identifier (required)
|
|
18
|
+
field-id Field identifier (required)
|
|
19
|
+
|
|
20
|
+
FLAGS
|
|
21
|
+
-t, --tab string Target tab (default: first existing tab, or "Main")
|
|
22
|
+
-l, --label string Display label for the field (inferred from field-id if omitted)
|
|
23
|
+
--default Set default value to true
|
|
24
|
+
--true-label string Label shown when toggle is on
|
|
25
|
+
--false-label string Label shown when toggle is off
|
|
26
|
+
--types string Output file for generated types (default: "prismicio-types.d.ts")
|
|
27
|
+
-h, --help Show help for command
|
|
28
|
+
|
|
29
|
+
EXAMPLES
|
|
30
|
+
prismic page-type add-field boolean homepage featured
|
|
31
|
+
prismic page-type add-field boolean article published --default
|
|
32
|
+
prismic page-type add-field boolean product available --true-label "In Stock" --false-label "Out of Stock"
|
|
33
|
+
`.trim();
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
export async function pageTypeAddFieldBoolean(): Promise<void> {
|
|
37
|
+
const {
|
|
38
|
+
values: {
|
|
39
|
+
help,
|
|
40
|
+
tab,
|
|
41
|
+
label,
|
|
42
|
+
default: defaultValue,
|
|
43
|
+
"true-label": trueLabel,
|
|
44
|
+
"false-label": falseLabel,
|
|
45
|
+
types,
|
|
46
|
+
},
|
|
47
|
+
positionals: [typeId, fieldId],
|
|
48
|
+
} = parseArgs({
|
|
49
|
+
args: process.argv.slice(5), // skip: node, script, "page-type", "add-field", "boolean"
|
|
50
|
+
options: {
|
|
51
|
+
tab: { type: "string", short: "t" },
|
|
52
|
+
label: { type: "string", short: "l" },
|
|
53
|
+
default: { type: "boolean" },
|
|
54
|
+
"true-label": { type: "string" },
|
|
55
|
+
"false-label": { type: "string" },
|
|
56
|
+
types: { type: "string" },
|
|
57
|
+
help: { type: "boolean", short: "h" },
|
|
58
|
+
},
|
|
59
|
+
allowPositionals: true,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (help) {
|
|
63
|
+
console.info(HELP);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!typeId) {
|
|
68
|
+
console.error("Missing required argument: type-id\n");
|
|
69
|
+
console.error("Usage: prismic page-type add-field boolean <type-id> <field-id>");
|
|
70
|
+
process.exitCode = 1;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!fieldId) {
|
|
75
|
+
console.error("Missing required argument: field-id\n");
|
|
76
|
+
console.error("Usage: prismic page-type add-field boolean <type-id> <field-id>");
|
|
77
|
+
process.exitCode = 1;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Parse and validate field path
|
|
82
|
+
const fieldPath = parseFieldPath(fieldId);
|
|
83
|
+
const pathValidation = validateNestedFieldPath(fieldPath);
|
|
84
|
+
if (!pathValidation.ok) {
|
|
85
|
+
console.error(pathValidation.error);
|
|
86
|
+
process.exitCode = 1;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const framework = await requireFramework();
|
|
91
|
+
if (!framework) return;
|
|
92
|
+
|
|
93
|
+
let model: CustomType;
|
|
94
|
+
try {
|
|
95
|
+
model = await framework.readCustomType(typeId);
|
|
96
|
+
} catch {
|
|
97
|
+
console.error(`Page type not found: ${typeId}\n\nCreate it first with: prismic page-type create ${typeId}`);
|
|
98
|
+
process.exitCode = 1;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Determine target tab
|
|
103
|
+
const existingTabs = Object.keys(model.json);
|
|
104
|
+
const targetTab = tab ?? existingTabs[0] ?? "Main";
|
|
105
|
+
|
|
106
|
+
// Initialize tab if it doesn't exist
|
|
107
|
+
if (!model.json[targetTab]) {
|
|
108
|
+
model.json[targetTab] = {};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Build field definition
|
|
112
|
+
const fieldDefinition: BooleanField = {
|
|
113
|
+
type: "Boolean",
|
|
114
|
+
config: {
|
|
115
|
+
label: label ?? humanReadable(fieldPath.type === "nested" ? fieldPath.nestedFieldId : fieldId),
|
|
116
|
+
...(defaultValue && { default_value: true }),
|
|
117
|
+
...(trueLabel && { placeholder_true: trueLabel }),
|
|
118
|
+
...(falseLabel && { placeholder_false: falseLabel }),
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// Add field to model
|
|
123
|
+
if (fieldPath.type === "nested") {
|
|
124
|
+
const groupResult = findGroupInTab(model.json[targetTab], fieldPath.groupId, targetTab);
|
|
125
|
+
if (!groupResult.ok) {
|
|
126
|
+
console.error(groupResult.error);
|
|
127
|
+
process.exitCode = 1;
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (groupResult.group.config.fields[fieldPath.nestedFieldId]) {
|
|
131
|
+
console.error(`Field "${fieldPath.nestedFieldId}" already exists in group "${fieldPath.groupId}"`);
|
|
132
|
+
process.exitCode = 1;
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
groupResult.group.config.fields[fieldPath.nestedFieldId] = fieldDefinition;
|
|
136
|
+
} else {
|
|
137
|
+
for (const [tabName, tabFields] of Object.entries(model.json)) {
|
|
138
|
+
if (tabFields[fieldId]) {
|
|
139
|
+
console.error(`Field "${fieldId}" already exists in tab "${tabName}"`);
|
|
140
|
+
process.exitCode = 1;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
for (const [groupFieldId, groupField] of Object.entries(tabFields)) {
|
|
144
|
+
if (isGroupField(groupField) && groupField.config.fields[fieldId]) {
|
|
145
|
+
console.error(`Field "${fieldId}" already exists in group "${groupFieldId}" in tab "${tabName}"`);
|
|
146
|
+
process.exitCode = 1;
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
model.json[targetTab][fieldId] = fieldDefinition;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Write updated model
|
|
155
|
+
await framework.updateCustomType(model);
|
|
156
|
+
|
|
157
|
+
if (fieldPath.type === "nested") {
|
|
158
|
+
console.info(`Added field "${fieldPath.nestedFieldId}" (Boolean) to group "${fieldPath.groupId}" in ${typeId}`);
|
|
159
|
+
} else {
|
|
160
|
+
console.info(`Added field "${fieldId}" (Boolean) to "${targetTab}" tab in ${typeId}`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
await buildTypes({ output: types });
|
|
165
|
+
console.info(`Updated types in ${types ?? "prismicio-types.d.ts"}`);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
console.warn(`Could not generate types: ${error instanceof Error ? error.message : error}`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
console.info();
|
|
171
|
+
console.info("Next: Add more fields with `prismic page-type add-field`");
|
|
172
|
+
|
|
173
|
+
if (framework) {
|
|
174
|
+
const docsPath = getDocsPath(framework.id);
|
|
175
|
+
console.info(
|
|
176
|
+
` Run \`prismic docs fetch ${docsPath}#write-page-components\` to learn how to implement a page file`,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
}
|