From 28790e98e13872116c067d3d34f45bd3b297a910 Mon Sep 17 00:00:00 2001 From: Darwin Date: Sun, 20 Jan 2019 11:27:02 -0600 Subject: [PATCH 1/3] init commit --- index.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..dadb274 --- /dev/null +++ b/index.js @@ -0,0 +1,24 @@ +#!/usr/bin/env node + +const readline = require('readline'); +const fs = require('fs') + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + +if(process.argv[0] === "init"){ + //do init stuff + console.log("I am doing init stuff"); + } + +// rl.question('What do you want to do? ', (answer) => { +// if (answer === 'init'){ +// console.log('Creating package.json'); +// fs.writeFile("package.json", "important info") +// } else { +// console.log('error') +// } +// rl.close(); +// }); \ No newline at end of file From bda3afcc1a0648b85ba5ec09f5a2a565c4e6b796 Mon Sep 17 00:00:00 2001 From: Darwin Risser Date: Mon, 21 Jan 2019 11:15:45 -0600 Subject: [PATCH 2/3] basic functionality added --- index.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++---- package.json | 1 + 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 package.json diff --git a/index.js b/index.js index dadb274..32d8094 100644 --- a/index.js +++ b/index.js @@ -8,10 +8,56 @@ const rl = readline.createInterface({ output: process.stdout }); -if(process.argv[0] === "init"){ - //do init stuff - console.log("I am doing init stuff"); - } +if(process.argv[2] === "init"){ + console.log("Get ready to init!"); + rl.question('What is your name? ', (name) => { + rl.question('What is your e-mail address? ', (email) => { + rl.question('What is your username? ', (username) => { + rl.question('What is your password? ', (password) => { + rl.question('What is your favorite color? ', (color) => { + let answers = { + name: name, + email: email, + username: username, + password: password, + color: color + }; + console.log("Created new package.JSON file:"); + console.log(answers); + let data = JSON.stringify(answers); + fs.writeFileSync('package.json', data); + rl.close(); + }) + }) + }) + }) + }) +} else { + console.log("error") + rl.close(); +}; + + + + + + + + + + + + + + + + + + +// if(process.argv[0] === "init"){ +// //do init stuff +// console.log("I am doing init stuff"); +// } // rl.question('What do you want to do? ', (answer) => { // if (answer === 'init'){ diff --git a/package.json b/package.json new file mode 100644 index 0000000..f9ab545 --- /dev/null +++ b/package.json @@ -0,0 +1 @@ +{"name":" ","email":"a","username":"a","password":"a","color":"a"} \ No newline at end of file From a4c1f7eb2b20646ad6acb5458df862f0dfbed4f8 Mon Sep 17 00:00:00 2001 From: Darwin Risser Date: Tue, 22 Jan 2019 07:40:11 -0600 Subject: [PATCH 3/3] all requirements working --- index.js | 80 ++++++++++++++++------------------------------------ package.json | 1 - 2 files changed, 25 insertions(+), 56 deletions(-) delete mode 100644 package.json diff --git a/index.js b/index.js index 32d8094..ffedce4 100644 --- a/index.js +++ b/index.js @@ -9,62 +9,32 @@ const rl = readline.createInterface({ }); if(process.argv[2] === "init"){ - console.log("Get ready to init!"); - rl.question('What is your name? ', (name) => { - rl.question('What is your e-mail address? ', (email) => { - rl.question('What is your username? ', (username) => { - rl.question('What is your password? ', (password) => { - rl.question('What is your favorite color? ', (color) => { - let answers = { - name: name, - email: email, - username: username, - password: password, - color: color - }; - console.log("Created new package.JSON file:"); - console.log(answers); - let data = JSON.stringify(answers); - fs.writeFileSync('package.json', data); - rl.close(); - }) + if (!fs.existsSync("./package.json")){ + console.log("Get ready to init!"); + rl.question('What is your name? ', (name) => { + rl.question('What is your e-mail address? ', (email) => { + rl.question('What is your username? ', (username) => { + rl.question('What is your password? ', (password) => { + rl.question('What is your favorite color? ', (color) => { + let answers = { + name: name, + email: email, + username: username, + password: password, + color: color + }; + console.log("Created new package.JSON file:"); + console.log(answers); + let data = JSON.stringify(answers); + fs.writeFileSync('package.json', data); + rl.close(); + }) + }) + }) }) }) - }) - }) -} else { + } else { console.log("error") rl.close(); -}; - - - - - - - - - - - - - - - - - - -// if(process.argv[0] === "init"){ -// //do init stuff -// console.log("I am doing init stuff"); -// } - -// rl.question('What do you want to do? ', (answer) => { -// if (answer === 'init'){ -// console.log('Creating package.json'); -// fs.writeFile("package.json", "important info") -// } else { -// console.log('error') -// } -// rl.close(); -// }); \ No newline at end of file + } +}; \ No newline at end of file diff --git a/package.json b/package.json deleted file mode 100644 index f9ab545..0000000 --- a/package.json +++ /dev/null @@ -1 +0,0 @@ -{"name":" ","email":"a","username":"a","password":"a","color":"a"} \ No newline at end of file