Skip to content

Commit

Permalink
(fix): reload docs preview server on specs outside of the fern folder (
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Aug 7, 2024
1 parent ae90036 commit 3d088d7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/cli/docs-preview/src/runPreviewServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ export async function runPreviewServer({
// initialize docs definition
docsDefinition = await reloadDocsDefinition();

const watcher = new Watcher(absoluteFilePathToFern, {
const additionalFilepaths = project.apiWorkspaces.flatMap((workspace) => workspace.getAbsoluteFilepaths());

const watcher = new Watcher([absoluteFilePathToFern, ...additionalFilepaths], {
recursive: true,
ignoreInitial: true,
debounce: 1000,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { TaskContext } from "@fern-api/task-context";
import { FernDefinition } from "../types/Workspace";
import { FernWorkspace } from "./FernWorkspace";
Expand All @@ -19,4 +20,9 @@ export abstract class AbstractAPIWorkspace<Settings> {
{ context }: { context?: TaskContext },
settings?: Settings
): Promise<FernWorkspace>;

/**
* @returns all filepaths related to this workspace
*/
public abstract getAbsoluteFilepaths(): AbsoluteFilePath[];
}
8 changes: 8 additions & 0 deletions packages/cli/workspace-loader/src/workspaces/FernWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export class FernWorkspace extends AbstractAPIWorkspace<void> {
public async toFernWorkspace(): Promise<FernWorkspace> {
return this;
}

public getAbsoluteFilepaths(): AbsoluteFilePath[] {
return [this.absoluteFilepath];
}
}

export declare namespace LazyFernWorkspace {
Expand Down Expand Up @@ -166,4 +170,8 @@ export class LazyFernWorkspace extends AbstractAPIWorkspace<OSSWorkspace.Setting

return workspace;
}

public getAbsoluteFilepaths(): AbsoluteFilePath[] {
return [this.absoluteFilepath];
}
}
10 changes: 10 additions & 0 deletions packages/cli/workspace-loader/src/workspaces/OSSWorkspace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FERN_PACKAGE_MARKER_FILENAME, generatorsYml } from "@fern-api/configuration";
import { isNonNullish } from "@fern-api/core-utils";
import { AbsoluteFilePath, RelativeFilePath } from "@fern-api/fs-utils";
import { convert } from "@fern-api/openapi-ir-to-fern";
import { parse, ParseOpenAPIOptions } from "@fern-api/openapi-parser";
Expand Down Expand Up @@ -119,6 +120,15 @@ export class OSSWorkspace extends AbstractAPIWorkspace<OSSWorkspace.Settings> {
changelog: this.changelog
});
}

public getAbsoluteFilepaths(): AbsoluteFilePath[] {
return [
this.absoluteFilepath,
...this.specs
.flatMap((spec) => [spec.absoluteFilepath, spec.absoluteFilepathToOverrides])
.filter(isNonNullish)
];
}
}

export function getOSSWorkspaceSettingsFromGeneratorInvocation(
Expand Down

0 comments on commit 3d088d7

Please sign in to comment.