feat(cli): add CLI --inspect[-brk] to support debugging without IDEs (#231)
This commit is contained in:
parent
f0f21db904
commit
9d76799072
19
src/cli.ts
19
src/cli.ts
|
@ -26,6 +26,13 @@ interface GlobalCLIOptions {
|
|||
outDir?: string
|
||||
}
|
||||
|
||||
interface DevCLIOptions {
|
||||
inspect?: boolean | string
|
||||
inspectBrk?: boolean | string
|
||||
remoteDebuggingPort?: string
|
||||
rendererOnly?: boolean
|
||||
}
|
||||
|
||||
function createInlineConfig(root: string, options: GlobalCLIOptions): InlineConfig {
|
||||
return {
|
||||
root,
|
||||
|
@ -59,13 +66,23 @@ cli
|
|||
.alias('serve')
|
||||
.alias('dev')
|
||||
.option('-w, --watch', `[boolean] rebuilds when main process or preload script modules have changed on disk`)
|
||||
.option('--inspect [port]', `[boolean | number] enable V8 inspector on the specified port`)
|
||||
.option('--inspectBrk [port]', `[boolean | number] enable V8 inspector on the specified port`)
|
||||
.option('--remoteDebuggingPort <port>', `[string] port for remote debugging`)
|
||||
.option('--rendererOnly', `[boolean] only dev server for the renderer`)
|
||||
.action(async (root: string, options: { remoteDebuggingPort?: string; rendererOnly: boolean } & GlobalCLIOptions) => {
|
||||
.action(async (root: string, options: DevCLIOptions & GlobalCLIOptions) => {
|
||||
if (options.remoteDebuggingPort) {
|
||||
process.env.REMOTE_DEBUGGING_PORT = options.remoteDebuggingPort
|
||||
}
|
||||
|
||||
if (options.inspect) {
|
||||
process.env.V8_INSPECTOR_PORT = typeof options.inspect === 'number' ? `${options.inspect}` : '5858'
|
||||
}
|
||||
|
||||
if (options.inspectBrk) {
|
||||
process.env.V8_INSPECTOR_BRK_PORT = typeof options.inspectBrk === 'number' ? `${options.inspectBrk}` : '5858'
|
||||
}
|
||||
|
||||
const { createServer } = await import('./server')
|
||||
const inlineConfig = createInlineConfig(root, options)
|
||||
|
||||
|
|
|
@ -118,11 +118,22 @@ export function startElectron(root: string | undefined, logger: Logger): ChildPr
|
|||
|
||||
const inspect = !!process.env.VSCODE_INSPECTOR_OPTIONS
|
||||
|
||||
const isDev = process.env.NODE_ENV_ELECTRON_VITE === 'development'
|
||||
|
||||
const args: string[] = []
|
||||
if (!!process.env.REMOTE_DEBUGGING_PORT && process.env.NODE_ENV_ELECTRON_VITE === 'development') {
|
||||
|
||||
if (!!process.env.REMOTE_DEBUGGING_PORT && isDev) {
|
||||
args.push(`--remote-debugging-port=${process.env.REMOTE_DEBUGGING_PORT}`)
|
||||
}
|
||||
|
||||
if (!!process.env.V8_INSPECTOR_PORT && isDev) {
|
||||
args.push(`--inspect=${process.env.V8_INSPECTOR_PORT}`)
|
||||
}
|
||||
|
||||
if (!!process.env.V8_INSPECTOR_BRK_PORT && isDev) {
|
||||
args.push(`--inspect-brk=${process.env.V8_INSPECTOR_BRK_PORT}`)
|
||||
}
|
||||
|
||||
const ps = spawn(electronPath, ['.'].concat(args))
|
||||
ps.stdout.on('data', chunk => {
|
||||
!inspect && chunk.toString().trim() && logger.info(chunk.toString())
|
||||
|
|
Loading…
Reference in a new issue