Skip to content

Commit f9755e9

Browse files
authored
Merge pull request OSSPhilippines#74 from scinscinscin/v4
Create centralized file for docs, repo link, other info
2 parents b55ccd8 + 6ba6b5d commit f9755e9

File tree

6 files changed

+50
-50
lines changed

6 files changed

+50
-50
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: 11 additions & 17 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,19 @@ 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
42-
43-
// Include GCash message if the query is to the PH
44-
response += chartType.toLowerCase().includes("philippines")
45-
? "(GCash) +639176462753".blue + "\n"
46-
: "";
40+
response += lines.sponsorMessage; // support msg
4741

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

5145
if (!quiet) {
5246
response += `${"═".repeat(60)}\n`;
53-
response += `Follow me on twitter for more updates!\n`;
47+
response += `${lines.twitterPlug}`;
5448
response +=
55-
["@warengonzaga", "#covid19trackercli"]
56-
.map((text) => text.black.bgCyan)
57-
.join(" ") + "\n";
49+
lines.handleHashtag.map((text) => text.black.bgCyan).join(" ") +
50+
"\n";
5851
}
5952

53+
response += "\n";
6054
return response;
6155
};

src/utils/generatePlainOutput.ts

Lines changed: 7 additions & 15 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,15 +20,10 @@ 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

27-
// Include GCash message if the query is to the PH
28-
let GCashMessage = chartType.toLowerCase().includes("philippines")
29-
? "(GCash) +639176462753\n"
30-
: "";
31-
3227
// Generate table
3328
let table = "";
3429

@@ -65,19 +60,17 @@ export const generatePlainOutput: (
6560
// Add the help msg and other messages
6661
if (!quiet)
6762
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",
63+
lines.helpMessage,
64+
lines.docsLink,
65+
lines.WNrepoLink,
7166
`\n${saying}\n`,
7267
]);
7368

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

7871
if (!quiet)
7972
responseArray.push(
80-
`Follow me on twitter for more updates!\n@warengonzaga #covid19trackercli`
73+
`${lines.twitterPlug}${lines.handleHashtag.join(" ")}`
8174
);
8275

8376
// Construct the final output
@@ -94,6 +87,5 @@ export const generatePlainOutput: (
9487
.join("\n");
9588

9689
response += "\n";
97-
9890
return response;
9991
};

src/utils/getResponses.ts

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

0 commit comments

Comments
 (0)