File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ const readline = require ( 'readline' ) ;
2
+ const fs = require ( "fs" ) ;
3
+ const package = fs . readFileSync ( "./package.json" , "utf-8" ) ;
4
+ const rl = readline . createInterface ( {
5
+ input : process . stdin ,
6
+ output : process . stdout ,
7
+ prompt : "-> "
8
+ } ) ;
9
+ const initProcess = {
10
+ steps : 0 ,
11
+ questions : [
12
+ "What is the name of your project ? Don't add space in the name. \n" ,
13
+ "Enter a description. \n" ,
14
+ "Enter the version of NodeJs that your project must use"
15
+ ]
16
+ }
17
+ const replaceContent = fieldToReplace => {
18
+ const newPackage = package . replace ( `"${ fieldToReplace } ": ""` , `"${ fieldToReplace } ": "${ input } "` ) ;
19
+ fs . writeFileSync ( "./package.json" , newPackage ) ;
20
+ initProcess . steps ++ ;
21
+ }
22
+
23
+ console . log ( "\x1b[33m%s\x1b[0m" , "Before starting we need some informations to configurate your project. \n" ) ;
24
+ console . log ( "Press enter to start" ) ;
25
+
26
+ rl . on ( "line" , input => {
27
+ if ( input === "" && initProcess . steps !== 0 ) {
28
+ console . log ( "\x1b[35m%s\x1b[0m" , "You should enter data !" ) ;
29
+ rl . prompt ( ) ;
30
+ } else {
31
+ console . log ( `${ initProcess . steps + 1 } - ${ initProcess . questions [ initProcess . steps ] } ` ) ;
32
+ rl . prompt ( ) ;
33
+
34
+ switch ( initProcess . steps ) {
35
+ case 0 :
36
+ initProcess . steps ++ ;
37
+ case 1 :
38
+ replaceContent ( "name" ) ;
39
+ break ;
40
+ case 2 :
41
+ replaceContent ( "description" ) ;
42
+ break ;
43
+ default :
44
+ break ;
45
+ }
46
+ }
47
+ } ) . on ( "close" , ( ) => {
48
+
49
+ } ) ;
You can’t perform that action at this time.
0 commit comments