-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview-list.ts
More file actions
59 lines (50 loc) · 1.54 KB
/
preview-list.ts
File metadata and controls
59 lines (50 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { getHost, getToken } from "../auth";
import { getPreviews, getSimulatorUrl } from "../clients/core";
import { createCommand, type CommandConfig } from "../lib/command";
import { stringify } from "../lib/json";
import { formatTable } from "../lib/string";
import { getRepositoryName } from "../project";
const config = {
name: "prismic preview list",
description: `
List all preview configurations in a Prismic repository.
By default, this command reads the repository from prismic.config.json at the
project root.
`,
options: {
json: { type: "boolean", description: "Output as JSON" },
repo: { type: "string", short: "r", description: "Repository domain" },
},
} satisfies CommandConfig;
export default createCommand(config, async ({ values }) => {
const { repo = await getRepositoryName(), json } = values;
const token = await getToken();
const host = await getHost();
const [previews, simulatorUrl] = await Promise.all([
getPreviews({ repo, token, host }),
getSimulatorUrl({ repo, token, host }),
]);
if (json) {
console.info(
stringify({
previews,
simulatorUrl: simulatorUrl ?? null,
}),
);
return;
}
if (previews.length === 0 && !simulatorUrl) {
console.info("No preview configurations found.");
return;
}
if (previews.length > 0) {
const rows = previews.map((preview) => [preview.url, preview.label]);
console.info(formatTable(rows, { headers: ["URL", "NAME"] }));
}
if (simulatorUrl) {
if (previews.length > 0) {
console.info("");
}
console.info(`Simulator: ${simulatorUrl}`);
}
});