Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hwee Meng Completed till add date #150

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"todoList":["1.[ ] - Eat alot more","2.[x] - Sleep alot more","3.[ ] - Walk alot more"]}
46 changes: 33 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
console.log("works!!", process.argv[2]);

var commandType = process.argv[2];

console.log("Your command was: "+commandType);

const jsonfile = require('jsonfile');

const file = 'data.json'

jsonfile.readFile(file, (err, obj) => {

console.log(obj);
obj["helloworld"] = "monkey";

jsonfile.writeFile(file, obj, (err) => {
console.log(err)
if (process.argv[2] === "add"){
jsonfile.readFile(file, (err, obj) => {
console.log("error of readfile is: =============");
console.log(err);
console.log("current to-do list is: =============");
console.log(obj);
obj["todoList"].push ((obj["todoList"].length +1) + ".[ ] - " + process.argv[3]);
jsonfile.writeFile(file, obj, (err) => {
console.log("error of writefile is: ==========")
console.log(err);
console.log(obj);
});
});
} else if (process.argv[2] === "show"){
jsonfile.readFile(file, (err, obj) => {
console.log("current to-do list is: =============");
console.log(err);
console.log(obj);
});
} else if (process.argv[2] === "done"){
jsonfile.readFile(file, (err, obj) => {
console.log("current to-do list is: =============");
console.log(err);
console.log(obj);
let afterSplit = obj["todoList"][(process.argv[3]-1)].split ("[ ]");
console.log(afterSplit[1]);
obj["todoList"][(process.argv[3]-1)] = parseInt(process.argv[3]) + ".[x]" + afterSplit[1];
jsonfile.writeFile(file, obj, (err) => {
console.log("error of writefile is: ==========")
console.log(err);
console.log(obj);
});
});

}
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.