Skip to content

Commit 17b7c91

Browse files
Changed code style and will check for the name afterwards
1 parent 1561512 commit 17b7c91

File tree

2 files changed

+49
-45
lines changed

2 files changed

+49
-45
lines changed

creator/src/configs/staticConf.js

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const fs = require("fs");
22
const server = require("../server/server.js");
33
const chalk = require('chalk');
44

5+
const inquirer = require('inquirer');
6+
57
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
68

79
async function static_object(config, name, path_) {
@@ -39,33 +41,58 @@ function draw() {
3941
}
4042
`
4143

42-
fs.mkdirSync(name);
44+
if(!fs.existsSync(name)){
45+
fs.mkdirSync(name);
4346

44-
console.log(chalk.white.bgCyan("\nInfo:") + chalk.greenBright(" Created Directory: " + name))
47+
console.log(chalk.white.bgCyan("\nInfo:") + chalk.greenBright(" Created Directory: " + name))
48+
49+
fs.appendFile(`${path_ + "/" + name}/index.html`, baseConfig, function (err) {
50+
if (err)
51+
throw err;
52+
console.log(chalk.white.bgCyan("\nInfo:") + chalk.greenBright(' Created index.html'));
53+
});
54+
55+
fs.appendFile(`${path_ + "/" + name}/sketch.js`, sketchjs, function (err) {
56+
if (err)
57+
throw err;
58+
console.log(chalk.white.bgCyan("Info:") + chalk.greenBright(' Created sketch.js'));
59+
});
4560

46-
fs.appendFile(`${path_ + "/" + name}/index.html`, baseConfig, function (err) {
47-
if (err)
48-
throw err;
49-
console.log(chalk.white.bgCyan("\nInfo:") + chalk.greenBright(' Created index.html'));
50-
});
61+
fs.appendFile(`${path_ + "/" + name}/style.css`, stylecss, function (err) {
62+
if (err)
63+
throw err;
64+
console.log(chalk.white.bgCyan("Info:") + chalk.greenBright(' Created style.css'));
65+
})
66+
67+
wait(1*1000).then(() => server(path_ + "/" + name));
68+
69+
return {
70+
baseConfig
71+
}
72+
}
5173

52-
fs.appendFile(`${path_ + "/" + name}/sketch.js`, sketchjs, function (err) {
53-
if (err)
54-
throw err;
55-
console.log(chalk.white.bgCyan("Info:") + chalk.greenBright(' Created sketch.js'));
56-
});
74+
else {
75+
const answers = await inquirer
76+
.prompt([
77+
{
78+
type: "confirm",
79+
name: "overwrite",
80+
message: "index.html already exists! Would you like to open live server here ?",
81+
default: false,
82+
}
83+
]);
5784

58-
fs.appendFile(`${path_ + "/" + name}/style.css`, stylecss, function (err) {
59-
if (err)
60-
throw err;
61-
console.log(chalk.white.bgCyan("Info:") + chalk.greenBright(' Created style.css'));
62-
})
63-
64-
wait(1*1000).then(() => server(path_ + "/" + name));
85+
if (!answers.overwrite) {
86+
console.log("Goodbye :)");
87+
return;
88+
}
6589

66-
return {
67-
baseConfig
90+
server(process.cwd() + "/" + name + "/");
6891
}
6992
}
7093

94+
95+
//// Ask to overtime the file
96+
97+
7198
module.exports = static_object;

creator/src/index.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,12 @@ async function config() {
4242
}
4343

4444
async function main() {
45-
const existindex = fs.existsSync("index.html");
4645

4746
// Clean Screen
4847
readline.cursorTo(process.stdout, 0, 0);
4948
readline.clearScreenDown(process.stdout);
5049

51-
if (!existindex) {
52-
// simply create new project
53-
await config();
54-
return;
55-
}
56-
57-
// Ask to overtime the file
58-
const answers = await inquirer
59-
.prompt([
60-
{
61-
type: "confirm",
62-
name: "overwrite",
63-
message: "index.html already exists! Would you like to open live server here ?",
64-
default: false,
65-
}
66-
]);
67-
68-
if (!answers.overwrite) {
69-
console.log("Goodbye :)");
70-
return;
71-
}
72-
73-
server(process.cwd());
50+
await config();
7451
}
7552

7653
main();

0 commit comments

Comments
 (0)