@@ -270,23 +270,57 @@ ALL_QUESTIONS.push(
270270)
271271
272272; ( async ( ) => {
273+ log ( '\n' , kleur . bold ( ) . underline ( 'Github' ) , '\n' )
274+ const { githubOrganisation, githubRepository } = await prompts (
275+ githubQuestions . map ( questionToPrompt ) ,
276+ {
277+ onCancel : ( ) => {
278+ process . exit ( 1 )
279+ }
280+ }
281+ )
273282
274- const environment = await selectWithCustom (
275- {
276- message : 'Choose a name and purpose for the environment?' ,
277- choices : [
278- { name : 'Development' , value : 'development' } ,
279- { name : 'Quality assurance (no PII data)' , value : 'qa' } ,
280- {
281- name : 'Staging (hosts PII data, no backups)' ,
282- value : 'staging'
283- } ,
283+ const { githubToken } = await promptAndStoreAnswer (
284+ '' ,
285+ githubTokenQuestion ,
286+ [ ]
287+ )
288+
289+ const octokit = new Octokit ( {
290+ auth : githubToken
291+ } )
292+ log ( kleur . green ( '\nSuccessfully logged in to Github\n' ) )
293+ let existingEnvironments = await getRepositoryEnvironments ( octokit , githubOrganisation , githubRepository ) ;
294+
295+ let defaultChoices = [
296+ { name : 'Development' , value : 'development' } ,
297+ { name : 'Quality assurance (no PII data)' , value : 'qa' } ,
298+ {
299+ name : 'Staging (hosts PII data, no backups)' ,
300+ value : 'staging'
301+ } ,
302+ {
303+ name : 'Production (hosts PII data, requires frequent backups)' ,
304+ value : 'production'
305+ } ,
306+ ]
307+ // Add only environments that are not already present
308+ const choices = [
309+ ...defaultChoices ,
310+ ...existingEnvironments
311+ . filter (
312+ ( env ) => ! defaultChoices . some ( ( choice ) => choice . value === env )
313+ )
314+ . map ( ( env ) => ( {
315+ name : env ,
316+ value : env
317+ } ) )
318+ ] ;
319+ const environment = await selectWithCustom (
284320 {
285- name : 'Production (hosts PII data, requires frequent backups)' ,
286- value : 'production'
287- } ,
288- ]
289- }
321+ message : 'Choose a name and purpose for the environment?' ,
322+ choices : choices
323+ }
290324 )
291325 let environment_type = 'non-production'
292326 if ( [ 'development' , 'qa' ] . includes ( environment ) ) {
@@ -304,6 +338,9 @@ ALL_QUESTIONS.push(
304338 }
305339 )
306340 }
341+ const environment_exists = existingEnvironments
342+ . map ( ( e ) => e . trim ( ) )
343+ . includes ( environment ) ;
307344 if ( ! environment ) {
308345 process . exit ( 1 )
309346 }
@@ -312,29 +349,6 @@ ALL_QUESTIONS.push(
312349 path : `${ process . cwd ( ) } /.env.${ environment } `
313350 } )
314351
315- log ( '\n' , kleur . bold ( ) . underline ( 'Github' ) , '\n' )
316-
317- const { githubOrganisation, githubRepository } = await prompts (
318- githubQuestions . map ( questionToPrompt ) ,
319- {
320- onCancel : ( ) => {
321- process . exit ( 1 )
322- }
323- }
324- )
325-
326- const { githubToken } = await promptAndStoreAnswer (
327- '' ,
328- githubTokenQuestion ,
329- [ ]
330- )
331-
332- const octokit = new Octokit ( {
333- auth : githubToken
334- } )
335-
336- let existingEnvironments = await getRepositoryEnvironments ( octokit , githubOrganisation , githubRepository ) ;
337-
338352 await createEnvironment (
339353 octokit ,
340354 environment ,
@@ -392,8 +406,6 @@ ALL_QUESTIONS.push(
392406 existingEnvironmentSecrets . length ,
393407 'secrets'
394408 )
395- } else {
396- log ( kleur . green ( '\nSuccessfully logged in to Github\n' ) )
397409 }
398410 if ( environment_type === 'production' ) {
399411 log ( '\n' , kleur . yellow ( ) . bold (
@@ -447,17 +459,16 @@ ALL_QUESTIONS.push(
447459 ssl_answers = await askQuestionWithEditor ( staticSSLCertQuestions , existingEnvironmentSecrets )
448460 }
449461
450- log ( '\n' , kleur . bold ( ) . underline ( 'Storage' ) )
462+ log ( '\n' , kleur . bold ( ) . underline ( 'Storage' ) , '\n' )
451463
452- let enableEncryption = true
464+ let enableEncryption = false
453465 const encryption_key_defined = findExistingValue (
454466 'ENCRYPTION_KEY' ,
455467 'SECRET' ,
456468 'ENVIRONMENT' ,
457469 existingValues
458470 )
459-
460- if ( ! encryption_key_defined ) {
471+ if ( ! encryption_key_defined && ! environment_exists ) {
461472 const answers_enable_encryption = await prompts (
462473 [
463474 {
@@ -471,7 +482,7 @@ ALL_QUESTIONS.push(
471482 )
472483 enableEncryption = answers_enable_encryption . enableEncryption
473484 }
474- if ( enableEncryption && ! encryption_key_defined ) {
485+ if ( enableEncryption && ! encryption_key_defined && ! environment_exists ) {
475486 log ( kleur . bold ( ) . green ( '✔' ) , kleur . bold ( ) . yellow ( ' Disk encryption is enabled' ) )
476487 await promptAndStoreAnswer ( environment , diskQuestions , existingValues )
477488 } else {
@@ -481,7 +492,11 @@ ALL_QUESTIONS.push(
481492 'ENVIRONMENT' ,
482493 existingValues
483494 )
484- log ( kleur . bold ( ) . green ( '✔' ) , kleur . bold ( ) . yellow ( 'Variable DISK_SPACE is read-only variable:' ) , DISK_SPACE ?. value )
495+ if ( ! DISK_SPACE ) {
496+ log ( kleur . bold ( ) . green ( '✔' ) , kleur . bold ( ) . grey ( 'All available disk space at /data will be used' ) )
497+ } else {
498+ log ( kleur . bold ( ) . green ( '✔' ) , kleur . bold ( ) . yellow ( 'Variable DISK_SPACE is read-only variable:' ) , DISK_SPACE ?. value )
499+ }
485500 }
486501
487502 // Backup and restore configuration
0 commit comments