From c00ca248c09d3f2c6ce09169a451ba43cf74bece Mon Sep 17 00:00:00 2001 From: Riguidix Rodz Date: Sat, 27 Jul 2019 19:41:33 -0600 Subject: [PATCH 01/11] Setting the Colors of Bootstrap as Template --- src/util/chalkExtra.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/util/chalkExtra.js diff --git a/src/util/chalkExtra.js b/src/util/chalkExtra.js new file mode 100644 index 0000000..7cae488 --- /dev/null +++ b/src/util/chalkExtra.js @@ -0,0 +1,11 @@ +/* + * This File will Handle a set of functions for remove the complexity or verbosity of + ** Console.log( chalk.background.foreground( "Long String Text" ) ); + */ + +'use strict'; + +const chalk = require('chalk'); + +// Bootstrap Colors Template +const primary = "#007bff", secondary = '#6c757d', success = '#28a745', info = '#17a2b8', warning = '#ffc107', danger = '#dc3545', light = '#f8f9fa', dark = '#343a40'; From 5fe50581c02f2509d49fe589aef8b4a5bbfde707 Mon Sep 17 00:00:00 2001 From: Riguidix Rodz Date: Sat, 27 Jul 2019 19:45:36 -0600 Subject: [PATCH 02/11] Setting the Types of Logs --- src/util/chalkExtra.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/util/chalkExtra.js b/src/util/chalkExtra.js index 7cae488..4ccd9b6 100644 --- a/src/util/chalkExtra.js +++ b/src/util/chalkExtra.js @@ -7,5 +7,17 @@ const chalk = require('chalk'); +// Types of Logs +const normal = console.log; +const error = console.error; +const info = console.info; +const warning = console.warn; + // Bootstrap Colors Template const primary = "#007bff", secondary = '#6c757d', success = '#28a745', info = '#17a2b8', warning = '#ffc107', danger = '#dc3545', light = '#f8f9fa', dark = '#343a40'; + +function Log(text, type) { + +} + +exports.Log = Log; \ No newline at end of file From a2f4a6eb50a0618668cf2c99c09248a6c5ef30ca Mon Sep 17 00:00:00 2001 From: Riguidix Rodz Date: Sat, 27 Jul 2019 19:56:50 -0600 Subject: [PATCH 03/11] Implementing for output the correctly Type --- src/util/chalkExtra.js | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/util/chalkExtra.js b/src/util/chalkExtra.js index 4ccd9b6..2ed3eaf 100644 --- a/src/util/chalkExtra.js +++ b/src/util/chalkExtra.js @@ -16,8 +16,46 @@ const warning = console.warn; // Bootstrap Colors Template const primary = "#007bff", secondary = '#6c757d', success = '#28a745', info = '#17a2b8', warning = '#ffc107', danger = '#dc3545', light = '#f8f9fa', dark = '#343a40'; -function Log(text, type) { +// Types of Messages +const primaryMsg = chalk.bold.bgHex(primary).hex(light); +const secondaryMsg = chalk.bold.bgHex(secondary).hex(light); +const successMsg = chalk.bold.bgHex(success).hex(light); +const infoMsg = chalk.bold.bgHex(info).hex(light); +const errorMsg = chalk.bold.bgHex(danger).hex(light); +const warningMsg = chalk.bgHex(warning).hex(dark); +const darkMsg = chalk.bold.bgHex(dark).hex(light); + +/** + * This is a function to display logs in terminal. + * @param {string} text - Text to display in the terminal + * @param {string} type - Define the type of log + * @returns {null} null + */ +function Log(text, type) { + switch(type.toLowerCase()) { + case "primary": + console.log(primaryMsg(text)); + break; + case "secondary": + console.log(secondaryMsg(text)); + break; + case "success": + console.log(successMsg("Success:", text)); + break; + case "info": + console.info(infoMsg("Info:", text)); + break; + case "error": + console.error(errorMsg("Error:", text)); + break; + case "warning": + console.log(warningMsg("Warning:", text)); + break; + case "dark": + console.log(darkMsg(text)); + break; + } } exports.Log = Log; \ No newline at end of file From 23f2153051239c7bdd83d8f6dbde67fc157e1785 Mon Sep 17 00:00:00 2001 From: Riguidix Rodz Date: Sat, 27 Jul 2019 20:01:14 -0600 Subject: [PATCH 04/11] Remplacing all Logs in Index.js --- src/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 752d2bc..1255115 100755 --- a/src/index.js +++ b/src/index.js @@ -10,6 +10,8 @@ const prompt = require('./util/prompt'); const showProfile = require('./util/profile'); const localStorage = require('./util/localStorage'); +const { Log } = require('./util/chalkExtra'); + const BOOKMARK_TAG = ' ![BOOKMARK]'; let articles; @@ -66,7 +68,7 @@ const postPrompt = () => { } openLink(answers); }).catch(err => { - console.log('unexpected error occurred :( - ', err); + Log(('unexpected error occurred :( - ', err), "error"); }); }else{ // remove the ![BOOKMARK] tag from title @@ -93,11 +95,11 @@ const postBookmarkPrompt = () => { opn(bookmark.find(data => data.title === answer.title).link); process.exit(); }).catch(err => { - console.log(err); + Log(err, "error"); }); }).catch(err => { - console.log(err); + Log(err, "error"); }); } @@ -142,7 +144,7 @@ const showAuthorProfile = (username) => { crawler.fetchAuthorProfile(username).then((profileInfo) => { countdown.stop(); if (!profileInfo.name) { - console.error("😱 User not found. Please try again."); + Log("😱 User not found. Please try again.", "error"); process.exit(1); } showProfile(profileInfo); @@ -235,7 +237,7 @@ program // error on unknown commands program.on('command:*', function () { - console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' ')); + Log(('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' ')),"error"); process.exit(1); }); From 308e570cfe07cf654aa29f561dab574f9a0df152 Mon Sep 17 00:00:00 2001 From: Riguidix Rodz Date: Sat, 27 Jul 2019 20:02:54 -0600 Subject: [PATCH 05/11] Remplacing all Logs in Prompt.js --- src/util/prompt.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/prompt.js b/src/util/prompt.js index 0cd2af9..97c5a23 100644 --- a/src/util/prompt.js +++ b/src/util/prompt.js @@ -3,6 +3,8 @@ // Native import const inquirer = require('inquirer'); +const { Log } = require('./util/chalkExtra'); + inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt')); /** @@ -34,7 +36,7 @@ const searchTags = (tags) => { const showPosts = (titles) => { if(titles.length === 0){ - console.error("😱 No posts found. Please try again."); + Log("😱 No posts found. Please try again.", "error"); process.exit(1); } From 54de7413db889a7715a29742f13fa365bb3ec67d Mon Sep 17 00:00:00 2001 From: Riguidix Rodz Date: Sat, 27 Jul 2019 20:08:44 -0600 Subject: [PATCH 06/11] Remplacing all Logs in Profile.js --- src/util/profile.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/util/profile.js b/src/util/profile.js index fc6425e..90889a4 100644 --- a/src/util/profile.js +++ b/src/util/profile.js @@ -2,6 +2,8 @@ const chalk = require('chalk'); +const { Log } = require('./util/chalkExtra'); + const log = console.log; const title = chalk.yellow; const body = chalk.green; @@ -13,10 +15,10 @@ const body = chalk.green; */ const showNameAndDesc = (profile) => { - log(title('name')) - log(body(profile.name)); - log(title('\ndescription')) - log(body(`${profile.desc}\n`)); + Log('name', 'primary'); + Log(profile.name, 'secondary'); + Log('\ndescription', 'primary'); + Log(`${profile.desc}\n`, 'secondary'); } /** @@ -27,8 +29,8 @@ const showNameAndDesc = (profile) => { const showAuthorInfo = (profile) => { profile.field.forEach((field, index) => { - log(title(field)); - log(body(`${profile.value[index]}\n`)); + Log(field, 'primary'); + Log(`${profile.value[index]}\n`, 'secondary'); }); } @@ -39,9 +41,9 @@ const showAuthorInfo = (profile) => { */ const showLinks = (profile) => { - log(title('links')); + Log('links', 'primary'); profile.links.forEach(link => { - log(body(link)); + Log(link, 'secondary'); }); } @@ -53,9 +55,10 @@ const showLinks = (profile) => { const showSidebarDetails = (profile) => { log(''); + Log('', 'dark'); profile.sidebarHeader.forEach((header, index) => { - log(title(header)); - log(body(`${profile.sidebarBody[index]}\n`)); + Log(header, 'primary'); + Log(`${profile.sidebarBody[index]}\n`, 'secondary') }); } @@ -66,9 +69,9 @@ const showSidebarDetails = (profile) => { */ const showStats = (profile) => { - log(title('stats')); + Log('stats', 'primary'); profile.stats.forEach(stat => { - log(body(stat)); + Log(stat, 'secondary'); }); } From f7e4cbcdd0c629da5a42253fcd08729aeba4735f Mon Sep 17 00:00:00 2001 From: Riguidix Rodz Date: Sat, 27 Jul 2019 20:10:40 -0600 Subject: [PATCH 07/11] Remplacing all Logs in Crawler.js --- src/util/crawler.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/crawler.js b/src/util/crawler.js index 220e707..1cb3551 100644 --- a/src/util/crawler.js +++ b/src/util/crawler.js @@ -6,6 +6,8 @@ const algoliasearch = require('algoliasearch'); const client = algoliasearch('YE5Y9R600C', 'OTU1YjU5MWNlZTk1MjQ0YmExOTRjZmY4NDM2ZTM2YWZiYTM2ODA2NThhMzNjMDkzYTEzYjFmNDY0MDcwNjRkOHJlc3RyaWN0SW5kaWNlcz1zZWFyY2hhYmxlc19wcm9kdWN0aW9uJTJDVGFnX3Byb2R1Y3Rpb24lMkNvcmRlcmVkX2FydGljbGVzX3Byb2R1Y3Rpb24lMkNvcmRlcmVkX2FydGljbGVzX2J5X3B1Ymxpc2hlZF9hdF9wcm9kdWN0aW9uJTJDb3JkZXJlZF9hcnRpY2xlc19ieV9wb3NpdGl2ZV9yZWFjdGlvbnNfY291bnRfcHJvZHVjdGlvbiUyQ29yZGVyZWRfY29tbWVudHNfcHJvZHVjdGlvbg=='); const index = client.initIndex('searchables_production'); +const { Log } = require('./util/chalkExtra'); + //Global Variable const xray = Xray({ filters: { @@ -134,7 +136,7 @@ const fetchAuthorProfile = (username) => { */ const fetchArticle = (url) => { - return xray(url, '#article-body | trim').then(data => console.log(data)); + return xray(url, '#article-body | trim').then(data => Log(data, 'dark')); } /** From 6afc985f73010689a661e4c2ea1e3394cac23d3f Mon Sep 17 00:00:00 2001 From: Riguidix Rodz Date: Sat, 27 Jul 2019 20:19:37 -0600 Subject: [PATCH 08/11] Removing Util from type in requires --- package-lock.json | 21 ++++++++++++++------- src/util/crawler.js | 2 +- src/util/profile.js | 2 +- src/util/prompt.js | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index d8f0e60..d284d32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -93,7 +93,8 @@ "acorn": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-2.7.0.tgz", - "integrity": "sha1-q259nYhqrKiwhbwzEreaGYQz8Oc=" + "integrity": "sha1-q259nYhqrKiwhbwzEreaGYQz8Oc=", + "optional": true }, "acorn-globals": { "version": "1.0.9", @@ -223,7 +224,8 @@ "assert-plus": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", + "optional": true }, "astral-regex": { "version": "1.0.0", @@ -463,7 +465,8 @@ "cssom": { "version": "0.3.4", "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.3.4.tgz", - "integrity": "sha512-+7prCSORpXNeR4/fUP3rL+TzqtiFfhMvTd7uEqMdgPvLPt4+uzFUeufx5RHjGTACCargg/DiEt/moMQmvnfkog==" + "integrity": "sha512-+7prCSORpXNeR4/fUP3rL+TzqtiFfhMvTd7uEqMdgPvLPt4+uzFUeufx5RHjGTACCargg/DiEt/moMQmvnfkog==", + "optional": true }, "cssstyle": { "version": "0.2.37", @@ -986,7 +989,8 @@ "extsprintf": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", - "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" + "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=", + "optional": true }, "fast-deep-equal": { "version": "2.0.1", @@ -1388,7 +1392,8 @@ "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", - "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", + "optional": true }, "jsdom": { "version": "7.2.2", @@ -1858,7 +1863,8 @@ "psl": { "version": "1.1.31", "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.31.tgz", - "integrity": "sha512-/6pt4+C+T+wZUieKR620OpzN/LlnNKuWjy1iFLQ/UG35JqHlR/89MP1d96dUfkf6Dne3TuLQzOYEYshJ+Hx8mw==" + "integrity": "sha512-/6pt4+C+T+wZUieKR620OpzN/LlnNKuWjy1iFLQ/UG35JqHlR/89MP1d96dUfkf6Dne3TuLQzOYEYshJ+Hx8mw==", + "optional": true }, "punycode": { "version": "2.1.1", @@ -2286,7 +2292,8 @@ "tweetnacl": { "version": "0.14.5", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", - "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", + "optional": true }, "type-check": { "version": "0.3.2", diff --git a/src/util/crawler.js b/src/util/crawler.js index 1cb3551..d6c9292 100644 --- a/src/util/crawler.js +++ b/src/util/crawler.js @@ -6,7 +6,7 @@ const algoliasearch = require('algoliasearch'); const client = algoliasearch('YE5Y9R600C', 'OTU1YjU5MWNlZTk1MjQ0YmExOTRjZmY4NDM2ZTM2YWZiYTM2ODA2NThhMzNjMDkzYTEzYjFmNDY0MDcwNjRkOHJlc3RyaWN0SW5kaWNlcz1zZWFyY2hhYmxlc19wcm9kdWN0aW9uJTJDVGFnX3Byb2R1Y3Rpb24lMkNvcmRlcmVkX2FydGljbGVzX3Byb2R1Y3Rpb24lMkNvcmRlcmVkX2FydGljbGVzX2J5X3B1Ymxpc2hlZF9hdF9wcm9kdWN0aW9uJTJDb3JkZXJlZF9hcnRpY2xlc19ieV9wb3NpdGl2ZV9yZWFjdGlvbnNfY291bnRfcHJvZHVjdGlvbiUyQ29yZGVyZWRfY29tbWVudHNfcHJvZHVjdGlvbg=='); const index = client.initIndex('searchables_production'); -const { Log } = require('./util/chalkExtra'); +const { Log } = require('./chalkExtra'); //Global Variable const xray = Xray({ diff --git a/src/util/profile.js b/src/util/profile.js index 90889a4..47a74e1 100644 --- a/src/util/profile.js +++ b/src/util/profile.js @@ -2,7 +2,7 @@ const chalk = require('chalk'); -const { Log } = require('./util/chalkExtra'); +const { Log } = require('./chalkExtra'); const log = console.log; const title = chalk.yellow; diff --git a/src/util/prompt.js b/src/util/prompt.js index 97c5a23..329f5ea 100644 --- a/src/util/prompt.js +++ b/src/util/prompt.js @@ -3,7 +3,7 @@ // Native import const inquirer = require('inquirer'); -const { Log } = require('./util/chalkExtra'); +const { Log } = require('./chalkExtra'); inquirer.registerPrompt('autocomplete', require('inquirer-autocomplete-prompt')); From 002e29d4e36793ca4b704f1a63308cb96c2b4596 Mon Sep 17 00:00:00 2001 From: Riguidix Rodz Date: Sat, 27 Jul 2019 20:20:13 -0600 Subject: [PATCH 09/11] Removing Unused Types --- src/util/chalkExtra.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/util/chalkExtra.js b/src/util/chalkExtra.js index 2ed3eaf..c0fb3fa 100644 --- a/src/util/chalkExtra.js +++ b/src/util/chalkExtra.js @@ -7,12 +7,6 @@ const chalk = require('chalk'); -// Types of Logs -const normal = console.log; -const error = console.error; -const info = console.info; -const warning = console.warn; - // Bootstrap Colors Template const primary = "#007bff", secondary = '#6c757d', success = '#28a745', info = '#17a2b8', warning = '#ffc107', danger = '#dc3545', light = '#f8f9fa', dark = '#343a40'; From 16403eb5cebef12e865cf00b178f8312ecb0223f Mon Sep 17 00:00:00 2001 From: Riguidix Rodz Date: Wed, 28 Aug 2019 20:50:22 -0600 Subject: [PATCH 10/11] Adding new ways of background colors for the prompts --- src/util/prompt.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/prompt.js b/src/util/prompt.js index 329f5ea..85deec3 100644 --- a/src/util/prompt.js +++ b/src/util/prompt.js @@ -17,7 +17,7 @@ const searchTags = (tags) => { return inquirer.prompt([{ type: 'autocomplete', name: 'tag', - message: '🕵🏻‍♂️ Search popular tags:', + message: Log('🕵🏻‍♂️ Search popular tags:', 'info'), pageSize: 4, source: function (answers, input) { return new Promise((resolve) => { @@ -43,7 +43,7 @@ const showPosts = (titles) => { return inquirer.prompt([{ type: 'rawlist', name: 'title', - message: '📚 Here are your posts:', + message: Log('📚 Here are your posts:', 'success'), choices: titles, paginated: true }]) @@ -59,7 +59,7 @@ const selectTimline = () => { return inquirer.prompt([{ type: 'list', name: 'timeline', - message: '📆 Please choose the timeline:', + message: Log('📆 Please choose the timeline:', "info"), choices: ["week","month","year","infinity"], paginated: true }]) @@ -75,7 +75,7 @@ const postOperation = (choices) => { return inquirer.prompt([{ type: 'list', name: 'postOperation', - message: 'What do we do with this post : ', + message: Log('What do we do with this post : ', "info"), choices: choices }]); } From 2b0700d9e86a870701f26e93edc36e1154d0dc1e Mon Sep 17 00:00:00 2001 From: Riguidix Rodz Date: Wed, 28 Aug 2019 20:50:51 -0600 Subject: [PATCH 11/11] Typo in a previous Commit --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 1255115..364e23a 100755 --- a/src/index.js +++ b/src/index.js @@ -236,8 +236,8 @@ program }) // error on unknown commands -program.on('command:*', function () { - Log(('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' ')),"error"); +program.on('command:*', function () { + Log('Invalid command: %s\nSee --help for a list of available commands. ' + program.args.join(' ') ,"error"); process.exit(1); });