diff --git a/creator/src/index.js b/creator/src/index.js index 0aec16c..7c2f5b3 100644 --- a/creator/src/index.js +++ b/creator/src/index.js @@ -12,52 +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 => { - config.name = answers.name; + if (!existindex) { + // simply create new project + await config(); + return; + } - switch(answers.type) { - case "static": - config = staticConf(config, answers.name, process.cwd()); - break; - } - // console.log(config); - }) -} - -if (existindex) { - inquirer + // Ask to overtime the file + const answers = await inquirer .prompt([ { type: "confirm", @@ -65,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