Skip to content

Commit

Permalink
(fix): support running docs dev server on a port (#3657)
Browse files Browse the repository at this point in the history
* (feat): support running docs dev server on a port

* (fix): package.json

* fix
  • Loading branch information
dsinghvi authored May 20, 2024
1 parent 353b66e commit a96ebe0
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 20 deletions.
20 changes: 16 additions & 4 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
9 changes: 8 additions & 1 deletion fern/pages/docs/introduction/development.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ folder and run the following command:
fern docs dev
```

A local preview of your documentation will be available at `http://localhost:3000`.
A local preview of your documentation will be available at `http://localhost:3000`.

By default, Fern will pick a port that is available on your computer. If you'd like to customize the port,
use the `--port` flag:

```bash
fern docs dev --port 3003
```

</Accordion>

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@
"@fern-api/yaml-migrations": "workspace:*",
"@fern-api/yaml-schema": "workspace:*",
"@fern-fern/fiddle-sdk": "^0.0.542",
"@types/get-port": "^4.2.0",
"ansi-escapes": "^5.0.0",
"axios": "^0.28.0",
"boxen": "^7.0.0",
"chalk": "^5.0.1",
"get-port": "^7.1.0",
"immer": "^9.0.15",
"is-ci": "^3.0.1",
"js-yaml": "^4.1.0",
Expand Down
24 changes: 15 additions & 9 deletions packages/cli/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { LogLevel, LOG_LEVELS } from "@fern-api/logger";
import { askToLogin, login } from "@fern-api/login";
import { loadProject, Project } from "@fern-api/project-loader";
import { FernCliError } from "@fern-api/task-context";
import getPort from "get-port";
import { Argv } from "yargs";
import { hideBin } from "yargs/helpers";
import yargs from "yargs/yargs";
Expand Down Expand Up @@ -39,6 +40,7 @@ import { writeDefinitionForWorkspaces } from "./commands/write-definition/writeD
import { FERN_CWD_ENV_VAR } from "./cwd";
import { rerunFernCliAtVersion } from "./rerunFernCliAtVersion";
import { isURL } from "./utils/isUrl";

interface GlobalCliOptions {
"log-level": LogLevel;
}
Expand Down Expand Up @@ -886,22 +888,26 @@ function addDocsPreviewCommand(cli: Argv<GlobalCliOptions>, cliContext: CliConte
cli.command(
"docs dev",
"Run a local development server to preview your docs",
(yargs) => {
// yargs.option("port", {
// number: true,
// description: "Run the development server on the following port"
// }),
return yargs;
},
async () => {
(yargs) =>
yargs.option("port", {
number: true,
description: "Run the development server on the following port"
}),
async (argv) => {
let port: number;
if (argv.port != null) {
port = argv.port;
} else {
port = await getPort({ port: [3000, 3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009, 3010] });
}
await previewDocsWorkspace({
loadProject: () =>
loadProjectAndRegisterWorkspacesWithContext(cliContext, {
defaultToAllApiWorkspaces: true,
commandLineApiWorkspace: undefined
}),
cliContext,
port: 3000
port
});
}
);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/mock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@fern-api/task-context": "workspace:*",
"@types/lodash-es": "^4.17.12",
"express": "^4.19.2",
"get-port": "7.0.0",
"get-port": "^7.1.0",
"lodash-es": "^4.17.21",
"url-join": "^5.0.0"
},
Expand Down
21 changes: 16 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3404,6 +3404,7 @@ __metadata:
"@fern-fern/fiddle-sdk": ^0.0.542
"@types/axios": ^0.14.0
"@types/boxen": ^3.0.1
"@types/get-port": ^4.2.0
"@types/is-ci": ^3.0.2
"@types/jest": ^29.0.3
"@types/js-yaml": ^4.0.8
Expand All @@ -3422,6 +3423,7 @@ __metadata:
env-cmd: toddbluhm/env-cmd
esbuild: ^0.15.7
eslint: ^8.56.0
get-port: ^7.1.0
immer: ^9.0.15
is-ci: ^3.0.1
jest: ^29.7.0
Expand Down Expand Up @@ -4136,7 +4138,7 @@ __metadata:
depcheck: ^1.4.6
eslint: ^8.56.0
express: ^4.19.2
get-port: 7.0.0
get-port: ^7.1.0
jest: ^29.7.0
lodash-es: ^4.17.21
organize-imports-cli: ^0.10.0
Expand Down Expand Up @@ -7119,6 +7121,15 @@ __metadata:
languageName: node
linkType: hard

"@types/get-port@npm:^4.2.0":
version: 4.2.0
resolution: "@types/get-port@npm:4.2.0"
dependencies:
get-port: "*"
checksum: 0c084e946089d310b2cfe130b0e4b8c25124800dfba069b756a4477a2e9cb9fabf4f5f59747d987492cbf25b72a24692f6bf1aee1fbfdc47411916221075eba3
languageName: node
linkType: hard

"@types/glob@npm:^8.0.0":
version: 8.1.0
resolution: "@types/glob@npm:8.1.0"
Expand Down Expand Up @@ -13347,10 +13358,10 @@ env-cmd@toddbluhm/env-cmd:
languageName: node
linkType: hard

"get-port@npm:7.0.0":
version: 7.0.0
resolution: "get-port@npm:7.0.0"
checksum: e9087f62d086bbb70f20c0a208e7cac552679c1426e29e0607eb1b8907a5cc4509337d5971b7f635385cd2a773a14cd21b7d9c3254a2eb5ebeaf5f8fde19fb07
"get-port@npm:*, get-port@npm:^7.1.0":
version: 7.1.0
resolution: "get-port@npm:7.1.0"
checksum: f4d23b43026124007663a899578cc87ff37bfcf645c5c72651e9810ebafc759857784e409fb8e0ada9b90e5c5db089b0ae2f5f6b49fba1ce2e0aff86094ab17d
languageName: node
linkType: hard

Expand Down

0 comments on commit a96ebe0

Please sign in to comment.