mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-08 14:14:56 +03:00
Added support for providing custom redoc JS source.
This commit is contained in:
parent
753b013eee
commit
ddcd0fbdbd
24
cli/index.ts
24
cli/index.ts
|
@ -29,6 +29,7 @@ interface Options {
|
||||||
templateFileName?: string;
|
templateFileName?: string;
|
||||||
templateOptions?: any;
|
templateOptions?: any;
|
||||||
redocOptions?: any;
|
redocOptions?: any;
|
||||||
|
customScript?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BUNDLES_DIR = dirname(require.resolve('redoc'));
|
const BUNDLES_DIR = dirname(require.resolve('redoc'));
|
||||||
|
@ -59,6 +60,12 @@ YargsParser.command(
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
yargs.option('customScript', {
|
||||||
|
describe: 'Include custom ReDoc JavaScript source file',
|
||||||
|
type: 'string',
|
||||||
|
default: null
|
||||||
|
});
|
||||||
|
|
||||||
yargs.demandOption('spec');
|
yargs.demandOption('spec');
|
||||||
return yargs;
|
return yargs;
|
||||||
},
|
},
|
||||||
|
@ -66,6 +73,7 @@ YargsParser.command(
|
||||||
const config: Options = {
|
const config: Options = {
|
||||||
ssr: argv.ssr as boolean,
|
ssr: argv.ssr as boolean,
|
||||||
watch: argv.watch as boolean,
|
watch: argv.watch as boolean,
|
||||||
|
customScript: argv.customScript as string,
|
||||||
templateFileName: argv.template as string,
|
templateFileName: argv.template as string,
|
||||||
templateOptions: argv.templateOptions || {},
|
templateOptions: argv.templateOptions || {},
|
||||||
redocOptions: argv.options || {},
|
redocOptions: argv.options || {},
|
||||||
|
@ -105,6 +113,12 @@ YargsParser.command(
|
||||||
default: false,
|
default: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
yargs.option('customScript', {
|
||||||
|
describe: 'Include custom ReDoc JavaScript source file',
|
||||||
|
type: 'string',
|
||||||
|
default: null
|
||||||
|
});
|
||||||
|
|
||||||
yargs.demandOption('spec');
|
yargs.demandOption('spec');
|
||||||
return yargs;
|
return yargs;
|
||||||
},
|
},
|
||||||
|
@ -117,6 +131,7 @@ YargsParser.command(
|
||||||
templateFileName: argv.template as string,
|
templateFileName: argv.template as string,
|
||||||
templateOptions: argv.templateOptions || {},
|
templateOptions: argv.templateOptions || {},
|
||||||
redocOptions: argv.options || {},
|
redocOptions: argv.options || {},
|
||||||
|
customScript: argv.customScript as string
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -147,8 +162,9 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) {
|
||||||
const server = createServer((request, response) => {
|
const server = createServer((request, response) => {
|
||||||
console.time('GET ' + request.url);
|
console.time('GET ' + request.url);
|
||||||
if (request.url === '/redoc.standalone.js') {
|
if (request.url === '/redoc.standalone.js') {
|
||||||
|
let actualRedocPath = options.customScript ? options.customScript : join(BUNDLES_DIR, 'redoc.standalone.js');
|
||||||
respondWithGzip(
|
respondWithGzip(
|
||||||
createReadStream(join(BUNDLES_DIR, 'redoc.standalone.js'), 'utf8'),
|
createReadStream(actualRedocPath, 'utf8'),
|
||||||
request,
|
request,
|
||||||
response,
|
response,
|
||||||
{
|
{
|
||||||
|
@ -216,7 +232,7 @@ async function bundle(pathToSpec, options: Options = {}) {
|
||||||
async function getPageHTML(
|
async function getPageHTML(
|
||||||
spec: any,
|
spec: any,
|
||||||
pathToSpec: string,
|
pathToSpec: string,
|
||||||
{ ssr, cdn, title, templateFileName, templateOptions, redocOptions = {} }: Options,
|
{ ssr, cdn, customScript, title, templateFileName, templateOptions, redocOptions = {} }: Options,
|
||||||
) {
|
) {
|
||||||
let html;
|
let html;
|
||||||
let css;
|
let css;
|
||||||
|
@ -233,9 +249,13 @@ async function getPageHTML(
|
||||||
state = await store.toJS();
|
state = await store.toJS();
|
||||||
|
|
||||||
if (!cdn) {
|
if (!cdn) {
|
||||||
|
if (customScript) {
|
||||||
|
redocStandaloneSrc = readFileSync(customScript);
|
||||||
|
} else {
|
||||||
redocStandaloneSrc = readFileSync(join(BUNDLES_DIR, 'redoc.standalone.js'));
|
redocStandaloneSrc = readFileSync(join(BUNDLES_DIR, 'redoc.standalone.js'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
templateFileName = templateFileName ? templateFileName : join(__dirname, './template.hbs');
|
templateFileName = templateFileName ? templateFileName : join(__dirname, './template.hbs');
|
||||||
const template = compile(readFileSync(templateFileName).toString());
|
const template = compile(readFileSync(templateFileName).toString());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user