@@ -25,108 +25,108 @@ const getHelp = () => chalk`
25
25
` ;
26
26
27
27
function parseArgsIntoOptions ( rowArgs ) {
28
- const projectName = rowArgs [ 2 ] ;
29
- let projectDirectory ;
30
- let args ;
31
-
32
- if ( ! projectName ) {
33
- console . error ( 'Please specify the project directory:' ) ;
34
- console . log (
35
- ` ${ chalk . cyan ( 'create-vue-library' ) } ${ chalk . green (
36
- '<project-directory>'
37
- ) } `
38
- ) ;
39
- console . log ( ) ;
40
- console . log ( 'For example:' ) ;
41
- console . log (
42
- ` ${ chalk . cyan ( 'create-vue-library' ) } ${ chalk . green ( 'my-vue-library' ) } `
43
- ) ;
44
- console . log ( ) ;
45
- console . log (
46
- `Run ${ chalk . cyan ( `${ 'create-vue-library' } --help` ) } to see all options.`
47
- ) ;
48
- process . exit ( 1 ) ;
49
- }
50
-
51
- projectDirectory = getAbsolutePath ( projectName ) ;
52
-
53
- try {
54
- args = arg (
55
- {
56
- '--help' : Boolean ,
57
- '--version' : Boolean ,
58
- '--template' : String ,
59
-
60
- '-h' : '--help' ,
61
- '-v' : '--version' ,
62
- '-t' : '--template' ,
63
- } ,
64
- {
65
- argv : rowArgs . slice ( 2 ) ,
66
- }
67
- ) ;
68
- } catch ( err ) {
69
- logError ( err . message ) ;
70
- process . exit ( 1 ) ;
71
- }
72
-
73
- if ( args [ '--version' ] ) {
74
- console . log ( pkg . version ) ;
75
- process . exit ( 0 ) ;
76
- }
77
-
78
- if ( args [ '--help' ] ) {
79
- console . log ( getHelp ( ) ) ;
80
- process . exit ( 0 ) ;
81
- }
82
-
83
- return {
84
- projectName,
85
- projectDirectory,
86
- template : args [ '--template' ] ,
87
- } ;
28
+ const projectName = rowArgs [ 2 ] ;
29
+ let projectDirectory ;
30
+ let args ;
31
+
32
+ if ( ! projectName ) {
33
+ console . error ( 'Please specify the project directory:' ) ;
34
+ console . log (
35
+ ` ${ chalk . cyan ( 'create-vue-library' ) } ${ chalk . green (
36
+ '<project-directory>'
37
+ ) } `
38
+ ) ;
39
+ console . log ( ) ;
40
+ console . log ( 'For example:' ) ;
41
+ console . log (
42
+ ` ${ chalk . cyan ( 'create-vue-library' ) } ${ chalk . green ( 'my-vue-library' ) } `
43
+ ) ;
44
+ console . log ( ) ;
45
+ console . log (
46
+ `Run ${ chalk . cyan ( `${ 'create-vue-library' } --help` ) } to see all options.`
47
+ ) ;
48
+ process . exit ( 1 ) ;
49
+ }
50
+
51
+ projectDirectory = getAbsolutePath ( projectName ) ;
52
+
53
+ try {
54
+ args = arg (
55
+ {
56
+ '--help' : Boolean ,
57
+ '--version' : Boolean ,
58
+ '--template' : String ,
59
+
60
+ '-h' : '--help' ,
61
+ '-v' : '--version' ,
62
+ '-t' : '--template' ,
63
+ } ,
64
+ {
65
+ argv : rowArgs . slice ( 2 ) ,
66
+ }
67
+ ) ;
68
+ } catch ( err ) {
69
+ logError ( err . message ) ;
70
+ process . exit ( 1 ) ;
71
+ }
72
+
73
+ if ( args [ '--version' ] ) {
74
+ console . log ( pkg . version ) ;
75
+ process . exit ( 0 ) ;
76
+ }
77
+
78
+ if ( args [ '--help' ] ) {
79
+ console . log ( getHelp ( ) ) ;
80
+ process . exit ( 0 ) ;
81
+ }
82
+
83
+ return {
84
+ projectName,
85
+ projectDirectory,
86
+ template : args [ '--template' ] ,
87
+ } ;
88
88
}
89
89
90
90
async function checkIsProjectDirectoryValid ( options ) {
91
- const isExists = await isFileOrDirExists ( options . projectDirectory ) ;
92
-
93
- if ( isExists ) {
94
- console . log (
95
- `Uh oh! Looks like there's already a directory called ${ chalk . red (
96
- options . projectName
97
- ) } .`
98
- ) ;
99
- console . log ( 'Please try a different name or delete that folder.' ) ;
100
- process . exit ( 1 ) ;
101
- }
91
+ const isExists = await isFileOrDirExists ( options . projectDirectory ) ;
92
+
93
+ if ( isExists ) {
94
+ console . log (
95
+ `Uh oh! Looks like there's already a directory called ${ chalk . red (
96
+ options . projectName
97
+ ) } .`
98
+ ) ;
99
+ console . log ( 'Please try a different name or delete that folder.' ) ;
100
+ process . exit ( 1 ) ;
101
+ }
102
102
}
103
103
104
104
async function proptForMissingOptions ( options ) {
105
- const defaultTemplate = 'basic' ;
106
-
107
- const questions = [ ] ;
108
- if ( ! options . template ) {
109
- questions . push ( {
110
- type : 'list' ,
111
- name : 'template' ,
112
- message : 'Please choose which project template to use' ,
113
- choices : [ 'basic' , 'typescript' , 'storybook' ] ,
114
- default : defaultTemplate ,
115
- } ) ;
116
- }
117
-
118
- const answers = await prompt ( questions ) ;
119
- return {
120
- ...options ,
121
- template : options . template || answers . template ,
122
- } ;
105
+ const defaultTemplate = 'basic' ;
106
+
107
+ const questions = [ ] ;
108
+ if ( ! options . template ) {
109
+ questions . push ( {
110
+ type : 'list' ,
111
+ name : 'template' ,
112
+ message : 'Please choose which project template to use' ,
113
+ choices : [ 'basic' , 'typescript' , 'storybook' ] ,
114
+ default : defaultTemplate ,
115
+ } ) ;
116
+ }
117
+
118
+ const answers = await prompt ( questions ) ;
119
+ return {
120
+ ...options ,
121
+ template : options . template || answers . template ,
122
+ } ;
123
123
}
124
124
125
125
export async function cli ( rowArgs ) {
126
- let options = parseArgsIntoOptions ( rowArgs ) ;
126
+ let options = parseArgsIntoOptions ( rowArgs ) ;
127
127
128
- await checkIsProjectDirectoryValid ( options ) ;
128
+ await checkIsProjectDirectoryValid ( options ) ;
129
129
130
- options = await proptForMissingOptions ( options ) ;
131
- await createProject ( options ) ;
130
+ options = await proptForMissingOptions ( options ) ;
131
+ await createProject ( options ) ;
132
132
}
0 commit comments