@@ -51,21 +51,29 @@ export default class MakePreloadFile extends BaseGenerator {
51
51
return this . environment . split ( ',' )
52
52
}
53
53
54
- return this . prompt . multiple ( 'Select the environment(s) in which you want to load this file' , [
54
+ return this . prompt . multiple (
55
+ 'Select the environment(s) in which you want to load this file' ,
56
+ [
57
+ {
58
+ name : 'console' ,
59
+ message : 'During ace commands' ,
60
+ } ,
61
+ {
62
+ name : 'web' ,
63
+ message : 'During HTTP server' ,
64
+ } ,
65
+ ] ,
55
66
{
56
- name : 'console' ,
57
- message : 'During ace commands' ,
58
- } ,
59
- {
60
- name : 'web' ,
61
- message : 'During HTTP server' ,
62
- } ,
63
- ] )
67
+ validate ( choices ) {
68
+ return choices && choices . length ? true : 'Please the environment for the preload file'
69
+ } ,
70
+ }
71
+ )
64
72
}
65
73
66
74
/**
67
75
* Validates environments to ensure they are allowed. Especially when
68
- * define as a flag.
76
+ * defined as a flag.
69
77
*/
70
78
private validateEnvironments (
71
79
environments : string [ ]
@@ -117,7 +125,12 @@ export default class MakePreloadFile extends BaseGenerator {
117
125
const relativePath = file . toJSON ( ) . relativepath
118
126
const rcFile = new files . AdonisRcFile ( ADONIS_ACE_CWD ( ) ! )
119
127
120
- rcFile . setPreload ( `./${ slash ( relativePath ) . replace ( extname ( relativePath ) , '' ) } ` , environments )
128
+ if ( environments && environments . length ) {
129
+ rcFile . setPreload ( `./${ slash ( relativePath ) . replace ( extname ( relativePath ) , '' ) } ` , environments )
130
+ } else {
131
+ rcFile . setPreload ( `./${ slash ( relativePath ) . replace ( extname ( relativePath ) , '' ) } ` )
132
+ }
133
+
121
134
rcFile . commit ( )
122
135
}
123
136
}
0 commit comments