@redocly/cli
Advanced tools
Comparing version 1.0.0-beta.102 to 1.0.0-beta.103
@@ -27,5 +27,8 @@ /// <reference types="jest" /> | ||
lint: { | ||
addIgnore: jest.Mock<any, any>; | ||
skipRules: jest.Mock<any, any>; | ||
skipPreprocessors: jest.Mock<any, any>; | ||
saveIgnore: jest.Mock<any, any>; | ||
skipDecorators: jest.Mock<any, any>; | ||
ignore: null; | ||
}; | ||
@@ -46,1 +49,2 @@ }, []>; | ||
export declare const slash: jest.Mock<any, any>; | ||
export declare const findConfig: jest.Mock<any, any>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.slash = exports.formatProblems = exports.getTotals = exports.bundle = exports.lint = exports.getMergedConfig = exports.loadConfig = exports.RedoclyClient = exports.__redoclyClient = void 0; | ||
exports.findConfig = exports.slash = exports.formatProblems = exports.getTotals = exports.bundle = exports.lint = exports.getMergedConfig = exports.loadConfig = exports.RedoclyClient = exports.__redoclyClient = void 0; | ||
const config_1 = require("./../../__tests__/fixtures/config"); | ||
exports.__redoclyClient = { | ||
@@ -19,6 +20,3 @@ isAuthorizedWithRedocly: jest.fn().mockResolvedValue(true), | ||
exports.RedoclyClient = jest.fn(() => exports.__redoclyClient); | ||
exports.loadConfig = jest.fn(() => ({ | ||
configFile: null, | ||
lint: { skipRules: jest.fn(), skipPreprocessors: jest.fn(), skipDecorators: jest.fn() }, | ||
})); | ||
exports.loadConfig = jest.fn(() => config_1.ConfigFixture); | ||
exports.getMergedConfig = jest.fn(); | ||
@@ -30,1 +28,2 @@ exports.lint = jest.fn(); | ||
exports.slash = jest.fn(); | ||
exports.findConfig = jest.fn(); |
/// <reference types="jest" /> | ||
export declare const getFallbackEntryPointsOrExit: jest.Mock<any, [entrypoints: any]>; | ||
export declare const getTotals: jest.Mock<{ | ||
errors: number; | ||
}, []>; | ||
export declare const dumpBundle: jest.Mock<string, []>; | ||
@@ -7,0 +4,0 @@ export declare const slash: jest.Mock<any, any>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.exitWithError = exports.handleError = exports.getOutputFileName = exports.printLintTotals = exports.printUnusedWarnings = exports.printExecutionTime = exports.getExecutionTime = exports.pluralize = exports.slash = exports.dumpBundle = exports.getTotals = exports.getFallbackEntryPointsOrExit = void 0; | ||
exports.exitWithError = exports.handleError = exports.getOutputFileName = exports.printLintTotals = exports.printUnusedWarnings = exports.printExecutionTime = exports.getExecutionTime = exports.pluralize = exports.slash = exports.dumpBundle = exports.getFallbackEntryPointsOrExit = void 0; | ||
exports.getFallbackEntryPointsOrExit = jest.fn((entrypoints) => entrypoints.map(() => ({ path: '' }))); | ||
exports.getTotals = jest.fn(() => ({ errors: 0 })); | ||
exports.dumpBundle = jest.fn(() => ''); | ||
@@ -7,0 +6,0 @@ exports.slash = jest.fn(); |
@@ -13,2 +13,3 @@ "use strict"; | ||
const openapi_core_1 = require("@redocly/openapi-core"); | ||
const utils_1 = require("../../utils"); | ||
const push_1 = require("../../commands/push"); | ||
@@ -36,3 +37,5 @@ jest.mock('fs'); | ||
branchName: 'test', | ||
'public': true | ||
'public': true, | ||
'batch-id': '123', | ||
'batch-size': 2, | ||
}); | ||
@@ -50,4 +53,30 @@ expect(redoclyClient.registryApi.prepareFileUpload).toBeCalledTimes(1); | ||
version: '1.0.0', | ||
batchId: '123', | ||
batchSize: 2, | ||
}); | ||
})); | ||
it('fails if batchId value is an empty string', () => __awaiter(void 0, void 0, void 0, function* () { | ||
yield push_1.handlePush({ | ||
upsert: true, | ||
entrypoint: 'spec.json', | ||
destination: '@org/my-api@1.0.0', | ||
branchName: 'test', | ||
'public': true, | ||
'batch-id': ' ', | ||
'batch-size': 2, | ||
}); | ||
expect(utils_1.exitWithError).toBeCalledTimes(1); | ||
})); | ||
it('fails if batchSize value is less than 2', () => __awaiter(void 0, void 0, void 0, function* () { | ||
yield push_1.handlePush({ | ||
upsert: true, | ||
entrypoint: 'spec.json', | ||
destination: '@org/my-api@1.0.0', | ||
branchName: 'test', | ||
'public': true, | ||
'batch-id': '123', | ||
'batch-size': 1, | ||
}); | ||
expect(utils_1.exitWithError).toBeCalledTimes(1); | ||
})); | ||
}); | ||
@@ -54,0 +83,0 @@ describe('transformPush', () => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("../utils"); | ||
jest.mock("os"); | ||
const colorette_1 = require("colorette"); | ||
jest.mock('os'); | ||
jest.mock('colorette'); | ||
describe('isSubdir', () => { | ||
@@ -42,1 +44,37 @@ it('can correctly determine if subdir', () => { | ||
}); | ||
describe('printConfigLintTotals', () => { | ||
const totalProblemsMock = { | ||
errors: 1, | ||
warnings: 0, | ||
ignored: 0, | ||
}; | ||
const redColoretteMocks = colorette_1.red; | ||
const yellowColoretteMocks = colorette_1.yellow; | ||
beforeEach(() => { | ||
yellowColoretteMocks.mockImplementation((text) => text); | ||
redColoretteMocks.mockImplementation((text) => text); | ||
jest.spyOn(process.stderr, 'write').mockImplementation(() => true); | ||
}); | ||
it('should print errors if such exist', () => { | ||
utils_1.printConfigLintTotals(totalProblemsMock); | ||
expect(process.stderr.write).toHaveBeenCalledWith('❌ Your config has 1 error.\n'); | ||
expect(redColoretteMocks).toHaveBeenCalledWith('❌ Your config has 1 error.\n'); | ||
}); | ||
it('should print warnign and error', () => { | ||
utils_1.printConfigLintTotals(Object.assign(Object.assign({}, totalProblemsMock), { warnings: 2 })); | ||
expect(process.stderr.write).toHaveBeenCalledWith('❌ Your config has 1 error and 2 warnings.\n'); | ||
expect(redColoretteMocks).toHaveBeenCalledWith('❌ Your config has 1 error and 2 warnings.\n'); | ||
}); | ||
it('should print warnign if no error', () => { | ||
utils_1.printConfigLintTotals(Object.assign(Object.assign({}, totalProblemsMock), { errors: 0, warnings: 2 })); | ||
expect(process.stderr.write).toHaveBeenCalledWith('You have 2 warnings.\n'); | ||
expect(yellowColoretteMocks).toHaveBeenCalledWith('You have 2 warnings.\n'); | ||
}); | ||
it('should print nothing if no error and no warnings', () => { | ||
const result = utils_1.printConfigLintTotals(Object.assign(Object.assign({}, totalProblemsMock), { errors: 0 })); | ||
expect(result).toBeUndefined(); | ||
expect(process.stderr.write).toHaveBeenCalledTimes(0); | ||
expect(yellowColoretteMocks).toHaveBeenCalledTimes(0); | ||
expect(redColoretteMocks).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |
@@ -1,3 +0,3 @@ | ||
import { OutputFormat } from '@redocly/openapi-core'; | ||
export declare function handleLint(argv: { | ||
import { OutputFormat, RuleSeverity } from '@redocly/openapi-core'; | ||
export declare type LintOptions = { | ||
entrypoints: string[]; | ||
@@ -8,5 +8,7 @@ 'max-problems'?: number; | ||
'skip-preprocessor'?: string[]; | ||
'lint-config': RuleSeverity; | ||
extends?: string[]; | ||
config?: string; | ||
format: OutputFormat; | ||
}, version: string): Promise<void>; | ||
}; | ||
export declare function handleLint(argv: LintOptions, version: string): Promise<void>; |
@@ -19,3 +19,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const config = yield openapi_core_1.loadConfig(argv.config, argv.extends); | ||
const config = yield openapi_core_1.loadConfig(argv.config, argv.extends, lintConfigCallback(argv, version)); | ||
const entrypoints = yield utils_1.getFallbackEntryPointsOrExit(argv.entrypoints, config); | ||
@@ -82,1 +82,24 @@ if (argv['generate-ignore-file']) { | ||
exports.handleLint = handleLint; | ||
function lintConfigCallback(argv, version) { | ||
if (argv['lint-config'] === 'off') { | ||
return; | ||
} | ||
return (config) => __awaiter(this, void 0, void 0, function* () { | ||
const { 'max-problems': maxProblems, format } = argv; | ||
const configPath = openapi_core_1.findConfig(argv.config) || ''; | ||
const stringYaml = openapi_core_1.stringifyYaml(config); | ||
const configContent = openapi_core_1.makeDocumentFromString(stringYaml, configPath); | ||
const problems = yield openapi_core_1.lintConfig({ | ||
document: configContent, | ||
severity: argv['lint-config'], | ||
}); | ||
const fileTotals = openapi_core_1.getTotals(problems); | ||
openapi_core_1.formatProblems(problems, { | ||
format, | ||
maxProblems, | ||
totals: fileTotals, | ||
version, | ||
}); | ||
utils_1.printConfigLintTotals(fileTotals); | ||
}); | ||
} |
@@ -35,4 +35,4 @@ "use strict"; | ||
<script src="${useRedocPro | ||
? 'https://cdn.jsdelivr.net/npm/@redocly/reference-docs@latest/dist/redocly-reference-docs.min.js' | ||
: 'https://cdn.jsdelivr.net/npm/redoc@latest/bundles/redoc.standalone.js'}"></script> | ||
? 'https://cdn.redoc.ly/reference-docs/latest/redocly-reference-docs.min.js' | ||
: 'https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js'}"></script> | ||
`, | ||
@@ -44,3 +44,3 @@ redocHTML: ` | ||
${useRedocPro | ||
? "window[window.__REDOC_EXPORT].setPublicPath('https://cdn.jsdelivr.net/npm/@redocly/reference-docs@latest/dist/');" | ||
? "window[window.__REDOC_EXPORT].setPublicPath('https://cdn.redoc.ly/reference-docs/latest/');" | ||
: ''} | ||
@@ -47,0 +47,0 @@ window[window.__REDOC_EXPORT].init("/openapi.json", ${JSON.stringify(redocOptions)}, container) |
@@ -7,3 +7,4 @@ import { Config, Region } from '@redocly/openapi-core'; | ||
upsert?: boolean; | ||
'run-id'?: string; | ||
'batch-id'?: string; | ||
'batch-size'?: number; | ||
region?: Region; | ||
@@ -10,0 +11,0 @@ 'skip-decorator'?: string[]; |
@@ -46,2 +46,4 @@ "use strict"; | ||
const { destination, branchName, upsert } = argv; | ||
const batchId = argv['batch-id']; | ||
const batchSize = argv['batch-size']; | ||
if (destination && | ||
@@ -59,2 +61,8 @@ !(validateDestination(destination) || validateDestinationWithoutOrganization(destination))) { | ||
} | ||
if (batchId && !batchId.trim()) { | ||
utils_1.exitWithError(`The ${colorette_1.blue(`batch-id`)} option value is not valid, please avoid using an empty string.`); | ||
} | ||
if (batchSize && batchSize < 2) { | ||
utils_1.exitWithError(`The ${colorette_1.blue(`batch-size`)} option value is not valid, please use the integer bigger than 1.`); | ||
} | ||
const apis = entrypoint ? { [`${name}@${version}`]: { root: entrypoint } } : config.apis; | ||
@@ -102,3 +110,5 @@ for (const [apiNameAndVersion, { root: entrypoint }] of Object.entries(apis)) { | ||
isUpsert: upsert, | ||
isPublic: argv['public'] | ||
isPublic: argv['public'], | ||
batchId: batchId, | ||
batchSize: batchSize, | ||
}); | ||
@@ -105,0 +115,0 @@ } |
@@ -81,4 +81,4 @@ #!/usr/bin/env node | ||
description: 'Skip automated x-tagGroups creation', | ||
type: 'boolean' | ||
} | ||
type: 'boolean', | ||
}, | ||
}), (argv) => { | ||
@@ -94,3 +94,12 @@ join_1.handleJoin(argv, version); | ||
upsert: { type: 'boolean', alias: 'u' }, | ||
'run-id': { type: 'string', requiresArg: true }, | ||
'batch-id': { | ||
description: 'Specifies the ID of the CI job that the current push will be associated with.', | ||
type: 'string', | ||
requiresArg: true, | ||
}, | ||
'batch-size': { | ||
description: 'Specifies the total number of CI jobs planned to be pushed.', | ||
type: 'number', | ||
requiresArg: true, | ||
}, | ||
region: { description: 'Specify a region.', alias: 'r', choices: types_1.regionChoices }, | ||
@@ -102,7 +111,9 @@ 'skip-decorator': { | ||
}, | ||
'public': { | ||
public: { | ||
description: 'Make API registry available to the public', | ||
type: 'boolean', | ||
}, | ||
}), push_1.transformPush(push_1.handlePush)) | ||
}) | ||
.implies('batch-id', 'batch-size') | ||
.implies('batch-size', 'batch-id'), push_1.transformPush(push_1.handlePush)) | ||
.command('lint [entrypoints...]', 'Lint definition.', (yargs) => yargs.positional('entrypoints', { array: true, type: 'string', demandOption: true }).option({ | ||
@@ -140,2 +151,11 @@ format: { | ||
}, | ||
'lint-config': { | ||
description: 'Apply severity for linting the config file.', | ||
choices: [ | ||
'warn', | ||
'error', | ||
'off', | ||
], | ||
default: 'warn', | ||
}, | ||
config: { | ||
@@ -142,0 +162,0 @@ description: 'Specify path to the config file.', |
@@ -20,2 +20,3 @@ import { BundleOutputFormat, Config, LintConfig } from '@redocly/openapi-core'; | ||
export declare function printLintTotals(totals: Totals, definitionsCount: number): void; | ||
export declare function printConfigLintTotals(totals: Totals): void; | ||
export declare function getOutputFileName(entrypoint: string, entries: number, output?: string, ext?: BundleOutputFormat): { | ||
@@ -22,0 +23,0 @@ outputFile: string; |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isSubdir = exports.exitWithError = exports.printUnusedWarnings = exports.getOutputFileName = exports.printLintTotals = exports.handleError = exports.pluralize = exports.writeYaml = exports.readYaml = exports.promptUser = exports.saveBundle = exports.dumpBundle = exports.CircularJSONNotSupportedError = exports.escapeLanguageName = exports.pathToFilename = exports.printExecutionTime = exports.getExecutionTime = exports.getFallbackEntryPointsOrExit = void 0; | ||
exports.isSubdir = exports.exitWithError = exports.printUnusedWarnings = exports.getOutputFileName = exports.printConfigLintTotals = exports.printLintTotals = exports.handleError = exports.pluralize = exports.writeYaml = exports.readYaml = exports.promptUser = exports.saveBundle = exports.dumpBundle = exports.CircularJSONNotSupportedError = exports.escapeLanguageName = exports.pathToFilename = exports.printExecutionTime = exports.getExecutionTime = exports.getFallbackEntryPointsOrExit = void 0; | ||
const path_1 = require("path"); | ||
@@ -215,2 +215,14 @@ const colorette_1 = require("colorette"); | ||
exports.printLintTotals = printLintTotals; | ||
function printConfigLintTotals(totals) { | ||
if (totals.errors > 0) { | ||
process.stderr.write(colorette_1.red(`❌ Your config has ${totals.errors} ${pluralize('error', totals.errors)}${totals.warnings > 0 | ||
? ` and ${totals.warnings} ${pluralize('warning', totals.warnings)}` | ||
: ''}.\n`)); | ||
} | ||
else if (totals.warnings > 0) { | ||
process.stderr.write(colorette_1.yellow(`You have ${totals.warnings} ${pluralize('warning', totals.warnings)}.\n`)); | ||
} | ||
; | ||
} | ||
exports.printConfigLintTotals = printConfigLintTotals; | ||
function getOutputFileName(entrypoint, entries, output, ext) { | ||
@@ -253,3 +265,3 @@ if (!output) { | ||
if (rules.length || preprocessors.length) { | ||
process.stderr.write(`Check the spelling and verify you added plugin prefix.\n`); | ||
process.stderr.write(`Check the spelling and verify the added plugin prefix.\n`); | ||
} | ||
@@ -256,0 +268,0 @@ } |
{ | ||
"name": "@redocly/cli", | ||
"version": "1.0.0-beta.102", | ||
"version": "1.0.0-beta.103", | ||
"description": "", | ||
@@ -38,3 +38,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@redocly/openapi-core": "1.0.0-beta.102", | ||
"@redocly/openapi-core": "1.0.0-beta.103", | ||
"assert-node-version": "^1.0.3", | ||
@@ -41,0 +41,0 @@ "chokidar": "^3.5.1", |
@@ -0,1 +1,3 @@ | ||
import { ConfigFixture } from './../../__tests__/fixtures/config'; | ||
export const __redoclyClient = { | ||
@@ -17,6 +19,3 @@ isAuthorizedWithRedocly: jest.fn().mockResolvedValue(true), | ||
export const RedoclyClient = jest.fn(() => __redoclyClient); | ||
export const loadConfig = jest.fn(() => ({ | ||
configFile: null, | ||
lint: { skipRules: jest.fn(), skipPreprocessors: jest.fn(), skipDecorators: jest.fn() }, | ||
})); | ||
export const loadConfig = jest.fn(() => ConfigFixture); | ||
export const getMergedConfig = jest.fn(); | ||
@@ -28,1 +27,2 @@ export const lint = jest.fn(); | ||
export const slash = jest.fn(); | ||
export const findConfig = jest.fn(); |
export const getFallbackEntryPointsOrExit = jest.fn((entrypoints) => entrypoints.map(() => ({ path: '' }))); | ||
export const getTotals = jest.fn(() => ({ errors: 0 })); | ||
export const dumpBundle = jest.fn(() => ''); | ||
@@ -4,0 +3,0 @@ export const slash = jest.fn(); |
import { Config, getMergedConfig } from '@redocly/openapi-core'; | ||
import { exitWithError } from '../../utils'; | ||
import { | ||
@@ -34,3 +35,5 @@ getApiEntrypoint, | ||
branchName: 'test', | ||
'public': true | ||
'public': true, | ||
'batch-id': '123', | ||
'batch-size': 2, | ||
}); | ||
@@ -49,4 +52,34 @@ | ||
version: '1.0.0', | ||
batchId: '123', | ||
batchSize: 2, | ||
}); | ||
}); | ||
it('fails if batchId value is an empty string', async () => { | ||
await handlePush({ | ||
upsert: true, | ||
entrypoint: 'spec.json', | ||
destination: '@org/my-api@1.0.0', | ||
branchName: 'test', | ||
'public': true, | ||
'batch-id': ' ', | ||
'batch-size': 2, | ||
}); | ||
expect(exitWithError).toBeCalledTimes(1); | ||
}); | ||
it('fails if batchSize value is less than 2', async () => { | ||
await handlePush({ | ||
upsert: true, | ||
entrypoint: 'spec.json', | ||
destination: '@org/my-api@1.0.0', | ||
branchName: 'test', | ||
'public': true, | ||
'batch-id': '123', | ||
'batch-size': 1, | ||
}); | ||
expect(exitWithError).toBeCalledTimes(1); | ||
}); | ||
}); | ||
@@ -53,0 +86,0 @@ |
@@ -1,5 +0,9 @@ | ||
import { isSubdir, pathToFilename } from '../utils'; | ||
import { Totals } from '@redocly/openapi-core'; | ||
import { isSubdir, pathToFilename, printConfigLintTotals} from '../utils'; | ||
import { red, yellow } from 'colorette'; | ||
jest.mock("os"); | ||
jest.mock('os'); | ||
jest.mock('colorette') | ||
describe('isSubdir', () => { | ||
@@ -51,1 +55,47 @@ it('can correctly determine if subdir', () => { | ||
}); | ||
describe('printConfigLintTotals', () => { | ||
const totalProblemsMock: Totals = { | ||
errors: 1, | ||
warnings: 0, | ||
ignored: 0, | ||
}; | ||
const redColoretteMocks = red as jest.Mock<any, any>; | ||
const yellowColoretteMocks = yellow as jest.Mock<any, any>; | ||
beforeEach(() => { | ||
yellowColoretteMocks.mockImplementation((text: string) => text); | ||
redColoretteMocks.mockImplementation((text: string) => text); | ||
jest.spyOn(process.stderr, 'write').mockImplementation(() => true); | ||
}); | ||
it('should print errors if such exist', () => { | ||
printConfigLintTotals(totalProblemsMock); | ||
expect(process.stderr.write).toHaveBeenCalledWith('❌ Your config has 1 error.\n'); | ||
expect(redColoretteMocks).toHaveBeenCalledWith('❌ Your config has 1 error.\n'); | ||
}); | ||
it('should print warnign and error', () => { | ||
printConfigLintTotals({ ...totalProblemsMock, warnings: 2 }); | ||
expect(process.stderr.write).toHaveBeenCalledWith( | ||
'❌ Your config has 1 error and 2 warnings.\n', | ||
); | ||
expect(redColoretteMocks).toHaveBeenCalledWith('❌ Your config has 1 error and 2 warnings.\n'); | ||
}); | ||
it('should print warnign if no error', () => { | ||
printConfigLintTotals({ ...totalProblemsMock, errors: 0, warnings: 2 }); | ||
expect(process.stderr.write).toHaveBeenCalledWith('You have 2 warnings.\n'); | ||
expect(yellowColoretteMocks).toHaveBeenCalledWith('You have 2 warnings.\n'); | ||
}); | ||
it('should print nothing if no error and no warnings', () => { | ||
const result = printConfigLintTotals({ ...totalProblemsMock, errors: 0 }); | ||
expect(result).toBeUndefined(); | ||
expect(process.stderr.write).toHaveBeenCalledTimes(0); | ||
expect(yellowColoretteMocks).toHaveBeenCalledTimes(0); | ||
expect(redColoretteMocks).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |
@@ -6,5 +6,12 @@ import { | ||
lint, | ||
loadConfig, | ||
lintConfig, | ||
findConfig, | ||
getMergedConfig, | ||
OutputFormat, | ||
makeDocumentFromString, | ||
loadConfig, | ||
stringifyYaml, | ||
RawConfig, | ||
RuleSeverity, | ||
ProblemSeverity, | ||
} from '@redocly/openapi-core'; | ||
@@ -17,3 +24,4 @@ import { | ||
printLintTotals, | ||
printUnusedWarnings, | ||
printConfigLintTotals, | ||
printUnusedWarnings | ||
} from '../utils'; | ||
@@ -24,16 +32,21 @@ import { Totals } from '../types'; | ||
export async function handleLint( | ||
argv: { | ||
entrypoints: string[]; | ||
'max-problems'?: number; | ||
'generate-ignore-file'?: boolean; | ||
'skip-rule'?: string[]; | ||
'skip-preprocessor'?: string[]; | ||
extends?: string[]; | ||
config?: string; | ||
format: OutputFormat; | ||
}, | ||
version: string, | ||
) { | ||
const config: Config = await loadConfig(argv.config, argv.extends); | ||
export type LintOptions = { | ||
entrypoints: string[]; | ||
'max-problems'?: number; | ||
'generate-ignore-file'?: boolean; | ||
'skip-rule'?: string[]; | ||
'skip-preprocessor'?: string[]; | ||
'lint-config': RuleSeverity; | ||
extends?: string[]; | ||
config?: string; | ||
format: OutputFormat; | ||
}; | ||
export async function handleLint(argv: LintOptions, version: string) { | ||
const config: Config = await loadConfig( | ||
argv.config, | ||
argv.extends, | ||
lintConfigCallback(argv, version) | ||
); | ||
const entrypoints = await getFallbackEntryPointsOrExit(argv.entrypoints, config); | ||
@@ -100,3 +113,3 @@ | ||
process.stderr.write( | ||
`Generated ignore file with ${totalIgnored} ${pluralize('problem', totalIgnored)}.\n\n`, | ||
`Generated ignore file with ${totalIgnored} ${pluralize('problem', totalIgnored)}.\n\n` | ||
); | ||
@@ -115,1 +128,29 @@ } else { | ||
} | ||
function lintConfigCallback(argv: LintOptions, version: string) { | ||
if (argv['lint-config'] === 'off') { | ||
return; | ||
} | ||
return async (config: RawConfig) => { | ||
const { 'max-problems': maxProblems, format } = argv; | ||
const configPath = findConfig(argv.config) || ''; | ||
const stringYaml = stringifyYaml(config); | ||
const configContent = makeDocumentFromString(stringYaml, configPath); | ||
const problems = await lintConfig({ | ||
document: configContent, | ||
severity: argv['lint-config'] as ProblemSeverity, | ||
}); | ||
const fileTotals = getTotals(problems); | ||
formatProblems(problems, { | ||
format, | ||
maxProblems, | ||
totals: fileTotals, | ||
version, | ||
}); | ||
printConfigLintTotals(fileTotals); | ||
}; | ||
} |
@@ -36,4 +36,4 @@ import { compile } from 'handlebars'; | ||
useRedocPro | ||
? 'https://cdn.jsdelivr.net/npm/@redocly/reference-docs@latest/dist/redocly-reference-docs.min.js' | ||
: 'https://cdn.jsdelivr.net/npm/redoc@latest/bundles/redoc.standalone.js' | ||
? 'https://cdn.redoc.ly/reference-docs/latest/redocly-reference-docs.min.js' | ||
: 'https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js' | ||
}"></script> | ||
@@ -47,3 +47,3 @@ `, | ||
useRedocPro | ||
? "window[window.__REDOC_EXPORT].setPublicPath('https://cdn.jsdelivr.net/npm/@redocly/reference-docs@latest/dist/');" | ||
? "window[window.__REDOC_EXPORT].setPublicPath('https://cdn.redoc.ly/reference-docs/latest/');" | ||
: '' | ||
@@ -50,0 +50,0 @@ } |
@@ -35,3 +35,4 @@ import * as fs from 'fs'; | ||
upsert?: boolean; | ||
'run-id'?: string; | ||
'batch-id'?: string; | ||
'batch-size'?: number; | ||
region?: Region; | ||
@@ -55,2 +56,5 @@ 'skip-decorator'?: string[]; | ||
const batchId = argv['batch-id']; | ||
const batchSize = argv['batch-size']; | ||
if ( | ||
@@ -87,2 +91,14 @@ destination && | ||
if (batchId && !batchId.trim()) { | ||
exitWithError( | ||
`The ${blue(`batch-id`)} option value is not valid, please avoid using an empty string.` | ||
); | ||
} | ||
if (batchSize && batchSize < 2) { | ||
exitWithError( | ||
`The ${blue(`batch-size`)} option value is not valid, please use the integer bigger than 1.` | ||
); | ||
} | ||
const apis = entrypoint ? { [`${name}@${version}`]: { root: entrypoint } } : config.apis; | ||
@@ -154,3 +170,5 @@ | ||
isUpsert: upsert, | ||
isPublic: argv['public'] | ||
isPublic: argv['public'], | ||
batchId: batchId, | ||
batchSize: batchSize, | ||
}); | ||
@@ -157,0 +175,0 @@ } catch (error) { |
@@ -6,3 +6,3 @@ #!/usr/bin/env node | ||
import { outputExtensions, regionChoices } from './types'; | ||
import { RedoclyClient, OutputFormat } from '@redocly/openapi-core'; | ||
import { RedoclyClient, OutputFormat, RuleSeverity } from '@redocly/openapi-core'; | ||
import { previewDocs } from './commands/preview-docs'; | ||
@@ -33,3 +33,3 @@ import { handleStats } from './commands/stats'; | ||
}), | ||
handleStats, | ||
handleStats | ||
) | ||
@@ -59,3 +59,3 @@ .command( | ||
.demandOption('entrypoint'), | ||
handleSplit, | ||
handleSplit | ||
) | ||
@@ -91,8 +91,8 @@ .command( | ||
description: 'Skip automated x-tagGroups creation', | ||
type: 'boolean' | ||
} | ||
type: 'boolean', | ||
}, | ||
}), | ||
(argv) => { | ||
handleJoin(argv, version); | ||
}, | ||
} | ||
) | ||
@@ -110,3 +110,13 @@ .command( | ||
upsert: { type: 'boolean', alias: 'u' }, | ||
'run-id': { type: 'string', requiresArg: true }, | ||
'batch-id': { | ||
description: | ||
'Specifies the ID of the CI job that the current push will be associated with.', | ||
type: 'string', | ||
requiresArg: true, | ||
}, | ||
'batch-size': { | ||
description: 'Specifies the total number of CI jobs planned to be pushed.', | ||
type: 'number', | ||
requiresArg: true, | ||
}, | ||
region: { description: 'Specify a region.', alias: 'r', choices: regionChoices }, | ||
@@ -118,8 +128,10 @@ 'skip-decorator': { | ||
}, | ||
'public': { | ||
public: { | ||
description: 'Make API registry available to the public', | ||
type: 'boolean', | ||
}, | ||
}), | ||
transformPush(handlePush), | ||
}) | ||
.implies('batch-id', 'batch-size') | ||
.implies('batch-size', 'batch-id'), | ||
transformPush(handlePush) | ||
) | ||
@@ -162,2 +174,11 @@ .command( | ||
}, | ||
'lint-config': { | ||
description: 'Apply severity for linting the config file.', | ||
choices: [ | ||
'warn', | ||
'error', | ||
'off', | ||
] as ReadonlyArray<RuleSeverity>, | ||
default: 'warn' as RuleSeverity, | ||
}, | ||
config: { | ||
@@ -177,3 +198,3 @@ description: 'Specify path to the config file.', | ||
handleLint(argv, version); | ||
}, | ||
} | ||
) | ||
@@ -254,3 +275,3 @@ .command( | ||
handleBundle(argv, version); | ||
}, | ||
} | ||
) | ||
@@ -272,3 +293,3 @@ .command( | ||
}), | ||
handleLogin, | ||
handleLogin | ||
) | ||
@@ -283,3 +304,3 @@ .command( | ||
process.stdout.write('Logged out from the Redocly account. ✋\n'); | ||
}, | ||
} | ||
) | ||
@@ -327,3 +348,3 @@ .command( | ||
}), | ||
previewDocs, | ||
previewDocs | ||
) | ||
@@ -330,0 +351,0 @@ .completion('completion', 'Generate completion script.') |
@@ -233,2 +233,20 @@ import { basename, dirname, extname, join, resolve } from 'path'; | ||
export function printConfigLintTotals(totals: Totals): void { | ||
if (totals.errors > 0) { | ||
process.stderr.write( | ||
red( | ||
`❌ Your config has ${totals.errors} ${pluralize('error', totals.errors)}${ | ||
totals.warnings > 0 | ||
? ` and ${totals.warnings} ${pluralize('warning', totals.warnings)}` | ||
: '' | ||
}.\n`, | ||
), | ||
); | ||
} else if (totals.warnings > 0) { | ||
process.stderr.write( | ||
yellow(`You have ${totals.warnings} ${pluralize('warning', totals.warnings)}.\n`), | ||
); | ||
}; | ||
} | ||
export function getOutputFileName( | ||
@@ -293,3 +311,3 @@ entrypoint: string, | ||
if (rules.length || preprocessors.length) { | ||
process.stderr.write(`Check the spelling and verify you added plugin prefix.\n`); | ||
process.stderr.write(`Check the spelling and verify the added plugin prefix.\n`); | ||
} | ||
@@ -296,0 +314,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
321646
98
7074
17
+ Added@redocly/openapi-core@1.0.0-beta.103(transitive)
- Removed@redocly/openapi-core@1.0.0-beta.102(transitive)