@@ -2,6 +2,8 @@ const fs = require("fs");
22const server = require ( "../server/server.js" ) ;
33const chalk = require ( 'chalk' ) ;
44
5+ const inquirer = require ( 'inquirer' ) ;
6+
57const wait = ms => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
68
79async 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+
7198module . exports = static_object ;
0 commit comments