Skip to content

Commit

Permalink
feat: support multiple custom domains (#3466)
Browse files Browse the repository at this point in the history
* feat: support multiple custom domains

* merge custom-domains
  • Loading branch information
abvthecity authored Apr 25, 2024
1 parent b885903 commit f3d1b1a
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 28 deletions.
8 changes: 7 additions & 1 deletion packages/cli/configuration/fern/definition/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ types:
DocsInstances:
properties:
url: string
"custom-domain": optional<string>
"custom-domain": optional<CustomDomain>
audiences:
type: optional<AudiencesConfig>
availability: in-development
Expand All @@ -53,6 +53,12 @@ types:
If `edit-this-page` is set, Fern will add an "Edit this page" link to the bottom of each page that links to the given GitHub repository.
availability: in-development

CustomDomain:
discriminated: false
union:
- string
- list<string>

# this is a partial object in case we want to add more options in the future
EditThisPageConfig:
properties:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

export type CustomDomain = string | string[];
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as FernDocsConfig from "../../..";

export interface DocsInstances {
url: string;
customDomain?: string;
customDomain?: FernDocsConfig.CustomDomain;
audiences?: FernDocsConfig.AudiencesConfig;
/** If `private` is set to true, Fern will protect the docs site with SSO. */
private?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "./DocsConfiguration";
export * from "./TabId";
export * from "./TabConfig";
export * from "./DocsInstances";
export * from "./CustomDomain";
export * from "./EditThisPageConfig";
export * from "./GithubEditThisPageConfig";
export * from "./AudiencesConfig";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as serializers from "../../..";
import * as FernDocsConfig from "../../../../api";
import * as core from "../../../../core";

export const CustomDomain: core.serialization.Schema<serializers.CustomDomain.Raw, FernDocsConfig.CustomDomain> =
core.serialization.undiscriminatedUnion([
core.serialization.string(),
core.serialization.list(core.serialization.string()),
]);

export declare namespace CustomDomain {
type Raw = string | string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export const DocsInstances: core.serialization.ObjectSchema<
FernDocsConfig.DocsInstances
> = core.serialization.object({
url: core.serialization.string(),
customDomain: core.serialization.property("custom-domain", core.serialization.string().optional()),
customDomain: core.serialization.property(
"custom-domain",
core.serialization.lazy(async () => (await import("../../..")).CustomDomain).optional()
),
audiences: core.serialization.lazy(async () => (await import("../../..")).AudiencesConfig).optional(),
private: core.serialization.boolean().optional(),
editThisPage: core.serialization.property(
Expand All @@ -23,7 +26,7 @@ export const DocsInstances: core.serialization.ObjectSchema<
export declare namespace DocsInstances {
interface Raw {
url: string;
"custom-domain"?: string | null;
"custom-domain"?: serializers.CustomDomain.Raw | null;
audiences?: serializers.AudiencesConfig.Raw | null;
private?: boolean | null;
"edit-this-page"?: serializers.EditThisPageConfig.Raw | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const VersionFileConfig: core.serialization.ObjectSchema<
core.serialization.lazyObject(async () => (await import("../../..")).TabConfig)
)
.optional(),
navigation: core.serialization.lazy(async () => (await import("../../..")).NavigationConfig)
navigation: core.serialization.lazy(async () => (await import("../../..")).NavigationConfig),
});

export declare namespace VersionFileConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "./DocsConfiguration";
export * from "./TabId";
export * from "./TabConfig";
export * from "./DocsInstances";
export * from "./CustomDomain";
export * from "./EditThisPageConfig";
export * from "./GithubEditThisPageConfig";
export * from "./AudiencesConfig";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,33 @@ export async function runRemoteGenerationForDocsWorkspace({
return;
}

if (instances.length === 1 && instances[0] != null) {
const instance = instances[0];
await context.runInteractiveTask({ name: instance.url }, async () => {
await publishDocs({
docsWorkspace,
customDomains: instance.customDomain != null ? [instance.customDomain] : [],
domain: instance.url,
token,
organization,
context,
fernWorkspaces,
version: "",
preview,
audiences: instance.audiences,
editThisPage: instance.editThisPage,
isPrivate: instance.private
});
});
return;
}

if (instances.length > 1 && instanceUrl == null) {
context.failAndThrow(`More than one docs instances. Please specify one (e.g. --instance ${instances[0]?.url})`);
return;
}

const maybeInstance = instances.find((instance) => instance.url === instanceUrl);
const maybeInstance = instances.find((instance) => instance.url === instanceUrl) ?? instances[0];

if (maybeInstance == null) {
context.failAndThrow(`No docs instance with url ${instanceUrl}. Failed to register.`);
return;
}

// TODO: validate custom domains
const customDomains: string[] = [];

if (maybeInstance.customDomain != null) {
if (typeof maybeInstance.customDomain === "string") {
customDomains.push(maybeInstance.customDomain);
} else if (Array.isArray(maybeInstance.customDomain)) {
customDomains.push(...maybeInstance.customDomain);
}
}

await context.runInteractiveTask({ name: maybeInstance.url }, async () => {
await publishDocs({
docsWorkspace,
customDomains: maybeInstance.customDomain != null ? [maybeInstance.customDomain] : [],
customDomains,
domain: maybeInstance.url,
token,
organization,
Expand Down

0 comments on commit f3d1b1a

Please sign in to comment.