From 786ab60eccc6de7feb2cbec0eb406c0fc0a68a31 Mon Sep 17 00:00:00 2001 From: Steffen Kreutz Date: Wed, 30 May 2018 08:41:39 +0200 Subject: [PATCH] Watch the directory that contains the specified spec instead of the spec itself --- cli/index.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/cli/index.ts b/cli/index.ts index 6281e5ca..f2dd4a3f 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -108,7 +108,7 @@ YargsParser.command( redocOptions: argv.options || {}, }); }, - ) +) .demandCommand() .options('t', { alias: 'template', @@ -159,11 +159,17 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) { server.listen(port, () => console.log(`Server started: http://127.0.0.1:${port}`)); if (options.watch && existsSync(pathToSpec)) { + const pathToSpecDirectory = dirname(pathToSpec); + const watchOptions = { + recursive: true + }; + watch( - pathToSpec, + pathToSpecDirectory, + watchOptions, debounce(async (event, filename) => { - if (event === 'change' || (event === 'rename' && existsSync(filename))) { - console.log(`${pathToSpec} changed, updating docs`); + if (event === 'change' || event === 'rename') { + console.log(`${join(pathToSpecDirectory, filename)} changed, updating docs`); try { spec = await loadAndBundleSpec(pathToSpec); pageHTML = await getPageHTML(spec, pathToSpec, options); @@ -174,7 +180,7 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) { } }, 2200), ); - console.log(`👀 Watching ${pathToSpec} for changes...`); + console.log(`👀 Watching ${pathToSpecDirectory} for changes...`); } } @@ -229,13 +235,13 @@ async function getPageHTML( ssr ? 'hydrate(__redoc_state, container);' : `init("spec.json", ${JSON.stringify(redocOptions)}, container)` - }; + }; `, redocHead: ssr ? (cdn - ? '' - : ``) + css + ? '' + : ``) + css : '', title, });