Skip to content
Draft
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
14 changes: 9 additions & 5 deletions src/commands/locale-add.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getHost, getToken } from "../auth";
import { upsertLocale } from "../clients/locale";
import { resolveEnvironment } from "../environments";
import { getEnvironment } from "../environments";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";
Expand All @@ -19,18 +19,22 @@ const config = {
options: {
master: { type: "boolean", description: "Set as the master locale" },
name: { type: "string", short: "n", description: "Custom display name (for custom locales)" },
repo: { type: "string", short: "r", description: "Repository domain" },
env: { type: "string", short: "e", description: "Environment domain" },
repo: { type: "string", short: "r", description: "Repository or environment domain" },
env: { type: "string", short: "e", description: "(deprecated) Alias for --repo" },
},
} satisfies CommandConfig;

export default createCommand(config, async ({ positionals, values }) => {
const [code] = positionals;
const { repo: parentRepo = await getRepositoryName(), env, master = false, name } = values;
const {
env,
repo = env ?? (await getEnvironment()) ?? (await getRepositoryName()),
master = false,
name,
} = values;

const token = await getToken();
const host = await getHost();
const repo = env ? await resolveEnvironment(env, { repo: parentRepo, token, host }) : parentRepo;

try {
await upsertLocale({ id: code, isMaster: master, customName: name }, { repo, token, host });
Expand Down
9 changes: 4 additions & 5 deletions src/commands/locale-list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getHost, getToken } from "../auth";
import { getLocales } from "../clients/locale";
import { resolveEnvironment } from "../environments";
import { getEnvironment } from "../environments";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { stringify } from "../lib/json";
import { UnknownRequestError } from "../lib/request";
Expand All @@ -17,17 +17,16 @@ const config = {
`,
options: {
json: { type: "boolean", description: "Output as JSON" },
repo: { type: "string", short: "r", description: "Repository domain" },
env: { type: "string", short: "e", description: "Environment domain" },
repo: { type: "string", short: "r", description: "Repository or environment domain" },
env: { type: "string", short: "e", description: "(deprecated) Alias for --repo" },
},
} satisfies CommandConfig;

export default createCommand(config, async ({ values }) => {
const { repo: parentRepo = await getRepositoryName(), env, json } = values;
const { env, repo = env ?? (await getEnvironment()) ?? (await getRepositoryName()), json } = values;

const token = await getToken();
const host = await getHost();
const repo = env ? await resolveEnvironment(env, { repo: parentRepo, token, host }) : parentRepo;

let locales;
try {
Expand Down
9 changes: 4 additions & 5 deletions src/commands/locale-remove.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getHost, getToken } from "../auth";
import { removeLocale } from "../clients/locale";
import { resolveEnvironment } from "../environments";
import { getEnvironment } from "../environments";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";
Expand All @@ -17,18 +17,17 @@ const config = {
code: { description: "Locale code (e.g. en-us, fr-fr)", required: true },
},
options: {
repo: { type: "string", short: "r", description: "Repository domain" },
env: { type: "string", short: "e", description: "Environment domain" },
repo: { type: "string", short: "r", description: "Repository or environment domain" },
env: { type: "string", short: "e", description: "(deprecated) Alias for --repo" },
},
} satisfies CommandConfig;

export default createCommand(config, async ({ positionals, values }) => {
const [code] = positionals;
const { repo: parentRepo = await getRepositoryName(), env } = values;
const { env, repo = env ?? (await getEnvironment()) ?? (await getRepositoryName()) } = values;

const token = await getToken();
const host = await getHost();
const repo = env ? await resolveEnvironment(env, { repo: parentRepo, token, host }) : parentRepo;

try {
await removeLocale(code, { repo, token, host });
Expand Down
9 changes: 4 additions & 5 deletions src/commands/locale-set-master.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getHost, getToken } from "../auth";
import { getLocales, upsertLocale } from "../clients/locale";
import { resolveEnvironment } from "../environments";
import { getEnvironment } from "../environments";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";
Expand All @@ -17,18 +17,17 @@ const config = {
code: { description: "Locale code (e.g. en-us, fr-fr)", required: true },
},
options: {
repo: { type: "string", short: "r", description: "Repository domain" },
env: { type: "string", short: "e", description: "Environment domain" },
repo: { type: "string", short: "r", description: "Repository or environment domain" },
env: { type: "string", short: "e", description: "(deprecated) Alias for --repo" },
},
} satisfies CommandConfig;

export default createCommand(config, async ({ positionals, values }) => {
const [code] = positionals;
const { repo: parentRepo = await getRepositoryName(), env } = values;
const { env, repo = env ?? (await getEnvironment()) ?? (await getRepositoryName()) } = values;

const token = await getToken();
const host = await getHost();
const repo = env ? await resolveEnvironment(env, { repo: parentRepo, token, host }) : parentRepo;

let locales;
try {
Expand Down
15 changes: 7 additions & 8 deletions src/commands/preview-add.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getHost, getToken } from "../auth";
import { addPreview } from "../clients/core";
import { resolveEnvironment } from "../environments";
import { getEnvironment } from "../environments";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";
Expand All @@ -18,14 +18,17 @@ const config = {
},
options: {
name: { type: "string", short: "n", description: "Display name (defaults to hostname)" },
repo: { type: "string", short: "r", description: "Repository domain" },
env: { type: "string", short: "e", description: "Environment domain" },
repo: { type: "string", short: "r", description: "Repository or environment domain" },
env: { type: "string", short: "e", description: "(deprecated) Alias for --repo" },
},
} satisfies CommandConfig;

export default createCommand(config, async ({ positionals, values }) => {
const [previewUrl] = positionals;
const { repo: parentRepo = await getRepositoryName(), env, name } = values;
const { env, name, repo = env ?? (await getEnvironment()) ?? (await getRepositoryName()) } = values;

const token = await getToken();
const host = await getHost();

let parsed: URL;
try {
Expand All @@ -38,10 +41,6 @@ export default createCommand(config, async ({ positionals, values }) => {
const websiteURL = `${parsed.protocol}//${parsed.host}`;
const resolverPath = parsed.pathname === "/" ? undefined : parsed.pathname;

const token = await getToken();
const host = await getHost();
const repo = env ? await resolveEnvironment(env, { repo: parentRepo, token, host }) : parentRepo;

try {
await addPreview({ name: displayName, websiteURL, resolverPath }, { repo, token, host });
} catch (error) {
Expand Down
9 changes: 4 additions & 5 deletions src/commands/preview-list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getHost, getToken } from "../auth";
import { getPreviews, getSimulatorUrl } from "../clients/core";
import { resolveEnvironment } from "../environments";
import { getEnvironment } from "../environments";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { stringify } from "../lib/json";
import { UnknownRequestError } from "../lib/request";
Expand All @@ -17,17 +17,16 @@ const config = {
`,
options: {
json: { type: "boolean", description: "Output as JSON" },
repo: { type: "string", short: "r", description: "Repository domain" },
env: { type: "string", short: "e", description: "Environment domain" },
repo: { type: "string", short: "r", description: "Repository or environment domain" },
env: { type: "string", short: "e", description: "(deprecated) Alias for --repo" },
},
} satisfies CommandConfig;

export default createCommand(config, async ({ values }) => {
const { repo: parentRepo = await getRepositoryName(), env, json } = values;
const { env, repo = env ?? (await getEnvironment()) ?? (await getRepositoryName()), json } = values;

const token = await getToken();
const host = await getHost();
const repo = env ? await resolveEnvironment(env, { repo: parentRepo, token, host }) : parentRepo;

let previews;
let simulatorUrl;
Expand Down
9 changes: 4 additions & 5 deletions src/commands/preview-remove.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getHost, getToken } from "../auth";
import { getPreviews, removePreview } from "../clients/core";
import { resolveEnvironment } from "../environments";
import { getEnvironment } from "../environments";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";
Expand All @@ -17,18 +17,17 @@ const config = {
url: { description: "Preview URL to remove", required: true },
},
options: {
repo: { type: "string", short: "r", description: "Repository domain" },
env: { type: "string", short: "e", description: "Environment domain" },
repo: { type: "string", short: "r", description: "Repository or environment domain" },
env: { type: "string", short: "e", description: "(deprecated) Alias for --repo" },
},
} satisfies CommandConfig;

export default createCommand(config, async ({ positionals, values }) => {
const [previewUrl] = positionals;
const { repo: parentRepo = await getRepositoryName(), env } = values;
const { env, repo = env ?? (await getEnvironment()) ?? (await getRepositoryName()) } = values;

const token = await getToken();
const host = await getHost();
const repo = env ? await resolveEnvironment(env, { repo: parentRepo, token, host }) : parentRepo;

let previews;
try {
Expand Down
9 changes: 4 additions & 5 deletions src/commands/preview-set-simulator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getHost, getToken } from "../auth";
import { setSimulatorUrl } from "../clients/core";
import { resolveEnvironment } from "../environments";
import { getEnvironment } from "../environments";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { UnknownRequestError } from "../lib/request";
import { getRepositoryName } from "../project";
Expand All @@ -23,14 +23,14 @@ const config = {
},
},
options: {
repo: { type: "string", short: "r", description: "Repository domain" },
env: { type: "string", short: "e", description: "Environment domain" },
repo: { type: "string", short: "r", description: "Repository or environment domain" },
env: { type: "string", short: "e", description: "(deprecated) Alias for --repo" },
},
} satisfies CommandConfig;

export default createCommand(config, async ({ positionals, values }) => {
const [urlArg] = positionals;
const { repo: parentRepo = await getRepositoryName(), env } = values;
const { env, repo = env ?? (await getEnvironment()) ?? (await getRepositoryName()) } = values;

let parsed: URL;
try {
Expand All @@ -46,7 +46,6 @@ export default createCommand(config, async ({ positionals, values }) => {

const token = await getToken();
const host = await getHost();
const repo = env ? await resolveEnvironment(env, { repo: parentRepo, token, host }) : parentRepo;

try {
await setSimulatorUrl(simulatorUrl, { repo, token, host });
Expand Down
14 changes: 6 additions & 8 deletions src/commands/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getAdapter } from "../adapters";
import { getHost, getToken } from "../auth";
import { getCustomTypes, getSlices } from "../clients/custom-types";
import { completeOnboardingStepsSilently } from "../clients/repository";
import { resolveEnvironment } from "../environments";
import { getEnvironment } from "../environments";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { diffArrays } from "../lib/diff";
import { getDirtyPaths, getGitRoot } from "../lib/git";
Expand All @@ -20,22 +20,20 @@ const config = {
`,
options: {
force: { type: "boolean", short: "f", description: "Overwrite local changes" },
repo: { type: "string", short: "r", description: "Repository domain" },
env: { type: "string", short: "e", description: "Environment domain" },
repo: { type: "string", short: "r", description: "Repository or environment domain" },
env: { type: "string", short: "e", description: "(deprecated) Alias for --repo" },
},
} satisfies CommandConfig;

export default createCommand(config, async ({ values }) => {
const { force = false, repo: parentRepo = await getRepositoryName(), env } = values;
const { env, force = false, repo = env ?? (await getEnvironment()) ?? (await getRepositoryName()) } = values;

const token = await getToken();
const host = await getHost();
const adapter = await getAdapter();
const projectRoot = await findProjectRoot();

const repo = env ? await resolveEnvironment(env, { repo: parentRepo, token, host }) : parentRepo;

console.info(`Pulling from repository: ${parentRepo}${env ? ` (env: ${env})` : ""}`);
console.info(`Pulling from repository: ${repo}`);

const [gitRoot, customTypeLibraries, sliceLibraries] = await Promise.all([
getGitRoot(projectRoot),
Expand Down Expand Up @@ -140,7 +138,7 @@ export default createCommand(config, async ({ values }) => {
await adapter.generateTypes();

await completeOnboardingStepsSilently({
repo: parentRepo,
repo,
token,
host,
stepIds: ["connectPrismic"],
Expand Down
33 changes: 14 additions & 19 deletions src/commands/push.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pascalCase } from "change-case";

import type { CustomType } from "@prismicio/types-internal/lib/customtypes";

import { pascalCase } from "change-case";

import { getAdapter } from "../adapters";
import { getHost, getToken } from "../auth";
import { getDocumentTotalByCustomTypes } from "../clients/core";
Expand All @@ -16,12 +16,9 @@ import {
updateCustomType,
updateSlice,
} from "../clients/custom-types";
import {
completeOnboardingStepsSilently,
type OnboardingStep,
} from "../clients/repository";
import { completeOnboardingStepsSilently, type OnboardingStep } from "../clients/repository";
import { getWorkingDocumentsUrlForCustomType, getCustomTypeListUrl } from "../clients/wroom";
import { resolveEnvironment } from "../environments";
import { getEnvironment } from "../environments";
import { CommandError, createCommand, type CommandConfig } from "../lib/command";
import { diffArrays } from "../lib/diff";
import { getDirtyPaths, getGitRoot } from "../lib/git";
Expand All @@ -40,22 +37,20 @@ const config = {
`,
options: {
force: { type: "boolean", short: "f", description: "Skip safety checks" },
repo: { type: "string", short: "r", description: "Repository domain" },
env: { type: "string", short: "e", description: "Environment domain" },
repo: { type: "string", short: "r", description: "Repository or environment domain" },
env: { type: "string", short: "e", description: "(deprecated) Alias for --repo" },
},
} satisfies CommandConfig;

export default createCommand(config, async ({ values }) => {
const { force = false, repo: parentRepo = await getRepositoryName(), env } = values;
const { env, force = false, repo = env ?? (await getEnvironment()) ?? (await getRepositoryName()) } = values;

const token = await getToken();
const host = await getHost();
const adapter = await getAdapter();
const projectRoot = await findProjectRoot();

const repo = env ? await resolveEnvironment(env, { repo: parentRepo, token, host }) : parentRepo;

console.info(`Pushing to repository: ${parentRepo}${env ? ` (env: ${env})` : ""}`);
console.info(`Pushing to repository: ${repo}`);

const [gitRoot, customTypeLibraries, sliceLibraries] = await Promise.all([
getGitRoot(projectRoot),
Expand Down Expand Up @@ -166,7 +161,7 @@ export default createCommand(config, async ({ values }) => {
}
if (onboardingSteps.length > 0) {
await completeOnboardingStepsSilently({
repo: parentRepo,
repo,
token,
host,
stepIds: onboardingSteps,
Expand Down Expand Up @@ -201,9 +196,9 @@ async function removeCustomTypeWithDocumentHandling(
if (!(await isDocumentsInUseError(error))) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new CommandError(
`Could not delete type "${id}": ${errorMessage}"` +
"\nPlease try again, or manually deleting the type at: " +
getCustomTypeListUrl({ repo, host, format: format ?? "custom" })
`Could not delete type "${id}": ${errorMessage}"` +
"\nPlease try again, or manually deleting the type at: " +
getCustomTypeListUrl({ repo, host, format: format ?? "custom" }),
);
}

Expand All @@ -213,7 +208,7 @@ async function removeCustomTypeWithDocumentHandling(
} catch {
throw new CommandError(
`Could not check whether type "${id}" has associated pages. ` +
"\nPlease try again, or manually delete any associated pages at: " +
"\nPlease try again, or manually delete any associated pages at: " +
getWorkingDocumentsUrlForCustomType({ repo, host, customTypeId: id }),
);
}
Expand All @@ -222,7 +217,7 @@ async function removeCustomTypeWithDocumentHandling(
const pluralPages = documentCount === 1 ? "page" : "pages";
throw new CommandError(
`Could not delete type "${id}" because it has${countLabel} associated ${pluralPages}. ` +
`\nDelete any associated pages manually before pushing at: ` +
`\nDelete any associated pages manually before pushing at: ` +
getWorkingDocumentsUrlForCustomType({ repo, host, customTypeId: id }),
);
}
Expand Down
Loading