mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-17 02:10:39 +03:00
feat(cli): watch the directory that contains the specified spec instead of the spec itself (#519)
Fixes #514
This commit is contained in:
parent
cddfb12806
commit
723516b089
14
cli/index.ts
14
cli/index.ts
|
@ -167,11 +167,17 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) {
|
||||||
server.listen(port, () => console.log(`Server started: http://127.0.0.1:${port}`));
|
server.listen(port, () => console.log(`Server started: http://127.0.0.1:${port}`));
|
||||||
|
|
||||||
if (options.watch && existsSync(pathToSpec)) {
|
if (options.watch && existsSync(pathToSpec)) {
|
||||||
|
const pathToSpecDirectory = dirname(pathToSpec);
|
||||||
|
const watchOptions = {
|
||||||
|
recursive: true
|
||||||
|
};
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
pathToSpec,
|
pathToSpecDirectory,
|
||||||
|
watchOptions,
|
||||||
debounce(async (event, filename) => {
|
debounce(async (event, filename) => {
|
||||||
if (event === 'change' || (event === 'rename' && existsSync(filename))) {
|
if (event === 'change' || event === 'rename') {
|
||||||
console.log(`${pathToSpec} changed, updating docs`);
|
console.log(`${join(pathToSpecDirectory, filename)} changed, updating docs`);
|
||||||
try {
|
try {
|
||||||
spec = await loadAndBundleSpec(pathToSpec);
|
spec = await loadAndBundleSpec(pathToSpec);
|
||||||
pageHTML = await getPageHTML(spec, pathToSpec, options);
|
pageHTML = await getPageHTML(spec, pathToSpec, options);
|
||||||
|
@ -182,7 +188,7 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) {
|
||||||
}
|
}
|
||||||
}, 2200),
|
}, 2200),
|
||||||
);
|
);
|
||||||
console.log(`👀 Watching ${pathToSpec} for changes...`);
|
console.log(`👀 Watching ${pathToSpecDirectory} for changes...`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user