Skip to content

Commit

Permalink
refactor(*): switch chalk -> colorette
Browse files Browse the repository at this point in the history
  • Loading branch information
Nytelife26 committed Apr 6, 2021
1 parent b6fbca7 commit 4d804e7
Show file tree
Hide file tree
Showing 37 changed files with 198 additions and 168 deletions.
12 changes: 7 additions & 5 deletions packages/docusaurus-init/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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`,
),
);
Expand All @@ -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;
});
}
Expand All @@ -50,7 +50,9 @@ program

program.arguments('<command>').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();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 18 additions & 16 deletions packages/docusaurus-init/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)',
Expand All @@ -114,24 +114,26 @@ 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.
try {
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;
}
Expand All @@ -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;
}

Expand All @@ -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;
}
}
Expand All @@ -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!');
Expand Down
8 changes: 4 additions & 4 deletions packages/docusaurus-migrate/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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`,
),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-migrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 4d804e7

Please sign in to comment.