1
+ import { fromPairs } from 'lodash' ;
2
+
1
3
import { HEROKU_ENV_VARIABLES_PREFIX } from '../constants' ;
2
4
import { exec , parseTable } from '../utils' ;
3
5
@@ -37,6 +39,16 @@ export function serializeConfigVar(
37
39
return `${ key } =${ quote } ${ value } ${ quote } ` ;
38
40
}
39
41
42
+ export function serializeConfigVars (
43
+ variables : Variables ,
44
+ quote : ConfigVarQuote = `'`
45
+ ) : SerializedConfigVar [ ] {
46
+ return Object . entries ( variables ) . reduce ( ( acc , [ key , value ] ) => {
47
+ acc . push ( serializeConfigVar ( key , value , quote ) ) ;
48
+ return acc ;
49
+ } , [ ] ) ;
50
+ }
51
+
40
52
export function addConfigVars (
41
53
variables : Variables ,
42
54
source : Variables ,
@@ -62,13 +74,26 @@ export function addConfigVars(
62
74
export async function setConfigVars ( options : {
63
75
appName : string ;
64
76
configVars : SerializedConfigVar [ ] ;
65
- } ) : Promise < void > {
77
+ } ) : Promise < Variables > {
66
78
const { appName, configVars = [ ] } = options ;
67
79
if ( configVars . length > 0 ) {
68
80
// outputs variables set to stdout key1: value1 \n key2: value2
69
81
// outputs success message to stderr Setting <configVars keys comma separated> and restarting ${appName}...
70
- await exec ( `heroku config:set --app=${ appName } ${ configVars . join ( ' ' ) } ` ) ;
82
+ const { stdout = '' } = await exec (
83
+ `heroku config:set --app=${ appName } ${ configVars . join ( ' ' ) } `
84
+ ) ;
85
+ const updatedConfigVarsMatrix = stdout
86
+ . trim ( )
87
+ . split ( '\n' )
88
+ . map ( ( line ) =>
89
+ line
90
+ . trim ( )
91
+ . split ( ':' )
92
+ . map ( ( el ) => el . trim ( ) )
93
+ ) ;
94
+ return fromPairs ( updatedConfigVarsMatrix ) ;
71
95
}
96
+ return undefined ;
72
97
}
73
98
74
99
/*
@@ -78,7 +103,7 @@ export async function mergeConfigVars(options: {
78
103
appName : string ;
79
104
variables ?: Variables ;
80
105
excludeKeys ?: string [ ] ;
81
- } ) : Promise < void > {
106
+ } ) : Promise < Variables > {
82
107
const { appName, variables = { } , excludeKeys = [ ] } = options ;
83
108
const currentConfigVars = await getConfigVars ( options ) ;
84
109
let configVars : SerializedConfigVar [ ] = [ ] ;
@@ -95,5 +120,5 @@ export async function mergeConfigVars(options: {
95
120
...configVars ,
96
121
...addConfigVars ( variables , currentConfigVars , excludeKeys ) ,
97
122
] ;
98
- await setConfigVars ( { appName, configVars } ) ;
123
+ return setConfigVars ( { appName, configVars } ) ;
99
124
}
0 commit comments