Skip to content
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
40 changes: 40 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// checking for first arg
if (process.argv[2] === "init") {
// 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: ", 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();
});
});
});
});
askQuestion();
});
}
askQuestion();
}
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Project Name": "dsfg",
"Author Name": "sdfg",
"Version": "sdfg",
"ID": "sdfg",
"Favorite Color": "sdfg"
}