diff --git a/data.json b/data.json new file mode 100644 index 0000000..e6b3138 --- /dev/null +++ b/data.json @@ -0,0 +1 @@ +{"todoItems":["1. [ ] - watch Netflix","2. [ ] - buy grocery","3. [ ] - send email","4. [ ] - check letterbox","5. [ ] - take medicine"]} diff --git a/index.js b/index.js index 9a12786..dc6dd16 100644 --- a/index.js +++ b/index.js @@ -1,19 +1,45 @@ -console.log("works!!", process.argv[2]); -var commandType = process.argv[2]; +let command = process.argv[2]; +let taskItem = process.argv[3]; -console.log("Your command was: "+commandType); +let unmarked = " "; +let marked = "x"; const jsonfile = require('jsonfile'); -const file = 'data.json' +const fileName = 'data.json' + + +const addData = (error, toDoList) => { +console.log(toDoList); +//adding task items to the list + if ( command === "add"){ + // let itemsCount = toDoList['todoItems'].push(taskItem); + // console.log("the item add is " + itemsCount); +//create an output format + let itemsCount = toDoList['todoItems'].length + 1 + let formattedData = itemsCount + "." + " [" + unmarked + "]" + " - " + taskItem; + console.log("the output is " + formattedData); + let addedItems = toDoList['todoItems'].push(formattedData); + console.log(addedItems); + console.log(toDoList['todoItems']); + //console.log(toDoList['todoItems'][0]); + } + if ( command === "show"){ + for ( let i = 0; i < toDoList['todoItems'].length; i++){ + console.log(toDoList['todoItems'][i]); + } + } + + +jsonfile.writeFile(fileName, toDoList) + +} + + +jsonfile.readFile(fileName, addData) +console.log("read File") + -jsonfile.readFile(file, (err, obj) => { - console.log(obj); - obj["helloworld"] = "monkey"; - 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..5fded2a --- /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/vigbit/cli-todo.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/vigbit/cli-todo/issues" + }, + "homepage": "https://github.com/vigbit/cli-todo#readme", + "dependencies": { + "jsonfile": "^6.0.1" + } +}