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

Yannie - (1)Add-to-list and (2)show-list are working #146

Open
wants to merge 1 commit 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
36 changes: 36 additions & 0 deletions command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const fs = require("fs");

const add = function (){
// console.log("hello")

var dataList = [];

try {
dataList = JSON.parse(fs.readFileSync("data.json"));
let listNum = dataList.length + 1;
let listItem = process.argv[3];
dataList.push({ listNum, listItem});
// console.log (dataList);
} catch (e) {
console.log("this is the error ==> " + e)
}

fs.writeFileSync("data.json",JSON.stringify(dataList));

}

const show = function (){
var dataList = [];
try {
dataList = JSON.parse(fs.readFileSync("data.json"));
} catch (e) {
console.log("this is the error ==> " + e)
}
console.log(dataList)
}


module.exports = {
add,
show
}
1 change: 1 addition & 0 deletions data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"listNum":1,"listItem":"Eat bak kut teh"},{"listNum":2,"listItem":"Wash Clothes"}]
57 changes: 45 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,52 @@
console.log("works!!", process.argv[2]);
console.log("Mmmmyyyy TO-DO LISSSTSSSS")
const command = require("./command")

var commandType = process.argv[2];
// node index.js add "eat bak kut teh"
// node index.js show
// node index.js mark 4

console.log("Your command was: "+commandType);
if (process.argv[2] === "add") {
console.log ("The list is getting longeeeerrrr!!!")
command.add ();

const jsonfile = require('jsonfile');
} else if (process.argv[2] === "show"){
console.log("Here is the list:")
command.show()

const file = 'data.json'
} else if (process.argv[2] === "mark"){
console.log("crossed means done")

jsonfile.readFile(file, (err, obj) => {
} else {
console.log("I dont understand your command")
}

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

jsonfile.writeFile(file, obj, (err) => {
console.log(err)
});
});










// 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)
// });
// });
218 changes: 218 additions & 0 deletions package-lock.json

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

23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"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/yannieyeung/cli-todo.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/yannieyeung/cli-todo/issues"
},
"homepage": "https://github.com/yannieyeung/cli-todo#readme",
"dependencies": {
"jsonfile": "^6.0.1",
"yargs": "^15.3.1"
}
}