From c35e1b6c8483ae3b0782310d7ba694976d6bdfa6 Mon Sep 17 00:00:00 2001 From: Pradumna Saraf Date: Thu, 16 Feb 2023 14:08:50 +0530 Subject: [PATCH 01/11] feat: break cli working into dir --- Notes.md | 3 + data/Pradumna.json | 7 + data/Pradumnasaraf.json | 0 package-lock.json | 4 +- src/addtestimonial/addTestimonial.js | 5 + src/createjson/createJson.js | 95 ++++++++++++++ src/{util => createjson/helper}/checkUser.js | 0 src/{util => createjson/helper}/createUser.js | 0 src/{util => createjson/helper}/questions.js | 0 src/createtestimonial/createTestimonial.js | 5 + src/index.js | 122 +++++------------- src/updatejson/updateJson.js | 5 + 12 files changed, 154 insertions(+), 92 deletions(-) create mode 100644 Notes.md create mode 100644 data/Pradumna.json create mode 100644 data/Pradumnasaraf.json create mode 100644 src/addtestimonial/addTestimonial.js create mode 100644 src/createjson/createJson.js rename src/{util => createjson/helper}/checkUser.js (100%) rename src/{util => createjson/helper}/createUser.js (100%) rename src/{util => createjson/helper}/questions.js (100%) create mode 100644 src/createtestimonial/createTestimonial.js create mode 100644 src/updatejson/updateJson.js diff --git a/Notes.md b/Notes.md new file mode 100644 index 0000000..3295642 --- /dev/null +++ b/Notes.md @@ -0,0 +1,3 @@ +Hey, this files will be for notes and anything we want to keep track of. + +- For temp basis I have created a folder with name `data` to test things out. \ No newline at end of file diff --git a/data/Pradumna.json b/data/Pradumna.json new file mode 100644 index 0000000..32a5571 --- /dev/null +++ b/data/Pradumna.json @@ -0,0 +1,7 @@ +{ + "name": "a", + "type": "Personal", + "bio": "asas", + "links": [], + "milestones": [] +} \ No newline at end of file diff --git a/data/Pradumnasaraf.json b/data/Pradumnasaraf.json new file mode 100644 index 0000000..e69de29 diff --git a/package-lock.json b/package-lock.json index 86a94a5..5b77eff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "linkfree-cli", - "version": "1.4.0", + "version": "1.4.2", "license": "MIT", "dependencies": { "axios": "^0.27.2", @@ -303,4 +303,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/addtestimonial/addTestimonial.js b/src/addtestimonial/addTestimonial.js new file mode 100644 index 0000000..097e08e --- /dev/null +++ b/src/addtestimonial/addTestimonial.js @@ -0,0 +1,5 @@ +const updateJson = () => { + console.log("Adding a testimonial"); +} + +module.exports = updateJson; \ No newline at end of file diff --git a/src/createjson/createJson.js b/src/createjson/createJson.js new file mode 100644 index 0000000..11fa9b0 --- /dev/null +++ b/src/createjson/createJson.js @@ -0,0 +1,95 @@ +#! /usr/bin/env node + +const chalk = require("chalk"); +const { prompt } = require("enquirer"); +const fs = require("fs"); +const createUser = require("./helper/createUser"); +const checkUser = require("./helper/checkUser"); +const { questions, addlinks } = require("./helper/questions"); +let githubUsername; +let json; + +const createJson = () => { + prompt([ + { + type: "input", + name: "githubUsername", + message: "What is your GitHub username? (case sensitive)", + }, + ]) + .then((answers) => { + githubUsername = answers.githubUsername; + if (githubUsername === "") { + console.log( + chalk.bgRed.bold(` Please enter a valid GitHub username. `) + ); + createJson(); + } else if (fs.existsSync(`./data/${githubUsername}.json`)) { + console.log( + chalk.bgYellow.bold(` File ${githubUsername}.json already exists!`) + ); + prompt([ + { + type: "confirm", + name: "overwrite", + message: "Do you want to overwrite the existing file?", + }, + ]).then((answers) => { + const { overwrite } = answers; + if (overwrite) { + console.log( + chalk.bgGreen.bold(` Proceed with overwriting file... `) + ); + start(githubUsername); + } else { + console.log(chalk.bgRed.bold(` File not overwritten! `)); + console.log("Restart the program to try again."); + process.exit(0); + } + }); + } else { + start(githubUsername); + } + }) + .catch((err) => { + console.log(err); + }); +}; + +async function start(githubUsername) { + await checkUser(githubUsername).then((result) => { + if (result === true) { + questions().then((answers) => { + json = answers; + prompt([ + { + type: "confirm", + name: "addLink", + message: "Do you want to add a link?", + }, + ]).then((answers) => { + const { addLink } = answers; + if (addLink) { + addlinkstojson(); + } else { + createUser(githubUsername, json); + } + }); + }); + } else { + console.log( + chalk.bgRed.bold( + ` User with username '${githubUsername}' does not exist on GitHub, try again! ` + ) + ); + createJson(); + } + }); +} + +async function addlinkstojson() { + json.links = await addlinks(true); + createUser(githubUsername, json); +} + +module.exports = createJson; diff --git a/src/util/checkUser.js b/src/createjson/helper/checkUser.js similarity index 100% rename from src/util/checkUser.js rename to src/createjson/helper/checkUser.js diff --git a/src/util/createUser.js b/src/createjson/helper/createUser.js similarity index 100% rename from src/util/createUser.js rename to src/createjson/helper/createUser.js diff --git a/src/util/questions.js b/src/createjson/helper/questions.js similarity index 100% rename from src/util/questions.js rename to src/createjson/helper/questions.js diff --git a/src/createtestimonial/createTestimonial.js b/src/createtestimonial/createTestimonial.js new file mode 100644 index 0000000..0ca1df8 --- /dev/null +++ b/src/createtestimonial/createTestimonial.js @@ -0,0 +1,5 @@ +const createTestimonial = () => { + console.log("Creating a testimonial"); +} + +module.exports = createTestimonial; \ No newline at end of file diff --git a/src/index.js b/src/index.js index a3130af..36cee09 100755 --- a/src/index.js +++ b/src/index.js @@ -2,100 +2,42 @@ const chalk = require("chalk"); const { prompt } = require("enquirer"); -const fs = require("fs"); -const createUser = require("./util/createUser"); -const checkUser = require("./util/checkUser"); -const { questions, addlinks } = require("./util/questions"); -let githubUsername; -let json; +const createJson = require("./createjson/createJson"); +const updateJson = require("./updatejson/updateJson"); +const addTestimonial = require("./addtestimonial/addTestimonial"); +const createTestimonial = require("./createtestimonial/createTestimonial"); console.log( - chalk.bgYellowBright.bold( - ` Welcome to LinkFree CLI! Let's get started by creating your JSON file. ` - ) + chalk.bgWhite.bold(` Welcome to LinkFree CLI! Let's get started. `) ); -init(); +const choices = [ + "Create a LinkFree JSON file", + "Update an existing JSON file", + "Provide a testimonial to a LinkFree user", + "Add a given testimonial to your JSON file", +]; -async function init() { - prompt([ - { - type: "input", - name: "githubUsername", - message: "What is your GitHub username? (case sensitive)", - }, - ]) - .then((answers) => { - githubUsername = answers.githubUsername; - if (githubUsername === "") { - console.log( - chalk.bgRed.bold(` Please enter a valid GitHub username. `) - ); - init(); - } else if (fs.existsSync(`./data/${githubUsername}.json`)) { - console.log( - chalk.bgYellow.bold(` File ${githubUsername}.json already exists!`) - ); - prompt([ - { - type: "confirm", - name: "overwrite", - message: "Do you want to overwrite the existing file?", - }, - ]).then((answers) => { - const { overwrite } = answers; - if (overwrite) { - console.log( - chalk.bgGreen.bold(` Proceed with overwriting file... `) - ); - start(githubUsername); - } else { - console.log(chalk.bgRed.bold(` File not overwritten! `)); - console.log("Restart the program to try again."); - process.exit(0); - } - }); - } else { - start(githubUsername); - } - }) - .catch((err) => { - console.log(err); - }); -} - -async function start(githubUsername) { - await checkUser(githubUsername).then((result) => { - if (result === true) { - questions().then((answers) => { - json = answers; - prompt([ - { - type: "confirm", - name: "addLink", - message: "Do you want to add a link?", - }, - ]).then((answers) => { - const { addLink } = answers; - if (addLink) { - addlinkstojson(); - } else { - createUser(githubUsername, json); - } - }); - }); - } else { - console.log( - chalk.bgRed.bold( - ` User with username '${githubUsername}' does not exist on GitHub, try again! ` - ) - ); - init(); +prompt([ + { + type: "select", + name: "selectedtask", + choices: choices, + message: "Choose an icon (Press down arrow to see more options)", + }, +]) + .then((answers) => { + const { selectedtask } = answers; + if (selectedtask === "Create a LinkFree JSON file") { + createJson(); + } else if (selectedtask === "Update an existing JSON file") { + updateJson(); + } else if (selectedtask === "Provide a testimonial to a LinkFree user") { + addTestimonial(); + } else if (selectedtask === "Add a given testimonial to your JSON file") { + createTestimonial(); } + }) + .catch((error) => { + console.error(error); }); -} - -async function addlinkstojson() { - json.links = await addlinks(true); - createUser(githubUsername, json); -} diff --git a/src/updatejson/updateJson.js b/src/updatejson/updateJson.js new file mode 100644 index 0000000..c14de11 --- /dev/null +++ b/src/updatejson/updateJson.js @@ -0,0 +1,5 @@ +const updateJson = () => { + console.log("Updating an existing JSON file"); +} + +module.exports = updateJson; \ No newline at end of file From 22f2e28a103f64e8fd6e8ccb47850e9e7d5c818e Mon Sep 17 00:00:00 2001 From: Ananya Nayak <55504616+Ananya2001-an@users.noreply.github.com> Date: Fri, 17 Feb 2023 16:33:48 +0530 Subject: [PATCH 02/11] feat: add update, create and testimonial feature (#24) --- Notes.md | 6 +- data/Ananya2001-an.json | 18 ++ data/Pradumna.json | 7 - data/Pradumnasaraf.json | 15 ++ src/addevent/addEvent.js | 3 + src/createjson/createJson.js | 51 +++-- src/createjson/helper/createUser.js | 15 +- src/createjson/helper/questions.js | 80 ------- src/createtestimonial/createTestimonial.js | 5 - .../giveTestimonial.js} | 0 src/index.js | 38 ++-- src/shared/assets/icons.js | 17 ++ .../helper => shared}/checkUser.js | 0 src/shared/questions/basics.js | 82 +++++++ src/shared/questions/links.js | 88 ++++++++ src/shared/questions/testimonials.js | 71 ++++++ src/updatejson/helper/checkUpdate.js | 37 +++ src/updatejson/updateJson.js | 213 +++++++++++++++++- 18 files changed, 604 insertions(+), 142 deletions(-) create mode 100644 data/Ananya2001-an.json delete mode 100644 data/Pradumna.json create mode 100644 src/addevent/addEvent.js delete mode 100644 src/createjson/helper/questions.js delete mode 100644 src/createtestimonial/createTestimonial.js rename src/{addtestimonial/addTestimonial.js => givetestimonial/giveTestimonial.js} (100%) create mode 100644 src/shared/assets/icons.js rename src/{createjson/helper => shared}/checkUser.js (100%) create mode 100644 src/shared/questions/basics.js create mode 100644 src/shared/questions/links.js create mode 100644 src/shared/questions/testimonials.js create mode 100644 src/updatejson/helper/checkUpdate.js diff --git a/Notes.md b/Notes.md index 3295642..fa0c1e7 100644 --- a/Notes.md +++ b/Notes.md @@ -1,3 +1,5 @@ -Hey, this files will be for notes and anything we want to keep track of. +Hey, this files will be for notes and anything we want to keep track of. -- For temp basis I have created a folder with name `data` to test things out. \ No newline at end of file +- For temp basis I have created a folder with name `data` to test things out. + +- Created shared folder for common assets being used by different functions diff --git a/data/Ananya2001-an.json b/data/Ananya2001-an.json new file mode 100644 index 0000000..2df463f --- /dev/null +++ b/data/Ananya2001-an.json @@ -0,0 +1,18 @@ +{ + "name": "Ananya Nayak", + "type": "Personal", + "bio": "Open source is fun", + "links": [ + { + "name": "YouTube: Learn more about Open Source", + "url": "https://youtube.com/eddiejaoude", + "icon": "FaYoutube" + }, + { + "name": "GitHub: Collaborate on Open Source", + "url": "https://github.com/eddiejaoude", + "icon": "FaGithub" + } + ], + "milestones": [] +} \ No newline at end of file diff --git a/data/Pradumna.json b/data/Pradumna.json deleted file mode 100644 index 32a5571..0000000 --- a/data/Pradumna.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "a", - "type": "Personal", - "bio": "asas", - "links": [], - "milestones": [] -} \ No newline at end of file diff --git a/data/Pradumnasaraf.json b/data/Pradumnasaraf.json index e69de29..8eb6093 100644 --- a/data/Pradumnasaraf.json +++ b/data/Pradumnasaraf.json @@ -0,0 +1,15 @@ +{ + "name": "Prad", + "type": "Personal", + "bio": "dev", + "links": [ + { + "name": "git", + "url": "jfhjhgjf", + "icon": "FaGithub" + } + ], + "testimonials": [ + "eddiejaoude" + ] +} \ No newline at end of file diff --git a/src/addevent/addEvent.js b/src/addevent/addEvent.js new file mode 100644 index 0000000..b92c2f1 --- /dev/null +++ b/src/addevent/addEvent.js @@ -0,0 +1,3 @@ +const addEvent = () => {}; + +module.exports = addEvent; diff --git a/src/createjson/createJson.js b/src/createjson/createJson.js index 11fa9b0..e00fd9c 100644 --- a/src/createjson/createJson.js +++ b/src/createjson/createJson.js @@ -4,9 +4,10 @@ const chalk = require("chalk"); const { prompt } = require("enquirer"); const fs = require("fs"); const createUser = require("./helper/createUser"); -const checkUser = require("./helper/checkUser"); -const { questions, addlinks } = require("./helper/questions"); -let githubUsername; +const checkUser = require("../shared/checkUser"); +const { basics } = require("../shared/questions/basics"); +const { addlinks } = require("../shared/questions/links"); +const updateJson = require("../updatejson/updateJson"); let json; const createJson = () => { @@ -18,7 +19,7 @@ const createJson = () => { }, ]) .then((answers) => { - githubUsername = answers.githubUsername; + const { githubUsername } = answers; if (githubUsername === "") { console.log( chalk.bgRed.bold(` Please enter a valid GitHub username. `) @@ -32,17 +33,15 @@ const createJson = () => { { type: "confirm", name: "overwrite", - message: "Do you want to overwrite the existing file?", + message: "Do you want to update the existing file?", }, ]).then((answers) => { const { overwrite } = answers; if (overwrite) { - console.log( - chalk.bgGreen.bold(` Proceed with overwriting file... `) - ); - start(githubUsername); + console.log(chalk.bgGreen.bold(` Proceed with updating file... `)); + updateJson(githubUsername); } else { - console.log(chalk.bgRed.bold(` File not overwritten! `)); + console.log(chalk.bgRed.bold(` File not updated! `)); console.log("Restart the program to try again."); process.exit(0); } @@ -59,22 +58,33 @@ const createJson = () => { async function start(githubUsername) { await checkUser(githubUsername).then((result) => { if (result === true) { - questions().then((answers) => { + basics().then(async (answers) => { json = answers; - prompt([ + await prompt([ { type: "confirm", name: "addLink", message: "Do you want to add a link?", }, - ]).then((answers) => { - const { addLink } = answers; - if (addLink) { - addlinkstojson(); - } else { - createUser(githubUsername, json); + ]).then(async (answers) => { + if (answers.addLink) { + json.links = await addlinks(true); } }); + + // await prompt([ + // { + // type: "confirm", + // name: "addMilestone", + // message: "Do you want to add a milestone?", + // }, + // ]).then(async (answers) => { + // if (answers.addMilestone) { + // json.milestones = await addmilestones(true); + // } + // }); + + createUser(githubUsername, json); }); } else { console.log( @@ -87,9 +97,4 @@ async function start(githubUsername) { }); } -async function addlinkstojson() { - json.links = await addlinks(true); - createUser(githubUsername, json); -} - module.exports = createJson; diff --git a/src/createjson/helper/createUser.js b/src/createjson/helper/createUser.js index bfffae1..e0ef829 100644 --- a/src/createjson/helper/createUser.js +++ b/src/createjson/helper/createUser.js @@ -2,14 +2,18 @@ const jsonFormat = require("json-format"); const chalk = require("chalk"); const fs = require("fs"); -async function createUserJson(githubUsername, answers) { +async function createUser(githubUsername, answers) { sampleJson = { name: `${answers.name}`, type: `${answers.type}`, bio: `${answers.bio}`, - links: answers.links ? answers.links : [], - milestones: answers.milestones ? answers.milestones : [], }; + if (answers.links) { + sampleJson.links = answers.links; + } + // if (answers.milestones) { + // sampleJson.milestones = answers.milestones; + // } const json = jsonFormat(sampleJson, { type: "space", size: 2 }); fs.writeFile(`./data/${githubUsername}.json`, json, (err) => { @@ -19,14 +23,15 @@ async function createUserJson(githubUsername, answers) { ` You are not in the root directory of LinkFree. Try again! ` ) ); + process.exit(0); } else { console.log( chalk.bgWhite.bold( - ` File with ${githubUsername}.json created successfully! ` + ` File ${githubUsername}.json created successfully! ` ) ); } }); } -module.exports = createUserJson; +module.exports = createUser; diff --git a/src/createjson/helper/questions.js b/src/createjson/helper/questions.js deleted file mode 100644 index 017f39b..0000000 --- a/src/createjson/helper/questions.js +++ /dev/null @@ -1,80 +0,0 @@ -const { prompt } = require("enquirer"); -const chalk = require("chalk"); -const axios = require("axios"); - -let links = []; -let icons = []; - -async function questions() { - const answers = await prompt([ - { - type: "input", - name: "name", - message: "What is your name (e.g. Jone Doe)?", - }, - { - type: "select", - name: "type", - message: "Your profile type?", - choices: ["Personal", "Community"], - }, - { - type: "input", - name: "bio", - message: "Add a short bio about yourself", - }, - ]); - return answers; -} - -async function geticons() { - try { - const response = await axios.get( - `https://raw.githubusercontent.com/EddieHubCommunity/LinkFree/main/config/icons.json` - ); - icons = Object.keys(response.data); - } catch (error) { - console.error(error); - } -} - -async function addlinks(bool) { - // wait for the icons to be fetched - await geticons(); - - while (bool) { - let answers = await prompt([ - { - type: "input", - name: "name", - message: "What is the name of the link?", - }, - { - type: "input", - name: "url", - message: "What is the URL of the link?", - }, - { - type: "select", - name: "icon", - choices: icons, - message: "Choose an icon (Press down arrow to see more options)", - }, - { - type: "confirm", - name: "addLink", - message: "Do you want to add another link?", - }, - ]); - links.push({ - name: answers.name, - url: answers.url, - icon: answers.icon, - }); - if (!answers.addLink) { - return links; - } - } -} - -module.exports = { questions, addlinks }; diff --git a/src/createtestimonial/createTestimonial.js b/src/createtestimonial/createTestimonial.js deleted file mode 100644 index 0ca1df8..0000000 --- a/src/createtestimonial/createTestimonial.js +++ /dev/null @@ -1,5 +0,0 @@ -const createTestimonial = () => { - console.log("Creating a testimonial"); -} - -module.exports = createTestimonial; \ No newline at end of file diff --git a/src/addtestimonial/addTestimonial.js b/src/givetestimonial/giveTestimonial.js similarity index 100% rename from src/addtestimonial/addTestimonial.js rename to src/givetestimonial/giveTestimonial.js diff --git a/src/index.js b/src/index.js index 36cee09..533423b 100755 --- a/src/index.js +++ b/src/index.js @@ -1,12 +1,11 @@ #! /usr/bin/env node - +const fs = require("fs"); const chalk = require("chalk"); const { prompt } = require("enquirer"); const createJson = require("./createjson/createJson"); -const updateJson = require("./updatejson/updateJson"); -const addTestimonial = require("./addtestimonial/addTestimonial"); -const createTestimonial = require("./createtestimonial/createTestimonial"); - +const checkUpdate = require("./updatejson/helper/checkUpdate"); +const giveTestimonial = require("./givetestimonial/giveTestimonial"); +const addEvent = require("./addevent/addEvent"); console.log( chalk.bgWhite.bold(` Welcome to LinkFree CLI! Let's get started. `) ); @@ -15,7 +14,7 @@ const choices = [ "Create a LinkFree JSON file", "Update an existing JSON file", "Provide a testimonial to a LinkFree user", - "Add a given testimonial to your JSON file", + "Add an event", ]; prompt([ @@ -23,19 +22,26 @@ prompt([ type: "select", name: "selectedtask", choices: choices, - message: "Choose an icon (Press down arrow to see more options)", + message: "Choose one option (Press down arrow to traverse the list)", }, ]) - .then((answers) => { + .then(async (answers) => { const { selectedtask } = answers; - if (selectedtask === "Create a LinkFree JSON file") { - createJson(); - } else if (selectedtask === "Update an existing JSON file") { - updateJson(); - } else if (selectedtask === "Provide a testimonial to a LinkFree user") { - addTestimonial(); - } else if (selectedtask === "Add a given testimonial to your JSON file") { - createTestimonial(); + switch (selectedtask) { + case "Create a LinkFree JSON file": { + createJson(); + break; + } + case "Update an existing JSON file": { + checkUpdate(); + break; + } + case "Provide a testimonial to a LinkFree user": { + giveTestimonial(); + break; + } + default: + addEvent(); } }) .catch((error) => { diff --git a/src/shared/assets/icons.js b/src/shared/assets/icons.js new file mode 100644 index 0000000..51af6d2 --- /dev/null +++ b/src/shared/assets/icons.js @@ -0,0 +1,17 @@ +const axios = require("axios"); +let icons = []; +async function geticons() { + try { + const response = await axios.get( + `https://raw.githubusercontent.com/EddieHubCommunity/LinkFree/main/config/icons.json` + ); + icons = Object.keys(response.data); + return icons; + } catch (error) { + console.error(error); + } +} + +module.exports = { + geticons, +}; diff --git a/src/createjson/helper/checkUser.js b/src/shared/checkUser.js similarity index 100% rename from src/createjson/helper/checkUser.js rename to src/shared/checkUser.js diff --git a/src/shared/questions/basics.js b/src/shared/questions/basics.js new file mode 100644 index 0000000..a511e11 --- /dev/null +++ b/src/shared/questions/basics.js @@ -0,0 +1,82 @@ +const { prompt } = require("enquirer"); + +async function basics() { + const answers = await prompt([ + { + type: "input", + name: "name", + message: "What is your name (e.g. Jone Doe)?", + }, + { + type: "select", + name: "type", + message: "Your profile type?", + choices: ["Personal", "Community"], + }, + { + type: "input", + name: "bio", + message: "Add a short bio about yourself", + }, + ]); + return answers; +} + +// async function addmilestones(bool) { +// await geticons(); +// while (bool) { +// let answers = await prompt([ +// { +// type: "input", +// name: "title", +// message: "What is the title of your milestone?", +// }, +// { +// type: "input", +// name: "date", +// message: "In which year you achieved it?", +// }, +// { +// type: "select", +// name: "icon", +// choices: icons, +// message: "Choose an icon (Press down arrow to see more options)", +// }, +// { +// type: "input", +// name: "description", +// message: "Give a short description for your milestone", +// }, +// { +// type: "input", +// name: "url", +// message: "Give a url related to your milestone", +// }, +// { +// type: "input", +// name: "color", +// message: "Give a color theme", +// }, +// { +// type: "confirm", +// name: "addMilestone", +// message: "Do you want to add another milestone?", +// }, +// ]); +// milestones.push({ +// title: answers.title, +// url: answers.url, +// icon: answers.icon, +// date: answers.date, +// description: answers.description, +// color: answers.color, +// }); +// if (!answers.addMilestone) { +// return milestones; +// } +// } +// } + +module.exports = { + basics, +}; diff --git a/src/shared/questions/links.js b/src/shared/questions/links.js new file mode 100644 index 0000000..341c429 --- /dev/null +++ b/src/shared/questions/links.js @@ -0,0 +1,88 @@ +const { prompt } = require("enquirer"); +const { geticons } = require("../assets/icons"); +let links = []; +let icons = []; + +async function addlinks(bool) { + icons = await geticons(); + + while (bool) { + let answers = await prompt([ + { + type: "input", + name: "name", + message: "What is the name of the link?", + }, + { + type: "input", + name: "url", + message: "What is the URL of the link?", + }, + { + type: "select", + name: "icon", + choices: icons, + message: "Choose an icon (Press down arrow to see more options)", + }, + { + type: "confirm", + name: "addLink", + message: "Do you want to add another link?", + }, + ]); + links.push({ + name: answers.name, + url: answers.url, + icon: answers.icon, + }); + if (!answers.addLink) { + return links; + } + } +} + +async function removelinks(links) { + let choiceLinks = links; + let stop = false; + while (!stop) { + const answers = await prompt([ + { + type: "select", + name: "link", + choices: choiceLinks, + message: "Choose which one you want to remove", + }, + ]); + choiceLinks = choiceLinks.filter((link) => link.name !== answers.link); + if (choiceLinks.length !== 0) { + const res = await prompt([ + { + type: "confirm", + name: "removeLink", + message: "Do you want to remove another link?", + }, + ]); + if (!res.removeLink) { + let result = []; + choiceLinks.map((link) => { + const { name, url, icon } = link; + result.push({ name, url, icon }); + }); + return result; + } + } else { + return []; + } + } +} + +function updatelinks(links) { + console.log("updating links"); + return links; +} + +module.exports = { + addlinks, + removelinks, + updatelinks, +}; diff --git a/src/shared/questions/testimonials.js b/src/shared/questions/testimonials.js new file mode 100644 index 0000000..cac721a --- /dev/null +++ b/src/shared/questions/testimonials.js @@ -0,0 +1,71 @@ +const { prompt } = require("enquirer"); +let testimonials = []; + +async function addtestimonials(bool) { + while (bool) { + let answers = await prompt([ + { + type: "input", + name: "name", + message: "Who gave the testimonial?(write their username)", + }, + { + type: "confirm", + name: "addTestimonial", + message: "Do you want to add another testimonial?", + }, + ]); + testimonials.push(answers.name); + if (!answers.addTestimonial) { + return testimonials; + } + } +} + +async function removetestimonials(testimonials) { + let choiceTestimonials = testimonials; + let stop = false; + while (!stop) { + const answers = await prompt([ + { + type: "select", + name: "testimonial", + choices: choiceTestimonials, + message: "Choose which one you want to remove", + }, + ]); + choiceTestimonials = choiceTestimonials.filter( + (testimonial) => testimonial.name !== answers.testimonial + ); + if (choiceTestimonials.length !== 0) { + const res = await prompt([ + { + type: "confirm", + name: "removeTestimonial", + message: "Do you want to remove another testimonial?", + }, + ]); + if (!res.removeTestimonial) { + let result = []; + choiceTestimonials.map((testimonial) => { + const { name } = testimonial; + result.push(name); + }); + return result; + } + } else { + return []; + } + } +} + +async function updatetestimonials(testimonials) { + console.log("updating testimonials"); + return testimonials; +} + +module.exports = { + addtestimonials, + removetestimonials, + updatetestimonials, +}; diff --git a/src/updatejson/helper/checkUpdate.js b/src/updatejson/helper/checkUpdate.js new file mode 100644 index 0000000..c396049 --- /dev/null +++ b/src/updatejson/helper/checkUpdate.js @@ -0,0 +1,37 @@ +const chalk = require("chalk"); +const fs = require("fs"); +const { prompt } = require("enquirer"); +const updateJson = require("../updateJson"); + +async function checkUpdate() { + const githubUsername = await getUsername(); + if (fs.existsSync(`./data/${githubUsername}.json`)) { + updateJson(githubUsername); + } else { + console.log( + chalk.bgYellow.bold( + ` File ${githubUsername}.json doesn't exist! Please enter valid username` + ) + ); + checkUpdate(); + } +} + +const getUsername = async () => { + const answers = await prompt([ + { + type: "input", + name: "name", + message: "What is your GitHub username? (case sensitive)", + }, + ]); + + if (answers.name === "") { + console.log(chalk.bgRed.bold(` Please enter a valid GitHub username. `)); + getUsername(); + } else { + return answers.name; + } +}; + +module.exports = checkUpdate; diff --git a/src/updatejson/updateJson.js b/src/updatejson/updateJson.js index c14de11..fa09783 100644 --- a/src/updatejson/updateJson.js +++ b/src/updatejson/updateJson.js @@ -1,5 +1,210 @@ -const updateJson = () => { - console.log("Updating an existing JSON file"); -} +const chalk = require("chalk"); +const { prompt } = require("enquirer"); +const fs = require("fs"); +const jsonFormat = require("json-format"); +const { + addlinks, + removelinks, + updatelinks, +} = require("../shared/questions/links"); +const { + addtestimonials, + removetestimonials, + updatetestimonials, +} = require("../shared/questions/testimonials"); -module.exports = updateJson; \ No newline at end of file +let json; +const updateJson = async (githubUsername) => { + await fs.readFile(`./data/${githubUsername}.json`, function (error, content) { + if (error) { + console.log(chalk.bgRed.bold("You are not in the root folder!")); + console.log("Restart the program to try again."); + process.exit(0); + } + json = JSON.parse(content); + }); + + await prompt([ + { + type: "confirm", + name: "name", + message: "Do you want to change your name?", + }, + ]).then(async (answers) => { + if (answers.name) { + await prompt([ + { + type: "input", + name: "name", + message: "What is your new name?", + }, + ]).then((answers) => (json.name = answers.name)); + } + }); + + await prompt([ + { + type: "confirm", + name: "type", + message: "Do you want to change your profile type?", + }, + ]).then(async (answers) => { + if (answers.type) { + await prompt([ + { + type: "select", + name: "type", + message: "Your new profile type?", + choices: ["Personal", "Community"], + }, + ]).then((answers) => (json.type = answers.type)); + } + }); + + await prompt([ + { + type: "confirm", + name: "bio", + message: "Do you want to change your bio?", + }, + ]).then(async (answers) => { + if (answers.bio) { + await prompt([ + { + type: "input", + name: "bio", + message: "Your new bio?", + }, + ]).then((answers) => (json.bio = answers.bio)); + } + }); + + await prompt([ + { + type: "confirm", + name: "link", + message: "Do you want to update your links?", + }, + ]).then(async (answers) => { + if (answers.link) { + await prompt([ + { + type: "select", + name: "operation", + message: "What you want to do?", + choices: ["add a link?", "remove a link?", "update a link?"], + }, + ]).then(async (answers) => { + switch (answers.operation) { + case "add a link?": { + if (json.links) { + json.links = [...json.links, ...(await addlinks(true))]; + } else { + json.links = [...(await addlinks(true))]; + } + break; + } + case "remove a link?": { + if (json.links) { + json.links = [...(await removelinks(json.links))]; + } else { + console.log( + chalk.bgYellow.bold("You don't have any links to remove!") + ); + } + break; + } + default: { + if (json.links) { + json.links = [...(await updatelinks(json.links))]; + } else { + console.log( + chalk.bgYellow.bold("You don't have any links to update!") + ); + } + } + } + }); + } + }); + + await prompt([ + { + type: "confirm", + name: "testimonial", + message: "Do you want to update your testimonials?", + }, + ]).then(async (answers) => { + if (answers.testimonial) { + await prompt([ + { + type: "select", + name: "operation", + message: "What you want to do?", + choices: [ + "add a testimonial?", + "remove a testimonial?", + "update a testimonial?", + ], + }, + ]).then(async (answers) => { + switch (answers.operation) { + case "add a testimonial?": { + if (json.testimonials) { + json.testimonials = [ + ...json.testimonials, + ...(await addtestimonials(true)), + ]; + } else { + json.testimonials = [...(await addtestimonials(true))]; + } + break; + } + case "remove a testimonial?": { + if (json.testimonials) { + json.testimonials = [ + ...(await removetestimonials(json.testimonials)), + ]; + } else { + console.log( + chalk.bgYellow.bold( + "You don't have any testimonials to remove!" + ) + ); + } + break; + } + default: { + if (json.testimonials) { + json.testimonials = [ + ...(await updatetestimonials(json.testimonials)), + ]; + } else { + console.log( + chalk.bgYellow.bold( + "You don't have any testimonials to update!" + ) + ); + } + } + } + }); + } + }); + + json = jsonFormat(json, { type: "space", size: 2 }); + fs.writeFile(`./data/${githubUsername}.json`, json, (err) => { + if (err) { + console.log(chalk.bgYellow.bold(` Couldn't update file. Try again! `)); + process.exit(0); + } else { + console.log( + chalk.bgWhite.bold( + ` File ${githubUsername}.json updated successfully! ` + ) + ); + } + }); +}; + +module.exports = updateJson; From 2656aaf62e208f72dbd9d668c2b6bda3dd07c528 Mon Sep 17 00:00:00 2001 From: Pradumna Saraf Date: Fri, 17 Feb 2023 19:26:46 +0530 Subject: [PATCH 03/11] feat: Add support for milestones, socials, and tags (#26) --- Notes.md | 2 + data/Ananya2001-an.json | 2 +- data/Pradumnasaraf.json | 6 +-- package.json | 2 +- src/addevent/addEvent.js | 4 +- src/createjson/createJson.js | 50 +++++++++++++---- src/createjson/helper/createUser.js | 19 ++++--- src/givetestimonial/giveTestimonial.js | 6 +-- src/shared/questions/basics.js | 55 ------------------- src/shared/questions/milestones.js | 75 ++++++++++++++++++++++++++ src/shared/questions/socials.js | 51 ++++++++++++++++++ src/shared/questions/tags.js | 38 +++++++++++++ 12 files changed, 228 insertions(+), 82 deletions(-) create mode 100644 src/shared/questions/milestones.js create mode 100644 src/shared/questions/socials.js create mode 100644 src/shared/questions/tags.js diff --git a/Notes.md b/Notes.md index fa0c1e7..e5f8c6b 100644 --- a/Notes.md +++ b/Notes.md @@ -3,3 +3,5 @@ Hey, this files will be for notes and anything we want to keep track of. - For temp basis I have created a folder with name `data` to test things out. - Created shared folder for common assets being used by different functions + +- Using Eddie's profile for ref https://github.com/EddieHubCommunity/LinkFree/blob/main/data/eddiejaoude.json diff --git a/data/Ananya2001-an.json b/data/Ananya2001-an.json index 2df463f..f8a73ed 100644 --- a/data/Ananya2001-an.json +++ b/data/Ananya2001-an.json @@ -15,4 +15,4 @@ } ], "milestones": [] -} \ No newline at end of file +} diff --git a/data/Pradumnasaraf.json b/data/Pradumnasaraf.json index 8eb6093..695dde3 100644 --- a/data/Pradumnasaraf.json +++ b/data/Pradumnasaraf.json @@ -9,7 +9,5 @@ "icon": "FaGithub" } ], - "testimonials": [ - "eddiejaoude" - ] -} \ No newline at end of file + "testimonials": ["eddiejaoude"] +} diff --git a/package.json b/package.json index 5f15114..1198045 100644 --- a/package.json +++ b/package.json @@ -37,4 +37,4 @@ "bugs": { "url": "https://github.com/Pradumnasaraf/LinkFRee-CLI.git/issues" } -} \ No newline at end of file +} diff --git a/src/addevent/addEvent.js b/src/addevent/addEvent.js index b92c2f1..39ae64f 100644 --- a/src/addevent/addEvent.js +++ b/src/addevent/addEvent.js @@ -1,3 +1,5 @@ -const addEvent = () => {}; +const addEvent = () => { + console.log("add event"); +}; module.exports = addEvent; diff --git a/src/createjson/createJson.js b/src/createjson/createJson.js index e00fd9c..3d4e686 100644 --- a/src/createjson/createJson.js +++ b/src/createjson/createJson.js @@ -7,7 +7,11 @@ const createUser = require("./helper/createUser"); const checkUser = require("../shared/checkUser"); const { basics } = require("../shared/questions/basics"); const { addlinks } = require("../shared/questions/links"); +const { addtags } = require("../shared/questions/tags"); +const { addmilestones } = require("../shared/questions/milestones"); +const { addsocials } = require("../shared/questions/socials"); const updateJson = require("../updatejson/updateJson"); + let json; const createJson = () => { @@ -72,17 +76,41 @@ async function start(githubUsername) { } }); - // await prompt([ - // { - // type: "confirm", - // name: "addMilestone", - // message: "Do you want to add a milestone?", - // }, - // ]).then(async (answers) => { - // if (answers.addMilestone) { - // json.milestones = await addmilestones(true); - // } - // }); + await prompt([ + { + type: "confirm", + name: "addTag", + message: "Do you want to add a tag?", + }, + ]).then(async (answers) => { + if (answers.addTag) { + json.tags = await addtags(true); + } + }); + + await prompt([ + { + type: "confirm", + name: "addSocial", + message: "Do you want to add a social?", + }, + ]).then(async (answers) => { + if (answers.addSocial) { + json.social = await addsocials(true); + } + }); + + await prompt([ + { + type: "confirm", + name: "addMilestone", + message: "Do you want to add a milestone?", + }, + ]).then(async (answers) => { + if (answers.addMilestone) { + json.milestones = await addmilestones(true); + } + }); createUser(githubUsername, json); }); diff --git a/src/createjson/helper/createUser.js b/src/createjson/helper/createUser.js index e0ef829..4e4bd6a 100644 --- a/src/createjson/helper/createUser.js +++ b/src/createjson/helper/createUser.js @@ -3,19 +3,26 @@ const chalk = require("chalk"); const fs = require("fs"); async function createUser(githubUsername, answers) { - sampleJson = { + jsonSchema = { name: `${answers.name}`, type: `${answers.type}`, bio: `${answers.bio}`, }; if (answers.links) { - sampleJson.links = answers.links; + jsonSchema.links = answers.links; + } + if (answers.milestones) { + jsonSchema.milestones = answers.milestones; + } + if (answers.tags) { + jsonSchema.tags = answers.tags; + } + + if (answers.social) { + jsonSchema.social = answers.social; } - // if (answers.milestones) { - // sampleJson.milestones = answers.milestones; - // } - const json = jsonFormat(sampleJson, { type: "space", size: 2 }); + const json = jsonFormat(jsonSchema, { type: "space", size: 2 }); fs.writeFile(`./data/${githubUsername}.json`, json, (err) => { if (err) { console.log( diff --git a/src/givetestimonial/giveTestimonial.js b/src/givetestimonial/giveTestimonial.js index 097e08e..bc601f7 100644 --- a/src/givetestimonial/giveTestimonial.js +++ b/src/givetestimonial/giveTestimonial.js @@ -1,5 +1,5 @@ const updateJson = () => { - console.log("Adding a testimonial"); -} + console.log("Adding a testimonial"); +}; -module.exports = updateJson; \ No newline at end of file +module.exports = updateJson; diff --git a/src/shared/questions/basics.js b/src/shared/questions/basics.js index a511e11..ac92540 100644 --- a/src/shared/questions/basics.js +++ b/src/shared/questions/basics.js @@ -22,61 +22,6 @@ async function basics() { return answers; } -// async function addmilestones(bool) { -// await geticons(); -// while (bool) { -// let answers = await prompt([ -// { -// type: "input", -// name: "title", -// message: "What is the title of your milestone?", -// }, -// { -// type: "input", -// name: "date", -// message: "In which year you achieved it?", -// }, -// { -// type: "select", -// name: "icon", -// choices: icons, -// message: "Choose an icon (Press down arrow to see more options)", -// }, -// { -// type: "input", -// name: "description", -// message: "Give a short description for your milestone", -// }, -// { -// type: "input", -// name: "url", -// message: "Give a url related to your milestone", -// }, -// { -// type: "input", -// name: "color", -// message: "Give a color theme", -// }, -// { -// type: "confirm", -// name: "addMilestone", -// message: "Do you want to add another milestone?", -// }, -// ]); -// milestones.push({ -// title: answers.title, -// url: answers.url, -// icon: answers.icon, -// date: answers.date, -// description: answers.description, -// color: answers.color, -// }); -// if (!answers.addMilestone) { -// return milestones; -// } -// } -// } - module.exports = { basics, }; diff --git a/src/shared/questions/milestones.js b/src/shared/questions/milestones.js new file mode 100644 index 0000000..8212a70 --- /dev/null +++ b/src/shared/questions/milestones.js @@ -0,0 +1,75 @@ +const { prompt } = require("enquirer"); +const { geticons } = require("../assets/icons"); + +let milestones = []; +let icons = []; + +async function addmilestones(bool) { + icons = await geticons(); + + while (bool) { + let answers = await prompt([ + { + type: "input", + name: "title", + message: "What is the title of your milestone?", + }, + { + type: "input", + name: "date", + message: "In which year you achieved it?", + }, + { + type: "select", + name: "icon", + choices: icons, + message: "Choose an icon (Press down arrow to see more options)", + }, + { + type: "input", + name: "description", + message: "Give a short description for your milestone", + }, + { + type: "input", + name: "url", + message: "Give a url related to your milestone", + }, + { + type: "input", + name: "color", + message: "Give a color theme", + }, + { + type: "confirm", + name: "addMilestone", + message: "Do you want to add another milestone?", + }, + ]); + milestones.push({ + title: answers.title, + url: answers.url, + icon: answers.icon, + date: answers.date, + description: answers.description, + color: answers.color, + }); + if (!answers.addMilestone) { + return milestones; + } + } +} + +async function removemilestones(milestones) { + console.log("Removing Milestones"); +} + +async function updateMilestones(milestones) { + console.log("Updating Milestones"); +} + +module.exports = { + addmilestones, + removemilestones, + updateMilestones, +}; diff --git a/src/shared/questions/socials.js b/src/shared/questions/socials.js new file mode 100644 index 0000000..4ca9ee9 --- /dev/null +++ b/src/shared/questions/socials.js @@ -0,0 +1,51 @@ +const { prompt } = require("enquirer"); +const { geticons } = require("../assets/icons"); + +let socials = []; +let icons = []; + +async function addsocials(bool) { + icons = await geticons(); + + while (bool) { + let answers = await prompt([ + { + type: "input", + name: "url", + message: "Add the url of your social media", + }, + { + type: "select", + name: "icon", + choices: icons, + message: "Choose an icon (Press down arrow to see more options)", + }, + { + type: "confirm", + name: "addsocials", + message: "Do you want to add another social media?", + }, + ]); + socials.push({ + icons: answers.icon, + url: answers.url, + }); + if (!answers.addsocials) { + return socials; + } + } +} + +async function removesocials() { + console.log("remove socials"); +} + +async function updatesocials() { + console.log("update socials"); +} + +module.exports = { + addsocials, + removesocials, + updatesocials, +}; diff --git a/src/shared/questions/tags.js b/src/shared/questions/tags.js new file mode 100644 index 0000000..68720d3 --- /dev/null +++ b/src/shared/questions/tags.js @@ -0,0 +1,38 @@ +const { prompt } = require("enquirer"); + +let tags = []; + +async function addtags(bool) { + while (bool) { + let answers = await prompt([ + { + type: "input", + name: "name", + message: "What is the name of the tag?", + }, + { + type: "confirm", + name: "addTag", + message: "Do you want to add another tag?", + }, + ]); + tags.push(answers.name); + if (!answers.addTag) { + return tags; + } + } +} + +async function removetags() { + console.log("remove tags"); +} + +async function updatetags() { + console.log("update tags"); +} + +module.exports = { + addtags, + removetags, + updatetags, +}; From f5a7b4d3562f372ddcd7ecc3a26d47c0e3d1868d Mon Sep 17 00:00:00 2001 From: Ananya Nayak <55504616+Ananya2001-an@users.noreply.github.com> Date: Mon, 20 Feb 2023 12:18:35 +0530 Subject: [PATCH 04/11] feat: created remove and update functions for all keys (#27) --- data/Ananya2001-an.json | 24 +++- src/shared/questions/links.js | 55 ++++++++- src/shared/questions/milestones.js | 109 +++++++++++++++++- src/shared/questions/socials.js | 91 ++++++++++++++- src/shared/questions/tags.js | 75 +++++++++++- src/shared/questions/testimonials.js | 39 ++++++- src/updatejson/updateJson.js | 165 +++++++++++++++++++++++++++ 7 files changed, 535 insertions(+), 23 deletions(-) diff --git a/data/Ananya2001-an.json b/data/Ananya2001-an.json index f8a73ed..ee2ab68 100644 --- a/data/Ananya2001-an.json +++ b/data/Ananya2001-an.json @@ -9,10 +9,24 @@ "icon": "FaYoutube" }, { - "name": "GitHub: Collaborate on Open Source", - "url": "https://github.com/eddiejaoude", - "icon": "FaGithub" + "name": "Github", + "url": "jsdhjsdhsjkds", + "icon": "FaFacebook" } ], - "milestones": [] -} + "milestones": [], + "testimonials": [ + "Prad" + ], + "tags": [ + "devops", + "reactjs", + "open source" + ], + "socials": [ + { + "url": "abc", + "icon": "FaApple" + } + ] +} \ No newline at end of file diff --git a/src/shared/questions/links.js b/src/shared/questions/links.js index 341c429..893a271 100644 --- a/src/shared/questions/links.js +++ b/src/shared/questions/links.js @@ -76,9 +76,58 @@ async function removelinks(links) { } } -function updatelinks(links) { - console.log("updating links"); - return links; +async function updatelinks(links) { + icons = await geticons(); + let choiceLinks = links; + let stop = false; + while (!stop) { + const answers = await prompt([ + { + type: "select", + name: "link", + choices: choiceLinks, + message: "Choose which one you want to update", + }, + ]); + const { name, url, icon, updateLink } = await prompt([ + { + type: "input", + name: "name", + message: "What is the new name of the link?", + }, + { + type: "input", + name: "url", + message: "What is the new URL of the link?", + }, + { + type: "select", + name: "icon", + choices: icons, + message: "Choose a new icon (Press down arrow to see more options)", + }, + { + type: "confirm", + name: "updateLink", + message: "Do you want to update another link?", + }, + ]); + choiceLinks.map((link) => { + if (link.name === answers.link) { + link.name = name; + link.url = url; + link.icon = icon; + } + }); + if (!updateLink) { + let result = []; + choiceLinks.map((link) => { + const { name, url, icon } = link; + result.push({ name, url, icon }); + }); + return result; + } + } } module.exports = { diff --git a/src/shared/questions/milestones.js b/src/shared/questions/milestones.js index 8212a70..4b331a1 100644 --- a/src/shared/questions/milestones.js +++ b/src/shared/questions/milestones.js @@ -61,15 +61,116 @@ async function addmilestones(bool) { } async function removemilestones(milestones) { - console.log("Removing Milestones"); + let choiceMilestones = milestones; + let stop = false; + while (!stop) { + const answers = await prompt([ + { + type: "select", + name: "milestone", + choices: choiceMilestones, + message: "Choose which one you want to remove", + }, + ]); + choiceMilestones = choiceMilestones.filter((milestone) => milestone.title !== answers.milestone); + if (choiceMilestones.length !== 0) { + const res = await prompt([ + { + type: "confirm", + name: "removeMilestone", + message: "Do you want to remove another milestone?", + }, + ]); + if (!res.removeMilestone) { + let result = []; + choiceMilestones.map((milestone) => { + const { title, url, icon, description, date, color } = milestone; + result.push({ title, url, icon, description, date, color }); + }); + return result; + } + } else { + return []; + } + } } -async function updateMilestones(milestones) { - console.log("Updating Milestones"); +async function updatemilestones(milestones) { + icons = await geticons(); + let choiceMilestones = milestones; + let stop = false; + while (!stop) { + const answers = await prompt([ + { + type: "select", + name: "milestone", + choices: choiceMilestones, + message: "Choose which one you want to update", + }, + ]); + const { title, date, icon, description, url, color, updateMilestone } = + await prompt([ + { + type: "input", + name: "title", + message: "What is the new title of the milestone?", + }, + { + type: "input", + name: "date", + message: "What is the new date of the milestone?", + }, + { + type: "select", + name: "icon", + choices: icons, + message: "Choose a new icon (Press down arrow to see more options)", + }, + { + type: "input", + name: "description", + message: "What is the new description of the milestone?", + }, + { + type: "input", + name: "url", + message: "What is the new URL of the milestone?", + }, + { + type: "input", + name: "color", + message: "What is the new color theme of the milestone?", + }, + { + type: "confirm", + name: "updateMilestone", + message: "Do you want to update another milestone?", + }, + ]); + choiceMilestones.map((milestone) => { + if (milestone.title === answers.milestone) { + milestone.name = title + milestone.title = title; + milestone.date = date + milestone.url = url; + milestone.icon = icon; + milestone.description = description + milestone.color = color + } + }); + if (!updateMilestone) { + let result = []; + choiceMilestones.map((milestone) => { + const { title, url, icon, description, date, color } = milestone; + result.push({ title, url, icon, description, date, color }); + }); + return result; + } + } } module.exports = { addmilestones, removemilestones, - updateMilestones, + updatemilestones, }; diff --git a/src/shared/questions/socials.js b/src/shared/questions/socials.js index 4ca9ee9..b5402fe 100644 --- a/src/shared/questions/socials.js +++ b/src/shared/questions/socials.js @@ -27,7 +27,7 @@ async function addsocials(bool) { }, ]); socials.push({ - icons: answers.icon, + icon: answers.icon, url: answers.url, }); if (!answers.addsocials) { @@ -36,12 +36,93 @@ async function addsocials(bool) { } } -async function removesocials() { - console.log("remove socials"); +async function removesocials(socials) { + let choiceSocials = socials; + let stop = false; + while (!stop) { + const answers = await prompt([ + { + type: "select", + name: "social", + choices: choiceSocials, + message: "Choose which one you want to remove", + }, + ]); + choiceSocials = choiceSocials.filter( + (social) => social.name !== answers.social + ); + if (choiceSocials.length !== 0) { + const res = await prompt([ + { + type: "confirm", + name: "removeSocial", + message: "Do you want to remove another social?", + }, + ]); + if (!res.removeSocial) { + let result = []; + choiceSocials.map((social) => { + const { url, icon } = social; + result.push({ url, icon }); + }); + return result; + } + } else { + return []; + } + } } -async function updatesocials() { - console.log("update socials"); +async function updatesocials(socials) { + icons = await geticons(); + let choiceSocials = socials; + let stop = false; + choiceSocials.map(social => { + social.name = social.url + }) + while (!stop) { + const answers = await prompt([ + { + type: "select", + name: "social", + choices: choiceSocials, + message: "Choose which one you want to update", + }, + ]); + const { url, icon, updateSocial } = await prompt([ + { + type: "input", + name: "url", + message: "What is the new URL of the social media?", + }, + { + type: "select", + name: "icon", + choices: icons, + message: "Choose a new icon (Press down arrow to see more options)", + }, + { + type: "confirm", + name: "updateSocial", + message: "Do you want to update another social?", + }, + ]); + choiceSocials.map((social) => { + if (social.name === answers.social) { + social.name = url + social.url = url; + social.icon = icon + } + }); + if (!updateSocial) { + let result = []; + choiceSocials.map((social) => { + const { url, icon } = social; + result.push({url, icon}); + }); + return result; + } + } } module.exports = { diff --git a/src/shared/questions/tags.js b/src/shared/questions/tags.js index 68720d3..a9eee69 100644 --- a/src/shared/questions/tags.js +++ b/src/shared/questions/tags.js @@ -23,12 +23,79 @@ async function addtags(bool) { } } -async function removetags() { - console.log("remove tags"); +async function removetags(tags) { + let choiceTags = tags; + let stop = false; + while (!stop) { + const answers = await prompt([ + { + type: "select", + name: "tag", + choices: choiceTags, + message: "Choose which one you want to remove", + }, + ]); + choiceTags = choiceTags.filter((tag) => tag.name !== answers.tag); + if (choiceTags.length !== 0) { + const res = await prompt([ + { + type: "confirm", + name: "removeTag", + message: "Do you want to remove another tag?", + }, + ]); + if (!res.removeTag) { + let result = []; + choiceTags.map((tag) => { + const { name } = tag; + result.push(name); + }); + return result; + } + } else { + return []; + } + } } -async function updatetags() { - console.log("update tags"); +async function updatetags(tags) { + let choiceTags = tags; + let stop = false; + while (!stop) { + const answers = await prompt([ + { + type: "select", + name: "tag", + choices: choiceTags, + message: "Choose which one you want to update", + }, + ]); + const { name, updateTag } = await prompt([ + { + type: "input", + name: "name", + message: "What is the new name of the tag?", + }, + { + type: "confirm", + name: "updateTag", + message: "Do you want to update another tag?", + }, + ]); + choiceTags.map((tag) => { + if (tag.name === answers.tag) { + tag.name = name; + } + }); + if (!updateTag) { + let result = []; + choiceTags.map((tag) => { + const { name } = tag; + result.push(name); + }); + return result; + } + } } module.exports = { diff --git a/src/shared/questions/testimonials.js b/src/shared/questions/testimonials.js index cac721a..e303852 100644 --- a/src/shared/questions/testimonials.js +++ b/src/shared/questions/testimonials.js @@ -60,8 +60,43 @@ async function removetestimonials(testimonials) { } async function updatetestimonials(testimonials) { - console.log("updating testimonials"); - return testimonials; + let choiceTestimonials = testimonials; + let stop = false; + while (!stop) { + const answers = await prompt([ + { + type: "select", + name: "testimonial", + choices: choiceTestimonials, + message: "Choose which one you want to update", + }, + ]); + const { name, updateTestimonial } = await prompt([ + { + type: "input", + name: "name", + message: "What is the new username?", + }, + { + type: "confirm", + name: "updateTestimonial", + message: "Do you want to update another testimonial?", + }, + ]); + choiceTestimonials.map((testimonial) => { + if (testimonial.name === answers.testimonial) { + testimonial.name = name; + } + }); + if (!updateTestimonial) { + let result = []; + choiceTestimonials.map((testimonial) => { + const { name } = testimonial; + result.push(name); + }); + return result; + } + } } module.exports = { diff --git a/src/updatejson/updateJson.js b/src/updatejson/updateJson.js index fa09783..0e35cb5 100644 --- a/src/updatejson/updateJson.js +++ b/src/updatejson/updateJson.js @@ -7,6 +7,17 @@ const { removelinks, updatelinks, } = require("../shared/questions/links"); +const { + addmilestones, + removemilestones, + updatemilestones, +} = require("../shared/questions/milestones"); +const { addtags, removetags, updatetags } = require("../shared/questions/tags"); +const { + addsocials, + removesocials, + updatesocials, +} = require("../shared/questions/socials"); const { addtestimonials, removetestimonials, @@ -79,6 +90,104 @@ const updateJson = async (githubUsername) => { } }); + await prompt([ + { + type: "confirm", + name: "tag", + message: "Do you want to update your tags?", + }, + ]).then(async (answers) => { + if (answers.tag) { + await prompt([ + { + type: "select", + name: "operation", + message: "What you want to do?", + choices: ["add a tag?", "remove a tag?", "update a tag?"], + }, + ]).then(async (answers) => { + switch (answers.operation) { + case "add a tag?": { + if (json.tags) { + json.tags = [...json.tags, ...(await addtags(true))]; + } else { + json.tags = [...(await addtags(true))]; + } + break; + } + case "remove a tag?": { + if (json.tags) { + json.tags = [...(await removetags(json.tags))]; + } else { + console.log( + chalk.bgYellow.bold("You don't have any tags to remove!") + ); + } + break; + } + default: { + if (json.tags) { + json.tags = [...(await updatetags(json.tags))]; + } else { + console.log( + chalk.bgYellow.bold("You don't have any tags to update!") + ); + } + } + } + }); + } + }); + + await prompt([ + { + type: "confirm", + name: "social", + message: "Do you want to update your socials?", + }, + ]).then(async (answers) => { + if (answers.social) { + await prompt([ + { + type: "select", + name: "operation", + message: "What you want to do?", + choices: ["add a social?", "remove a social?", "update a social?"], + }, + ]).then(async (answers) => { + switch (answers.operation) { + case "add a social?": { + if (json.socials) { + json.socials = [...json.socials, ...(await addsocials(true))]; + } else { + json.socials = [...(await addsocials(true))]; + } + break; + } + case "remove a social?": { + if (json.socials) { + json.socials = [...(await removesocials(json.socials))]; + } else { + console.log( + chalk.bgYellow.bold("You don't have any socials to remove!") + ); + } + break; + } + default: { + if (json.socials) { + json.socials = [...(await updatesocials(json.socials))]; + } else { + console.log( + chalk.bgYellow.bold("You don't have any socials to update!") + ); + } + } + } + }); + } + }); + await prompt([ { type: "confirm", @@ -192,6 +301,62 @@ const updateJson = async (githubUsername) => { } }); + await prompt([ + { + type: "confirm", + name: "milestone", + message: "Do you want to update your milestones?", + }, + ]).then(async (answers) => { + if (answers.milestone) { + await prompt([ + { + type: "select", + name: "operation", + message: "What you want to do?", + choices: [ + "add a milestone?", + "remove a milestone?", + "update a milestone?", + ], + }, + ]).then(async (answers) => { + switch (answers.operation) { + case "add a milestone?": { + if (json.milestones) { + json.milestones = [ + ...json.milestones, + ...(await addmilestones(true)), + ]; + } else { + json.milestones = [...(await addmilestones(true))]; + } + break; + } + case "remove a milestone?": { + if (json.milestones) { + json.milestones = [...(await removemilestones(json.milestones))]; + } else { + console.log( + chalk.bgYellow.bold("You don't have any milestones to remove!") + ); + } + break; + } + default: { + if (json.milestones) { + json.milestones = [...(await updatemilestones(json.milestones))]; + } else { + console.log( + chalk.bgYellow.bold("You don't have any milestones to update!") + ); + } + } + } + }); + } + }); + json = jsonFormat(json, { type: "space", size: 2 }); fs.writeFile(`./data/${githubUsername}.json`, json, (err) => { if (err) { From 67d6324d7bb8b3fcb6141e5b200c013df2a7b48e Mon Sep 17 00:00:00 2001 From: Pradumna Saraf Date: Mon, 20 Feb 2023 17:36:13 +0530 Subject: [PATCH 05/11] feat: Add support for testimonials - main prompt (#29) --- src/givetestimonial/giveTestimonial.js | 117 +++++++++++++++++- .../helper/checkTestimonial.js | 16 +++ .../helper/createTestimonialFile.js | 105 ++++++++++++++++ 3 files changed, 234 insertions(+), 4 deletions(-) create mode 100644 src/givetestimonial/helper/checkTestimonial.js create mode 100644 src/givetestimonial/helper/createTestimonialFile.js diff --git a/src/givetestimonial/giveTestimonial.js b/src/givetestimonial/giveTestimonial.js index bc601f7..6dd0ef5 100644 --- a/src/givetestimonial/giveTestimonial.js +++ b/src/givetestimonial/giveTestimonial.js @@ -1,5 +1,114 @@ -const updateJson = () => { - console.log("Adding a testimonial"); -}; +const enquirer = require("enquirer"); +const fs = require("fs"); +const chalk = require("chalk"); +const createtestimonialfile = require("./helper/createTestimonialFile"); +const checktestimonial = require("./helper/checkTestimonial"); -module.exports = updateJson; +let testimonialWriter; +let testimonialReceiver; + +async function givetestimonial() { + let answers = await enquirer.prompt([ + { + type: "input", + name: "githubUsername", + message: "What is your GitHub username? (case sensitive)", + }, + ]); + const { githubUsername } = answers; + testimonialWriter = githubUsername; + if (githubUsername === "") { + console.log(chalk.bgRed.bold(` Please enter a valid GitHub username. `)); + givetestimonial(); + } else if (!fs.existsSync(`./data/${githubUsername}.json`)) { + console.log( + chalk.bgYellow.bold( + ` You don't have a LinkFree JSON file!. Create an account first! ` + ) + ); + process.exit(0); + } else { + let answers = await enquirer.prompt([ + { + type: "input", + name: "githubUsername", + message: + "What is the GitHub username of the person you want to give a testimonial to? (case sensitive)", + }, + ]); + const { githubUsername } = answers; + testimonialReceiver = githubUsername; + if (githubUsername === "") { + console.log(chalk.bgRed.bold(` Please enter a valid GitHub username. `)); + givetestimonial(); + } else if (!fs.existsSync(`./data/${githubUsername}.json`)) { + console.log( + chalk.bgYellow.bold( + ` The person you want to give a testimonial to doesn't have a LinkFree JSON file!. Ask them to create an account first! ` + ) + ); + process.exit(0); + } else { + if (testimonialReceiver == testimonialWriter) { + console.log( + chalk.bgRed.bold(` You can't give a testimonial to yourself! `) + ); + process.exit(0); + } else if ( + await checktestimonial(testimonialWriter, testimonialReceiver) + ) { + console.log( + chalk.bgRed.bold( + ` You have already given a testimonial to this person! ` + ) + ); + process.exit(0); + } else { + let title = await testimonialtitle(); + let description = await testimonialdescription(); + createtestimonialfile( + testimonialWriter, + testimonialReceiver, + title, + description + ); + } + } + } +} + +async function testimonialtitle() { + let answers = await enquirer.prompt([ + { + type: "input", + name: "testimonialtitle", + message: "What is the title of your testimonial?", + }, + ]); + const { testimonialtitle } = answers; + if (testimonialtitle === "") { + console.log(chalk.bgRed.bold(` Please enter a valid testimonial title. `)); + testimonialtitle(); + } else { + return testimonialtitle; + } +} + +async function testimonialdescription() { + let answers = await enquirer.prompt([ + { + type: "input", + name: "testimonial", + message: "What is your testimonial?", + }, + ]); + const { testimonial } = answers; + if (testimonial === "") { + console.log(chalk.bgRed.bold(` Please enter a valid testimonial. `)); + testimonialdescription(); + } else { + return testimonial; + } +} + +module.exports = givetestimonial; diff --git a/src/givetestimonial/helper/checkTestimonial.js b/src/givetestimonial/helper/checkTestimonial.js new file mode 100644 index 0000000..95bf4c4 --- /dev/null +++ b/src/givetestimonial/helper/checkTestimonial.js @@ -0,0 +1,16 @@ +const fs = require("fs"); + +// Check if the user has already given a testimonial to the person +async function checktestimonial(testimonialWritter, testimonialReceiver) { + if ( + fs.existsSync( + `./data/${testimonialReceiver}/testimonials/${testimonialWritter}.json` + ) + ) { + return true; + } else { + return false; + } +} + +module.exports = checktestimonial; diff --git a/src/givetestimonial/helper/createTestimonialFile.js b/src/givetestimonial/helper/createTestimonialFile.js new file mode 100644 index 0000000..96641e8 --- /dev/null +++ b/src/givetestimonial/helper/createTestimonialFile.js @@ -0,0 +1,105 @@ +const fs = require("fs"); +const chalk = require("chalk"); +const jsonFormat = require("json-format"); + +async function createtestimonialfile( + testimonialWritter, + testimonialReceiver, + title, + description +) { + jsonSchema = { + title: `${title}`, + description: `${description}`, + date: `${getdate()}`, + }; + + const json = jsonFormat(jsonSchema, { type: "space", size: 2 }); + + // Check if we are in the root directory of LinkFree + if (fs.existsSync("./data")) { + // Check if user reciving the testimonial has a "testimonials" directory. + if (fs.existsSync(`./data/${testimonialReceiver}/testimonials`)) { + fs.writeFile( + `./data/${testimonialReceiver}/testimonials/${testimonialWritter}.json`, + json, + (err) => { + if (err) { + console.log( + chalk.bgYellow.bold( + `Something went wrong while creating the file. Try again! part 1` + ) + ); + process.exit(0); + } else { + console.log( + chalk.bgWhite.bold( + ` File ${testimonialReceiver}.json created successfully! ` + ) + ); + } + } + ); + } else { + // If the user doesn't have a "testimonials" directory, create one. + fs.promises + .mkdir(`./data/${testimonialReceiver}/testimonials`, { + recursive: true, + }) + .then(() => { + fs.writeFile( + `./data/${testimonialReceiver}/testimonials/${testimonialWritter}.json`, + json, + (err) => { + if (err) { + console.log( + chalk.bgYellow.bold( + `Something went wrong while creating the file. Try again! part 2` + ) + ); + process.exit(0); + } else { + console.log( + chalk.bgWhite.bold( + ` File ${testimonialReceiver}.json created successfully! ` + ) + ); + } + } + ); + }) + .catch(() => { + console.log( + chalk.bgYellow.bold( + `Something went wrong while creating the directory. Try again!` + ) + ); + process.exit(0); + }); + } + } else { + console.log( + chalk.bgYellow.bold( + ` You are not in the root directory of LinkFree. Try again! ` + ) + ); + process.exit(0); + } +} + +function getdate() { + // get in the format of YYYY-MM-DD + let date = new Date(); + let year = date.getFullYear(); + let month = date.getMonth() + 1; + let day = date.getDate(); + if (month < 10) { + month = "0" + month; + } + if (day < 10) { + day = "0" + day; + } + return year + "-" + month + "-" + day; +} + +module.exports = createtestimonialfile; From 4311d58e8f29f9bb9c292248f891f92b5f5f9592 Mon Sep 17 00:00:00 2001 From: Ananya Nayak <55504616+Ananya2001-an@users.noreply.github.com> Date: Tue, 21 Feb 2023 17:04:39 +0530 Subject: [PATCH 06/11] feat: add events support - main prompt (#30) --- .../events/2023-09-08-kubecon-2023.json | 12 +++ .../testimonials/Ananya2001-an.json | 5 + src/addevent/addEvent.js | 73 ++++++++++++- src/addevent/helper/createEventFile.js | 101 ++++++++++++++++++ .../helper/checkTestimonial.js | 4 +- .../helper/createTestimonialFile.js | 8 +- 6 files changed, 195 insertions(+), 8 deletions(-) create mode 100644 data/Ananya2001-an/events/2023-09-08-kubecon-2023.json create mode 100644 data/Pradumnasaraf/testimonials/Ananya2001-an.json create mode 100644 src/addevent/helper/createEventFile.js diff --git a/data/Ananya2001-an/events/2023-09-08-kubecon-2023.json b/data/Ananya2001-an/events/2023-09-08-kubecon-2023.json new file mode 100644 index 0000000..fedcefe --- /dev/null +++ b/data/Ananya2001-an/events/2023-09-08-kubecon-2023.json @@ -0,0 +1,12 @@ +{ + "isVirtual": true, + "isInPerson": true, + "color": "blue", + "name": "kubecon 2023", + "description": "hello", + "date": { + "start": "2023-09-08T00-00-00.000+00:00", + "end": "2023-09-09T00-00-00.000+00:00" + }, + "url": "jdhgfh" +} \ No newline at end of file diff --git a/data/Pradumnasaraf/testimonials/Ananya2001-an.json b/data/Pradumnasaraf/testimonials/Ananya2001-an.json new file mode 100644 index 0000000..49f30ec --- /dev/null +++ b/data/Pradumnasaraf/testimonials/Ananya2001-an.json @@ -0,0 +1,5 @@ +{ + "title": "Great work", + "description": "greatttt", + "date": "2023-02-21" +} \ No newline at end of file diff --git a/src/addevent/addEvent.js b/src/addevent/addEvent.js index 39ae64f..b2e3af1 100644 --- a/src/addevent/addEvent.js +++ b/src/addevent/addEvent.js @@ -1,5 +1,74 @@ -const addEvent = () => { - console.log("add event"); +const enquirer = require("enquirer"); +const fs = require("fs"); +const chalk = require("chalk"); +const createEventFile = require("./helper/createEventFile"); + +const addEvent = async () => { + let answers = await enquirer.prompt([ + { + type: "input", + name: "githubUsername", + message: "What is your GitHub username? (case sensitive)", + }, + ]); + let eventWriter = answers.githubUsername; + + if (eventWriter === "") { + console.log(chalk.bgRed.bold(` Please enter a valid GitHub username. `)); + addEvent(); + } else if (!fs.existsSync(`./data/${eventWriter}.json`)) { + console.log( + chalk.bgYellow.bold( + ` You don't have a LinkFree JSON file!. Create an account first! ` + ) + ); + process.exit(0); + } else { + let answers = await enquirer.prompt([ + { + type: "confirm", + name: "virtual", + message: "Is the event virtual?", + }, + { + type: "confirm", + name: "inperson", + message: "Is the event in person?", + }, + { + type: "input", + name: "name", + message: "What is the name of the event?", + }, + { + type: "input", + name: "description", + message: "Give a description of the event", + }, + { + type: "input", + name: "url", + message: "Give associated URL for the event", + }, + { + type: "input", + name: "startDate", + message: "Give event start date and time (Supported format: 2023-08-09T00:00:00.000+00:00)", + }, + { + type: "input", + name: "endDate", + message: "Give event end date and time (Supported format: 2023-08-09T00:00:00.000+00:00)", + }, + { + type: "input", + name: "color", + message: "Give a color theme", + }, + ]); + + createEventFile(eventWriter, answers); + } }; module.exports = addEvent; diff --git a/src/addevent/helper/createEventFile.js b/src/addevent/helper/createEventFile.js new file mode 100644 index 0000000..88cba8c --- /dev/null +++ b/src/addevent/helper/createEventFile.js @@ -0,0 +1,101 @@ +const fs = require("fs"); +const chalk = require("chalk"); +const jsonFormat = require("json-format"); + +function createEventFile(eventWriter, answers) { + const { virtual, inperson, name, description, url, startDate, endDate, color } = + answers; + let jsonSchema = { + isVirtual: Boolean(virtual), + isInPerson: Boolean(inperson), + color:color, + name: name, + description: description, + date: { + start: startDate, + end: endDate, + }, + url: url, + }; + + const json = jsonFormat(jsonSchema, { type: "space", size: 2 }); + + if (fs.existsSync("./data")) { + if (fs.existsSync(`./data/${eventWriter}/events`)) { + fs.writeFile( + `./data/${eventWriter}/events/${startDate.split('T')[0]}-${name.toLowerCase().split(' ').join('-')}.json`, + json, + (err) => { + if (err) { + console.log( + chalk.bgYellow.bold( + `Something went wrong while creating the file. Try again! part 1` + ) + ); + process.exit(0); + } else { + console.log( + chalk.bgWhite.bold( + ` File ${startDate.split("T")[0]}-${name + .toLowerCase() + .split(" ") + .join("-")}.json created successfully! ` + ) + ); + } + } + ); + } else { + // If the user doesn't have a "events" directory, create one. + fs.promises + .mkdir(`./data/${eventWriter}/events`, { + recursive: true, + }) + .then(() => { + fs.writeFile( + `./data/${eventWriter}/events/${startDate.split("T")[0]}-${name + .toLowerCase() + .split(" ") + .join("-")}.json`, + json, + (err) => { + if (err) { + console.log( + chalk.bgYellow.bold( + `Something went wrong while creating the file. Try again! part 2` + ) + ); + process.exit(0); + } else { + console.log( + chalk.bgWhite.bold( + ` File ${startDate.split("T")[0]}-${name + .toLowerCase() + .split(" ") + .join("-")}.json created successfully! ` + ) + ); + } + } + ); + }) + .catch(() => { + console.log( + chalk.bgYellow.bold( + `Something went wrong while creating the directory. Try again!` + ) + ); + process.exit(0); + }); + } + } else { + console.log( + chalk.bgYellow.bold( + ` You are not in the root directory of LinkFree. Try again! ` + ) + ); + process.exit(0); + } +} + +module.exports = createEventFile; diff --git a/src/givetestimonial/helper/checkTestimonial.js b/src/givetestimonial/helper/checkTestimonial.js index 95bf4c4..60272a7 100644 --- a/src/givetestimonial/helper/checkTestimonial.js +++ b/src/givetestimonial/helper/checkTestimonial.js @@ -1,10 +1,10 @@ const fs = require("fs"); // Check if the user has already given a testimonial to the person -async function checktestimonial(testimonialWritter, testimonialReceiver) { +async function checktestimonial(testimonialWriter, testimonialReceiver) { if ( fs.existsSync( - `./data/${testimonialReceiver}/testimonials/${testimonialWritter}.json` + `./data/${testimonialReceiver}/testimonials/${testimonialWriter}.json` ) ) { return true; diff --git a/src/givetestimonial/helper/createTestimonialFile.js b/src/givetestimonial/helper/createTestimonialFile.js index 96641e8..a57ffe8 100644 --- a/src/givetestimonial/helper/createTestimonialFile.js +++ b/src/givetestimonial/helper/createTestimonialFile.js @@ -3,12 +3,12 @@ const chalk = require("chalk"); const jsonFormat = require("json-format"); async function createtestimonialfile( - testimonialWritter, + testimonialWriter, testimonialReceiver, title, description ) { - jsonSchema = { + let jsonSchema = { title: `${title}`, description: `${description}`, date: `${getdate()}`, @@ -21,7 +21,7 @@ async function createtestimonialfile( // Check if user reciving the testimonial has a "testimonials" directory. if (fs.existsSync(`./data/${testimonialReceiver}/testimonials`)) { fs.writeFile( - `./data/${testimonialReceiver}/testimonials/${testimonialWritter}.json`, + `./data/${testimonialReceiver}/testimonials/${testimonialWriter}.json`, json, (err) => { if (err) { @@ -48,7 +48,7 @@ async function createtestimonialfile( }) .then(() => { fs.writeFile( - `./data/${testimonialReceiver}/testimonials/${testimonialWritter}.json`, + `./data/${testimonialReceiver}/testimonials/${testimonialWriter}.json`, json, (err) => { if (err) { From e21788400f5cdbf7f15edcf5852ccc2ae30b8939 Mon Sep 17 00:00:00 2001 From: Pradumna Saraf Date: Wed, 22 Feb 2023 17:42:45 +0530 Subject: [PATCH 07/11] feat: Add optional keys to Events (#32) --- src/addevent/addEvent.js | 32 +++++++++++++---- src/addevent/helper/createEventFile.js | 49 ++++++++++++++++++++------ 2 files changed, 64 insertions(+), 17 deletions(-) diff --git a/src/addevent/addEvent.js b/src/addevent/addEvent.js index b2e3af1..7899606 100644 --- a/src/addevent/addEvent.js +++ b/src/addevent/addEvent.js @@ -25,14 +25,26 @@ const addEvent = async () => { process.exit(0); } else { let answers = await enquirer.prompt([ + { + type: "select", + name: "userStatus", + message: "Are you the event organizer or a participant? (This is optional.)", + choices: ["Organizer", "Participant", "None - Skip this question"], + }, + { + type: "input", + name: "speakerDetails", + message: + "Give your topic of your talk at the event. (This is optional. Press enter to skip.)", + }, { type: "confirm", - name: "virtual", + name: "isVirtual", message: "Is the event virtual?", }, { type: "confirm", - name: "inperson", + name: "isInPerson", message: "Is the event in person?", }, { @@ -52,13 +64,21 @@ const addEvent = async () => { }, { type: "input", - name: "startDate", - message: "Give event start date and time (Supported format: 2023-08-09T00:00:00.000+00:00)", + name: "start", + message: + "Give event start date and time (Supported format: 2023-08-09T00:00:00.000+00:00)", + }, + { + type: "input", + name: "end", + message: + "Give event end date and time (Supported format: 2023-08-09T00:00:00.000+00:00)", }, { type: "input", - name: "endDate", - message: "Give event end date and time (Supported format: 2023-08-09T00:00:00.000+00:00)", + name: "cfpClose", + message: + "Give CFP end date and time (Supported format: 2023-08-09T00:00:00.000+00:00) - (This is optional. Press enter to skip.)", }, { type: "input", diff --git a/src/addevent/helper/createEventFile.js b/src/addevent/helper/createEventFile.js index 88cba8c..78a3514 100644 --- a/src/addevent/helper/createEventFile.js +++ b/src/addevent/helper/createEventFile.js @@ -3,27 +3,54 @@ const chalk = require("chalk"); const jsonFormat = require("json-format"); function createEventFile(eventWriter, answers) { - const { virtual, inperson, name, description, url, startDate, endDate, color } = - answers; + const { + userStatus, + speakerDetails, + isVirtual, + isInPerson, + name, + description, + url, + start, + end, + cfpClose, + color, + } = answers; + let jsonSchema = { - isVirtual: Boolean(virtual), - isInPerson: Boolean(inperson), - color:color, + isVirtual: Boolean(isVirtual), + isInPerson: Boolean(isInPerson), + color: color, name: name, description: description, date: { - start: startDate, - end: endDate, + start: start, + end: end, }, url: url, }; + if (cfpClose) { + jsonSchema.date.cfpClose = cfpClose; + } + + if (userStatus === "Organizer" || userStatus === "Participant") { + jsonSchema.userStatus = userStatus; + } + + if (speakerDetails) { + jsonSchema.speakerDetails = speakerDetails; + } + const json = jsonFormat(jsonSchema, { type: "space", size: 2 }); if (fs.existsSync("./data")) { if (fs.existsSync(`./data/${eventWriter}/events`)) { fs.writeFile( - `./data/${eventWriter}/events/${startDate.split('T')[0]}-${name.toLowerCase().split(' ').join('-')}.json`, + `./data/${eventWriter}/events/${start.split("T")[0]}-${name + .toLowerCase() + .split(" ") + .join("-")}.json`, json, (err) => { if (err) { @@ -36,7 +63,7 @@ function createEventFile(eventWriter, answers) { } else { console.log( chalk.bgWhite.bold( - ` File ${startDate.split("T")[0]}-${name + ` File ${start.split("T")[0]}-${name .toLowerCase() .split(" ") .join("-")}.json created successfully! ` @@ -53,7 +80,7 @@ function createEventFile(eventWriter, answers) { }) .then(() => { fs.writeFile( - `./data/${eventWriter}/events/${startDate.split("T")[0]}-${name + `./data/${eventWriter}/events/${start.split("T")[0]}-${name .toLowerCase() .split(" ") .join("-")}.json`, @@ -69,7 +96,7 @@ function createEventFile(eventWriter, answers) { } else { console.log( chalk.bgWhite.bold( - ` File ${startDate.split("T")[0]}-${name + ` File ${start.split("T")[0]}-${name .toLowerCase() .split(" ") .join("-")}.json created successfully! ` From a849b47e9bcb2b54a8505fe01ee6a380ac35ee43 Mon Sep 17 00:00:00 2001 From: Pradumna Saraf Date: Wed, 22 Feb 2023 19:23:26 +0530 Subject: [PATCH 08/11] feat: Add optional key in Milestone (#33) --- src/shared/questions/milestones.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/shared/questions/milestones.js b/src/shared/questions/milestones.js index 4b331a1..9ec15e6 100644 --- a/src/shared/questions/milestones.js +++ b/src/shared/questions/milestones.js @@ -40,6 +40,12 @@ async function addmilestones(bool) { name: "color", message: "Give a color theme", }, + { + type: "select", + name: "isGoal", + message: "Is this a future goal? (This is optional question)", + choices: ["Yes", "Skip this question"], + }, { type: "confirm", name: "addMilestone", @@ -54,6 +60,10 @@ async function addmilestones(bool) { description: answers.description, color: answers.color, }); + + if (answers.isGoal === "Yes") { + milestones[milestones.length - 1].isGoal = true; + } if (!answers.addMilestone) { return milestones; } From 45ce7b680e3b07168706914fb9703d63cd87590f Mon Sep 17 00:00:00 2001 From: Ananya Nayak <55504616+Ananya2001-an@users.noreply.github.com> Date: Wed, 22 Feb 2023 23:53:16 +0530 Subject: [PATCH 09/11] fix: remove blank keys from JSON (#34) --- data/Ananya2001-an.json | 21 --------------------- src/shared/questions/socials.js | 3 +++ src/updatejson/updateJson.js | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/data/Ananya2001-an.json b/data/Ananya2001-an.json index ee2ab68..3d8f5c6 100644 --- a/data/Ananya2001-an.json +++ b/data/Ananya2001-an.json @@ -2,31 +2,10 @@ "name": "Ananya Nayak", "type": "Personal", "bio": "Open source is fun", - "links": [ - { - "name": "YouTube: Learn more about Open Source", - "url": "https://youtube.com/eddiejaoude", - "icon": "FaYoutube" - }, - { - "name": "Github", - "url": "jsdhjsdhsjkds", - "icon": "FaFacebook" - } - ], - "milestones": [], "testimonials": [ "Prad" ], "tags": [ - "devops", - "reactjs", "open source" - ], - "socials": [ - { - "url": "abc", - "icon": "FaApple" - } ] } \ No newline at end of file diff --git a/src/shared/questions/socials.js b/src/shared/questions/socials.js index b5402fe..6aa1f3b 100644 --- a/src/shared/questions/socials.js +++ b/src/shared/questions/socials.js @@ -39,6 +39,9 @@ async function addsocials(bool) { async function removesocials(socials) { let choiceSocials = socials; let stop = false; + choiceSocials.map((social) => { + social.name = social.url; + }); while (!stop) { const answers = await prompt([ { diff --git a/src/updatejson/updateJson.js b/src/updatejson/updateJson.js index 0e35cb5..af8361d 100644 --- a/src/updatejson/updateJson.js +++ b/src/updatejson/updateJson.js @@ -118,6 +118,9 @@ const updateJson = async (githubUsername) => { case "remove a tag?": { if (json.tags) { json.tags = [...(await removetags(json.tags))]; + if(json.tags.length === 0){ + delete json.tags + } } else { console.log( chalk.bgYellow.bold("You don't have any tags to remove!") @@ -167,6 +170,9 @@ const updateJson = async (githubUsername) => { case "remove a social?": { if (json.socials) { json.socials = [...(await removesocials(json.socials))]; + if (json.socials.length === 0) { + delete json.socials; + } } else { console.log( chalk.bgYellow.bold("You don't have any socials to remove!") @@ -216,6 +222,9 @@ const updateJson = async (githubUsername) => { case "remove a link?": { if (json.links) { json.links = [...(await removelinks(json.links))]; + if (json.links.length === 0) { + delete json.links; + } } else { console.log( chalk.bgYellow.bold("You don't have any links to remove!") @@ -241,7 +250,7 @@ const updateJson = async (githubUsername) => { { type: "confirm", name: "testimonial", - message: "Do you want to update your testimonials?", + message: "Do you want to update your testimonials (usernames)?", }, ]).then(async (answers) => { if (answers.testimonial) { @@ -274,6 +283,9 @@ const updateJson = async (githubUsername) => { json.testimonials = [ ...(await removetestimonials(json.testimonials)), ]; + if (json.testimonials.length === 0) { + delete json.testimonials; + } } else { console.log( chalk.bgYellow.bold( @@ -336,6 +348,9 @@ const updateJson = async (githubUsername) => { case "remove a milestone?": { if (json.milestones) { json.milestones = [...(await removemilestones(json.milestones))]; + if (json.milestones.length === 0) { + delete json.milestones; + } } else { console.log( chalk.bgYellow.bold("You don't have any milestones to remove!") From 486325c67b48dc1ce0f5cebc419258ea55034e26 Mon Sep 17 00:00:00 2001 From: Pradumna Saraf Date: Thu, 23 Feb 2023 00:20:35 +0530 Subject: [PATCH 10/11] feat: Add bug report from CLI (#35) --- package-lock.json | 80 +++++++++++++++++++++++++++++++++++++- package.json | 3 +- src/index.js | 8 +++- src/reportbug/reportBug.js | 46 ++++++++++++++++++++++ 4 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 src/reportbug/reportBug.js diff --git a/package-lock.json b/package-lock.json index 5b77eff..d5be65c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,8 @@ "axios": "^0.27.2", "chalk": "^4.1.2", "enquirer": "^2.3.6", - "json-format": "^1.0.1" + "json-format": "^1.0.1", + "open": "^8.4.2" }, "bin": { "linkfree-cli": "src/index.js" @@ -94,6 +95,14 @@ "node": ">= 0.8" } }, + "node_modules/define-lazy-prop": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-2.0.0.tgz", + "integrity": "sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==", + "engines": { + "node": ">=8" + } + }, "node_modules/delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -151,6 +160,31 @@ "node": ">=8" } }, + "node_modules/is-docker": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", + "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", + "bin": { + "is-docker": "cli.js" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-wsl": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", + "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", + "dependencies": { + "is-docker": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/json-format": { "version": "1.0.1", "license": "MIT" @@ -174,6 +208,22 @@ "node": ">= 0.6" } }, + "node_modules/open": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/open/-/open-8.4.2.tgz", + "integrity": "sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==", + "dependencies": { + "define-lazy-prop": "^2.0.0", + "is-docker": "^2.1.1", + "is-wsl": "^2.2.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/prettier": { "version": "2.7.1", "dev": true, @@ -247,6 +297,11 @@ "delayed-stream": "~1.0.0" } }, + "define-lazy-prop": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-2.0.0.tgz", + "integrity": "sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==" + }, "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -276,6 +331,19 @@ "has-flag": { "version": "4.0.0" }, + "is-docker": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", + "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==" + }, + "is-wsl": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", + "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", + "requires": { + "is-docker": "^2.0.0" + } + }, "json-format": { "version": "1.0.1" }, @@ -292,6 +360,16 @@ "mime-db": "1.52.0" } }, + "open": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/open/-/open-8.4.2.tgz", + "integrity": "sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==", + "requires": { + "define-lazy-prop": "^2.0.0", + "is-docker": "^2.1.1", + "is-wsl": "^2.2.0" + } + }, "prettier": { "version": "2.7.1", "dev": true diff --git a/package.json b/package.json index 1198045..1f55a48 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "axios": "^0.27.2", "chalk": "^4.1.2", "enquirer": "^2.3.6", - "json-format": "^1.0.1" + "json-format": "^1.0.1", + "open": "^8.4.2" }, "devDependencies": { "prettier": "^2.7.1" diff --git a/src/index.js b/src/index.js index 533423b..6dcc3d7 100755 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,7 @@ const createJson = require("./createjson/createJson"); const checkUpdate = require("./updatejson/helper/checkUpdate"); const giveTestimonial = require("./givetestimonial/giveTestimonial"); const addEvent = require("./addevent/addEvent"); +const reportBug = require("./reportbug/reportBug"); console.log( chalk.bgWhite.bold(` Welcome to LinkFree CLI! Let's get started. `) ); @@ -15,6 +16,7 @@ const choices = [ "Update an existing JSON file", "Provide a testimonial to a LinkFree user", "Add an event", + "🐛 Report a bug", ]; prompt([ @@ -40,8 +42,12 @@ prompt([ giveTestimonial(); break; } - default: + case "Add an event": { addEvent(); + break; + } + default: + reportBug(); } }) .catch((error) => { diff --git a/src/reportbug/reportBug.js b/src/reportbug/reportBug.js new file mode 100644 index 0000000..acac222 --- /dev/null +++ b/src/reportbug/reportBug.js @@ -0,0 +1,46 @@ +const open = require("open"); +const enquirer = require("enquirer"); + +async function reportBug() { + const questions = await enquirer.prompt([ + { + type: "input", + name: "username", + message: "What is your GitHub username?", + }, + { + type: "input", + name: "title", + message: "What is the title of the bug?", + }, + { + type: "input", + name: "description", + message: "Describe a description of the bug", + }, + ]); + const { username, title, description } = questions; + const url = urlBuilder(username, title, description); + + const openBrowser = await enquirer.prompt([ + { + type: "confirm", + name: "openBrowser", + message: + "Thank you for taking the time to report the bug. For submitting it, you will be redirected to GitHub Issues. Do you want to open the browser?", + }, + ]); + if (openBrowser.openBrowser) { + await open(url); + } +} + +function urlBuilder(username, title, description) { + title = title.replace(/\s/g, "+"); + description = description.replace(/\s/g, "+"); + + URL = `https://github.com/Pradumnasaraf/LinkFree-CLI/issues/new?assignees=&labels=bug&template=bug.yaml&title=${title}+Report+by+@${username}&description=${description}`; + return URL; +} + +module.exports = reportBug; From 8a8aa7955d7ad99f088fb1034156ee1285b43b63 Mon Sep 17 00:00:00 2001 From: Pradumna Saraf Date: Thu, 23 Feb 2023 11:48:52 +0530 Subject: [PATCH 11/11] chore: minor refactoring and docs update (#36) * remove test data * bump up CLI version * delete notes.md * update CHANGELOG * update readme * Update README.md * Update README.md * Update CHANGELOG.md * Update README.md * prettier * Update README.md * Update README.md * Update README.md --- CHANGELOG.md | 19 +++ Notes.md | 7 - README.md | 39 +++--- data/Ananya2001-an.json | 11 -- .../events/2023-09-08-kubecon-2023.json | 12 -- data/Pradumnasaraf.json | 13 -- .../testimonials/Ananya2001-an.json | 5 - package-lock.json | 4 +- package.json | 2 +- src/addevent/addEvent.js | 3 +- src/shared/questions/milestones.js | 132 +++++++++--------- src/shared/questions/socials.js | 12 +- src/shared/questions/tags.js | 120 ++++++++-------- src/updatejson/updateJson.js | 4 +- 14 files changed, 178 insertions(+), 205 deletions(-) delete mode 100644 Notes.md delete mode 100644 data/Ananya2001-an.json delete mode 100644 data/Ananya2001-an/events/2023-09-08-kubecon-2023.json delete mode 100644 data/Pradumnasaraf.json delete mode 100644 data/Pradumnasaraf/testimonials/Ananya2001-an.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f21b6a..2c00f5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,22 @@ +## [2.0.0](https://github.com/Pradumnasaraf/LinkFree-CLI/compare/v1.4.2...v2.0.0) (2023-02-23) + +### Breaking Changes + +* The CLI now uses a diffent function/folder handling structure. This means the newer version features will not work with the older version of the CLI. Please update to the latest version of the CLI to use the new features. + +### Features + +* Added support to update the JSON function https://github.com/Pradumnasaraf/LinkFree-CLI/pull/24 +* Add support to add milestones, socials, and tags https://github.com/Pradumnasaraf/LinkFree-CLI/pull/26 +* Add support to create remove and update keys by https://github.com/Pradumnasaraf/LinkFree-CLI/pull/27 +* Add support to add events https://github.com/Pradumnasaraf/LinkFree-CLI/pull/30 +* Add supported to for optional key to Events and Milestone https://github.com/Pradumnasaraf/LinkFree-CLI/pull/32 https://github.com/Pradumnasaraf/LinkFree-CLI/pull/33 +* Support for reporting a bug from CLI https://github.com/Pradumnasaraf/LinkFree-CLI/pull/35 + +### Fix +* Removes empty keys from json when value is not there https://github.com/Pradumnasaraf/LinkFree-CLI/pull/34 + + ## [1.4.2](https://github.com/Pradumnasaraf/LinkFree-CLI/compare/v1.4.1...v1.4.2) (2023-02-15) diff --git a/Notes.md b/Notes.md deleted file mode 100644 index e5f8c6b..0000000 --- a/Notes.md +++ /dev/null @@ -1,7 +0,0 @@ -Hey, this files will be for notes and anything we want to keep track of. - -- For temp basis I have created a folder with name `data` to test things out. - -- Created shared folder for common assets being used by different functions - -- Using Eddie's profile for ref https://github.com/EddieHubCommunity/LinkFree/blob/main/data/eddiejaoude.json diff --git a/README.md b/README.md index fa821d6..9240874 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,42 @@ -

LinkFree CLI

+

LinkFree CLI

-**LinkFree CLI** is a command line tool that helps you to create your **[LinkFree](https://github.com/EddieHubCommunity/LinkFree)** profile through CLI. +
+ + +**LinkFree CLI** is a command line tool that helps us to create and update your **[LinkFree](https://github.com/EddieHubCommunity/LinkFree)** profile through CLI. We can also give testimonials and events through it.
-
[![NPM Package](https://github.com/Pradumnasaraf/LinkFree-CLI/actions/workflows/publish.yml/badge.svg)](https://github.com/Pradumnasaraf/LinkFree-CLI/actions/workflows/publish.yml) [![Releases](https://github.com/Pradumnasaraf/LinkFree-CLI/actions/workflows/releases.yml/badge.svg)](https://github.com/Pradumnasaraf/LinkFree-CLI/actions/workflows/releases.yml) -[![.github/workflows/greetings.yml](https://github.com/Pradumnasaraf/LinkFree-CLI/actions/workflows/greetings.yml/badge.svg)](https://github.com/Pradumnasaraf/LinkFree-CLI/actions/workflows/greetings.yml) [![Npm package total downloads](https://badgen.net/npm/dt/linkfree-cli)](https://npmjs.com/package/linkfree-cli)
-## Demo +![LinkFree CLI demo GIF](https://user-images.githubusercontent.com/51878265/220831787-93c6b920-2961-4729-8a2c-0ac576658d83.gif) -![LinkFree CLI](https://user-images.githubusercontent.com/51878265/200193639-0e2d6d23-5f85-48e8-9563-8879b4efb18a.gif) +### ⭐️ Features -## Using the CLI (Commands) +- Creating a LinkFree profile. +- Updating a LinkFree profile. +- Giving a testimonial to a LinkFree profile. +- Adding events (conferences, meetups, etc). -> **Note** First fork the [LinkFree](https://github.com/EddieHubCommunity/LinkFree) repo before using it. -- **To install it globally.** +### 👨‍💻 Using the CLI tool -```bash -npm install -g linkfree-cli +Make sure you have cloned the [LinkFree](https://github.com/EddieHubCommunity/LinkFree) repo and in the root directory of the repo and installed the dependencies. -linkfree-Cli -``` - -It will then prompt you to questions. - -- **To execute the package directly, without installing it.** +- To trigger the CLI, run the following command in the bash terminal. ```bash npx linkfree-cli ``` -It will then prompt you to questions. +### 📝 License + +This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) for details. -## Contributions +### 🛡 Security -Feel free to contribute to the repo. Just make sure you Open an [Issue](https://github.com/Pradumnasaraf/LinkFree-CLI/issues) first before raising the Pull Request +If you discover a security vulnerability within this project, please check the [SECURITY](SECURITY.md) for more information. diff --git a/data/Ananya2001-an.json b/data/Ananya2001-an.json deleted file mode 100644 index 3d8f5c6..0000000 --- a/data/Ananya2001-an.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "Ananya Nayak", - "type": "Personal", - "bio": "Open source is fun", - "testimonials": [ - "Prad" - ], - "tags": [ - "open source" - ] -} \ No newline at end of file diff --git a/data/Ananya2001-an/events/2023-09-08-kubecon-2023.json b/data/Ananya2001-an/events/2023-09-08-kubecon-2023.json deleted file mode 100644 index fedcefe..0000000 --- a/data/Ananya2001-an/events/2023-09-08-kubecon-2023.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "isVirtual": true, - "isInPerson": true, - "color": "blue", - "name": "kubecon 2023", - "description": "hello", - "date": { - "start": "2023-09-08T00-00-00.000+00:00", - "end": "2023-09-09T00-00-00.000+00:00" - }, - "url": "jdhgfh" -} \ No newline at end of file diff --git a/data/Pradumnasaraf.json b/data/Pradumnasaraf.json deleted file mode 100644 index 695dde3..0000000 --- a/data/Pradumnasaraf.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "Prad", - "type": "Personal", - "bio": "dev", - "links": [ - { - "name": "git", - "url": "jfhjhgjf", - "icon": "FaGithub" - } - ], - "testimonials": ["eddiejaoude"] -} diff --git a/data/Pradumnasaraf/testimonials/Ananya2001-an.json b/data/Pradumnasaraf/testimonials/Ananya2001-an.json deleted file mode 100644 index 49f30ec..0000000 --- a/data/Pradumnasaraf/testimonials/Ananya2001-an.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "title": "Great work", - "description": "greatttt", - "date": "2023-02-21" -} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d5be65c..5406e82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "linkfree-cli", - "version": "1.4.2", + "version": "2.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "linkfree-cli", - "version": "1.4.2", + "version": "2.0.0", "license": "MIT", "dependencies": { "axios": "^0.27.2", diff --git a/package.json b/package.json index 1f55a48..b5eb253 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "linkfree-cli", - "version": "1.4.2", + "version": "2.0.0", "description": "Create LinkFree profile.json file though CLI", "main": "src/index.js", "bin": "src/index.js", diff --git a/src/addevent/addEvent.js b/src/addevent/addEvent.js index 7899606..39a169a 100644 --- a/src/addevent/addEvent.js +++ b/src/addevent/addEvent.js @@ -28,7 +28,8 @@ const addEvent = async () => { { type: "select", name: "userStatus", - message: "Are you the event organizer or a participant? (This is optional.)", + message: + "Are you the event organizer or a participant? (This is optional.)", choices: ["Organizer", "Participant", "None - Skip this question"], }, { diff --git a/src/shared/questions/milestones.js b/src/shared/questions/milestones.js index 9ec15e6..bde8866 100644 --- a/src/shared/questions/milestones.js +++ b/src/shared/questions/milestones.js @@ -82,7 +82,9 @@ async function removemilestones(milestones) { message: "Choose which one you want to remove", }, ]); - choiceMilestones = choiceMilestones.filter((milestone) => milestone.title !== answers.milestone); + choiceMilestones = choiceMilestones.filter( + (milestone) => milestone.title !== answers.milestone + ); if (choiceMilestones.length !== 0) { const res = await prompt([ { @@ -106,77 +108,77 @@ async function removemilestones(milestones) { } async function updatemilestones(milestones) { - icons = await geticons(); - let choiceMilestones = milestones; - let stop = false; - while (!stop) { - const answers = await prompt([ + icons = await geticons(); + let choiceMilestones = milestones; + let stop = false; + while (!stop) { + const answers = await prompt([ + { + type: "select", + name: "milestone", + choices: choiceMilestones, + message: "Choose which one you want to update", + }, + ]); + const { title, date, icon, description, url, color, updateMilestone } = + await prompt([ + { + type: "input", + name: "title", + message: "What is the new title of the milestone?", + }, + { + type: "input", + name: "date", + message: "What is the new date of the milestone?", + }, { type: "select", - name: "milestone", - choices: choiceMilestones, - message: "Choose which one you want to update", + name: "icon", + choices: icons, + message: "Choose a new icon (Press down arrow to see more options)", + }, + { + type: "input", + name: "description", + message: "What is the new description of the milestone?", + }, + { + type: "input", + name: "url", + message: "What is the new URL of the milestone?", + }, + { + type: "input", + name: "color", + message: "What is the new color theme of the milestone?", + }, + { + type: "confirm", + name: "updateMilestone", + message: "Do you want to update another milestone?", }, ]); - const { title, date, icon, description, url, color, updateMilestone } = - await prompt([ - { - type: "input", - name: "title", - message: "What is the new title of the milestone?", - }, - { - type: "input", - name: "date", - message: "What is the new date of the milestone?", - }, - { - type: "select", - name: "icon", - choices: icons, - message: "Choose a new icon (Press down arrow to see more options)", - }, - { - type: "input", - name: "description", - message: "What is the new description of the milestone?", - }, - { - type: "input", - name: "url", - message: "What is the new URL of the milestone?", - }, - { - type: "input", - name: "color", - message: "What is the new color theme of the milestone?", - }, - { - type: "confirm", - name: "updateMilestone", - message: "Do you want to update another milestone?", - }, - ]); + choiceMilestones.map((milestone) => { + if (milestone.title === answers.milestone) { + milestone.name = title; + milestone.title = title; + milestone.date = date; + milestone.url = url; + milestone.icon = icon; + milestone.description = description; + milestone.color = color; + } + }); + if (!updateMilestone) { + let result = []; choiceMilestones.map((milestone) => { - if (milestone.title === answers.milestone) { - milestone.name = title - milestone.title = title; - milestone.date = date - milestone.url = url; - milestone.icon = icon; - milestone.description = description - milestone.color = color - } + const { title, url, icon, description, date, color } = milestone; + result.push({ title, url, icon, description, date, color }); }); - if (!updateMilestone) { - let result = []; - choiceMilestones.map((milestone) => { - const { title, url, icon, description, date, color } = milestone; - result.push({ title, url, icon, description, date, color }); - }); - return result; - } + return result; } + } } module.exports = { diff --git a/src/shared/questions/socials.js b/src/shared/questions/socials.js index 6aa1f3b..be5cc69 100644 --- a/src/shared/questions/socials.js +++ b/src/shared/questions/socials.js @@ -80,9 +80,9 @@ async function updatesocials(socials) { icons = await geticons(); let choiceSocials = socials; let stop = false; - choiceSocials.map(social => { - social.name = social.url - }) + choiceSocials.map((social) => { + social.name = social.url; + }); while (!stop) { const answers = await prompt([ { @@ -112,16 +112,16 @@ async function updatesocials(socials) { ]); choiceSocials.map((social) => { if (social.name === answers.social) { - social.name = url + social.name = url; social.url = url; - social.icon = icon + social.icon = icon; } }); if (!updateSocial) { let result = []; choiceSocials.map((social) => { const { url, icon } = social; - result.push({url, icon}); + result.push({ url, icon }); }); return result; } diff --git a/src/shared/questions/tags.js b/src/shared/questions/tags.js index a9eee69..157c27b 100644 --- a/src/shared/questions/tags.js +++ b/src/shared/questions/tags.js @@ -24,70 +24,27 @@ async function addtags(bool) { } async function removetags(tags) { - let choiceTags = tags; - let stop = false; - while (!stop) { - const answers = await prompt([ - { - type: "select", - name: "tag", - choices: choiceTags, - message: "Choose which one you want to remove", - }, - ]); - choiceTags = choiceTags.filter((tag) => tag.name !== answers.tag); - if (choiceTags.length !== 0) { - const res = await prompt([ - { - type: "confirm", - name: "removeTag", - message: "Do you want to remove another tag?", - }, - ]); - if (!res.removeTag) { - let result = []; - choiceTags.map((tag) => { - const { name } = tag; - result.push(name); - }); - return result; - } - } else { - return []; - } - } -} - -async function updatetags(tags) { - let choiceTags = tags; - let stop = false; - while (!stop) { - const answers = await prompt([ - { - type: "select", - name: "tag", - choices: choiceTags, - message: "Choose which one you want to update", - }, - ]); - const { name, updateTag } = await prompt([ - { - type: "input", - name: "name", - message: "What is the new name of the tag?", - }, + let choiceTags = tags; + let stop = false; + while (!stop) { + const answers = await prompt([ + { + type: "select", + name: "tag", + choices: choiceTags, + message: "Choose which one you want to remove", + }, + ]); + choiceTags = choiceTags.filter((tag) => tag.name !== answers.tag); + if (choiceTags.length !== 0) { + const res = await prompt([ { type: "confirm", - name: "updateTag", - message: "Do you want to update another tag?", + name: "removeTag", + message: "Do you want to remove another tag?", }, ]); - choiceTags.map((tag) => { - if (tag.name === answers.tag) { - tag.name = name; - } - }); - if (!updateTag) { + if (!res.removeTag) { let result = []; choiceTags.map((tag) => { const { name } = tag; @@ -95,7 +52,50 @@ async function updatetags(tags) { }); return result; } + } else { + return []; } + } +} + +async function updatetags(tags) { + let choiceTags = tags; + let stop = false; + while (!stop) { + const answers = await prompt([ + { + type: "select", + name: "tag", + choices: choiceTags, + message: "Choose which one you want to update", + }, + ]); + const { name, updateTag } = await prompt([ + { + type: "input", + name: "name", + message: "What is the new name of the tag?", + }, + { + type: "confirm", + name: "updateTag", + message: "Do you want to update another tag?", + }, + ]); + choiceTags.map((tag) => { + if (tag.name === answers.tag) { + tag.name = name; + } + }); + if (!updateTag) { + let result = []; + choiceTags.map((tag) => { + const { name } = tag; + result.push(name); + }); + return result; + } + } } module.exports = { diff --git a/src/updatejson/updateJson.js b/src/updatejson/updateJson.js index af8361d..cfe37b8 100644 --- a/src/updatejson/updateJson.js +++ b/src/updatejson/updateJson.js @@ -118,8 +118,8 @@ const updateJson = async (githubUsername) => { case "remove a tag?": { if (json.tags) { json.tags = [...(await removetags(json.tags))]; - if(json.tags.length === 0){ - delete json.tags + if (json.tags.length === 0) { + delete json.tags; } } else { console.log(