Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/modern-keys-spend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/rspeedy": patch
---

Support cli flag `--base` to specify the base path of the server.
2 changes: 2 additions & 0 deletions packages/rspeedy/core/src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function apply(program: Command): Command {
.description(
'Run the dev server and watch for source file changes while serving.',
)
.option('--base <base>', 'specify the base path of the server')
.action(
(devOptions: DevOptions) =>
import('./dev.js').then(({ dev }) =>
Expand All @@ -75,6 +76,7 @@ export function apply(program: Command): Command {
const previewCommand = program.command('preview')
previewCommand
.description('Preview the production build outputs locally.')
.option('--base <base>', 'specify the base path of the server')
.action((previewOptions: PreviewOptions) =>
import('./preview.js').then(({ preview }) =>
preview.call(previewCommand, cwd, previewOptions)
Expand Down
9 changes: 8 additions & 1 deletion packages/rspeedy/core/src/cli/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { loadConfig, resolveConfigPath } from '../config/loadConfig.js'
import { createRspeedy } from '../create-rspeedy.js'
import { exit } from './exit.js'

export type DevOptions = CommonOptions
export interface DevOptions extends CommonOptions {
base?: string | undefined
}

export async function dev(
this: Command,
Expand All @@ -29,6 +31,11 @@ export async function dev(
configPath,
})

if (devOptions.base) {
rspeedyConfig.server ??= {}
rspeedyConfig.server.base = devOptions.base
}

const watchedFiles = [configPath]

if (Array.isArray(rspeedyConfig.dev?.watchFiles)) {
Expand Down
17 changes: 13 additions & 4 deletions packages/rspeedy/core/src/cli/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,31 @@ import color from 'picocolors'

import type { CommonOptions } from './commands.js'
import { exit } from './exit.js'
import { loadConfig } from '../config/loadConfig.js'
import { loadConfig, resolveConfigPath } from '../config/loadConfig.js'
import { createRspeedy } from '../create-rspeedy.js'

export type PreviewOptions = CommonOptions
export interface PreviewOptions extends CommonOptions {
base?: string | undefined
}

export async function preview(
this: Command,
cwd: string,
options: PreviewOptions,
previewOptions: PreviewOptions,
): Promise<void> {
try {
const configPath = resolveConfigPath(cwd, previewOptions.config)

const { content: rspeedyConfig } = await loadConfig({
cwd,
configPath: options.config,
configPath,
})

if (previewOptions.base) {
rspeedyConfig.server ??= {}
rspeedyConfig.server.base = previewOptions.base
}

const rspeedy = await createRspeedy({ cwd, rspeedyConfig })

await rspeedy.initConfigs()
Expand Down
2 changes: 2 additions & 0 deletions website/docs/en/guide/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The `rspeedy dev` command is used to start a local dev server and compile the so
Usage: rspeedy dev [options]

Options:
-b --base <base> specify the base path of the server
-c --config <config> specify the configuration file, can be a relative or absolute path
-h, --help display help for command
```
Expand Down Expand Up @@ -94,6 +95,7 @@ The `rspeedy preview` command is used to preview the production build outputs lo
Usage: rspeedy preview [options]

Options:
-b --base <base> specify the base path of the server
-c --config <config> specify the configuration file, can be a relative or absolute path
-h, --help display help for command
```
Expand Down
2 changes: 2 additions & 0 deletions website/docs/zh/guide/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Commands:
Usage: rspeedy dev [options]

Options:
-b --base <base> specify the base path of the server
-c --config <config> specify the configuration file, can be a relative or absolute path
-h, --help display help for command
```
Expand Down Expand Up @@ -94,6 +95,7 @@ Options:
Usage: rspeedy preview [options]

Options:
-b --base <base> specify the base path of the server
-c --config <config> specify the configuration file, can be a relative or absolute path
-h, --help display help for command
```
Expand Down
Loading