diff --git a/packages/docusaurus-init/bin/index.js b/packages/docusaurus-init/bin/index.js index 242f4c5e7fa5..c661f56c6761 100755 --- a/packages/docusaurus-init/bin/index.js +++ b/packages/docusaurus-init/bin/index.js @@ -7,7 +7,7 @@ * LICENSE file in the root directory of this source tree. */ -const chalk = require('chalk'); +const colorette = require('colorette'); const semver = require('semver'); const path = require('path'); const program = require('commander'); @@ -16,8 +16,8 @@ const requiredVersion = require('../package.json').engines.node; if (!semver.satisfies(process.version, requiredVersion)) { console.log( - chalk.red(`\nMinimum node version not met :)`) + - chalk.yellow( + colorette.red(`\nMinimum node version not met :)`) + + colorette.yellow( `\nYou are using Node ${process.version}, Requirement: Node ${requiredVersion}.\n`, ), ); @@ -27,7 +27,7 @@ if (!semver.satisfies(process.version, requiredVersion)) { function wrapCommand(fn) { return (...args) => fn(...args).catch((err) => { - console.error(chalk.red(err.stack)); + console.error(colorette.red(err.stack)); process.exitCode = 1; }); } @@ -50,7 +50,9 @@ program program.arguments('').action((cmd) => { program.outputHelp(); - console.log(` ${chalk.red(`\n Unknown command ${chalk.yellow(cmd)}.`)}`); + console.log( + ` ${colorette.red(`\n Unknown command ${colorette.yellow(cmd)}.`)}`, + ); console.log(); }); diff --git a/packages/docusaurus-init/package.json b/packages/docusaurus-init/package.json index 641207424305..03915270835a 100644 --- a/packages/docusaurus-init/package.json +++ b/packages/docusaurus-init/package.json @@ -22,7 +22,7 @@ }, "license": "MIT", "dependencies": { - "chalk": "^4.1.0", + "colorette": "^1.2.2", "commander": "^5.1.0", "fs-extra": "^9.1.0", "lodash": "^4.17.20", diff --git a/packages/docusaurus-init/src/index.ts b/packages/docusaurus-init/src/index.ts index bb096f6f2d5a..bc114c064467 100644 --- a/packages/docusaurus-init/src/index.ts +++ b/packages/docusaurus-init/src/index.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import chalk from 'chalk'; +import colorette from 'colorette'; import fs from 'fs-extra'; import {execSync} from 'child_process'; import prompts, {Choice} from 'prompts'; @@ -76,7 +76,7 @@ export default async function init( } if (!name) { - throw new Error(chalk.red('A site name is required')); + throw new Error(colorette.red('A site name is required')); } const dest = path.resolve(rootDir, name); @@ -105,7 +105,7 @@ export default async function init( if (url && isValidGitRepoUrl(url)) { return true; } - return chalk.red(`Invalid repository URL`); + return colorette.red(`Invalid repository URL`); }, message: 'Enter a repository URL from GitHub, BitBucket, GitLab, or any other public repo. \n(e.g: https://github.com/ownerName/repoName.git)', @@ -114,16 +114,18 @@ export default async function init( } console.log(); - console.log(chalk.cyan('Creating new Docusaurus project ...')); + console.log(colorette.cyan('Creating new Docusaurus project ...')); console.log(); if (template && isValidGitRepoUrl(template)) { - console.log(`Cloning Git template: ${chalk.cyan(template)}`); + console.log(`Cloning Git template: ${colorette.cyan(template)}`); if ( shell.exec(`git clone --recursive ${template} ${dest}`, {silent: true}) .code !== 0 ) { - throw new Error(chalk.red(`Cloning Git template: ${template} failed!`)); + throw new Error( + colorette.red(`Cloning Git template: ${template} failed!`), + ); } } else if (template && templates.includes(template)) { // Docusaurus templates. @@ -131,7 +133,7 @@ export default async function init( await fs.copy(path.resolve(templatesDir, template), dest); } catch (err) { console.log( - `Copying Docusaurus template: ${chalk.cyan(template)} failed!`, + `Copying Docusaurus template: ${colorette.cyan(template)} failed!`, ); throw err; } @@ -147,7 +149,7 @@ export default async function init( private: true, }); } catch (err) { - console.log(chalk.red('Failed to update package.json')); + console.log(colorette.red('Failed to update package.json')); throw err; } @@ -164,12 +166,12 @@ export default async function init( const pkgManager = useYarn ? 'yarn' : 'npm'; if (!cliOptions.skipInstall) { - console.log(`Installing dependencies with: ${chalk.cyan(pkgManager)}`); + console.log(`Installing dependencies with: ${colorette.cyan(pkgManager)}`); try { shell.exec(`cd "${name}" && ${useYarn ? 'yarn' : 'npm install'}`); } catch (err) { - console.log(chalk.red('Installation failed')); + console.log(colorette.red('Installation failed')); throw err; } } @@ -182,22 +184,22 @@ export default async function init( : path.relative(process.cwd(), name); console.log(); - console.log(`Success! Created ${chalk.cyan(cdpath)}`); + console.log(`Success! Created ${colorette.cyan(cdpath)}`); console.log('Inside that directory, you can run several commands:'); console.log(); - console.log(chalk.cyan(` ${pkgManager} start`)); + console.log(colorette.cyan(` ${pkgManager} start`)); console.log(' Starts the development server.'); console.log(); - console.log(chalk.cyan(` ${pkgManager} ${useYarn ? '' : 'run '}build`)); + console.log(colorette.cyan(` ${pkgManager} ${useYarn ? '' : 'run '}build`)); console.log(' Bundles the app into static files for production.'); console.log(); - console.log(chalk.cyan(` ${pkgManager} deploy`)); + console.log(colorette.cyan(` ${pkgManager} deploy`)); console.log(' Publish website to GitHub pages.'); console.log(); console.log('We suggest that you begin by typing:'); console.log(); - console.log(chalk.cyan(' cd'), cdpath); - console.log(` ${chalk.cyan(`${pkgManager} start`)}`); + console.log(colorette.cyan(' cd'), cdpath); + console.log(` ${colorette.cyan(`${pkgManager} start`)}`); console.log(); console.log('Happy hacking!'); diff --git a/packages/docusaurus-migrate/bin/index.js b/packages/docusaurus-migrate/bin/index.js index a9d0a901ae34..dc37af34353b 100755 --- a/packages/docusaurus-migrate/bin/index.js +++ b/packages/docusaurus-migrate/bin/index.js @@ -7,7 +7,7 @@ * LICENSE file in the root directory of this source tree. */ -const chalk = require('chalk'); +const colorette = require('colorette'); const semver = require('semver'); const cli = require('commander'); const path = require('path'); @@ -19,15 +19,15 @@ const {migrateDocusaurusProject, migrateMDToMDX} = require('../lib'); function wrapCommand(fn) { return (...args) => fn(...args).catch((err) => { - console.error(chalk.red(err.stack)); + console.error(colorette.red(err.stack)); process.exitCode = 1; }); } if (!semver.satisfies(process.version, requiredVersion)) { console.log( - chalk.red(`\nMinimum Node version not met :(`) + - chalk.yellow( + colorette.red(`\nMinimum Node version not met :(`) + + colorette.yellow( `\n\nYou are using Node ${process.version}. We require Node ${requiredVersion} or up!\n`, ), ); diff --git a/packages/docusaurus-migrate/package.json b/packages/docusaurus-migrate/package.json index 78f050621406..00a40c7aa8cd 100644 --- a/packages/docusaurus-migrate/package.json +++ b/packages/docusaurus-migrate/package.json @@ -25,8 +25,8 @@ "dependencies": { "@babel/preset-env": "^7.12.16", "@mapbox/hast-util-to-jsx": "^1.0.0", - "chalk": "^4.1.0", "color": "^3.1.3", + "colorette": "^1.2.2", "commander": "^5.1.0", "fs-extra": "^9.1.0", "glob": "^7.1.6", diff --git a/packages/docusaurus-migrate/src/index.ts b/packages/docusaurus-migrate/src/index.ts index 4f2a5ceb7eaf..8b204e47a573 100644 --- a/packages/docusaurus-migrate/src/index.ts +++ b/packages/docusaurus-migrate/src/index.ts @@ -7,7 +7,7 @@ import * as fs from 'fs-extra'; import importFresh from 'import-fresh'; -import chalk from 'chalk'; +import colorette from 'colorette'; import glob from 'glob'; import Color from 'color'; @@ -113,24 +113,24 @@ export async function migrateDocusaurusProject( try { createClientRedirects(siteConfig, deps, config); console.log( - chalk.green('Successfully created client redirect for non clean URL'), + colorette.green('Successfully created client redirect for non clean URL'), ); } catch (errorInClientRedirect) { console.log( - chalk.red(`Error while creating redirects: ${errorInClientRedirect}`), + colorette.red(`Error while creating redirects: ${errorInClientRedirect}`), ); } if (shouldMigratePages) { try { createPages(newDir, siteDir); console.log( - chalk.green( + colorette.green( 'Successfully created pages (check migration page for more details)', ), ); } catch (errorInMigratingPages) { console.log( - chalk.red( + colorette.red( `Error occurred while creating pages: ${errorInMigratingPages}`, ), ); @@ -139,13 +139,13 @@ export async function migrateDocusaurusProject( try { createDefaultLandingPage(newDir); console.log( - chalk.green( + colorette.green( 'Successfully created landing page (check migration page for more details)', ), ); } catch (errorInLandingPage) { console.log( - chalk.red( + colorette.red( `Error occurred while creating landing page: ${errorInLandingPage}`, ), ); @@ -154,17 +154,19 @@ export async function migrateDocusaurusProject( try { migrateStaticFiles(siteDir, newDir); - console.log(chalk.green('Successfully migrated static folder')); + console.log(colorette.green('Successfully migrated static folder')); } catch (errorInStatic) { console.log( - chalk.red(`Error occurred while copying static folder: ${errorInStatic}`), + colorette.red( + `Error occurred while copying static folder: ${errorInStatic}`, + ), ); } try { migrateBlogFiles(siteDir, newDir, classicPreset, shouldMigrateMdFiles); } catch (errorInMigratingBlogs) { console.log( - chalk.red( + colorette.red( `Error occurred while migrating blogs: ${errorInMigratingBlogs}`, ), ); @@ -173,7 +175,7 @@ export async function migrateDocusaurusProject( handleVersioning(siteDir, siteConfig, newDir, config, shouldMigrateMdFiles); } catch (errorInVersion) { console.log( - chalk.red( + colorette.red( `Error occurred while migrating versioned docs: ${errorInVersion}`, ), ); @@ -182,13 +184,15 @@ export async function migrateDocusaurusProject( try { migrateLatestDocs(siteDir, newDir, shouldMigrateMdFiles, classicPreset); } catch (errorInDoc) { - chalk.red(`Error occurred while migrating docs: ${errorInDoc}`); + colorette.red(`Error occurred while migrating docs: ${errorInDoc}`); } try { migrateLatestSidebar(siteDir, newDir, classicPreset, siteConfig); } catch (error) { - console.log(chalk.red(`Error occurred while migrating sidebar: ${error}`)); + console.log( + colorette.red(`Error occurred while migrating sidebar: ${error}`), + ); } try { @@ -197,20 +201,20 @@ export async function migrateDocusaurusProject( `module.exports=${JSON.stringify(config, null, 2)}`, ); console.log( - chalk.green( + colorette.green( `Successfully created a new config file with new navbar and footer config`, ), ); } catch (error) { console.log( - chalk.red(`Error occurred while creating config file: ${error}`), + colorette.red(`Error occurred while creating config file: ${error}`), ); } try { migratePackageFile(siteDir, deps, newDir); } catch (error) { console.log( - chalk.red( + colorette.red( `Error occurred while creating package.json file for project: ${error}`, ), ); @@ -275,9 +279,9 @@ export function createConfigFile({ } }); console.log( - `${chalk.yellow( + `${colorette.yellow( 'Following Fields from siteConfig.js will be added to docusaurus.config.js in `customFields`', - )}\n${chalk.yellow(Object.keys(customConfigFields).join('\n'))}`, + )}\n${colorette.yellow(Object.keys(customConfigFields).join('\n'))}`, ); let v2DocsPath: string | undefined; @@ -415,7 +419,7 @@ function createPages(newDir: string, siteDir: string): void { fs.writeFileSync(filePath, migratePage(content)); }); } catch (error) { - console.log(chalk.red(`Unable to migrate Pages : ${error}`)); + console.log(colorette.red(`Unable to migrate Pages : ${error}`)); createDefaultLandingPage(newDir); } } else { @@ -458,12 +462,14 @@ function migrateBlogFiles( }); classicPreset.blog.path = 'blog'; console.log( - chalk.green( + colorette.green( `Successfully migrated blogs to version 2 with change in frontmatter`, ), ); } else { - console.log(chalk.yellow(`Blog not found. Skipping migration for blog`)); + console.log( + colorette.yellow(`Blog not found. Skipping migration for blog`), + ); } } @@ -495,7 +501,7 @@ function handleVersioning( migrateMDFiles, ); console.log( - chalk.green( + colorette.green( `Successfully migrated version docs and sidebar. The following doc versions have been created: \n${loadedVersions.join( '\n', )}`, @@ -503,7 +509,7 @@ function handleVersioning( ); } else { console.log( - chalk.yellow( + colorette.yellow( 'Versioned docs not found. Skipping migration for versioned docs', ), ); @@ -698,7 +704,7 @@ function migrateLatestSidebar( ); } catch { console.log( - chalk.yellow(`Sidebar not found. Skipping migration for sidebar`), + colorette.yellow(`Sidebar not found. Skipping migration for sidebar`), ); } if (siteConfig.colors) { @@ -740,10 +746,10 @@ function migrateLatestDocs( const content = String(fs.readFileSync(file)); fs.writeFileSync(file, sanitizedFileContent(content, migrateMDFiles)); }); - console.log(chalk.green(`Successfully migrated docs to version 2`)); + console.log(colorette.green(`Successfully migrated docs to version 2`)); } else { console.log( - chalk.yellow(`Docs folder not found. Skipping migration for docs`), + colorette.yellow(`Docs folder not found. Skipping migration for docs`), ); } } @@ -782,7 +788,7 @@ function migratePackageFile( path.join(newDir, 'package.json'), JSON.stringify(packageFile, null, 2), ); - console.log(chalk.green(`Successfully migrated package.json file`)); + console.log(colorette.green(`Successfully migrated package.json file`)); } export async function migrateMDToMDX( diff --git a/packages/docusaurus-plugin-client-redirects/package.json b/packages/docusaurus-plugin-client-redirects/package.json index 30a7af5204c6..38679ed86261 100644 --- a/packages/docusaurus-plugin-client-redirects/package.json +++ b/packages/docusaurus-plugin-client-redirects/package.json @@ -21,7 +21,7 @@ "@docusaurus/types": "2.0.0-alpha.72", "@docusaurus/utils": "2.0.0-alpha.72", "@docusaurus/utils-validation": "2.0.0-alpha.72", - "chalk": "^3.0.0", + "colorette": "^1.2.2", "eta": "^1.11.0", "fs-extra": "^9.1.0", "globby": "^11.0.2", diff --git a/packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts b/packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts index 599990b2a436..06c4c6188930 100644 --- a/packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts +++ b/packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts @@ -18,7 +18,7 @@ import { } from './extensionRedirects'; import {validateRedirect} from './redirectValidation'; -import chalk from 'chalk'; +import colorette from 'colorette'; export default function collectRedirects( pluginContext: PluginContext, @@ -75,7 +75,7 @@ function filterUnwantedRedirects( ([from, groupedFromRedirects]) => { if (groupedFromRedirects.length > 1) { console.error( - chalk.red( + colorette.red( `@docusaurus/plugin-client-redirects: multiple redirects are created with the same "from" pathname=${from} It is not possible to redirect the same pathname to multiple destinations: - ${groupedFromRedirects.map((r) => JSON.stringify(r)).join('\n- ')} @@ -93,7 +93,7 @@ It is not possible to redirect the same pathname to multiple destinations: ); if (redirectsOverridingExistingPath.length > 0) { console.error( - chalk.red( + colorette.red( `@docusaurus/plugin-client-redirects: some redirects would override existing paths, and will be ignored: - ${redirectsOverridingExistingPath.map((r) => JSON.stringify(r)).join('\n- ')} `, diff --git a/packages/docusaurus-plugin-content-blog/package.json b/packages/docusaurus-plugin-content-blog/package.json index 2d4264d502d1..a58c4f0799e6 100644 --- a/packages/docusaurus-plugin-content-blog/package.json +++ b/packages/docusaurus-plugin-content-blog/package.json @@ -23,7 +23,7 @@ "@docusaurus/types": "2.0.0-alpha.72", "@docusaurus/utils": "2.0.0-alpha.72", "@docusaurus/utils-validation": "2.0.0-alpha.72", - "chalk": "^4.1.0", + "colorette": "^1.2.2", "feed": "^4.2.2", "fs-extra": "^9.1.0", "globby": "^11.0.2", diff --git a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts index c0465346eb1c..298f234fce78 100644 --- a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts +++ b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts @@ -7,7 +7,7 @@ import fs from 'fs-extra'; import globby from 'globby'; -import chalk from 'chalk'; +import colorette from 'colorette'; import path from 'path'; import readingTime from 'reading-time'; import {Feed} from 'feed'; @@ -152,7 +152,7 @@ export async function generateBlogPosts( if (frontMatter.id) { console.warn( - chalk.yellow( + colorette.yellow( `${blogFileName} - 'id' header option is deprecated. Please use 'slug' option instead.`, ), ); diff --git a/packages/docusaurus-plugin-content-docs/package.json b/packages/docusaurus-plugin-content-docs/package.json index 4956f93069e3..4d4d5d54fc48 100644 --- a/packages/docusaurus-plugin-content-docs/package.json +++ b/packages/docusaurus-plugin-content-docs/package.json @@ -29,7 +29,7 @@ "@docusaurus/types": "2.0.0-alpha.72", "@docusaurus/utils": "2.0.0-alpha.72", "@docusaurus/utils-validation": "2.0.0-alpha.72", - "chalk": "^4.1.0", + "colorette": "^1.2.2", "execa": "^5.0.0", "fs-extra": "^9.1.0", "globby": "^11.0.2", diff --git a/packages/docusaurus-plugin-content-docs/src/options.ts b/packages/docusaurus-plugin-content-docs/src/options.ts index e7f7bcb1c71b..8f6cc67040fd 100644 --- a/packages/docusaurus-plugin-content-docs/src/options.ts +++ b/packages/docusaurus-plugin-content-docs/src/options.ts @@ -13,7 +13,7 @@ import { URISchema, } from '@docusaurus/utils-validation'; import {OptionValidationContext, ValidationResult} from '@docusaurus/types'; -import chalk from 'chalk'; +import colorette from 'colorette'; import admonitions from 'remark-admonitions'; export const DEFAULT_OPTIONS: Omit = { @@ -96,7 +96,7 @@ export function validateOptions({ // "slug: /" is better because the home doc can be different across versions if (options.homePageId) { console.log( - chalk.red( + colorette.red( `The docs plugin option homePageId=${options.homePageId} is deprecated. To make a doc the "home", prefer frontmatter: "slug: /"`, ), ); @@ -104,7 +104,7 @@ export function validateOptions({ if (typeof options.excludeNextVersionDocs !== 'undefined') { console.log( - chalk.red( + colorette.red( `The docs plugin option excludeNextVersionDocs=${ options.excludeNextVersionDocs } is deprecated. Use the includeCurrentVersion=${!options.excludeNextVersionDocs} option instead!"`, diff --git a/packages/docusaurus-plugin-content-docs/src/versions.ts b/packages/docusaurus-plugin-content-docs/src/versions.ts index 732d9eecd77c..a7ad5b731ca6 100644 --- a/packages/docusaurus-plugin-content-docs/src/versions.ts +++ b/packages/docusaurus-plugin-content-docs/src/versions.ts @@ -24,7 +24,7 @@ import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants'; import {LoadContext} from '@docusaurus/types'; import {getPluginI18nPath, normalizeUrl, posixPath} from '@docusaurus/utils'; import {difference} from 'lodash'; -import chalk from 'chalk'; +import colorette from 'colorette'; // retro-compatibility: no prefix for the default plugin id function addPluginIdPrefix(fileOrDir: string, pluginId: string): string { @@ -343,7 +343,7 @@ function checkVersionMetadataPaths({ // See https://github.com/facebook/docusaurus/issues/3366 if (!fs.existsSync(sidebarFilePath)) { console.log( - chalk.yellow( + colorette.yellow( `The sidebar file of docs version [${versionName}] does not exist. It is optional, but should rather be provided at ${sidebarFilePath}`, ), ); diff --git a/packages/docusaurus-theme-classic/package.json b/packages/docusaurus-theme-classic/package.json index b365f32da8af..0e48432152f8 100644 --- a/packages/docusaurus-theme-classic/package.json +++ b/packages/docusaurus-theme-classic/package.json @@ -34,8 +34,8 @@ "@mdx-js/mdx": "^1.6.21", "@mdx-js/react": "^1.6.21", "@types/react-toggle": "^4.0.2", - "chalk": "^4.1.0", "clsx": "^1.1.1", + "colorette": "^1.2.2", "copy-text-to-clipboard": "^3.0.0", "fs-extra": "^9.1.0", "globby": "^11.0.2", diff --git a/packages/docusaurus-theme-classic/update-code-translations.js b/packages/docusaurus-theme-classic/update-code-translations.js index d4ef57fe3e5b..d54bbd70c286 100644 --- a/packages/docusaurus-theme-classic/update-code-translations.js +++ b/packages/docusaurus-theme-classic/update-code-translations.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -const chalk = require('chalk'); +const colorette = require('colorette'); const path = require('path'); const fs = require('fs-extra'); const globby = require('globby'); @@ -41,7 +41,7 @@ function logSection(title) { console.log(``); console.log(``); console.log(`##############################`); - console.log(`## ${chalk.blue(title)}`); + console.log(`## ${colorette.blue(title)}`); } function logKeys(keys) { @@ -135,7 +135,7 @@ async function updateBaseFile(baseFile) { if (unknownMessages.length) { console.log( - chalk.red(`Some messages exist in base.json but were not found by the code extractor! + colorette.red(`Some messages exist in base.json but were not found by the code extractor! They won't be removed automatically, so do the cleanup manually if necessary! ${logKeys(unknownMessages)}`), ); @@ -177,7 +177,7 @@ async function updateLocaleCodeTranslations(localeFile, baseFileMessages) { if (unknownMessages.length) { console.log( - chalk.red(`Some localized messages do not exist in base.json! + colorette.red(`Some localized messages do not exist in base.json! You may want to delete these! ${logKeys(unknownMessages)}`), ); @@ -196,7 +196,7 @@ ${logKeys(unknownMessages)}`), if (untranslatedKeys.length) { console.warn( - chalk.yellow(`Some messages do not seem to be translated! + colorette.yellow(`Some messages do not seem to be translated! ${logKeys(untranslatedKeys)}`), ); } @@ -221,12 +221,14 @@ function run() { updateCodeTranslations().then( () => { console.log(''); - console.log(chalk.green('updateCodeTranslations end')); + console.log(colorette.green('updateCodeTranslations end')); console.log(''); }, (e) => { console.log(''); - console.error(chalk.red(`updateCodeTranslations failure: ${e.message}`)); + console.error( + colorette.red(`updateCodeTranslations failure: ${e.message}`), + ); console.log(''); console.error(e.stack); console.log(''); diff --git a/packages/docusaurus-utils-validation/package.json b/packages/docusaurus-utils-validation/package.json index 158e15d48054..6dc8dd423394 100644 --- a/packages/docusaurus-utils-validation/package.json +++ b/packages/docusaurus-utils-validation/package.json @@ -19,7 +19,7 @@ "license": "MIT", "dependencies": { "@docusaurus/utils": "2.0.0-alpha.72", - "chalk": "^4.1.0", + "colorette": "^1.2.2", "joi": "^17.4.0", "tslib": "^2.1.0" }, diff --git a/packages/docusaurus-utils-validation/src/validationUtils.ts b/packages/docusaurus-utils-validation/src/validationUtils.ts index 1ec61a338d51..326bd1a18a51 100644 --- a/packages/docusaurus-utils-validation/src/validationUtils.ts +++ b/packages/docusaurus-utils-validation/src/validationUtils.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ import Joi from './Joi'; -import chalk from 'chalk'; +import colorette from 'colorette'; import {PluginIdSchema} from './validationSchemas'; // TODO temporary escape hatch for alpha-60: to be removed soon @@ -19,7 +19,7 @@ export const isValidationDisabledEscapeHatch = if (isValidationDisabledEscapeHatch) { console.error( - chalk.red( + colorette.red( 'You should avoid using DISABLE_DOCUSAURUS_VALIDATION escape hatch, this will be removed', ), ); @@ -27,7 +27,7 @@ if (isValidationDisabledEscapeHatch) { export const logValidationBugReportHint = (): void => { console.log( - `\n${chalk.red('A validation error occured.')}${chalk.cyanBright( + `\n${colorette.red('A validation error occured.')}${colorette.cyanBright( '\nThe validation system was added recently to Docusaurus as an attempt to avoid user configuration errors.' + '\nWe may have made some mistakes.' + '\nIf you think your configuration is valid and should keep working, please open a bug report.', diff --git a/packages/docusaurus-utils/package.json b/packages/docusaurus-utils/package.json index fd05c998b2f1..e856c9bd5fa7 100644 --- a/packages/docusaurus-utils/package.json +++ b/packages/docusaurus-utils/package.json @@ -20,7 +20,7 @@ "dependencies": { "@docusaurus/types": "2.0.0-alpha.72", "@types/github-slugger": "^1.3.0", - "chalk": "^4.1.0", + "colorette": "^1.2.2", "escape-string-regexp": "^4.0.0", "fs-extra": "^9.1.0", "gray-matter": "^4.0.2", diff --git a/packages/docusaurus-utils/src/index.ts b/packages/docusaurus-utils/src/index.ts index 35b0df6b3196..d477b9d67ec9 100644 --- a/packages/docusaurus-utils/src/index.ts +++ b/packages/docusaurus-utils/src/index.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import chalk from 'chalk'; +import colorette from 'colorette'; import path from 'path'; import matter from 'gray-matter'; import {createHash} from 'crypto'; @@ -588,13 +588,19 @@ export function reportMessage( case 'ignore': break; case 'log': - console.log(chalk.bold.blue('info ') + chalk.blue(message)); + console.log( + colorette.bold(colorette.blue('info ')) + colorette.blue(message), + ); break; case 'warn': - console.warn(chalk.bold.yellow('warn ') + chalk.yellow(message)); + console.warn( + colorette.bold(colorette.yellow('warn ')) + colorette.yellow(message), + ); break; case 'error': - console.error(chalk.bold.red('error ') + chalk.red(message)); + console.error( + colorette.bold(colorette.red('error ')) + colorette.red(message), + ); break; case 'throw': throw new Error(message); diff --git a/packages/docusaurus/bin/docusaurus.js b/packages/docusaurus/bin/docusaurus.js index cb153e8f1b71..74bad332e68e 100755 --- a/packages/docusaurus/bin/docusaurus.js +++ b/packages/docusaurus/bin/docusaurus.js @@ -7,7 +7,7 @@ * LICENSE file in the root directory of this source tree. */ -const chalk = require('chalk'); +const colorette = require('colorette'); const fs = require('fs-extra'); const semver = require('semver'); const path = require('path'); @@ -65,11 +65,11 @@ if (notifier.update && notifier.update.current !== notifier.update.latest) { }; const docusaurusUpdateMessage = boxen( - `Update available ${chalk.dim(`${notifier.update.current}`)}${chalk.reset( - ' → ', - )}${chalk.green( + `Update available ${colorette.dim( + `${notifier.update.current}`, + )}${colorette.reset(' → ')}${colorette.green( `${notifier.update.latest}`, - )}\n\nTo upgrade Docusaurus packages with the latest version, run the following command:\n${chalk.cyan( + )}\n\nTo upgrade Docusaurus packages with the latest version, run the following command:\n${colorette.cyan( `${upgradeCommand}`, )}`, boxenOptions, @@ -81,8 +81,8 @@ if (notifier.update && notifier.update.current !== notifier.update.latest) { // notify user if node version needs to be updated if (!semver.satisfies(process.version, requiredVersion)) { console.log( - chalk.red(`\nMinimum Node version not met :(`) + - chalk.yellow( + colorette.red(`\nMinimum Node version not met :(`) + + colorette.yellow( `\n\nYou are using Node ${process.version}. We require Node ${requiredVersion} or up!\n`, ), ); @@ -92,7 +92,7 @@ if (!semver.satisfies(process.version, requiredVersion)) { function wrapCommand(fn) { return (...args) => fn(...args).catch((err) => { - console.error(chalk.red(err.stack)); + console.error(colorette.red(err.stack)); process.exitCode = 1; }); } @@ -294,7 +294,9 @@ cli cli.arguments('').action((cmd) => { cli.outputHelp(); - console.log(` ${chalk.red(`\n Unknown command ${chalk.yellow(cmd)}.`)}`); + console.log( + ` ${colorette.red(`\n Unknown command ${colorette.yellow(cmd)}.`)}`, + ); console.log(); }); diff --git a/packages/docusaurus/package.json b/packages/docusaurus/package.json index dd63a030d05a..4c654e57e3ed 100644 --- a/packages/docusaurus/package.json +++ b/packages/docusaurus/package.json @@ -61,9 +61,9 @@ "babel-plugin-dynamic-import-node": "2.3.0", "boxen": "^5.0.0", "cache-loader": "^4.1.0", - "chalk": "^4.1.0", "chokidar": "^3.5.1", "clean-css": "^5.1.1", + "colorette": "^1.2.2", "commander": "^5.1.0", "copy-webpack-plugin": "^6.4.1", "core-js": "^3.9.1", diff --git a/packages/docusaurus/src/choosePort.ts b/packages/docusaurus/src/choosePort.ts index de6879cfecf9..fa796914ebdf 100644 --- a/packages/docusaurus/src/choosePort.ts +++ b/packages/docusaurus/src/choosePort.ts @@ -13,7 +13,7 @@ import {execSync} from 'child_process'; import detect from 'detect-port'; import isRoot from 'is-root'; -import chalk from 'chalk'; +import colorette from 'colorette'; import prompts from 'prompts'; const isInteractive = process.stdout.isTTY; @@ -69,10 +69,10 @@ function getProcessForPort(port: number): string | null { const directory = getDirectoryOfProcessById(processId); const command = getProcessCommand(processId); return ( - chalk.cyan(command) + - chalk.grey(` (pid ${processId})\n`) + - chalk.blue(' in ') + - chalk.cyan(directory) + colorette.cyan(command) + + colorette.gray(` (pid ${processId})\n`) + + colorette.blue(' in ') + + colorette.cyan(directory) ); } catch (e) { return null; @@ -104,7 +104,7 @@ export default async function choosePort( const question: prompts.PromptObject = { type: 'confirm', name: 'shouldChangePort', - message: `${chalk.yellow( + message: `${colorette.yellow( `${message}${ existingProcess ? ` Probably:\n ${existingProcess}` : '' }`, @@ -119,16 +119,16 @@ export default async function choosePort( } }); } else { - console.log(chalk.red(message)); + console.log(colorette.red(message)); resolve(null); } return null; }), (err) => { throw new Error( - `${chalk.red(`Could not find an open port at ${chalk.bold(host)}.`)}\n${ - `Network error message: ${err.message}` || err - }\n`, + `${colorette.red( + `Could not find an open port at ${colorette.bold(host)}.`, + )}\n${`Network error message: ${err.message}` || err}\n`, ); }, ); diff --git a/packages/docusaurus/src/client/serverEntry.js b/packages/docusaurus/src/client/serverEntry.js index 156a68eaf625..97d637054d29 100644 --- a/packages/docusaurus/src/client/serverEntry.js +++ b/packages/docusaurus/src/client/serverEntry.js @@ -26,7 +26,7 @@ import { createStatefulLinksCollector, ProvideLinksCollector, } from './LinksCollector'; -import chalk from 'chalk'; +import colorette from 'colorette'; // eslint-disable-next-line no-restricted-imports import {memoize} from 'lodash'; @@ -46,7 +46,7 @@ export default async function render(locals) { return await doRender(locals); } catch (e) { console.error( - chalk.red( + colorette.red( `Docusaurus Node/SSR could not render static page with path=${locals.path} because of error: ${e.message}`, ), ); @@ -147,7 +147,7 @@ async function doRender(locals) { e.message.includes("Cannot read property 'replace' of undefined") ) { console.error( - chalk.red( + colorette.red( '\nDocusaurus user: you probably have this known error due to using a monorepo/workspace.\nWe have a workaround for you, check https://github.com/facebook/docusaurus/issues/3515\n', ), ); diff --git a/packages/docusaurus/src/commands/build.ts b/packages/docusaurus/src/commands/build.ts index 4a11df5f1f1f..30f333f26522 100644 --- a/packages/docusaurus/src/commands/build.ts +++ b/packages/docusaurus/src/commands/build.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import chalk from 'chalk'; +import colorette from 'colorette'; import CopyWebpackPlugin from 'copy-webpack-plugin'; import fs from 'fs-extra'; import path from 'path'; @@ -51,7 +51,7 @@ export default async function build( forceTerminate, isLastLocale, }); - // console.log(chalk.green(`Site successfully built in locale=${locale}`)); + // console.log(colorette.green(`Site successfully built in locale=${locale}`)); return result; } catch (e) { console.error(`error building locale=${locale}`); @@ -72,7 +72,7 @@ export default async function build( } else { if (i18n.locales.length > 1) { console.log( - chalk.yellow( + colorette.yellow( `\nSite will be built for all these locales: - ${i18n.locales.join('\n- ')}`, ), @@ -111,7 +111,7 @@ async function buildLocale({ process.env.BABEL_ENV = 'production'; process.env.NODE_ENV = 'production'; console.log( - chalk.blue(`\n[${locale}] Creating an optimized production build...`), + colorette.blue(`\n[${locale}] Creating an optimized production build...`), ); const props: Props = await load(siteDir, { @@ -240,14 +240,14 @@ async function buildLocale({ }); console.log( - `${chalk.green(`Success!`)} Generated static files in ${chalk.cyan( + `${colorette.green(`Success!`)} Generated static files in ${colorette.cyan( path.relative(process.cwd(), outDir), )}.`, ); if (isLastLocale) { console.log( - `\nUse ${chalk.greenBright( + `\nUse ${colorette.greenBright( '`npm run serve`', )} to test your build locally.\n`, ); diff --git a/packages/docusaurus/src/commands/clear.ts b/packages/docusaurus/src/commands/clear.ts index 03389606659d..412fc2c115b1 100644 --- a/packages/docusaurus/src/commands/clear.ts +++ b/packages/docusaurus/src/commands/clear.ts @@ -6,14 +6,14 @@ */ import fs from 'fs-extra'; import path from 'path'; -import chalk = require('chalk'); +import colorette from 'colorette'; import {DEFAULT_BUILD_DIR_NAME, GENERATED_FILES_DIR_NAME} from '../constants'; function removePath(fsPath: string) { return fs .remove(path.join(fsPath)) .then(() => { - console.log(`${chalk.green(`Removing ${fsPath}`)}`); + console.log(`${colorette.green(`Removing ${fsPath}`)}`); }) .catch((err) => { console.error(`Could not remove ${fsPath}`); diff --git a/packages/docusaurus/src/commands/deploy.ts b/packages/docusaurus/src/commands/deploy.ts index 748f268cd959..450c40551764 100644 --- a/packages/docusaurus/src/commands/deploy.ts +++ b/packages/docusaurus/src/commands/deploy.ts @@ -7,7 +7,7 @@ import fs from 'fs-extra'; import shell from 'shelljs'; -import chalk from 'chalk'; +import colorette from 'colorette'; import {loadContext} from '../server'; import build from './build'; import {BuildCLIOptions} from '@docusaurus/types'; @@ -26,13 +26,13 @@ function shellExecLog(cmd) { try { const result = shell.exec(cmd); console.log( - `${chalk.cyan('CMD:')} ${obfuscateGitPass(cmd)} ${chalk.cyan( + `${colorette.cyan('CMD:')} ${obfuscateGitPass(cmd)} ${colorette.cyan( `(code=${result.code})`, )}`, ); return result; } catch (e) { - console.log(`${chalk.red('CMD:')} ${obfuscateGitPass(cmd)}`); + console.log(`${colorette.red('CMD:')} ${obfuscateGitPass(cmd)}`); throw e; } } @@ -70,7 +70,7 @@ export default async function deploy( `Missing project organization name. Did you forget to define 'organizationName' in ${siteConfigPath}? You may also export it via the ORGANIZATION_NAME environment variable.`, ); } - console.log(`${chalk.cyan('organizationName:')} ${organizationName}`); + console.log(`${colorette.cyan('organizationName:')} ${organizationName}`); const projectName = process.env.PROJECT_NAME || @@ -81,7 +81,7 @@ export default async function deploy( `Missing project name. Did you forget to define 'projectName' in ${siteConfigPath}? You may also export it via the PROJECT_NAME environment variable.`, ); } - console.log(`${chalk.cyan('projectName:')} ${projectName}`); + console.log(`${colorette.cyan('projectName:')} ${projectName}`); // We never deploy on pull request. const isPullRequest = @@ -95,7 +95,7 @@ export default async function deploy( const deploymentBranch = process.env.DEPLOYMENT_BRANCH || (projectName.indexOf('.github.io') !== -1 ? 'master' : 'gh-pages'); - console.log(`${chalk.cyan('deploymentBranch:')} ${deploymentBranch}`); + console.log(`${colorette.cyan('deploymentBranch:')} ${deploymentBranch}`); const githubHost = process.env.GITHUB_HOST || siteConfig.githubHost || 'github.com'; @@ -116,7 +116,7 @@ export default async function deploy( : nonSshRemoteBranch; console.log( - `${chalk.cyan('Remote branch:')} ${obfuscateGitPass(remoteBranch)}`, + `${colorette.cyan('Remote branch:')} ${obfuscateGitPass(remoteBranch)}`, ); // Check if this is a cross-repo publish. diff --git a/packages/docusaurus/src/commands/serve.ts b/packages/docusaurus/src/commands/serve.ts index 09184389e530..5bed857ce342 100644 --- a/packages/docusaurus/src/commands/serve.ts +++ b/packages/docusaurus/src/commands/serve.ts @@ -8,7 +8,7 @@ import http from 'http'; import serveHandler from 'serve-handler'; import boxen from 'boxen'; -import chalk from 'chalk'; +import colorette from 'colorette'; import path from 'path'; import build from './build'; @@ -48,7 +48,7 @@ export default async function serve( }); console.log( boxen( - `${chalk.green(`Serving ${cliOptions.dir}!`)}\n\n- Local: http://${ + `${colorette.green(`Serving ${cliOptions.dir}!`)}\n\n- Local: http://${ cliOptions.host }:${port}`, { diff --git a/packages/docusaurus/src/commands/start.ts b/packages/docusaurus/src/commands/start.ts index 328093c139a1..3913b6128e83 100644 --- a/packages/docusaurus/src/commands/start.ts +++ b/packages/docusaurus/src/commands/start.ts @@ -6,7 +6,7 @@ */ import {normalizeUrl, posixPath} from '@docusaurus/utils'; -import chalk = require('chalk'); +import colorette from 'colorette'; import chokidar from 'chokidar'; import express from 'express'; import HtmlWebpackPlugin from 'html-webpack-plugin'; @@ -38,7 +38,7 @@ export default async function start( ): Promise { process.env.NODE_ENV = 'development'; process.env.BABEL_ENV = 'development'; - console.log(chalk.blue('Starting the development server...')); + console.log(colorette.blue('Starting the development server...')); function loadSite() { return load(siteDir, { @@ -64,7 +64,9 @@ export default async function start( const urls = prepareUrls(protocol, host, port); const openUrl = normalizeUrl([urls.localUrlForBrowser, baseUrl]); - console.log(chalk.cyanBright(`Docusaurus website is running at: ${openUrl}`)); + console.log( + colorette.cyanBright(`Docusaurus website is running at: ${openUrl}`), + ); // Reload files processing. const reload = debounce(() => { @@ -72,11 +74,13 @@ export default async function start( .then(({baseUrl: newBaseUrl}) => { const newOpenUrl = normalizeUrl([urls.localUrlForBrowser, newBaseUrl]); console.log( - chalk.cyanBright(`Docusaurus website is running at: ${newOpenUrl}`), + colorette.cyanBright( + `Docusaurus website is running at: ${newOpenUrl}`, + ), ); }) .catch((err) => { - console.error(chalk.red(err.stack)); + console.error(colorette.red(err.stack)); }); }, 500); const {siteConfig, plugins = []} = props; diff --git a/packages/docusaurus/src/commands/swizzle.ts b/packages/docusaurus/src/commands/swizzle.ts index 52849f098adb..6fd042b133f9 100644 --- a/packages/docusaurus/src/commands/swizzle.ts +++ b/packages/docusaurus/src/commands/swizzle.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import chalk = require('chalk'); +import colorette from 'colorette'; import fs from 'fs-extra'; import importFresh from 'import-fresh'; import path from 'path'; @@ -88,14 +88,15 @@ function themeComponents( const components = colorCode(themePath, plugin); if (components.length === 0) { - return `${chalk.red('No component to swizzle')}`; + return `${colorette.red('No component to swizzle')}`; } return ` -${chalk.cyan('Theme components available for swizzle')} +${colorette.cyan('Theme components available for swizzle')} + +${colorette.green('green =>')} recommended: lower breaking change risk +${colorette.red('red =>')} internal: higher breaking change risk -${chalk.green('green =>')} safe: lower breaking change risk -${chalk.red('red =>')} unsafe: higher breaking change risk ${components.join('\n')} `; @@ -123,8 +124,8 @@ function colorCode( ); return [ - ...greenComponents.map((component) => chalk.green(`safe: ${component}`)), - ...redComponents.map((component) => chalk.red(`unsafe: ${component}`)), + ...greenComponents.map((component) => colorette.green(component)), + ...redComponents.map((component) => colorette.red(component)), ]; } @@ -163,7 +164,7 @@ export default async function swizzle( suggestion = name; } }); - chalk.red( + colorette.red( `Theme ${themeName} not found. ${ suggestion ? `Did you mean "${suggestion}" ?` @@ -207,7 +208,7 @@ export default async function swizzle( if (!themePath) { console.warn( - chalk.yellow( + colorette.yellow( typescript ? `${themeName} does not provide TypeScript theme code via "getTypeScriptThemePath()".` : `${themeName} does not provide any theme code.`, @@ -245,8 +246,8 @@ export default async function swizzle( if (mostSuitableMatch !== componentName) { mostSuitableComponent = mostSuitableMatch; console.log( - chalk.red(`Component "${componentName}" doesn't exists.`), - chalk.yellow( + colorette.red(`Component "${componentName}" doesn't exists.`), + colorette.yellow( `"${mostSuitableComponent}" is swizzled instead of "${componentName}".`, ), ); @@ -271,7 +272,9 @@ export default async function swizzle( suggestion = name; } }); - console.warn(chalk.red(`Component ${mostSuitableComponent} not found.`)); + console.warn( + colorette.red(`Component ${mostSuitableComponent} not found.`), + ); console.warn( suggestion ? `Did you mean "${suggestion}"?` @@ -283,7 +286,7 @@ export default async function swizzle( if (!components.includes(mostSuitableComponent) && !danger) { console.warn( - chalk.red( + colorette.red( `${mostSuitableComponent} is an internal component, and have a higher breaking change probability. If you want to swizzle it, use the "--danger" flag.`, ), ); @@ -293,12 +296,14 @@ export default async function swizzle( await fs.copy(fromPath, toPath); const relativeDir = path.relative(process.cwd(), toPath); - const fromMsg = chalk.blue( + const fromMsg = colorette.blue( mostSuitableComponent - ? `${themeName} ${chalk.yellow(mostSuitableComponent)}` + ? `${themeName} ${colorette.yellow(mostSuitableComponent)}` : themeName, ); - const toMsg = chalk.cyan(relativeDir); + const toMsg = colorette.cyan(relativeDir); - console.log(`\n${chalk.green('Success!')} Copied ${fromMsg} to ${toMsg}.\n`); + console.log( + `\n${colorette.green('Success!')} Copied ${fromMsg} to ${toMsg}.\n`, + ); } diff --git a/packages/docusaurus/src/commands/writeHeadingIds.ts b/packages/docusaurus/src/commands/writeHeadingIds.ts index 63b422289d4d..32f69ed3c271 100644 --- a/packages/docusaurus/src/commands/writeHeadingIds.ts +++ b/packages/docusaurus/src/commands/writeHeadingIds.ts @@ -7,7 +7,7 @@ import fs from 'fs-extra'; import GithubSlugger from 'github-slugger'; -import chalk from 'chalk'; +import colorette from 'colorette'; import {loadContext, loadPluginConfigs} from '../server'; import initPlugins from '../server/plugins/init'; @@ -117,14 +117,14 @@ export default async function writeHeadingIds(siteDir: string): Promise { if (pathsModified.length) { console.log( - chalk.green(`Heading ids added to markdown files (${ + colorette.green(`Heading ids added to markdown files (${ pathsModified.length }/${markdownFiles.length} files): - ${pathsModified.join('\n- ')}`), ); } else { console.log( - chalk.yellow( + colorette.yellow( `${markdownFiles.length} markdown files already have explicit heading ids`, ), ); diff --git a/packages/docusaurus/src/server/i18n.ts b/packages/docusaurus/src/server/i18n.ts index db26fc634510..f6905deb874c 100644 --- a/packages/docusaurus/src/server/i18n.ts +++ b/packages/docusaurus/src/server/i18n.ts @@ -9,7 +9,7 @@ import path from 'path'; import {normalizeUrl} from '@docusaurus/utils'; import {getLangDir} from 'rtl-detect'; import {NODE_MAJOR_VERSION} from '../constants'; -import chalk from 'chalk'; +import colorette from 'colorette'; function getDefaultLocaleLabel(locale: string) { // Intl.DisplayNames is ES2021 - Node14+ @@ -45,7 +45,7 @@ export async function loadI18n( if (!i18nConfig.locales.includes(currentLocale)) { console.warn( - chalk.yellow( + colorette.yellow( `The locale=${currentLocale} was not found in your site configuration: config.i18n.locales=[${i18nConfig.locales.join( ',', )}] @@ -60,7 +60,7 @@ Note: Docusaurus only support running one locale at a time.`, if (shouldWarnAboutNodeVersion(NODE_MAJOR_VERSION, locales)) { console.warn( - chalk.yellow( + colorette.yellow( `To use Docusaurus i18n, it is strongly advised to use NodeJS >= 14 (instead of ${NODE_MAJOR_VERSION})`, ), ); diff --git a/packages/docusaurus/src/server/index.ts b/packages/docusaurus/src/server/index.ts index 57ec879a1cdc..51aa2592f0fe 100644 --- a/packages/docusaurus/src/server/index.ts +++ b/packages/docusaurus/src/server/index.ts @@ -7,7 +7,7 @@ import {generate} from '@docusaurus/utils'; import path, {join} from 'path'; -import chalk from 'chalk'; +import colorette from 'colorette'; import ssrDefaultTemplate from '../client/templates/ssr.html.template'; import { DEFAULT_BUILD_DIR_NAME, @@ -358,7 +358,7 @@ function checkDocusaurusPackagesVersion(siteMetadata: DocusaurusSiteMetadata) { // should we throw instead? // It still could work with different versions console.warn( - chalk.red( + colorette.red( `Bad ${plugin} version ${versionInfo.version}.\nAll official @docusaurus/* packages should have the exact same version as @docusaurus/core (${docusaurusVersion}).\nMaybe you want to check, or regenerate your yarn.lock or package-lock.json file?`, ), ); diff --git a/packages/docusaurus/src/server/plugins/index.ts b/packages/docusaurus/src/server/plugins/index.ts index 3da9916c5fe0..a0de180f093e 100644 --- a/packages/docusaurus/src/server/plugins/index.ts +++ b/packages/docusaurus/src/server/plugins/index.ts @@ -18,7 +18,7 @@ import { ThemeConfig, } from '@docusaurus/types'; import initPlugins, {InitPlugin} from './init'; -import chalk from 'chalk'; +import colorette from 'colorette'; import {DEFAULT_PLUGIN_ID} from '../../constants'; import {chain} from 'lodash'; import {localizePluginTranslationFile} from '../translations/translations'; @@ -197,7 +197,7 @@ export async function loadPlugins({ // deprecated since alpha-60 // TODO, 1 user reported usage of this lifecycle! https://github.com/facebook/docusaurus/issues/3918 console.error( - chalk.red( + colorette.red( 'plugin routesLoaded lifecycle is deprecated. If you think we should keep this lifecycle, please report here: https://github.com/facebook/docusaurus/issues/3918', ), ); diff --git a/packages/docusaurus/src/server/translations/translations.ts b/packages/docusaurus/src/server/translations/translations.ts index 205632e0bcdf..7bda1e86d754 100644 --- a/packages/docusaurus/src/server/translations/translations.ts +++ b/packages/docusaurus/src/server/translations/translations.ts @@ -15,7 +15,7 @@ import { } from '@docusaurus/types'; import {getPluginI18nPath, toMessageRelativeFilePath} from '@docusaurus/utils'; import {Joi} from '@docusaurus/utils-validation'; -import chalk from 'chalk'; +import colorette from 'colorette'; export type WriteTranslationsOptions = { override?: boolean; @@ -115,7 +115,7 @@ export async function writeTranslationFileContent({ ); if (unknownKeys.length > 0) { console.warn( - chalk.yellow(`Some translation keys looks unknown to us in file ${filePath} + colorette.yellow(`Some translation keys looks unknown to us in file ${filePath} Maybe you should remove them? - ${unknownKeys.join('\n- ')}`), ); @@ -289,7 +289,7 @@ export function applyDefaultCodeTranslations({ ); if (unusedDefaultCodeMessages.length > 0) { console.warn( - chalk.yellow(`Unused default message codes found. + colorette.yellow(`Unused default message codes found. Please report this Docusaurus issue. - ${unusedDefaultCodeMessages.join('\n- ')} `), diff --git a/packages/docusaurus/src/server/translations/translationsExtractor.ts b/packages/docusaurus/src/server/translations/translationsExtractor.ts index b4bc5e783141..cb4587f94405 100644 --- a/packages/docusaurus/src/server/translations/translationsExtractor.ts +++ b/packages/docusaurus/src/server/translations/translationsExtractor.ts @@ -7,7 +7,7 @@ import fs from 'fs-extra'; import traverse, {Node} from '@babel/traverse'; import generate from '@babel/generator'; -import chalk from 'chalk'; +import colorette from 'colorette'; import {parse, types as t, NodePath, TransformOptions} from '@babel/core'; import {flatten} from 'lodash'; import {TranslationFileContent, TranslationMessage} from '@docusaurus/types'; @@ -105,7 +105,7 @@ function logSourceCodeFileTranslationsWarnings( sourceCodeFilesTranslations.forEach(({sourceCodeFilePath, warnings}) => { if (warnings.length > 0) { console.warn( - `Translation extraction warnings for file path=${sourceCodeFilePath}:\n- ${chalk.yellow( + `Translation extraction warnings for file path=${sourceCodeFilePath}:\n- ${colorette.yellow( warnings.join('\n\n- '), )}`, ); diff --git a/packages/docusaurus/src/webpack/client.ts b/packages/docusaurus/src/webpack/client.ts index 92bf28ad3209..3e8dc4b1abad 100644 --- a/packages/docusaurus/src/webpack/client.ts +++ b/packages/docusaurus/src/webpack/client.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import chalk from 'chalk'; +import colorette from 'colorette'; import path from 'path'; import {Configuration} from 'webpack'; import merge from 'webpack-merge'; @@ -51,7 +51,7 @@ export default function createClientConfig( compiler.hooks.done.tap('client:done', (stats) => { if (stats.hasErrors()) { console.log( - chalk.red( + colorette.red( 'Client bundle compiled with errors therefore further build is impossible.', ), ); diff --git a/packages/docusaurus/src/webpack/utils.ts b/packages/docusaurus/src/webpack/utils.ts index 2aae9eee1a83..693343d4c7d0 100644 --- a/packages/docusaurus/src/webpack/utils.ts +++ b/packages/docusaurus/src/webpack/utils.ts @@ -22,7 +22,7 @@ import OptimizeCSSAssetsPlugin from 'optimize-css-assets-webpack-plugin'; import CleanCss from 'clean-css'; import path from 'path'; import crypto from 'crypto'; -import chalk from 'chalk'; +import colorette from 'colorette'; import {TransformOptions} from '@babel/core'; import { ConfigureWebpackFn, @@ -413,7 +413,9 @@ function validateKeyAndCerts({cert, key, keyFile, crtFile}) { encrypted = crypto.publicEncrypt(cert, Buffer.from('test')); } catch (err) { throw new Error( - `The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`, + `The certificate "${colorette.yellow(crtFile)}" is invalid.\n${ + err.message + }`, ); } @@ -422,7 +424,7 @@ function validateKeyAndCerts({cert, key, keyFile, crtFile}) { crypto.privateDecrypt(key, encrypted); } catch (err) { throw new Error( - `The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${ + `The certificate key "${colorette.yellow(keyFile)}" is invalid.\n${ err.message }`, ); @@ -433,9 +435,9 @@ function validateKeyAndCerts({cert, key, keyFile, crtFile}) { function readEnvFile(file, type) { if (!fs.existsSync(file)) { throw new Error( - `You specified ${chalk.cyan( + `You specified ${colorette.cyan( type, - )} in your env, but the file "${chalk.yellow(file)}" can't be found.`, + )} in your env, but the file "${colorette.yellow(file)}" can't be found.`, ); } return fs.readFileSync(file);