@@ -62,15 +62,22 @@ if (commandLength >= 3) {
62
62
if ( ( options [ 0 ] ) === '--controller' ) {
63
63
64
64
const controllerNames = options . slice ( 1 , options . length )
65
- controllerNames . forEach ( name => {
66
- const filename = `${ name } `
67
- createController ( filename )
68
- } )
69
-
70
- new Promise ( resolve => setTimeout ( resolve , 1000 ) ) . then ( ( ) => {
71
- console . log ( `✅🌈 You have created controller file!\n` )
65
+ if ( controllerNames . length > 0 ) {
66
+ controllerNames . forEach ( name => {
67
+ const filename = `${ name } `
68
+ createController ( filename )
69
+ } )
70
+
71
+ new Promise ( resolve => setTimeout ( resolve , 1000 ) ) . then ( ( ) => {
72
+ console . log ( `✅🌈 You have created controller file!\n` )
73
+ process . exit ( 0 )
74
+ } )
75
+ }
76
+ else {
77
+ console . log ( `\x1b[41mcontroller name can't be blank!!\x1b[0m\n` )
78
+ console . log ( `\x1b[33m[TRY]: \x1b[30mnpm run create:controller controllername\x1b[0m\n\n` )
72
79
process . exit ( 0 )
73
- } )
80
+ }
74
81
}
75
82
76
83
@@ -80,15 +87,22 @@ if (commandLength >= 3) {
80
87
if ( ( options [ 0 ] ) === '--model' ) {
81
88
82
89
const modelNames = options . slice ( 1 , options . length )
83
- modelNames . forEach ( name => {
84
- const filename = `${ name } `
85
- createModel ( filename )
86
- } )
87
-
88
- new Promise ( resolve => setTimeout ( resolve , 1000 ) ) . then ( ( ) => {
89
- console . log ( `✅🌈 You have created model file!\n` )
90
+ if ( modelNames . length > 0 ) {
91
+ modelNames . forEach ( name => {
92
+ const filename = `${ name } `
93
+ createModel ( filename )
94
+ } )
95
+
96
+ new Promise ( resolve => setTimeout ( resolve , 1000 ) ) . then ( ( ) => {
97
+ console . log ( `✅🌈 You have created model file!\n` )
98
+ process . exit ( 0 )
99
+ } )
100
+ }
101
+ else {
102
+ console . log ( `\x1b[41mmodel name can't be blank!!\x1b[0m\n` )
103
+ console . log ( `\x1b[33m[TRY]: \x1b[30mnpm run create:model modelname\x1b[0m\n\n` )
90
104
process . exit ( 0 )
91
- } )
105
+ }
92
106
}
93
107
94
108
@@ -97,34 +111,49 @@ if (commandLength >= 3) {
97
111
*/
98
112
if ( ( options [ 0 ] ) === '--route' ) {
99
113
100
- const modelNames = options . slice ( 1 , options . length )
101
- modelNames . forEach ( name => {
102
- const filename = `${ name } `
103
- createRoutes ( filename )
104
- } )
105
-
106
- new Promise ( resolve => setTimeout ( resolve , 1000 ) ) . then ( ( ) => {
107
- console . log ( `✅🌈 You have created model file!\n` )
114
+ const routeNames = options . slice ( 1 , options . length )
115
+ if ( routeNames . length > 0 ) {
116
+ routeNames . forEach ( name => {
117
+ const filename = `${ name } `
118
+ createRoutes ( filename )
119
+ } )
120
+
121
+ new Promise ( resolve => setTimeout ( resolve , 1000 ) ) . then ( ( ) => {
122
+ console . log ( `✅🌈 You have created route file!\n` )
123
+ process . exit ( 0 )
124
+ } )
125
+ }
126
+ else {
127
+ console . log ( `\x1b[41mroute name can't be blank!!\x1b[0m\n` )
128
+ console . log ( `\x1b[33m[TRY]: \x1b[30mnpm run create:route routename\x1b[0m\n\n` )
108
129
process . exit ( 0 )
109
- } )
130
+ }
110
131
}
111
132
112
133
/**
113
134
* Create Controller, Create Route, Create Model
114
135
*/
115
136
if ( ( options [ 0 ] ) === '--rcm' ) {
116
137
117
- const modelNames = options . slice ( 1 , options . length )
118
- modelNames . forEach ( name => {
119
- const filename = `${ name } `
120
- createRoutes ( filename )
121
- createController ( filename )
122
- createModel ( filename )
123
- } )
124
-
125
- new Promise ( resolve => setTimeout ( resolve , 1000 ) ) . then ( ( ) => {
126
- console . log ( `✅🌈 All file created!\n` )
138
+ const rcmNames = options . slice ( 1 , options . length )
139
+ if ( rcmNames . length > 0 ) {
140
+ rcmNames . forEach ( name => {
141
+ const filename = `${ name } `
142
+ createRoutes ( filename )
143
+ createController ( filename )
144
+ createModel ( filename )
145
+ } )
146
+
147
+ new Promise ( resolve => setTimeout ( resolve , 1000 ) ) . then ( ( ) => {
148
+ console . log ( `✅🌈 All file created!\n` )
149
+ process . exit ( 0 )
150
+ } )
151
+ }
152
+ else
153
+ {
154
+ console . log ( `\x1b[41mrcm name can't be blank!!\x1b[0m\n` )
155
+ console . log ( `\x1b[33m[TRY]: \x1b[30mnpm run create:rcm rcmname\x1b[0m\n\n` )
127
156
process . exit ( 0 )
128
- } )
157
+ }
129
158
}
130
159
}
0 commit comments