Skip to content

Commit

Permalink
chore: fix output formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tatomyr committed Jan 2, 2025
1 parent 704ee33 commit aec9136
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
8 changes: 4 additions & 4 deletions __tests__/miscellaneous/apply-per-api-decorators/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ components:
bundling nested/openapi/main.yaml...
📦 Created a bundle for nested/openapi/main.yaml at stdout <test>ms.
bundling https:/raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml...
📦 Created a bundle for https:/raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml at stdout <test>ms.
bundling https://raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml...
📦 Created a bundle for https://raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml at stdout <test>ms.
`;

exports[`E2E miscellaneous lint a specific api (when the api is specified as an alias and it points to an external URL) 1`] = `
validating https:/raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml...
validating https://raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml...
[1] https://raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml:2:1 at #/info/contact
Info object should contain \`contact\` field.
Expand All @@ -58,7 +58,7 @@ Info object should contain \`contact\` field.
Error was generated by the info-contact rule.
https:/raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml: validated in <test>ms
https://raw.githubusercontent.com/Redocly/redocly-cli/refs/heads/main/__tests__/miscellaneous/apply-per-api-decorators/nested/openapi/main.yaml: validated in <test>ms
❌ Validation failed with 1 error.
run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file.
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/commands/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
saveBundle,
sortTopLevelKeysForOas,
checkForDeprecatedOptions,
formatPath,
} from '../utils/miscellaneous';

import type { OutputExtensions, Skips, Totals, VerifyConfigOptions } from '../types';
Expand Down Expand Up @@ -55,7 +56,7 @@ export async function handleBundle({
styleguide.skipPreprocessors(argv['skip-preprocessor']);
styleguide.skipDecorators(argv['skip-decorator']);

process.stderr.write(gray(`bundling ${relative(process.cwd(), path)}...\n`));
process.stderr.write(gray(`bundling ${formatPath(path)}...\n`));

const {
bundle: result,
Expand Down Expand Up @@ -118,20 +119,20 @@ export async function handleBundle({
if (fileTotals.errors > 0) {
if (argv.force) {
process.stderr.write(
`❓ Created a bundle for ${blue(relative(process.cwd(), path))} at ${blue(
`❓ Created a bundle for ${blue(formatPath(path))} at ${blue(
outputFile || 'stdout'
)} with errors ${green(elapsed)}.\n${yellow('Errors ignored because of --force')}.\n`
);
} else {
process.stderr.write(
`❌ Errors encountered while bundling ${blue(
relative(process.cwd(), path)
formatPath(path)
)}: bundle not created (use --force to ignore errors).\n`
);
}
} else {
process.stderr.write(
`📦 Created a bundle for ${blue(relative(process.cwd(), path))} at ${blue(
`📦 Created a bundle for ${blue(formatPath(path))} at ${blue(
outputFile || 'stdout'
)} ${green(elapsed)}.\n`
);
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { pluralize } from '@redocly/openapi-core/lib/utils';
import {
checkIfRulesetExist,
exitWithError,
formatPath,
getExecutionTime,
getFallbackApisOrExit,
handleError,
Expand Down Expand Up @@ -75,7 +76,7 @@ export async function handleLint({
)} configuration by default.\n\n`
);
}
process.stderr.write(gray(`validating ${relative(process.cwd(), path)}...\n`));
process.stderr.write(gray(`validating ${formatPath(path)}...\n`));
const results = await lint({
ref: path,
config: resolvedConfig,
Expand All @@ -102,7 +103,7 @@ export async function handleLint({
}

const elapsed = getExecutionTime(startedAt);
process.stderr.write(gray(`${relative(process.cwd(), path)}: validated in ${elapsed}\n\n`));
process.stderr.write(gray(`${formatPath(path)}: validated in ${elapsed}\n\n`));
} catch (e) {
handleError(e, path);
}
Expand Down
9 changes: 8 additions & 1 deletion packages/cli/src/utils/miscellaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function getFallbackApisOrExit(
if (isNotEmptyArray(filteredInvalidEntrypoints)) {
for (const { path } of filteredInvalidEntrypoints) {
process.stderr.write(
yellow(`\n${relative(process.cwd(), path)} ${red(`does not exist or is invalid.\n\n`)}`)
yellow(`\n${formatPath(path)} ${red(`does not exist or is invalid.\n\n`)}`)
);
}
exitWithError('Please provide a valid path.');
Expand Down Expand Up @@ -702,3 +702,10 @@ export function notifyAboutIncompatibleConfigOptions(
}
}
}

export function formatPath(path: string) {
if (isAbsoluteUrl(path)) {
return path;
}
return relative(process.cwd(), path);
}

0 comments on commit aec9136

Please sign in to comment.