fix: show help on invalid CLI commands and debounce watch rebuilds
- Change .showHelpOnFail(false) to true for better new-user UX - Add 100ms debounce to watch mode rebuilds to batch rapid file changes
This commit is contained in:
@@ -278,7 +278,7 @@ yargs(hideBin(process.argv))
|
|||||||
await handlePluginStatus()
|
await handlePluginStatus()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.showHelpOnFail(false)
|
.showHelpOnFail(true)
|
||||||
.help()
|
.help()
|
||||||
.strict()
|
.strict()
|
||||||
.demandCommand().argv
|
.demandCommand().argv
|
||||||
|
|||||||
@@ -165,30 +165,34 @@ async function startWatching(
|
|||||||
})
|
})
|
||||||
|
|
||||||
const changes: ChangeEvent[] = []
|
const changes: ChangeEvent[] = []
|
||||||
|
let rebuildTimeout: ReturnType<typeof setTimeout> | null = null
|
||||||
|
const scheduleRebuild = () => {
|
||||||
|
if (rebuildTimeout) clearTimeout(rebuildTimeout)
|
||||||
|
rebuildTimeout = setTimeout(() => {
|
||||||
|
rebuildTimeout = null
|
||||||
|
rebuild(changes, clientRefresh, buildData).catch((err) => {
|
||||||
|
console.error(styleText("red", "Rebuild failed:"), err.message ?? err)
|
||||||
|
})
|
||||||
|
}, 100)
|
||||||
|
}
|
||||||
watcher
|
watcher
|
||||||
.on("add", (fp) => {
|
.on("add", (fp) => {
|
||||||
fp = toPosixPath(fp)
|
fp = toPosixPath(fp)
|
||||||
if (buildData.ignored(fp)) return
|
if (buildData.ignored(fp)) return
|
||||||
changes.push({ path: fp as FilePath, type: "add" })
|
changes.push({ path: fp as FilePath, type: "add" })
|
||||||
rebuild(changes, clientRefresh, buildData).catch((err) => {
|
scheduleRebuild()
|
||||||
console.error(styleText("red", "Rebuild failed:"), err.message ?? err)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.on("change", (fp) => {
|
.on("change", (fp) => {
|
||||||
fp = toPosixPath(fp)
|
fp = toPosixPath(fp)
|
||||||
if (buildData.ignored(fp)) return
|
if (buildData.ignored(fp)) return
|
||||||
changes.push({ path: fp as FilePath, type: "change" })
|
changes.push({ path: fp as FilePath, type: "change" })
|
||||||
rebuild(changes, clientRefresh, buildData).catch((err) => {
|
scheduleRebuild()
|
||||||
console.error(styleText("red", "Rebuild failed:"), err.message ?? err)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.on("unlink", (fp) => {
|
.on("unlink", (fp) => {
|
||||||
fp = toPosixPath(fp)
|
fp = toPosixPath(fp)
|
||||||
if (buildData.ignored(fp)) return
|
if (buildData.ignored(fp)) return
|
||||||
changes.push({ path: fp as FilePath, type: "delete" })
|
changes.push({ path: fp as FilePath, type: "delete" })
|
||||||
rebuild(changes, clientRefresh, buildData).catch((err) => {
|
scheduleRebuild()
|
||||||
console.error(styleText("red", "Rebuild failed:"), err.message ?? err)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return async () => {
|
return async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user