diff --git a/data.json b/data.json new file mode 100644 index 0000000..3cc5b6a --- /dev/null +++ b/data.json @@ -0,0 +1,10 @@ +{ + "toDoList": [ + "1. [ ] - Take a shower", + "2. [ ] - Brush teeth", + "3. [ ] - Prepare breakfast", + "4. [ ] - Eat breakfast", + "5. [ ] - Report sick", + "6. [ ] - Take MC" + ] +} \ No newline at end of file diff --git a/index.js b/index.js index 9a12786..813ca57 100644 --- a/index.js +++ b/index.js @@ -1,19 +1,29 @@ -console.log("works!!", process.argv[2]); +console.log("NODEEEEE"); var commandType = process.argv[2]; +var commandItem = process.argv[3]; +var selectedInput = process.argv[4]; -console.log("Your command was: "+commandType); +console.log("Your command was: " + commandType); const jsonfile = require('jsonfile'); -const file = 'data.json' +const file = 'data.json'; jsonfile.readFile(file, (err, obj) => { - console.log(obj); - obj["helloworld"] = "monkey"; + if (process.argv[2] === "add") { + var newInputNumber = obj["toDoList"].length + 1; + var newInput = newInputNumber + ". [ ] - " + commandItem; + obj["toDoList"].push(newInput); + } else if (process.argv[2] === "show") { + for (let i = 0; i < obj["toDoList"].length; i++) { + console.log(obj["toDoList"][i]); + } + console.log(obj); + // } else if (process.argv[2] === "done") { + // var completedTask = selectedInput - 1; - jsonfile.writeFile(file, obj, (err) => { - console.log(err) - }); -}); + // } + jsonfile.writeFile(file, obj, (err) => { console.log(err); }) + }) diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..a56377e --- /dev/null +++ b/package-lock.json @@ -0,0 +1,28 @@ +{ + "name": "cli-todo", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "graceful-fs": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz", + "integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==", + "optional": true + }, + "jsonfile": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.0.1.tgz", + "integrity": "sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg==", + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^1.0.0" + } + }, + "universalify": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz", + "integrity": "sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..fd31f4a --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "cli-todo", + "version": "1.0.0", + "description": "![https://i.giphy.com/media/26ufnwz3wDUli7GU0/giphy.webp](https://i.giphy.com/media/26ufnwz3wDUli7GU0/giphy.webp)", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/YusofGotboudine/cli-todo.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/YusofGotboudine/cli-todo/issues" + }, + "homepage": "https://github.com/YusofGotboudine/cli-todo#readme", + "dependencies": { + "jsonfile": "^6.0.1" + } +}