Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ name: validate
on: push

jobs:
format:
runs-on: blacksmith-2vcpu-ubuntu-2404-arm
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
- run: npm ci
- id: format
continue-on-error: true
run: npm run format -- --check
- name: Report format failures
if: steps.format.outcome == 'failure'
run: echo "::warning::Code is not formatted. Run \`npm run format\` locally."

lint:
runs-on: blacksmith-2vcpu-ubuntu-2404-arm
steps:
Expand Down
5 changes: 1 addition & 4 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ export abstract class Adapter {
abstract readonly localPreviewConfig: LocalDevelopmentPreview;

get localPreviewUrl(): string {
return new URL(
this.localPreviewConfig.resolverPath,
this.localPreviewConfig.websiteURL,
).href;
return new URL(this.localPreviewConfig.resolverPath, this.localPreviewConfig.websiteURL).href;
}

get localSimulatorUrl(): string {
Expand Down
5 changes: 1 addition & 4 deletions src/adapters/sveltekit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import type {
CustomType,
SharedSlice,
} from "@prismicio/types-internal/lib/customtypes";
import type { CustomType, SharedSlice } from "@prismicio/types-internal/lib/customtypes";

import { pascalCase } from "change-case";
import { loadFile } from "magicast";
Expand Down
5 changes: 4 additions & 1 deletion src/commands/field-add-rich-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export default createCommand(config, async ({ positionals, values }) => {
label: label ?? capitalCase(fieldId),
placeholder,
...(isSingle ? { single: allow } : { multi: allow }),
labels: labels?.split(",").map(label => label.trim()).filter(Boolean),
labels: labels
?.split(",")
.map((label) => label.trim())
.filter(Boolean),
allowTargetBlank,
},
};
Expand Down
4 changes: 3 additions & 1 deletion src/commands/field-edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ export default createCommand(config, async ({ positionals, values }) => {
"--allow accepts a single link type. Prismic links allow either one type or all types.",
);
} else {
throw new CommandError("--allow for link fields must be one of: document, media, web, any");
throw new CommandError(
"--allow for link fields must be one of: document, media, web, any",
);
}
}
if ("field" in values) {
Expand Down
23 changes: 13 additions & 10 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { DEFAULT_PRISMIC_HOST, env } from "../env";
import { openBrowser } from "../lib/browser";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { diffArrays } from "../lib/diff";
import { installDependencies, readPackageJson, removeDependencies, updatePackageJsonName } from "../lib/packageJson";
import {
installDependencies,
readPackageJson,
removeDependencies,
updatePackageJsonName,
} from "../lib/packageJson";
import {
addPreview,
getPreviews,
Expand All @@ -17,9 +22,9 @@ import {
} from "../lib/prismic/clients/core";
import { getCustomTypes, getSlices } from "../lib/prismic/clients/custom-types";
import { getRepository, type Repository } from "../lib/prismic/clients/repository";
import { completeOnboardingSteps } from "../lib/prismic/onboarding";
import { getProfile } from "../lib/prismic/clients/user";
import { canonicalizeCustomType, canonicalizeSlice } from "../lib/prismic/models";
import { completeOnboardingSteps } from "../lib/prismic/onboarding";
import { ForbiddenRequestError, UnauthorizedRequestError } from "../lib/request";
import { sentryCaptureError } from "../lib/sentry";
import { dedent } from "../lib/string";
Expand Down Expand Up @@ -241,9 +246,7 @@ export default createCommand(config, async ({ values }) => {

const hasStarterModelChanges =
isExistingProjectHandoff &&
[customTypeOps, sliceOps].some(
(ops) => ops.update.length > 0 || ops.delete.length > 0,
);
[customTypeOps, sliceOps].some((ops) => ops.update.length > 0 || ops.delete.length > 0);

if (!hasStarterModelChanges) {
for (const slice of sliceOps.update) {
Expand Down Expand Up @@ -314,17 +317,17 @@ async function completeStarterHandoff(
config: { repo: string; token: string | undefined; host: string },
): Promise<void> {
try {
const hostedPreviewURL = new URL(
adapter.localPreviewConfig.resolverPath,
starter.deploymentUrl,
).href;
const hostedPreviewURL = new URL(adapter.localPreviewConfig.resolverPath, starter.deploymentUrl)
.href;
const previews = await getPreviews(config);
await Promise.all(
previews
.filter((preview) => preview.url === hostedPreviewURL)
.map((preview) => removePreview(preview.id, config)),
);
const hasDevelopmentPreview = previews.some((preview) => preview.url === adapter.localPreviewUrl);
const hasDevelopmentPreview = previews.some(
(preview) => preview.url === adapter.localPreviewUrl,
);
if (!hasDevelopmentPreview) {
await addPreview(adapter.localPreviewConfig, config);
}
Expand Down
6 changes: 5 additions & 1 deletion test/field-add-content-relationship.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {
} from "./it";

it("supports --help", async ({ expect, prismic }) => {
const { stdout, stderr, exitCode } = await prismic("field", ["add", "content-relationship", "--help"]);
const { stdout, stderr, exitCode } = await prismic("field", [
"add",
"content-relationship",
"--help",
]);
expect(exitCode, stderr).toBe(0);
expect(stdout).toContain("prismic field add content-relationship <id> [options]");
});
Expand Down
14 changes: 12 additions & 2 deletions test/field-add-uid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ it("adds a uid field to a custom type", async ({ expect, prismic, project }) =>
const customType = buildCustomType();
await writeLocalCustomType(project, customType);

const { stdout, stderr, exitCode } = await prismic("field", ["add", "uid", "--to-type", customType.id]);
const { stdout, stderr, exitCode } = await prismic("field", [
"add",
"uid",
"--to-type",
customType.id,
]);
expect(exitCode, stderr).toBe(0);
expect(stdout).toContain("Field added: uid");

Expand All @@ -23,7 +28,12 @@ it("adds a uid field to a page type", async ({ expect, prismic, project }) => {
const pageType = buildCustomType({ format: "page" });
await writeLocalCustomType(project, pageType);

const { stdout, stderr, exitCode } = await prismic("field", ["add", "uid", "--to-type", pageType.id]);
const { stdout, stderr, exitCode } = await prismic("field", [
"add",
"uid",
"--to-type",
pageType.id,
]);
expect(exitCode, stderr).toBe(0);
expect(stdout).toContain("Field added: uid");

Expand Down
7 changes: 6 additions & 1 deletion test/field-view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ it("views a field in a slice", async ({ expect, prismic, project }) => {
};
await writeLocalSlice(project, slice);

const { stdout, stderr, exitCode } = await prismic("field", ["view", "title", "--from-slice", slice.id]);
const { stdout, stderr, exitCode } = await prismic("field", [
"view",
"title",
"--from-slice",
slice.id,
]);
expect(exitCode, stderr).toBe(0);
expect(stdout).toContain("Type: StructuredText");
expect(stdout).toContain("Label: Title");
Expand Down
12 changes: 8 additions & 4 deletions test/init.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { access, mkdir, readFile, rm, writeFile } from "node:fs/promises";
import { describe } from "vitest";

import { buildCustomType, captureOutput, it, readLocalCustomType, writeLocalCustomType } from "./it";
import {
buildCustomType,
captureOutput,
it,
readLocalCustomType,
writeLocalCustomType,
} from "./it";
import {
addPreview,
createInstantStartRepository,
Expand Down Expand Up @@ -379,9 +385,7 @@ it("fails when the starter repository has no models", async ({
await deleteDocumentsByCustomType(customType.id, { repo, token, host });
await deleteCustomType(customType.id, { repo, token, host });
}
await Promise.all(
slices.map((slice) => deleteSlice(slice.id, { repo, token, host })),
);
await Promise.all(slices.map((slice) => deleteSlice(slice.id, { repo, token, host })));

const { stderr, exitCode } = await prismic("init", ["--repo", repo, "--no-setup"]);
expect(exitCode).toBe(1);
Expand Down
5 changes: 4 additions & 1 deletion test/preview-set-simulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ it.sequential("sets simulator URL", async ({ expect, prismic, repo, token, host

// Must be sequential because the repo only has one simulator URL.
it.sequential("appends /slice-simulator to URL", async ({ expect, prismic }) => {
const { stdout, stderr, exitCode } = await prismic("preview", ["set-simulator", "https://example.com"]);
const { stdout, stderr, exitCode } = await prismic("preview", [
"set-simulator",
"https://example.com",
]);
expect(exitCode, stderr).toBe(0);
expect(stdout).toContain("Simulator URL set: https://example.com/slice-simulator");
});
10 changes: 3 additions & 7 deletions test/prismic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ export async function createInstantStartRepository(config: AuthConfig): Promise<
headers: { Authorization: `Bearer ${config.token}` },
});
if (!res.ok)
throw new Error(
`Failed to create Instant Start repository: ${res.status} ${await res.text()}`,
);
throw new Error(`Failed to create Instant Start repository: ${res.status} ${await res.text()}`);
const data = await res.json();
return data.repositoryId;
}
Expand All @@ -55,8 +53,7 @@ export async function getOnboardingCompletedSteps(config: RepoConfig): Promise<s
const res = await fetch(url, {
headers: { Authorization: `Bearer ${config.token}`, repository: config.repo },
});
if (!res.ok)
throw new Error(`Failed to get onboarding state: ${res.status} ${await res.text()}`);
if (!res.ok) throw new Error(`Failed to get onboarding state: ${res.status} ${await res.text()}`);
const data = await res.json();
return data.completedSteps;
}
Expand Down Expand Up @@ -132,8 +129,7 @@ export async function deleteDocumentsByCustomType(
},
body: JSON.stringify({ customtype_ids: [customTypeId] }),
});
if (!res.ok)
throw new Error(`Failed to delete documents: ${res.status} ${await res.text()}`);
if (!res.ok) throw new Error(`Failed to delete documents: ${res.status} ${await res.text()}`);
}

export async function getSlices(config: RepoConfig): Promise<SharedSlice[]> {
Expand Down
7 changes: 6 additions & 1 deletion test/slice-connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ it("connects a slice to a type", async ({ expect, prismic, project }) => {
await writeLocalSlice(project, slice);
await writeLocalCustomType(project, customType);

const { stdout, stderr, exitCode } = await prismic("slice", ["connect", slice.id, "--to", customType.id]);
const { stdout, stderr, exitCode } = await prismic("slice", [
"connect",
slice.id,
"--to",
customType.id,
]);
expect(exitCode, stderr).toBe(0);
expect(stdout).toContain(`Connected slice "${slice.id}" to "${customType.id}"`);

Expand Down
7 changes: 6 additions & 1 deletion test/slice-edit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ it("edits a slice name", async ({ expect, prismic, project }) => {

const newName = `SliceS${crypto.randomUUID().split("-")[0]}`;

const { stdout, stderr, exitCode } = await prismic("slice", ["edit", slice.id, "--name", newName]);
const { stdout, stderr, exitCode } = await prismic("slice", [
"edit",
slice.id,
"--name",
newName,
]);
expect(exitCode, stderr).toBe(0);
expect(stdout).toContain(`Slice updated: "${newName}"`);

Expand Down
7 changes: 6 additions & 1 deletion test/type-add-tab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ it("adds a tab to a type", async ({ expect, prismic, project }) => {

const tabName = `Tab${crypto.randomUUID().split("-")[0]}`;

const { stdout, stderr, exitCode } = await prismic("type", ["add-tab", tabName, "--to", customType.id]);
const { stdout, stderr, exitCode } = await prismic("type", [
"add-tab",
tabName,
"--to",
customType.id,
]);
expect(exitCode, stderr).toBe(0);
expect(stdout).toContain(`Added tab "${tabName}" to "${customType.id}"`);

Expand Down
7 changes: 6 additions & 1 deletion test/type-create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ it("creates a custom type", async ({ expect, prismic, project }) => {
it("creates a page type with --format page", async ({ expect, prismic, project }) => {
const { label } = buildCustomType({ format: "page" });

const { stdout, stderr, exitCode } = await prismic("type", ["create", label!, "--format", "page"]);
const { stdout, stderr, exitCode } = await prismic("type", [
"create",
label!,
"--format",
"page",
]);
expect(exitCode, stderr).toBe(0);
expect(stdout).toContain(`Created type "${label}"`);

Expand Down
Loading