Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { errorHandler } from "./api/errorHandler";
import { plainRouter } from "./api/plainRouter";
import { router } from "./api/router";
import { userAgentMiddleware } from "./api/userAgent";
import { lines } from "./utils/getResponses";

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

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

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

app.listen(port, () => {
console.log(`Express listening on port ${port}`);
Expand Down
6 changes: 2 additions & 4 deletions src/api/userAgent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Request, Response, NextFunction } from "express";
const { version } = require("../../package.json");
import { lines } from "../utils/getResponses";

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

Expand Down
17 changes: 10 additions & 7 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argv from "minimist";
import { lines, welcomeMessage } from "./utils/getResponses";
import {
globalHistory,
globalInformation,
Expand All @@ -16,9 +17,7 @@ const args = argv(process.argv.slice(2));
let { history, mode, help, quiet, plain } = args;
const country = args._[0];

const { version } = require("../package.json");

const helpMessage = `COVID-19 Tracker & CLI v${version} by Waren Gonzaga with Wareneutron Developers
const helpMessage = `${welcomeMessage}
Usage: covid [COUNTRY] [OPTIONS...]

Country: Can be a country name or ISO 3166-1 alpha-2 country code
Expand All @@ -32,9 +31,9 @@ Options:
--plain Enable plain mode

Useful Links:
Docs: docs.wareneutron.com/covid19-tracker-cli
Repo: repo.wareneutron.com/covid19-tracker-cli
Donate: wareneutron.com/donate`;
${lines.docsLink}
${lines.WNrepoLink}
${lines.WNDonateLink}`;

let output: string = "";
const main = async () => {
Expand Down Expand Up @@ -72,7 +71,11 @@ const main = async () => {
}
}

console.log(output);
// remove magic? newline
let response = output.split("\n");
response.pop();

console.log(response.join("\n"));
};

main().catch((err) => {
Expand Down
28 changes: 11 additions & 17 deletions src/utils/generateOutput.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { generateColorTable } from "./generateTable";
import { getTimestamp } from "./getTimestamp";
import { getSaying } from "./getSaying";

const { version } = require("../../package.json");
import { lines } from "./getResponses";

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

data.unshift(timestamp);
if (!quiet) data.unshift(header);

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

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

response += `Love this project? Help us to help others by means of coffee!\n`; // support msg

// Include GCash message if the query is to the PH
response += chartType.toLowerCase().includes("philippines")
? "(GCash) +639176462753".blue + "\n"
: "";
response += lines.sponsorMessage; // support msg

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

if (!quiet) {
response += `${"═".repeat(60)}\n`;
response += `Follow me on twitter for more updates!\n`;
response += `${lines.twitterPlug}`;
response +=
["@warengonzaga", "#covid19trackercli"]
.map((text) => text.black.bgCyan)
.join(" ") + "\n";
lines.handleHashtag.map((text) => text.black.bgCyan).join(" ") +
"\n";
}

response += "\n";
return response;
};
22 changes: 7 additions & 15 deletions src/utils/generatePlainOutput.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PlainData } from "./getInformation";
import { lines } from "./getResponses";
import { getSaying } from "./getSaying";
import { getTimestamp } from "./getTimestamp";
const { version } = require("../../package.json");

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

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

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

// Generate table
let table = "";

Expand Down Expand Up @@ -65,19 +60,17 @@ export const generatePlainOutput: (
// Add the help msg and other messages
if (!quiet)
responseArray = responseArray.concat([
"Help: Try to append the URL with /help to learn more...",
"Source: https://www.worldometers.info/coronavirus/",
"Code: https://github.com/warengonzaga/covid19-tracker-cli",
lines.helpMessage,
lines.docsLink,
lines.WNrepoLink,
`\n${saying}\n`,
]);

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

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

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

response += "\n";

return response;
};
18 changes: 18 additions & 0 deletions src/utils/getResponses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { version } = require("../../package.json");

// This file is a centralized location to get responses to the user
// Such as the BMC link, the twitter link, github repo page etc.

export const welcomeMessage = `Welcome to COVID-19 Tracker & CLI v${version} by Waren Gonzaga with Wareneutron Developers`;
export const lines = {
notFound: `\n${welcomeMessage}\n\nPlease visit: https://warengonza.ga/covid19-tracker-cli\n\n`,
defaultHeader: `COVID-19 Tracker & CLI v${version}`,
helpMessage: `Help: Try to append the URL with /help to learn more...`,
sponsorMessage: `Love this project? Help us to help others by means of coffee!\n`,
BMCLink: `(Buy Me A Coffee) warengonza.ga/coffee4dev`,
twitterPlug: `Follow me on twitter for more updates!\n`,
handleHashtag: ["@warengonzaga", "#covid19trackercli"],
docsLink: "Docs: docs.wareneutron.com/covid19-tracker-cli",
WNrepoLink: "Repo: repo.wareneutron.com/covid19-tracker-cli",
WNDonateLink: "Donate: wareneutron.com/donate",
};