fix(cap-vite): duplicate shortcut hint
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import type { Result } from 'tinyexec'
|
import type { Result } from 'tinyexec'
|
||||||
import type { Logger, Plugin } from 'vite'
|
import type { Plugin } from 'vite'
|
||||||
|
|
||||||
import type { CapacitorPlatform } from './native'
|
import type { CapacitorPlatform } from './native'
|
||||||
|
|
||||||
@@ -33,10 +33,6 @@ async function stopCapProcess(current: Result | undefined) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function startCapProcess(cwd: string, capArgs: string[], url: URL) {
|
function startCapProcess(cwd: string, capArgs: string[], url: URL) {
|
||||||
console.info('\n----------------------\n')
|
|
||||||
console.info('Running cap run', ...capArgs)
|
|
||||||
console.info('[cap-vite] Press R to restart cap run. Press Ctrl+C to exit.')
|
|
||||||
|
|
||||||
return x('cap', ['run', ...capArgs], {
|
return x('cap', ['run', ...capArgs], {
|
||||||
throwOnError: false,
|
throwOnError: false,
|
||||||
nodeOptions: {
|
nodeOptions: {
|
||||||
@@ -52,7 +48,6 @@ function startCapProcess(cwd: string, capArgs: string[], url: URL) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function bindCapViteShortcuts(
|
function bindCapViteShortcuts(
|
||||||
logger: Logger,
|
|
||||||
onRestart: () => void,
|
onRestart: () => void,
|
||||||
onShutdown: () => Promise<void>,
|
onShutdown: () => Promise<void>,
|
||||||
) {
|
) {
|
||||||
@@ -95,7 +90,6 @@ function bindCapViteShortcuts(
|
|||||||
}
|
}
|
||||||
|
|
||||||
process.stdin.on('keypress', onKeyPress)
|
process.stdin.on('keypress', onKeyPress)
|
||||||
logger.info('[cap-vite] Terminal shortcuts enabled: R restarts cap run.')
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
process.stdin.off('keypress', onKeyPress)
|
process.stdin.off('keypress', onKeyPress)
|
||||||
@@ -133,6 +127,9 @@ export function capVitePlugin(options: CapVitePluginOptions): Plugin {
|
|||||||
function launchCapProcess() {
|
function launchCapProcess() {
|
||||||
const url = pickServerUrl(server)
|
const url = pickServerUrl(server)
|
||||||
currentCapProcess = startCapProcess(cwd, resolvedCapArgs, url)
|
currentCapProcess = startCapProcess(cwd, resolvedCapArgs, url)
|
||||||
|
currentCapProcess.then(() => {
|
||||||
|
logger.info(`[cap-vite] Ran "cap run ${resolvedCapArgs.join(' ')}". Press R to re-run. Press Ctrl+C to exit.`)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function requestRestart(reason: string) {
|
function requestRestart(reason: string) {
|
||||||
@@ -156,7 +153,7 @@ export function capVitePlugin(options: CapVitePluginOptions): Plugin {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(`[cap-vite] ${activeReason}. Re-running cap run ${resolvedPlatform}.`)
|
logger.info(`[cap-vite] ${activeReason}. Re-running "cap run ${resolvedCapArgs.join(' ')}".`)
|
||||||
const previous = currentCapProcess
|
const previous = currentCapProcess
|
||||||
currentCapProcess = undefined
|
currentCapProcess = undefined
|
||||||
await stopCapProcess(previous)
|
await stopCapProcess(previous)
|
||||||
@@ -215,7 +212,7 @@ export function capVitePlugin(options: CapVitePluginOptions): Plugin {
|
|||||||
|
|
||||||
server.httpServer?.once('listening', () => {
|
server.httpServer?.once('listening', () => {
|
||||||
launchCapProcess()
|
launchCapProcess()
|
||||||
disposeShortcut = bindCapViteShortcuts(logger, () => requestRestart('manual restart requested'), shutdown)
|
disposeShortcut = bindCapViteShortcuts(() => requestRestart('manual restart requested'), shutdown)
|
||||||
})
|
})
|
||||||
server.httpServer?.once('close', handleShutdownRequest)
|
server.httpServer?.once('close', handleShutdownRequest)
|
||||||
process.once('SIGINT', handleShutdownRequest)
|
process.once('SIGINT', handleShutdownRequest)
|
||||||
|
|||||||
Reference in New Issue
Block a user