diff --git a/.pnp.cjs b/.pnp.cjs index 2697eb7e01a..a3a7a7950de 100644 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -6440,6 +6440,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["@fern-fern/fiddle-sdk", "npm:0.0.542"],\ ["@types/axios", "npm:0.14.0"],\ ["@types/boxen", "npm:3.0.1"],\ + ["@types/get-port", "npm:4.2.0"],\ ["@types/is-ci", "npm:3.0.2"],\ ["@types/jest", "npm:29.0.3"],\ ["@types/js-yaml", "npm:4.0.8"],\ @@ -6458,6 +6459,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["env-cmd", "https://github.com/toddbluhm/env-cmd.git#commit=8f35b71651f6a78710308ff38ab30896ea72ee8b"],\ ["esbuild", "npm:0.15.7"],\ ["eslint", "npm:8.56.0"],\ + ["get-port", "npm:7.1.0"],\ ["immer", "npm:9.0.15"],\ ["is-ci", "npm:3.0.1"],\ ["jest", "virtual:816fb67d993b0978271f762d4ccbec7209ef2546c234ca6e241662d44336c8e32c1c3c07189cfe14b67974a4840e1ed140408a7403bf9deb68c1953445072efe#npm:29.7.0"],\ @@ -7213,7 +7215,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["depcheck", "npm:1.4.6"],\ ["eslint", "npm:8.56.0"],\ ["express", "npm:4.19.2"],\ - ["get-port", "npm:7.0.0"],\ + ["get-port", "npm:7.1.0"],\ ["jest", "virtual:816fb67d993b0978271f762d4ccbec7209ef2546c234ca6e241662d44336c8e32c1c3c07189cfe14b67974a4840e1ed140408a7403bf9deb68c1953445072efe#npm:29.7.0"],\ ["lodash-es", "npm:4.17.21"],\ ["organize-imports-cli", "npm:0.10.0"],\ @@ -10554,6 +10556,16 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "linkType": "HARD"\ }]\ ]],\ + ["@types/get-port", [\ + ["npm:4.2.0", {\ + "packageLocation": "./.yarn/cache/@types-get-port-npm-4.2.0-c594c92c19-0c084e9460.zip/node_modules/@types/get-port/",\ + "packageDependencies": [\ + ["@types/get-port", "npm:4.2.0"],\ + ["get-port", "npm:7.1.0"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["@types/glob", [\ ["npm:8.1.0", {\ "packageLocation": "./.yarn/cache/@types-glob-npm-8.1.0-bdb9d0520c-9101f3a906.zip/node_modules/@types/glob/",\ @@ -17695,10 +17707,10 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { }]\ ]],\ ["get-port", [\ - ["npm:7.0.0", {\ - "packageLocation": "./.yarn/cache/get-port-npm-7.0.0-72b8a92f99-e9087f62d0.zip/node_modules/get-port/",\ + ["npm:7.1.0", {\ + "packageLocation": "./.yarn/cache/get-port-npm-7.1.0-4ef4f09d7c-f4d23b4302.zip/node_modules/get-port/",\ "packageDependencies": [\ - ["get-port", "npm:7.0.0"]\ + ["get-port", "npm:7.1.0"]\ ],\ "linkType": "HARD"\ }]\ diff --git a/.yarn/cache/@types-get-port-npm-4.2.0-c594c92c19-0c084e9460.zip b/.yarn/cache/@types-get-port-npm-4.2.0-c594c92c19-0c084e9460.zip new file mode 100644 index 00000000000..11ba81d0e15 Binary files /dev/null and b/.yarn/cache/@types-get-port-npm-4.2.0-c594c92c19-0c084e9460.zip differ diff --git a/.yarn/cache/get-port-npm-7.0.0-72b8a92f99-e9087f62d0.zip b/.yarn/cache/get-port-npm-7.0.0-72b8a92f99-e9087f62d0.zip deleted file mode 100644 index 3d2ff5a4376..00000000000 Binary files a/.yarn/cache/get-port-npm-7.0.0-72b8a92f99-e9087f62d0.zip and /dev/null differ diff --git a/.yarn/cache/get-port-npm-7.1.0-4ef4f09d7c-f4d23b4302.zip b/.yarn/cache/get-port-npm-7.1.0-4ef4f09d7c-f4d23b4302.zip new file mode 100644 index 00000000000..bf369630364 Binary files /dev/null and b/.yarn/cache/get-port-npm-7.1.0-4ef4f09d7c-f4d23b4302.zip differ diff --git a/fern/pages/docs/introduction/development.mdx b/fern/pages/docs/introduction/development.mdx index 576eb63e6a7..b09c6b2a61b 100644 --- a/fern/pages/docs/introduction/development.mdx +++ b/fern/pages/docs/introduction/development.mdx @@ -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 +``` diff --git a/packages/cli/cli/package.json b/packages/cli/cli/package.json index fb473060659..45dcb998a35 100644 --- a/packages/cli/cli/package.json +++ b/packages/cli/cli/package.json @@ -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", diff --git a/packages/cli/cli/src/cli.ts b/packages/cli/cli/src/cli.ts index ff09fd1a855..08693f33dff 100644 --- a/packages/cli/cli/src/cli.ts +++ b/packages/cli/cli/src/cli.ts @@ -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"; @@ -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; } @@ -886,14 +888,18 @@ function addDocsPreviewCommand(cli: Argv, 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, { @@ -901,7 +907,7 @@ function addDocsPreviewCommand(cli: Argv, cliContext: CliConte commandLineApiWorkspace: undefined }), cliContext, - port: 3000 + port }); } ); diff --git a/packages/cli/mock/package.json b/packages/cli/mock/package.json index 37aba9aa2e8..0074c520eda 100644 --- a/packages/cli/mock/package.json +++ b/packages/cli/mock/package.json @@ -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" }, diff --git a/yarn.lock b/yarn.lock index 1f5c87ff87c..449ef11338e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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 @@ -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 @@ -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 @@ -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" @@ -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