Skip to content

Commit 1aecda6

Browse files
authored
chore: merge pull request #38 from threeal/adopt-esm
Adopt ECMAScript Modules
2 parents db66123 + 822a135 commit 1aecda6

38 files changed

+112
-163
lines changed

.pnp.cjs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
File renamed without changes.

dist/google-rank.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

dist/google-rank.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/google-rank.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env node
2+
import chalk from "chalk";
3+
import ora from "ora";
4+
import * as utils from "./utils/index.mjs";
5+
async function run() {
6+
const parser = new utils.ArgumentsParser();
7+
const args = await parser.parse();
8+
const rankByKeywords = [];
9+
for (const keyword of args.keywords) {
10+
const prom = utils.googleGetWebsiteRank(args.website, keyword, {
11+
maxPage: args.maxPage,
12+
});
13+
rankByKeywords.push([keyword, prom]);
14+
}
15+
process.stdout.write(`Ranks for ${chalk.blueBright(args.website)} website:\n`);
16+
const loading = ora("Getting ranks...");
17+
loading.start();
18+
for (const [keyword, prom] of rankByKeywords) {
19+
loading.text = `Getting ranks of ${chalk.blueBright(keyword)} keyword...`;
20+
const str = utils.formatKeywordRank(keyword, await prom);
21+
process.stdout.write(`\r\x1b[K${str}\n`);
22+
}
23+
loading.stop();
24+
}
25+
run();
26+
//# sourceMappingURL=google-rank.mjs.map

dist/google-rank.mjs.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

dist/utils/arguments.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/utils/arguments.js renamed to dist/utils/arguments.mjs

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,16 @@
1-
"use strict";
2-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3-
if (k2 === undefined) k2 = k;
4-
var desc = Object.getOwnPropertyDescriptor(m, k);
5-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6-
desc = { enumerable: true, get: function() { return m[k]; } };
7-
}
8-
Object.defineProperty(o, k2, desc);
9-
}) : (function(o, m, k, k2) {
10-
if (k2 === undefined) k2 = k;
11-
o[k2] = m[k];
12-
}));
13-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14-
Object.defineProperty(o, "default", { enumerable: true, value: v });
15-
}) : function(o, v) {
16-
o["default"] = v;
17-
});
18-
var __importStar = (this && this.__importStar) || function (mod) {
19-
if (mod && mod.__esModule) return mod;
20-
var result = {};
21-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22-
__setModuleDefault(result, mod);
23-
return result;
24-
};
25-
Object.defineProperty(exports, "__esModule", { value: true });
26-
exports.ArgumentsParser = void 0;
27-
const commander_1 = require("commander");
28-
const fs = __importStar(require("fs"));
29-
const readline = __importStar(require("readline"));
1+
import { Command } from "commander";
2+
import * as fs from "fs";
3+
import * as readline from "readline";
304
/**
315
* Represents the arguments and options parser of the program.
326
*/
33-
class ArgumentsParser {
7+
export class ArgumentsParser {
348
#program;
359
/**
3610
* Constructs a new instance of the arguments and options parser of the program.
3711
*/
3812
constructor() {
39-
this.#program = new commander_1.Command();
13+
this.#program = new Command();
4014
// Sets up the arguments and options available in the program
4115
this.#program
4216
.argument("<website>", "website name")
@@ -69,7 +43,6 @@ class ArgumentsParser {
6943
return args;
7044
}
7145
}
72-
exports.ArgumentsParser = ArgumentsParser;
7346
/**
7447
* Reads keywords from the specified file.
7548
* @param filename - The file to read keywords from.
@@ -86,4 +59,4 @@ async function readKeywordsFromFile(filename) {
8659
}
8760
return keywords;
8861
}
89-
//# sourceMappingURL=arguments.js.map
62+
//# sourceMappingURL=arguments.mjs.map

dist/utils/arguments.mjs.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/utils/format.d.ts renamed to dist/utils/format.d.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GoogleWebsiteRank } from "./google";
1+
import { GoogleWebsiteRank } from "./google.mjs";
22
/**
33
* Formats the rank of a keyword as a string.
44
* @param keyword - The keyword string.

dist/utils/format.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

dist/utils/format.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/utils/format.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import chalk from "chalk";
2+
function formatPageRank(rank) {
3+
if (rank === undefined)
4+
return `page ${chalk.blackBright("?")}`;
5+
return rank.page <= 0
6+
? `page ${chalk.greenBright(rank.page + 1)}`
7+
: `page ${chalk.redBright(rank.page + 1)}`;
8+
}
9+
function formatRank(rank) {
10+
if (rank === undefined)
11+
return `rank ${chalk.blackBright("?")}`;
12+
return rank.page <= 0 && rank.rank <= 2
13+
? `rank ${chalk.greenBright(rank.rank + 1)}`
14+
: `rank ${chalk.redBright(rank.rank + 1)}`;
15+
}
16+
/**
17+
* Formats the rank of a keyword as a string.
18+
* @param keyword - The keyword string.
19+
* @param rank - The rank of the keyword.
20+
* @returns A formatted string. The rank will be displayed as a question mark if it is undefined.
21+
*/
22+
export function formatKeywordRank(keyword, rank) {
23+
return `${formatPageRank(rank)} ${formatRank(rank)} ${keyword}`;
24+
}
25+
//# sourceMappingURL=format.mjs.map

dist/utils/format.mjs.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

dist/utils/google.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)