mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-16 18:00:33 +03:00
feat: support .redocly.yaml for options for redoc-cli (#1981)
Co-authored-by: Anastasiia Derymarko < anastasiia@redocly.com> Co-authored-by: Adam Altman <adam@redoc.ly> Co-authored-by: Ivana Isadora Devcic <33730345+skadinna@users.noreply.github.com>
This commit is contained in:
parent
7988e8137c
commit
1f417d67c6
9
.github/workflows/unit-tests.yml
vendored
9
.github/workflows/unit-tests.yml
vendored
|
@ -6,7 +6,8 @@ jobs:
|
||||||
build-and-unit:
|
build-and-unit:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run bundle
|
- run: npm ci --prefix cli
|
||||||
- run: npm test
|
- run: npm run bundle
|
||||||
|
- run: npm test
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -28,6 +28,7 @@ bundles/
|
||||||
typings/*
|
typings/*
|
||||||
!typings/styled-patch.d.ts
|
!typings/styled-patch.d.ts
|
||||||
cli/index.js
|
cli/index.js
|
||||||
|
cli/__test__/*/**/*.html
|
||||||
|
|
||||||
/benchmark/revisions
|
/benchmark/revisions
|
||||||
|
|
||||||
|
|
|
@ -31,4 +31,10 @@ Some examples:
|
||||||
- Bundle using a custom template and add custom `templateOptions`:<br/>
|
- Bundle using a custom template and add custom `templateOptions`:<br/>
|
||||||
`$ redoc-cli build [spec] -t custom.hbs --templateOptions.metaDescription "Page meta description"`
|
`$ redoc-cli build [spec] -t custom.hbs --templateOptions.metaDescription "Page meta description"`
|
||||||
|
|
||||||
|
#### With a Redocly configuration file ([more info](https://redocly.com/docs/cli/configuration/#redocly-configuration-file)):
|
||||||
|
|
||||||
|
1. Go to folder with your Redocly configuration file (`.redocly.yaml` or `redocly.yaml`) and your OpenAPI definition file.
|
||||||
|
2. Build the site using the `build` command (options from the Redocly configuration file will be automatically fetched):
|
||||||
|
`redoc build openapi.yaml`
|
||||||
|
|
||||||
For more details, run `redoc-cli --help`.
|
For more details, run `redoc-cli --help`.
|
||||||
|
|
2
cli/__test__/build/configRedoc/.redocly.yaml
Normal file
2
cli/__test__/build/configRedoc/.redocly.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
features.openapi:
|
||||||
|
disableSearch: true
|
30
cli/__test__/build/configRedoc/index.test.ts
Normal file
30
cli/__test__/build/configRedoc/index.test.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import { spawnSync } from 'child_process';
|
||||||
|
import { readFileSync } from 'fs';
|
||||||
|
|
||||||
|
describe('build', () => {
|
||||||
|
it('should use .redocly.yaml', () => {
|
||||||
|
const r = spawnSync(
|
||||||
|
'node',
|
||||||
|
['../../../index.js', 'build', ' ../../../../demo/openapi.yaml', '--output=redocTest.html'],
|
||||||
|
{
|
||||||
|
cwd: __dirname,
|
||||||
|
shell: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const out = r.stdout.toString('utf-8');
|
||||||
|
const err = r.stderr.toString('utf-8');
|
||||||
|
const result = `${out}\n${err}`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const redocStaticFile = readFileSync(`${__dirname}/redocTest.html`, 'utf8');
|
||||||
|
expect(redocStaticFile).toContain('"options":{"disableSearch":true}');
|
||||||
|
expect(redocStaticFile).not.toContain('role="search"');
|
||||||
|
} catch (err) {
|
||||||
|
expect(err.toString()).toContain('{"options":{"disableSearch":"true"}');
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(result).toContain('Found .redocly.yaml and using features.openapi options');
|
||||||
|
expect(result).toContain('bundled successfully');
|
||||||
|
});
|
||||||
|
});
|
34
cli/__test__/build/configRedoc/inlineOptions.test.ts
Normal file
34
cli/__test__/build/configRedoc/inlineOptions.test.ts
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import { spawnSync } from 'child_process';
|
||||||
|
import { readFileSync } from 'fs';
|
||||||
|
|
||||||
|
describe('build with inline options', () => {
|
||||||
|
it('should use inline options and ignore .redocly.yaml', () => {
|
||||||
|
const r = spawnSync(
|
||||||
|
'node',
|
||||||
|
[
|
||||||
|
'../../../index.js',
|
||||||
|
'build',
|
||||||
|
' ../../../../demo/openapi.yaml',
|
||||||
|
'--options.disableSearch="false" ',
|
||||||
|
],
|
||||||
|
{
|
||||||
|
cwd: __dirname,
|
||||||
|
shell: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const out = r.stdout.toString('utf-8');
|
||||||
|
const err = r.stderr.toString('utf-8');
|
||||||
|
const result = `${out}\n${err}`;
|
||||||
|
expect(result).not.toContain('Found .redocly.yaml and using features.openapi options');
|
||||||
|
expect(result).toContain('bundled successfully');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const redocStaticFile = readFileSync(`${__dirname}/redoc-static.html`, 'utf8');
|
||||||
|
expect(redocStaticFile).toContain('"options":{"disableSearch":"false"}');
|
||||||
|
expect(redocStaticFile).toContain('role="search"');
|
||||||
|
} catch (err) {
|
||||||
|
expect(err.toString()).toContain('"options":{"disableSearch":"false"}');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
17
cli/index.ts
17
cli/index.ts
|
@ -25,6 +25,12 @@ import {
|
||||||
import * as mkdirp from 'mkdirp';
|
import * as mkdirp from 'mkdirp';
|
||||||
|
|
||||||
import * as YargsParser from 'yargs';
|
import * as YargsParser from 'yargs';
|
||||||
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
|
import { findConfig } from '@redocly/openapi-core';
|
||||||
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
|
import { parseYaml } from '@redocly/openapi-core';
|
||||||
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
|
import { Config } from '@redocly/openapi-core';
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
ssr?: boolean;
|
ssr?: boolean;
|
||||||
|
@ -447,6 +453,17 @@ function getObjectOrJSON(options) {
|
||||||
handleError(e);
|
handleError(e);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
const configFile = findConfig();
|
||||||
|
if (configFile) {
|
||||||
|
console.log(`Found ${configFile} and using features.openapi options`);
|
||||||
|
try {
|
||||||
|
const config = parseYaml(readFileSync(configFile, 'utf-8')) as Config;
|
||||||
|
|
||||||
|
return config['features.openapi'];
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(`Found ${configFile} but failed to parse: ${e.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
"bundle:standalone": "webpack --env production --env standalone --mode=production",
|
"bundle:standalone": "webpack --env production --env standalone --mode=production",
|
||||||
"bundle:lib": "webpack --mode=production && npm run declarations",
|
"bundle:lib": "webpack --mode=production && npm run declarations",
|
||||||
"bundle:browser": "webpack --env production --env browser --mode=production",
|
"bundle:browser": "webpack --env production --env browser --mode=production",
|
||||||
"bundle": "npm run bundle:clean && npm run bundle:lib && npm run bundle:browser && npm run bundle:standalone",
|
"bundle": "npm run bundle:clean && npm run bundle:lib && npm run bundle:browser && npm run bundle:standalone && npm run compile:cli",
|
||||||
"declarations": "tsc --emitDeclarationOnly -p tsconfig.lib.json && cp -R src/types typings/",
|
"declarations": "tsc --emitDeclarationOnly -p tsconfig.lib.json && cp -R src/types typings/",
|
||||||
"stats": "webpack --env production --env standalone --json --profile --mode=production > stats.json",
|
"stats": "webpack --env production --env standalone --json --profile --mode=production > stats.json",
|
||||||
"prettier": "prettier --write \"cli/index.ts\" \"src/**/*.{ts,tsx}\"",
|
"prettier": "prettier --write \"cli/index.ts\" \"src/**/*.{ts,tsx}\"",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user