From 78540b9e17b00fa41dc8fb952a2da2023f51fe32 Mon Sep 17 00:00:00 2001 From: Abby Gottlich Date: Thu, 17 Jan 2019 20:22:36 -0600 Subject: [PATCH 1/3] package.json added --- package.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..f27a7c1 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "acapm", + "version": "1.0.0", + "description": "* Create a node program * Check for the first process argument to be init * If the first argument is init continue processing else end the program * check if a file named package.json already exists, if it does exit the program * Use readline to ask for 5 inputs * Create a string that is a json object * The key values should be the inputs you get from the user * Save this json to a file called package.json", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/abbygottlich/acapm.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/abbygottlich/acapm/issues" + }, + "homepage": "https://github.com/abbygottlich/acapm#readme" +} From 13d09b1744a78a55f9f9517969f77a7dbcc31368 Mon Sep 17 00:00:00 2001 From: Abby Gottlich Date: Tue, 22 Jan 2019 10:35:03 -0600 Subject: [PATCH 2/3] readline prompts working --- README.md | 10 +++++----- index.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 index.js diff --git a/README.md b/README.md index 9f3edd9..2395b23 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,12 @@ * Create a node program * Check for the first process argument to be init -* If the first argument is init continue processing else end the program -* check if a file named package.json already exists, if it does exit the program +*** If the first argument is init continue processing else end the program +*** check if a file named package.json already exists, if it does exit the program * Use readline to ask for 5 inputs -* Create a string that is a json object -* The key values should be the inputs you get from the user -* Save this json to a file called package.json +*** Create a string that is a json object +*** The key values should be the inputs you get from the user +*** Save this json to a file called package.json # Bonus * Don't hardcode 5 readlines diff --git a/index.js b/index.js new file mode 100644 index 0000000..63ba187 --- /dev/null +++ b/index.js @@ -0,0 +1,52 @@ +// console.log(process.argv); +// process.argv.forEach(function(val, index, array) { +// console.log(index + ": " + val); +// }); + +// checking for first arg +if (process.argv[2] === "init") { + // check to see if package.json already exists, else exit program + // prompt questions + const readline = require("readline"); + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + + function askQuestion() { + rl.question("Project Name: ", answer => { + rl.question("Author Name: ", answer => { + rl.question("Version: ", answer => { + rl.question("ID: ", answer => { + rl.question("Favorite Color: ", answer => { + console.log("Prompts completed."); + }); + }); + }); + }); + askQuestion(); + }); + } + askQuestion(); +} +// if first arg is not "init", exit the program + +// writing file +// let fs = require("fs"); + +// fs.writeFile("myNewFile.txt", "Important Info", err => { +// if (err) throw err; +// console.log("The file was successfully saved!"); +// }); + +// reading file +// const fs = require("fs"); + +// fs.readFile("myNewFile.txt", "utf8", fileWasRead); + +// function fileWasRead(err, data) { +// if (err) { +// return console.log(err); +// } +// console.log(data); +// } From 3c8f0420afe9902378a49de91d72a35a456accaa Mon Sep 17 00:00:00 2001 From: Abby Gottlich Date: Tue, 22 Jan 2019 15:16:10 -0600 Subject: [PATCH 3/3] added JSON object, converted to string, created new package --- README.md | 10 +++++----- index.js | 54 ++++++++++++++++++++-------------------------------- package.json | 24 ++++++----------------- 3 files changed, 32 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 2395b23..9f3edd9 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,12 @@ * Create a node program * Check for the first process argument to be init -*** If the first argument is init continue processing else end the program -*** check if a file named package.json already exists, if it does exit the program +* If the first argument is init continue processing else end the program +* check if a file named package.json already exists, if it does exit the program * Use readline to ask for 5 inputs -*** Create a string that is a json object -*** The key values should be the inputs you get from the user -*** Save this json to a file called package.json +* Create a string that is a json object +* The key values should be the inputs you get from the user +* Save this json to a file called package.json # Bonus * Don't hardcode 5 readlines diff --git a/index.js b/index.js index 63ba187..945339c 100644 --- a/index.js +++ b/index.js @@ -1,25 +1,34 @@ -// console.log(process.argv); -// process.argv.forEach(function(val, index, array) { -// console.log(index + ": " + val); -// }); - // checking for first arg if (process.argv[2] === "init") { - // check to see if package.json already exists, else exit program // prompt questions const readline = require("readline"); + const fs = require("fs"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); function askQuestion() { - rl.question("Project Name: ", answer => { - rl.question("Author Name: ", answer => { - rl.question("Version: ", answer => { - rl.question("ID: ", answer => { - rl.question("Favorite Color: ", answer => { - console.log("Prompts completed."); + rl.question("Project Name: ", name => { + rl.question("Author Name: ", author => { + rl.question("Version: ", version => { + rl.question("ID: ", id => { + rl.question("Favorite Color: ", color => { + // saved responses in JSON object + const response = { + "Project Name": name, + "Author Name": author, + "Version": version, + "ID": id, + "Favorite Color": color + }; + // JSON object converted to string and new package created + const obj = JSON.stringify(response, "", "\t") + fs.writeFile("package.json", obj, (err) => { + if (err) throw err; + console.log("The file was successfully saved!"); + }); + rl.close(); }); }); }); @@ -29,24 +38,3 @@ if (process.argv[2] === "init") { } askQuestion(); } -// if first arg is not "init", exit the program - -// writing file -// let fs = require("fs"); - -// fs.writeFile("myNewFile.txt", "Important Info", err => { -// if (err) throw err; -// console.log("The file was successfully saved!"); -// }); - -// reading file -// const fs = require("fs"); - -// fs.readFile("myNewFile.txt", "utf8", fileWasRead); - -// function fileWasRead(err, data) { -// if (err) { -// return console.log(err); -// } -// console.log(data); -// } diff --git a/package.json b/package.json index f27a7c1..27faec9 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,7 @@ { - "name": "acapm", - "version": "1.0.0", - "description": "* Create a node program * Check for the first process argument to be init * If the first argument is init continue processing else end the program * check if a file named package.json already exists, if it does exit the program * Use readline to ask for 5 inputs * Create a string that is a json object * The key values should be the inputs you get from the user * Save this json to a file called package.json", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/abbygottlich/acapm.git" - }, - "author": "", - "license": "ISC", - "bugs": { - "url": "https://github.com/abbygottlich/acapm/issues" - }, - "homepage": "https://github.com/abbygottlich/acapm#readme" -} + "Project Name": "dsfg", + "Author Name": "sdfg", + "Version": "sdfg", + "ID": "sdfg", + "Favorite Color": "sdfg" +} \ No newline at end of file