mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-10 23:02:56 +02:00
feat(logger): new "url" format, add double quotes around paths (#7019)
* refactor(logger): add double quotes around paths * Introduce url formatter * Fix
This commit is contained in:
parent
2bcac29cd4
commit
a307da0b9f
7 changed files with 21 additions and 11 deletions
|
@ -11,7 +11,12 @@ import logger from '../index';
|
|||
describe('formatters', () => {
|
||||
it('path', () => {
|
||||
// cSpell:ignore mhey
|
||||
expect(logger.path('hey')).toMatchInlineSnapshot(`"[36m[4mhey[24m[39m"`);
|
||||
expect(logger.path('hey')).toMatchInlineSnapshot(`"[36m[4m\\"hey\\"[24m[39m"`);
|
||||
});
|
||||
it('url', () => {
|
||||
expect(logger.url('https://docusaurus.io/')).toMatchInlineSnapshot(
|
||||
`"[36m[4mhttps://docusaurus.io/[24m[39m"`,
|
||||
);
|
||||
});
|
||||
it('id', () => {
|
||||
expect(logger.name('hey')).toMatchInlineSnapshot(`"[34m[1mhey[22m[39m"`);
|
||||
|
@ -40,8 +45,7 @@ describe('interpolate', () => {
|
|||
expect(
|
||||
logger.interpolate`The package at path=${'packages/docusaurus'} has number=${10} files. name=${'Babel'} is exported here subdue=${'(as a preset)'} that you can with code=${"require.resolve('@docusaurus/core/lib/babel/preset')"}`,
|
||||
).toMatchInlineSnapshot(
|
||||
// cSpell:ignore mpackages
|
||||
`"The package at [36m[4mpackages/docusaurus[24m[39m has [33m10[39m files. [34m[1mBabel[22m[39m is exported here [90m(as a preset)[39m that you can with [36m\`require.resolve('@docusaurus/core/lib/babel/preset')\`[39m"`,
|
||||
`"The package at [36m[4m\\"packages/docusaurus\\"[24m[39m has [33m10[39m files. [34m[1mBabel[22m[39m is exported here [90m(as a preset)[39m that you can with [36m\`require.resolve('@docusaurus/core/lib/babel/preset')\`[39m"`,
|
||||
);
|
||||
});
|
||||
it('interpolates arrays with flags', () => {
|
||||
|
|
|
@ -9,7 +9,8 @@ import chalk, {type Chalk} from 'chalk';
|
|||
|
||||
type InterpolatableValue = string | number | (string | number)[];
|
||||
|
||||
const path = (msg: unknown): string => chalk.cyan(chalk.underline(msg));
|
||||
const path = (msg: unknown): string => chalk.cyan(chalk.underline(`"${msg}"`));
|
||||
const url = (msg: unknown): string => chalk.cyan(chalk.underline(msg));
|
||||
const name = (msg: unknown): string => chalk.blue(chalk.bold(msg));
|
||||
const code = (msg: unknown): string => chalk.cyan(`\`${msg}\``);
|
||||
const subdue: Chalk = chalk.gray;
|
||||
|
@ -30,6 +31,8 @@ function interpolate(
|
|||
switch (flag[0]) {
|
||||
case 'path=':
|
||||
return path;
|
||||
case 'url=':
|
||||
return url;
|
||||
case 'number=':
|
||||
return num;
|
||||
case 'name=':
|
||||
|
@ -131,6 +134,7 @@ const logger = {
|
|||
bold: chalk.bold,
|
||||
dim: chalk.dim,
|
||||
path,
|
||||
url,
|
||||
name,
|
||||
code,
|
||||
subdue,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue