Skip to content

Commit 991e044

Browse files
author
scinorandex
committed
Add central location for links
1 parent b55ccd8 commit 991e044

File tree

6 files changed

+57
-40
lines changed

6 files changed

+57
-40
lines changed

src/api.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { errorHandler } from "./api/errorHandler";
44
import { plainRouter } from "./api/plainRouter";
55
import { router } from "./api/router";
66
import { userAgentMiddleware } from "./api/userAgent";
7+
import { lines } from "./utils/getResponses";
78

8-
const { version } = require("../package.json");
99
const port = parseInt(process.env.PORT!) || 7070;
1010

1111
const app = express();
@@ -23,12 +23,7 @@ app.use(["/quiet", "/"], router);
2323
app.use("/", errorHandler);
2424

2525
// Not found handler
26-
app.use("*", (_req, res) =>
27-
res.status(404).send(
28-
`Welcome to COVID-19 Tracker & CLI v${version} by Waren Gonzaga with Wareneutron Developers\n
29-
Please visit: https://warengonza.ga/covid19-tracker-cli\n`
30-
)
31-
);
26+
app.use("*", (_req, res) => res.status(404).send(lines.notFound));
3227

3328
app.listen(port, () => {
3429
console.log(`Express listening on port ${port}`);

src/api/userAgent.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Request, Response, NextFunction } from "express";
2-
const { version } = require("../../package.json");
2+
import { lines } from "../utils/getResponses";
33

44
// Type of middleware and handler
55
export type Handler = (
@@ -28,9 +28,7 @@ export const userAgentMiddleware: Handler = (req, res, next) => {
2828
*/
2929
const userAgent = req.headers["user-agent"];
3030
if (!isTerminal(userAgent)) {
31-
res.send(
32-
`Welcome to COVID-19 Tracker CLI v${version} by Waren Gonzaga with Wareneutron Developers\nPlease visit: https://warengonza.ga/covid19-tracker-cli\n`
33-
);
31+
res.send(lines.notFound);
3432
return;
3533
}
3634

src/cli.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argv from "minimist";
2+
import { lines, welcomeMessage } from "./utils/getResponses";
23
import {
34
globalHistory,
45
globalInformation,
@@ -16,9 +17,7 @@ const args = argv(process.argv.slice(2));
1617
let { history, mode, help, quiet, plain } = args;
1718
const country = args._[0];
1819

19-
const { version } = require("../package.json");
20-
21-
const helpMessage = `COVID-19 Tracker & CLI v${version} by Waren Gonzaga with Wareneutron Developers
20+
const helpMessage = `${welcomeMessage}
2221
Usage: covid [COUNTRY] [OPTIONS...]
2322
2423
Country: Can be a country name or ISO 3166-1 alpha-2 country code
@@ -32,9 +31,9 @@ Options:
3231
--plain Enable plain mode
3332
3433
Useful Links:
35-
Docs: docs.wareneutron.com/covid19-tracker-cli
36-
Repo: repo.wareneutron.com/covid19-tracker-cli
37-
Donate: wareneutron.com/donate`;
34+
${lines.docsLink}
35+
${lines.WNrepoLink}
36+
${lines.WNDonateLink}`;
3837

3938
let output: string = "";
4039
const main = async () => {
@@ -72,7 +71,11 @@ const main = async () => {
7271
}
7372
}
7473

75-
console.log(output);
74+
// remove magic? newline
75+
let response = output.split("\n");
76+
response.pop();
77+
78+
console.log(response.join("\n"));
7679
};
7780

7881
main().catch((err) => {

src/utils/generateOutput.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { generateColorTable } from "./generateTable";
22
import { getTimestamp } from "./getTimestamp";
33
import { getSaying } from "./getSaying";
4-
5-
const { version } = require("../../package.json");
4+
import { lines } from "./getResponses";
65

76
/**
87
*
@@ -19,17 +18,17 @@ export const generateOutput: (
1918
quiet?: boolean
2019
) => string = (chartType, updateTime, data, quiet) => {
2120
quiet = quiet === undefined ? true : quiet;
22-
let header = `COVID-19 Tracker & CLI v${version} - ${chartType}`;
21+
let header = `${lines.defaultHeader} - ${chartType}`;
2322
let timestamp = getTimestamp(updateTime).yellow;
2423

2524
data.unshift(timestamp);
2625
if (!quiet) data.unshift(header);
2726

2827
if (!quiet)
2928
data = data.concat([
30-
"Help: Try to append the URL with /help to learn more...",
31-
"Docs: docs.wareneutron.com/covid19-tracker-cli",
32-
"Repo: repo.wareneutron.com/covid19-tracker-cli",
29+
lines.helpMessage,
30+
lines.docsLink,
31+
lines.WNrepoLink,
3332
]);
3433

3534
let response = generateColorTable(data, "cyan");
@@ -38,24 +37,24 @@ export const generateOutput: (
3837
response += `\n${"═".repeat(60)}\n`;
3938
}
4039

41-
response += `Love this project? Help us to help others by means of coffee!\n`; // support msg
40+
response += lines.sponsorMessage; // support msg
4241

4342
// Include GCash message if the query is to the PH
4443
response += chartType.toLowerCase().includes("philippines")
45-
? "(GCash) +639176462753".blue + "\n"
44+
? lines.GCashMessage.blue + "\n"
4645
: "";
4746

4847
// @ts-expect-error: Missing type definitions causes TS to highlight brightRed
49-
response += `(Buy Us A Coffee) wareneutron.com/donate\n`.brightRed; //BMC link
48+
response += `${lines.BMCLink}\n`.brightRed; //BMC link
5049

5150
if (!quiet) {
5251
response += `${"═".repeat(60)}\n`;
53-
response += `Follow me on twitter for more updates!\n`;
52+
response += `${lines.twitterPlug}`;
5453
response +=
55-
["@warengonzaga", "#covid19trackercli"]
56-
.map((text) => text.black.bgCyan)
57-
.join(" ") + "\n";
54+
lines.handleHashtag.map((text) => text.black.bgCyan).join(" ") +
55+
"\n";
5856
}
5957

58+
response += "\n";
6059
return response;
6160
};

src/utils/generatePlainOutput.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { PlainData } from "./getInformation";
2+
import { lines } from "./getResponses";
23
import { getSaying } from "./getSaying";
34
import { getTimestamp } from "./getTimestamp";
4-
const { version } = require("../../package.json");
55

66
/**
77
* @param info The plain data that will be shown at the top in two columns
@@ -20,13 +20,13 @@ export const generatePlainOutput: (
2020
let line = extraRows === undefined ? "-".repeat(60) : "-".repeat(68);
2121
line += "\n";
2222

23-
let header = `COVID-19 Tracker & CLI v${version} - ${chartType}`;
23+
let header = `${lines.defaultHeader} - ${chartType}`;
2424
let timestamp = getTimestamp(metainfo.updated as number);
2525
let saying = getSaying();
2626

2727
// Include GCash message if the query is to the PH
2828
let GCashMessage = chartType.toLowerCase().includes("philippines")
29-
? "(GCash) +639176462753\n"
29+
? lines.GCashMessage + "\n"
3030
: "";
3131

3232
// Generate table
@@ -65,19 +65,19 @@ export const generatePlainOutput: (
6565
// Add the help msg and other messages
6666
if (!quiet)
6767
responseArray = responseArray.concat([
68-
"Help: Try to append the URL with /help to learn more...",
69-
"Source: https://www.worldometers.info/coronavirus/",
70-
"Code: https://github.com/warengonzaga/covid19-tracker-cli",
68+
lines.helpMessage,
69+
lines.source,
70+
lines.repoLink,
7171
`\n${saying}\n`,
7272
]);
7373

7474
responseArray.push(
75-
`Love this project? Help us to help others by means of coffee!\n${GCashMessage}(Buy Me A Coffee) warengonza.ga/coffee4dev`
75+
`${lines.sponsorMessage}${GCashMessage}${lines.BMCLink}`
7676
);
7777

7878
if (!quiet)
7979
responseArray.push(
80-
`Follow me on twitter for more updates!\n@warengonzaga #covid19trackercli`
80+
`${lines.twitterPlug}${lines.handleHashtag.join(" ")}`
8181
);
8282

8383
// Construct the final output
@@ -94,6 +94,5 @@ export const generatePlainOutput: (
9494
.join("\n");
9595

9696
response += "\n";
97-
9897
return response;
9998
};

src/utils/getResponses.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { version } = require("../../package.json");
2+
3+
/**
4+
* This file is a centralized location to get responses to the user
5+
* Such as the BMC link, the twitter link, github repo page etc.
6+
*/
7+
8+
export const welcomeMessage = `Welcome to COVID-19 Tracker & CLI v${version} by Waren Gonzaga with Wareneutron Developers`;
9+
export const lines = {
10+
notFound: `\n${welcomeMessage}\n\nPlease visit: https://warengonza.ga/covid19-tracker-cli\n\n`,
11+
defaultHeader: `COVID-19 Tracker & CLI v${version}`,
12+
helpMessage: `Help: Try to append the URL with /help to learn more...`,
13+
source: `Source: https://www.worldometers.info/coronavirus`,
14+
repoLink: `Code: https://github.com/warengonzaga/covid19-tracker-cli`,
15+
sponsorMessage: `Love this project? Help us to help others by means of coffee!\n`,
16+
GCashMessage: `(GCash) +639176462753`,
17+
BMCLink: `(Buy Me A Coffee) warengonza.ga/coffee4dev`,
18+
twitterPlug: `Follow me on twitter for more updates!\n`,
19+
handleHashtag: ["@warengonzaga", "#covid19trackercli"],
20+
docsLink: "Docs: docs.wareneutron.com/covid19-tracker-cli",
21+
WNrepoLink: "Repo: repo.wareneutron.com/covid19-tracker-cli",
22+
WNDonateLink: "Donate: wareneutron.com/donate",
23+
};

0 commit comments

Comments
 (0)