Skip to content

Commit

Permalink
fix: rename bandle command and add deprecate notice (#1935)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Hotsiy <gotsijroman@gmail.com>
  • Loading branch information
AlexVarchuk and RomanHotsiy committed Mar 21, 2022
1 parent 0c23f8d commit eb096b6
Showing 1 changed file with 75 additions and 52 deletions.
127 changes: 75 additions & 52 deletions cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,58 @@ export const mimeTypes = {

const BUNDLES_DIR = dirname(require.resolve('redoc'));

/* tslint:disable-next-line */
const builderForBuildCommand = yargs => {
yargs.positional('spec', {
describe: 'path or URL to your spec',
});

yargs.option('o', {
describe: 'Output file',
alias: 'output',
type: 'string',
default: 'redoc-static.html',
});

yargs.options('title', {
describe: 'Page Title',
type: 'string',
});

yargs.options('disableGoogleFont', {
describe: 'Disable Google Font',
type: 'boolean',
default: false,
});

yargs.option('cdn', {
describe: 'Do not include ReDoc source code into html page, use link to CDN instead',
type: 'boolean',
default: false,
});

yargs.demandOption('spec');
return yargs;
};

const handlerForBuildCommand = async (argv: any) => {
const config = {
ssr: true,
output: argv.o as string,
cdn: argv.cdn as boolean,
title: argv.title as string,
disableGoogleFont: argv.disableGoogleFont as boolean,
templateFileName: argv.template as string,
templateOptions: argv.templateOptions || {},
redocOptions: getObjectOrJSON(argv.options),
};

try {
await bundle(argv.spec, config);
} catch (e) {
handleError(e);
}
};

YargsParser.command(
'serve <spec>',
'start the server',
Expand Down Expand Up @@ -122,60 +173,32 @@ YargsParser.command(
handleError(e);
}
},
[
res => {
console.log(
`\n⚠️ This command is deprecated. Use "npx @redocly/openapi-cli preview-docs petstore.yaml"\n`,
);
return res;
},
],
)
.command(
'build <spec>',
'build definition into zero-dependency HTML-file',
builderForBuildCommand,
handlerForBuildCommand,
)
.command(
'bundle <spec>',
'bundle spec into zero-dependency HTML-file',
yargs => {
yargs.positional('spec', {
describe: 'path or URL to your spec',
});

yargs.option('o', {
describe: 'Output file',
alias: 'output',
type: 'string',
default: 'redoc-static.html',
});

yargs.options('title', {
describe: 'Page Title',
type: 'string',
});

yargs.options('disableGoogleFont', {
describe: 'Disable Google Font',
type: 'boolean',
default: false,
});

yargs.option('cdn', {
describe: 'Do not include ReDoc source code into html page, use link to CDN instead',
type: 'boolean',
default: false,
});

yargs.demandOption('spec');
return yargs;
},
async (argv: any) => {
const config = {
ssr: true,
output: argv.o as string,
cdn: argv.cdn as boolean,
title: argv.title as string,
disableGoogleFont: argv.disableGoogleFont as boolean,
templateFileName: argv.template as string,
templateOptions: argv.templateOptions || {},
redocOptions: getObjectOrJSON(argv.options),
};

try {
await bundle(argv.spec, config);
} catch (e) {
handleError(e);
}
},
'bundle spec into zero-dependency HTML-file [deprecated]',
builderForBuildCommand,
handlerForBuildCommand,
[
res => {
console.log(`\n⚠️ This command is deprecated. Use "build" command instead.\n`);
return res;
},
],
)
.demandCommand()
.options('t', {
Expand Down

0 comments on commit eb096b6

Please sign in to comment.