File tree Expand file tree Collapse file tree 4 files changed +1750
-942
lines changed Expand file tree Collapse file tree 4 files changed +1750
-942
lines changed Original file line number Diff line number Diff line change @@ -6,17 +6,29 @@ const chalk = require('chalk');
6
6
const header = require ( '../lib/header' ) ;
7
7
const question = require ( '../lib/question' ) ;
8
8
const create = require ( '../lib/create' ) ;
9
+ const ifdir = require ( '../lib/ifdir' ) ;
9
10
10
11
const main = async ( ) => {
11
- header . init ( ) ;
12
+ header . init ( ) ;
12
13
13
- const input = await question . questions ( ) ;
14
- // console.log(input);
15
- const { filename, extension } = input ;
16
- // console.log(filename);
17
- create . create ( filename , extension ) ;
14
+ const result = await ifdir . ask ( ) ;
18
15
19
- console . log ( chalk . blue ( 'File created successfully' ) + chalk . red ( '!!!' ) ) ;
16
+ const { isdir } = result ;
17
+
18
+ if ( isdir === 'd' ) {
19
+ const dir_res = await ifdir . getdir ( ) ;
20
+ const { dirname } = dir_res ;
21
+ create . createdir ( dirname ) ;
22
+
23
+ return ;
24
+ } else {
25
+ const input = await question . questions ( ) ;
26
+ // console.log(input);
27
+ const { filename, extension } = input ;
28
+ // console.log(filename);
29
+ create . create ( filename , extension ) ;
30
+ console . log ( chalk . blue ( 'File created successfully' ) + chalk . red ( '!!!' ) ) ;
31
+ }
20
32
} ;
21
33
22
34
main ( ) ;
Original file line number Diff line number Diff line change 1
1
const shell = require ( 'shelljs' ) ;
2
2
3
3
exports . create = ( filename , extension ) => {
4
- const filePath = `${ process . cwd ( ) } /${ filename } .${ extension } ` ;
5
- // console.log(filePath);
6
- shell . touch ( filePath ) ;
4
+ const filePath = `${ process . cwd ( ) } /${ filename } .${ extension } ` ;
5
+ // console.log(filePath);
6
+ shell . touch ( filePath ) ;
7
7
} ;
8
+
9
+ exports . createdir = ( dirname ) => {
10
+ const path = `${ process . cwd ( ) } /${ dirname } ` ;
11
+ shell . mkdir ( path ) ;
12
+ }
Original file line number Diff line number Diff line change
1
+ const inquirer = require ( 'inquirer' )
2
+
3
+ exports . ask = ( ) => {
4
+ const question = [
5
+ {
6
+ name : 'isdir' ,
7
+ type : 'input' ,
8
+ message : 'Do you want to create directory (d) or file (f) ? (d/f) ' ,
9
+ } ,
10
+ ] ;
11
+
12
+ return inquirer . prompt ( question ) ;
13
+ } ;
14
+
15
+ exports . getdir = ( ) => {
16
+ const getdir = [
17
+ {
18
+ name : 'dirname' ,
19
+ type : 'input' ,
20
+ message : 'Directory name: ' ,
21
+ } ,
22
+ ] ;
23
+
24
+ return inquirer . prompt ( getdir ) ;
25
+ } ;
You can’t perform that action at this time.
0 commit comments