@donmur247/heyyou 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ name: "Publish HeyYou CLI to npm"
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ publish:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - name: Checkout code
10
+ uses: actions/checkout@v6
11
+
12
+ - name: Set up Node.js
13
+ uses: actions/setup-node@v6
14
+ with:
15
+ node-version: "24"
16
+ registry-url: "https://registry.npmjs.org/"
17
+
18
+ - name: Install dependencies and build
19
+ run: |
20
+ npm install
21
+ npm run build
22
+
23
+ - name: Publish to npm
24
+ env:
25
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
26
+ run: npm publish --access public
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # heyYou!
2
+ A simple CLI program to display quote of the day for You!
3
+
4
+ Start your day with the right quote whether it's random, simply funny or inspirational.
5
+
6
+ This project is based on Mixed Messages project from Codecademy's back-end engineering capstone project.
7
+
8
+ Feel free to contribute with this project to expand it as the scope of this project is to cover basic fundamentals of Javascript project configuration using `nodejs`.
9
+
10
+ I used Typescript in this project to give type-hinting that I love to have for every project that I work on.
11
+
12
+ ## Install
13
+ ```
14
+ npm install heyyou
15
+ ```
16
+
17
+ ## Usage
18
+ Starting your day is easy as typing this to the terminal.
19
+
20
+ ```
21
+ heyyou
22
+ Hello, user!
23
+
24
+ ╭────────────────────────────────────────────────────────────────────────╮
25
+ │ │
26
+ │ "It does not matter how slowly you go as long as you do not stop." │
27
+ │ - Confucius │
28
+ │ │
29
+ ╰────────────────────────────────────────────────────────────────────────╯
30
+ ```
31
+ By default it gives you random quotes from provided `json` data that come with the project.
32
+
33
+ ```
34
+ heyyou --help
35
+
36
+ Usage: heyYou [options]
37
+
38
+ A CLI app to give user a random quote of the day.
39
+
40
+ Options:
41
+ -f, --funny Start your day with a funny quote.
42
+ -i, --inspire Get a random inspiring quote of the day.
43
+ -a, --api Get a random quote from thequoteshub API.
44
+ -h, --help display help for command
45
+ ```
46
+ Will show the help option.
47
+
48
+ ```
49
+ heyyou -f
50
+
51
+ Hey hey, user!
52
+
53
+ ╭────────────────────────────────────────────────────────────────────────╮
54
+ │ │
55
+ │ "Be nice to nerds. You may end up working for them. We all could." │
56
+ │ - Charles J. Sykes │
57
+ │ │
58
+ ╰────────────────────────────────────────────────────────────────────────╯
59
+ ```
60
+ Option for funny quotes.
61
+
62
+ ```
63
+ heyyou -i
64
+
65
+ Believe in yourself, user!
66
+
67
+ ╭────────────────────────────────────────────────────────────────────────────────╮
68
+ │ │
69
+ │ "Remember that wherever your heart is, there you will find your treasure." │
70
+ │ - Paulo Coelho │
71
+ │ │
72
+ ╰────────────────────────────────────────────────────────────────────────────────╯
73
+ ```
74
+ Inspirational quotes.
75
+
76
+ ```
77
+ heyyou -a
78
+
79
+ Here's a random quote for you, user!
80
+
81
+ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
82
+ │ │
83
+ │ "...Stories want to be told. Stories have a power of their own ... You can't write a story until you've felt it. │
84
+ │ Breathed it in. Walked with your characters. Talked with them." │
85
+ │ - Angelica Banks │
86
+ │ │
87
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
88
+ ```
89
+ Getting random quotes from `thequoteshub.com` API. Currently this is hardcoded in the code for fundamental practice. Ideally should be put as configurable option and payloads.
90
+
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ #! /usr/bin/env node
2
+ "use strict";
3
+ // Main entry point for heyYou CLI app.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ // Third-party modules
6
+ const commander_1 = require("commander");
7
+ // Local modules
8
+ const utils_1 = require("./utils");
9
+ // Initialize CLI app
10
+ const app = new commander_1.Command();
11
+ app
12
+ .name("heyYou")
13
+ .description("A CLI app to give user a random quote of the day.")
14
+ .addOption(new commander_1.Option("-f, --funny", "Start your day with a funny quote."))
15
+ .addOption(new commander_1.Option("-i, --inspire", "Get a random inspiring quote of the day."))
16
+ .addOption(new commander_1.Option("-a, --api", "Get a random quote from thequoteshub API."))
17
+ .action((options, app) => {
18
+ if (options.funny && options.inspire && options.api) {
19
+ console.log("Please choose either --funny, --inspire, or --api, but not all three.");
20
+ console.log("Have a nice one! :)");
21
+ process.exit(0);
22
+ }
23
+ })
24
+ .parse(process.argv);
25
+ const options = app.opts();
26
+ // Main logic to handle user input and provide quotes
27
+ if (!process.argv.slice(2).length) {
28
+ console.log(`Hello, ${(0, utils_1.getUsername)()}!\n`);
29
+ console.log((0, utils_1.getDefaultQuote)());
30
+ }
31
+ if (options.funny) {
32
+ console.log(`Hey hey, ${(0, utils_1.getUsername)()}!\n`);
33
+ console.log((0, utils_1.getFunnyQuote)());
34
+ }
35
+ if (options.inspire) {
36
+ console.log(`Believe in yourself, ${(0, utils_1.getUsername)()}!\n`);
37
+ console.log((0, utils_1.getInspiringQuote)());
38
+ }
39
+ if (options.api) {
40
+ console.log(`Here's a random quote for you, ${(0, utils_1.getUsername)()}!\n`);
41
+ (0, utils_1.getRandomQuoteFromAPI)().then((quote) => console.log(quote));
42
+ }
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAEA,uCAAuC;;AAEvC,sBAAsB;AACtB,yCAA4C;AAE5C,gBAAgB;AAChB,mCAAgH;AAEhH,qBAAqB;AACrB,MAAM,GAAG,GAAG,IAAI,mBAAO,EAAE,CAAC;AAC1B,GAAG;KACE,IAAI,CAAC,QAAQ,CAAC;KACd,WAAW,CAAC,mDAAmD,CAAC;KAChE,SAAS,CAAC,IAAI,kBAAM,CAAC,aAAa,EAAE,oCAAoC,CAAC,CAAC;KAC1E,SAAS,CAAC,IAAI,kBAAM,CAAC,eAAe,EAAE,0CAA0C,CAAC,CAAC;KAClF,SAAS,CAAC,IAAI,kBAAM,CAAC,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E,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAChE,CAAC"}
package/dist/utils.js ADDED
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ // Utility module for the heyYou CLI application.
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.getUsername = getUsername;
17
+ exports.getDefaultQuote = getDefaultQuote;
18
+ exports.getFunnyQuote = getFunnyQuote;
19
+ exports.getInspiringQuote = getInspiringQuote;
20
+ exports.getRandomQuoteFromAPI = getRandomQuoteFromAPI;
21
+ const fs_1 = __importDefault(require("fs"));
22
+ const boxen_1 = __importDefault(require("boxen"));
23
+ const chalk_1 = __importDefault(require("chalk"));
24
+ // Function to return current username
25
+ function getUsername() {
26
+ return process.env.USER || "User";
27
+ }
28
+ // Function to return a quote based on provided quote from a json file where it randomly
29
+ // selects a quote and returns a dictionary with the quote and its author.
30
+ function getQuoteFromFile(filePath) {
31
+ try {
32
+ const data = JSON.parse(fs_1.default.readFileSync(filePath, "utf-8"));
33
+ const randomIndex = Math.floor(Math.random() * data.length);
34
+ return data[randomIndex];
35
+ }
36
+ catch (error) {
37
+ console.error("Error reading quote file:", error);
38
+ return { quote: "Failed to load quote.", author: "Unknown" };
39
+ }
40
+ }
41
+ // Function to format a quote in a box using boxen and chalk for styling
42
+ function formatQuote(quote, author) {
43
+ const formattedQuote = chalk_1.default.cyan(`"${quote}"\n- ${author}`);
44
+ const boxedQuote = (0, boxen_1.default)(formattedQuote, { padding: 1, borderColor: "green", borderStyle: "round" });
45
+ return boxedQuote;
46
+ }
47
+ // Function to return default quote
48
+ function getDefaultQuote() {
49
+ const quoteData = getQuoteFromFile("src/quotes/default.json");
50
+ return formatQuote(quoteData.quote, quoteData.author);
51
+ }
52
+ // Function to return funny quote
53
+ function getFunnyQuote() {
54
+ const quoteData = getQuoteFromFile("src/quotes/funny.json");
55
+ return formatQuote(quoteData.quote, quoteData.author);
56
+ }
57
+ // Function to return inspiring quote
58
+ function getInspiringQuote() {
59
+ const quoteData = getQuoteFromFile("src/quotes/inspire.json");
60
+ return formatQuote(quoteData.quote, quoteData.author);
61
+ }
62
+ // Function get random quote from thequoteshub API
63
+ function getRandomQuoteFromAPI() {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ const url = "https://thequoteshub.com/api/random-quote";
66
+ try {
67
+ const response = yield fetch(url);
68
+ if (!response.ok) {
69
+ throw new Error(`Error! Responsestatus: ${response.status}`);
70
+ }
71
+ const data = yield response.json();
72
+ return formatQuote(data.text, data.author);
73
+ }
74
+ catch (error) {
75
+ console.error("Error fetching quote from API:", error);
76
+ return formatQuote("Failed to fetch quote.", "Unknown");
77
+ }
78
+ });
79
+ }
80
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA,iDAAiD;;;;;;;;;;;;;;AAOxC,kCAAW;AAAE,0CAAe;AAAE,sCAAa;AAAE,8CAAiB;AAAE,sDAAqB;AAL9F,4CAAoB;AACpB,kDAA0B;AAC1B,kDAA0B;AAK1B,sCAAsC;AACtC,SAAS,WAAW;IAChB,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM,C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CAAC,CAAC;AAC1D,CAAC;AAED,qCAAqC;AACrC,SAAS,iBAAiB;IACtB,MAAM,SAAS,GAAG,gBAAgB,CAAC,yBAAyB,CAAC,CAAC;IAC9D,OAAO,WAAW,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;AAC1D,CAAC;AAWD,kDAAkD;AAClD,SAAe,qBAAqB;;QAChC,MAAM,GAAG,GAAW,2CAA2C,CAAC;QAChE,IAAI,CAAC;YACD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;YAClC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CAAC,0BAA0B,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;YACjE,CAAC;YACD,MAAM,IAAI,GAAU,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAC1C,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC/C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;YACvD,OAAO,WAAW,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;QAC5D,CAAC;IACL,CAAC;CAAA"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@donmur247/heyyou",
3
+ "version": "1.0.0",
4
+ "description": "Start your day with this CLI app that delivers a daily dose of quotes!",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "heyyou": "./dist/index.js"
8
+ },
9
+ "scripts": {
10
+ "build": "npx tsc"
11
+ },
12
+ "keywords": ["cli", "quotes", "daily", "inspiration", "funny", "npmtool"],
13
+ "author": "Donny Murdiyono",
14
+ "license": "ISC",
15
+ "repository": "https://github.com/donmur247/heyyou",
16
+ "homepage": "https://github.com/donmur247/heyyou#readme",
17
+ "type": "commonjs",
18
+ "dependencies": {
19
+ "boxen": "^8.0.1",
20
+ "chalk": "^5.6.2",
21
+ "commander": "^14.0.3"
22
+ },
23
+ "devDependencies": {
24
+ "@types/node": "^25.6.2",
25
+ "typescript": "^6.0.3"
26
+ }
27
+ }
package/src/index.ts ADDED
@@ -0,0 +1,49 @@
1
+ #! /usr/bin/env node
2
+
3
+ // Main entry point for heyYou CLI app.
4
+
5
+ // Third-party modules
6
+ import { Command, Option } from "commander";
7
+
8
+ // Local modules
9
+ import { getUsername, getDefaultQuote, getFunnyQuote, getInspiringQuote, getRandomQuoteFromAPI } from "./utils";
10
+
11
+ // Initialize CLI app
12
+ const app = new Command();
13
+ app
14
+ .name("heyYou")
15
+ .description("A CLI app to give user a random quote of the day.")
16
+ .addOption(new Option("-f, --funny", "Start your day with a funny quote."))
17
+ .addOption(new Option("-i, --inspire", "Get a random inspiring quote of the day."))
18
+ .addOption(new Option("-a, --api", "Get a random quote from thequoteshub API."))
19
+ .action((options, app) => {
20
+ if (options.funny && options.inspire && options.api) {
21
+ console.log("Please choose either --funny, --inspire, or --api, but not all three.");
22
+ console.log("Have a nice one! :)");
23
+ process.exit(0);
24
+ }
25
+ })
26
+ .parse(process.argv);
27
+
28
+ const options = app.opts();
29
+
30
+ // Main logic to handle user input and provide quotes
31
+ if (!process.argv.slice(2).length) {
32
+ console.log(`Hello, ${getUsername()}!\n`);
33
+ console.log(getDefaultQuote());
34
+ }
35
+
36
+ if (options.funny) {
37
+ console.log(`Hey hey, ${getUsername()}!\n`);
38
+ console.log(getFunnyQuote());
39
+ }
40
+
41
+ if (options.inspire) {
42
+ console.log(`Believe in yourself, ${getUsername()}!\n`);
43
+ console.log(getInspiringQuote());
44
+ }
45
+
46
+ if (options.api) {
47
+ console.log(`Here's a random quote for you, ${getUsername()}!\n`);
48
+ getRandomQuoteFromAPI().then((quote) => console.log(quote));
49
+ }
@@ -0,0 +1,22 @@
1
+ [
2
+ {
3
+ "quote": "The only way to do great work is to love what you do.",
4
+ "author": "Steve Jobs"
5
+ },
6
+ {
7
+ "quote": "Success is not the key to happiness. Happiness is the key to success. If you love what you are doing, you will be successful.",
8
+ "author": "Albert Schweitzer"
9
+ },
10
+ {
11
+ "quote": "Don't watch the clock; do what it does. Keep going.",
12
+ "author": "Sam Levenson"
13
+ },
14
+ {
15
+ "quote": "The future belongs to those who believe in the beauty of their dreams.",
16
+ "author": "Eleanor Roosevelt"
17
+ },
18
+ {
19
+ "quote": "It does not matter how slowly you go as long as you do not stop.",
20
+ "author": "Confucius"
21
+ }
22
+ ]
@@ -0,0 +1,22 @@
1
+ [
2
+ {
3
+ "quote": "You only live once, but if you do it right, once is enough.",
4
+ "author": "Mae West"
5
+ },
6
+ {
7
+ "quote": "A day without sunshine is like, you know, night.",
8
+ "author": "Steve Martin"
9
+ },
10
+ {
11
+ "quote": "I love deadlines. I love the whooshing noise they make as they go by.",
12
+ "author": "Douglas Adams"
13
+ },
14
+ {
15
+ "quote": "Anyone who thinks sitting in church can make you a Christian must also think that sitting in a garage can make you a car.",
16
+ "author": "Garrison Keillor"
17
+ },
18
+ {
19
+ "quote": "Be nice to nerds. You may end up working for them. We all could.",
20
+ "author": "Charles J. Sykes"
21
+ }
22
+ ]
@@ -0,0 +1,22 @@
1
+ [
2
+ {
3
+ "quote": "Be who you are and say what you feel, because those who mind don't matter, and those who matter don't mind.",
4
+ "author": "Bernard M. Baruch"
5
+ },
6
+ {
7
+ "quote": "Remember that wherever your heart is, there you will find your treasure.",
8
+ "author": "Paulo Coelho"
9
+ },
10
+ {
11
+ "quote": "Confidence is ignorance. If you're feeling cocky, it's because there's something you don't know.",
12
+ "author": "Eoin Colfer"
13
+ },
14
+ {
15
+ "quote": "Success is most often achieved by those who don't know that failure is inevitable.",
16
+ "author": "Coco Chanel"
17
+ },
18
+ {
19
+ "quote": "To share your weakness is to make yourself vulnerable; to make yourself vulnerable is to show your strength.",
20
+ "author": "Criss Jami"
21
+ }
22
+ ]
package/src/utils.ts ADDED
@@ -0,0 +1,77 @@
1
+ // Utility module for the heyYou CLI application.
2
+
3
+ import fs from "fs";
4
+ import boxen from "boxen";
5
+ import chalk from "chalk";
6
+ import { format } from "path";
7
+
8
+ export { getUsername, getDefaultQuote, getFunnyQuote, getInspiringQuote, getRandomQuoteFromAPI };
9
+
10
+ // Function to return current username
11
+ function getUsername(): string {
12
+ return process.env.USER || "User";
13
+ }
14
+
15
+ // Function to return a quote based on provided quote from a json file where it randomly
16
+ // selects a quote and returns a dictionary with the quote and its author.
17
+ function getQuoteFromFile(filePath: string): { quote: string; author: string } {
18
+ try {
19
+ const data = JSON.parse(fs.readFileSync(filePath, "utf-8"));
20
+ const randomIndex = Math.floor(Math.random() * data.length);
21
+ return data[randomIndex];
22
+ } catch (error) {
23
+ console.error("Error reading quote file:", error);
24
+ return { quote: "Failed to load quote.", author: "Unknown" };
25
+ }
26
+ }
27
+
28
+ // Function to format a quote in a box using boxen and chalk for styling
29
+ function formatQuote(quote: string, author: string): string {
30
+ const formattedQuote = chalk.cyan(`"${quote}"\n- ${author}`);
31
+ const boxedQuote = boxen(formattedQuote, { padding: 1, borderColor: "green", borderStyle: "round" });
32
+ return boxedQuote;
33
+ }
34
+
35
+
36
+ // Function to return default quote
37
+ function getDefaultQuote(): string {
38
+ const quoteData = getQuoteFromFile("src/quotes/default.json");
39
+ return formatQuote(quoteData.quote, quoteData.author);
40
+ }
41
+
42
+ // Function to return funny quote
43
+ function getFunnyQuote(): string {
44
+ const quoteData = getQuoteFromFile("src/quotes/funny.json");
45
+ return formatQuote(quoteData.quote, quoteData.author);
46
+ }
47
+
48
+ // Function to return inspiring quote
49
+ function getInspiringQuote(): string {
50
+ const quoteData = getQuoteFromFile("src/quotes/inspire.json");
51
+ return formatQuote(quoteData.quote, quoteData.author);
52
+ }
53
+
54
+ // Interface for quote data
55
+ interface Quote {
56
+ text: string;
57
+ author: string;
58
+ tags: string[];
59
+ id: Number;
60
+ author_id: string;
61
+ }
62
+
63
+ // Function get random quote from thequoteshub API
64
+ async function getRandomQuoteFromAPI(): Promise<string> {
65
+ const url: string = "https://thequoteshub.com/api/random-quote";
66
+ try {
67
+ const response = await fetch(url);
68
+ if (!response.ok) {
69
+ throw new Error(`Error! Responsestatus: ${response.status}`);
70
+ }
71
+ const data: Quote = await response.json();
72
+ return formatQuote(data.text, data.author);
73
+ } catch (error) {
74
+ console.error("Error fetching quote from API:", error);
75
+ return formatQuote("Failed to fetch quote.", "Unknown");
76
+ }
77
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "src",
4
+ "outDir": "dist",
5
+ "strict": true,
6
+ "target": "es6",
7
+ "module": "commonjs",
8
+ "sourceMap": true,
9
+ "esModuleInterop": true,
10
+ "types": ["node"],
11
+ "moduleResolution": "node",
12
+ "ignoreDeprecations": "6.0"
13
+ }
14
+ }