mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-09 06:34:53 +03:00
chore: resolve discussion
This commit is contained in:
parent
ff8a7f7218
commit
d6150199bf
33
cli/index.ts
33
cli/index.ts
|
@ -13,7 +13,7 @@ import * as zlib from 'zlib';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { createStore, loadAndBundleSpec, Redoc } from 'redoc';
|
import { createStore, loadAndBundleSpec, Redoc } from 'redoc';
|
||||||
|
|
||||||
import {watch} from 'chokidar';
|
import { watch } from 'chokidar';
|
||||||
import { createReadStream, existsSync, readFileSync, ReadStream, writeFileSync } from 'fs';
|
import { createReadStream, existsSync, readFileSync, ReadStream, writeFileSync } from 'fs';
|
||||||
import * as mkdirp from 'mkdirp';
|
import * as mkdirp from 'mkdirp';
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ YargsParser.command(
|
||||||
yargs.demandOption('spec');
|
yargs.demandOption('spec');
|
||||||
return yargs;
|
return yargs;
|
||||||
},
|
},
|
||||||
async argv => {
|
async (argv: any) => {
|
||||||
const config = {
|
const config = {
|
||||||
ssr: argv.ssr,
|
ssr: argv.ssr,
|
||||||
watch: argv.watch,
|
watch: argv.watch,
|
||||||
|
@ -105,7 +105,7 @@ YargsParser.command(
|
||||||
yargs.demandOption('spec');
|
yargs.demandOption('spec');
|
||||||
return yargs;
|
return yargs;
|
||||||
},
|
},
|
||||||
async argv => {
|
async (argv: any) => {
|
||||||
const config = {
|
const config = {
|
||||||
ssr: true,
|
ssr: true,
|
||||||
output: argv.o,
|
output: argv.o,
|
||||||
|
@ -176,26 +176,25 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) {
|
||||||
|
|
||||||
const watcher = watch(pathToSpecDirectory, watchOptions);
|
const watcher = watch(pathToSpecDirectory, watchOptions);
|
||||||
const log = console.log.bind(console);
|
const log = console.log.bind(console);
|
||||||
|
|
||||||
|
const handlePath = async path => {
|
||||||
|
try {
|
||||||
|
spec = await loadAndBundleSpec(pathToSpec);
|
||||||
|
pageHTML = await getPageHTML(spec, pathToSpec, options);
|
||||||
|
log('Updated successfully');
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error while updating: ', e.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
watcher
|
watcher
|
||||||
.on('change', async path => {
|
.on('change', async path => {
|
||||||
log(`${path} changed, updating docs`);
|
log(`${path} changed, updating docs`);
|
||||||
try {
|
handlePath(path);
|
||||||
spec = await loadAndBundleSpec(pathToSpec);
|
|
||||||
pageHTML = await getPageHTML(spec, pathToSpec, options);
|
|
||||||
log('Updated successfully');
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Error while updating: ', e.message);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on('add', async path => {
|
.on('add', async path => {
|
||||||
log(`File ${path} added, updating docs`);
|
log(`File ${path} added, updating docs`);
|
||||||
try {
|
handlePath(path);
|
||||||
spec = await loadAndBundleSpec(pathToSpec);
|
|
||||||
pageHTML = await getPageHTML(spec, pathToSpec, options);
|
|
||||||
log('Updated successfully');
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Error while updating: ', e.message);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.on('addDir', path => {
|
.on('addDir', path => {
|
||||||
log(`↗ Directory ${path} added. Files in here will trigger reload.`);
|
log(`↗ Directory ${path} added. Files in here will trigger reload.`);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user