@@ -138,6 +138,37 @@ async function recaptcha(): Promise<void> {
138
138
fs . appendFileSync ( ".env" , `${ key } =${ config [ key ] } \n` ) ;
139
139
}
140
140
}
141
+ async function recaptchaSiteKey ( ) : Promise < void > {
142
+ console . log (
143
+ "\nPlease visit this URL to set up reCAPTCHA:\n\nhttps://www.google.com/recaptcha/admin/create"
144
+ ) ;
145
+ console . log (
146
+ '\nSelect reCAPTCHA v2 and the "I`m not a robot" checkbox option'
147
+ ) ;
148
+ console . log (
149
+ '\nAdd "localhost" in domains and accept the terms, then press submit'
150
+ ) ;
151
+
152
+ const { recaptchaSiteKey } = await inquirer . prompt ( [
153
+ {
154
+ type : "input" ,
155
+ name : "recaptchaSiteKey" ,
156
+ message : "Enter your reCAPTCHA site key:" ,
157
+ validate : async ( input : string ) : Promise < boolean | string > => {
158
+ if ( validateRecaptcha ( input ) ) {
159
+ return true ;
160
+ }
161
+ return "Invalid reCAPTCHA site key. Please try again." ;
162
+ } ,
163
+ } ,
164
+ ] ) ;
165
+ const config = dotenv . parse ( fs . readFileSync ( ".env" ) ) ;
166
+ config . RECAPTCHA_SITE_KEY = recaptchaSiteKey ;
167
+ fs . writeFileSync ( ".env" , "" ) ;
168
+ for ( const key in config ) {
169
+ fs . appendFileSync ( ".env" , `${ key } =${ config [ key ] } \n` ) ;
170
+ }
171
+ }
141
172
142
173
function isValidEmail ( email : string ) : boolean {
143
174
const pattern = / ^ [ a - z A - Z 0 - 9 _ . + - ] + @ [ a - z A - Z 0 - 9 - ] + \. [ a - z A - Z 0 - 9 - .] + $ / ;
@@ -350,6 +381,17 @@ async function main(): Promise<void> {
350
381
await recaptcha ( ) ;
351
382
}
352
383
384
+ const { shouldSetRecaptchaSiteKey } = await inquirer . prompt ( {
385
+ type : "confirm" ,
386
+ name : "shouldSetRecaptchaSiteKey" ,
387
+ message : "Would you like to set up a reCAPTCHA site key?" ,
388
+ default : true ,
389
+ } ) ;
390
+
391
+ if ( shouldSetRecaptchaSiteKey ) {
392
+ await recaptchaSiteKey ( ) ;
393
+ }
394
+
353
395
if ( process . env . MAIL_USERNAME ) {
354
396
console . log (
355
397
`\nMail username already exists with the value ${ process . env . MAIL_USERNAME } `
0 commit comments