Skip to content

Commit

Permalink
feat: add color to the output using Chalk
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal committed Jul 17, 2023
1 parent aa304f2 commit 4b98890
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
19 changes: 17 additions & 2 deletions lib/google-rank.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/google-rank.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"test": "dev test"
},
"dependencies": {
"chalk": "^4.1.2",
"commander": "^11.0.0",
"googlethis": "^1.7.1"
},
Expand Down
15 changes: 13 additions & 2 deletions src/google-rank.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node

import chalk from "chalk";
import { program } from "commander";
import { getWebsiteRank, WebsiteRank } from "./utils";

Expand All @@ -22,13 +23,23 @@ async function run() {
rankByKeywords.push([keyword, prom]);
}

process.stdout.write(`Ranks for ${website} website:\n`);
process.stdout.write(`Ranks for ${chalk.blueBright(website)} website:\n`);
for (const [keyword, prom] of rankByKeywords) {
const rank = await prom;
if (rank === undefined) {
process.stdout.write(`page ? rank ?`);
} else {
process.stdout.write(`page ${rank.page + 1} rank ${rank.rank + 1}`);
if (rank.page <= 0) {
process.stdout.write(`page ${chalk.greenBright(rank.page + 1)}`);
} else {
process.stdout.write(`page ${chalk.redBright(rank.page + 1)}`);
}

if (rank.page <= 0 && rank.rank <= 2) {
process.stdout.write(` rank ${chalk.greenBright(rank.rank + 1)}`);
} else {
process.stdout.write(` rank ${chalk.redBright(rank.rank + 1)}`);
}
}
process.stdout.write(` ${keyword}\n`);
}
Expand Down

0 comments on commit 4b98890

Please sign in to comment.