From fe8b69c19fd1a63538a0a02fcf63582a69811f07 Mon Sep 17 00:00:00 2001 From: Manmeet Maan Date: Fri, 3 Jul 2020 18:01:40 +0530 Subject: [PATCH 1/2] Removed unsed mutation config --- creator/src/index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/creator/src/index.js b/creator/src/index.js index 0aec16c..96e5713 100644 --- a/creator/src/index.js +++ b/creator/src/index.js @@ -45,14 +45,11 @@ function config() { } ]) .then(answers => { - config.name = answers.name; - switch(answers.type) { case "static": - config = staticConf(config, answers.name, process.cwd()); + staticConf(config, answers.name, process.cwd()); break; } - // console.log(config); }) } From bdae491eb693c034bc9d99cee6ac43e6bb11e748 Mon Sep 17 00:00:00 2001 From: Manmeet Maan Date: Sat, 4 Jul 2020 13:58:46 +0530 Subject: [PATCH 2/2] use async functions --- creator/src/index.js | 98 ++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/creator/src/index.js b/creator/src/index.js index 96e5713..7c2f5b3 100644 --- a/creator/src/index.js +++ b/creator/src/index.js @@ -12,49 +12,50 @@ const readline = require('readline'); const staticConf = require("./configs/staticConf.js"); const server = require("./server/server.js"); -const existindex = fs.existsSync("index.html"); - -// Clean Screen +// Rest of code -const blank = '\n'.repeat(process.stdout.rows); +async function config() { + const answers = await inquirer + .prompt([ + { + type: "text", + name: "name", + message: "What is the name of the project ?", + default: path.basename(process.cwd()), + }, + { + type: "list", + name: "type", + message: "Do you want to integrate node.js with the p5.js app ?", + choices: [ + "static", + "node" + ] + } + ]); -console.log(blank); + switch (answers.type) { + case "static": + await staticConf(config, answers.name, process.cwd()); + break; + } +} -readline.cursorTo(process.stdout, 0, 0); -readline.clearScreenDown(process.stdout); +async function main() { + const existindex = fs.existsSync("index.html"); -// Rest of code + // Clean Screen + readline.cursorTo(process.stdout, 0, 0); + readline.clearScreenDown(process.stdout); -function config() { - inquirer - .prompt([ - { - type: "text", - name: "name", - message: "What is the name of the project ?", - default: path.basename(process.cwd()), - }, - { - type: "list", - name: "type", - message: "Do you want to integrate node.js with the p5.js app ?", - choices: [ - "static", - "node" - ] - } - ]) - .then(answers => { - switch(answers.type) { - case "static": - staticConf(config, answers.name, process.cwd()); - break; - } - }) -} + if (!existindex) { + // simply create new project + await config(); + return; + } -if (existindex) { - inquirer + // Ask to overtime the file + const answers = await inquirer .prompt([ { type: "confirm", @@ -62,15 +63,14 @@ if (existindex) { message: "index.html already exists! Would you like to open live server here ?", default: false, } - ]) - .then(answers => { - if (answers.overwrite) { - server(process.cwd()) - } else{ - console.log("Goodbye :)") - } - }) -} -else{ - config(); -} \ No newline at end of file + ]); + + if (!answers.overwrite) { + console.log("Goodbye :)"); + return; + } + + server(process.cwd()); +} + +main(); \ No newline at end of file