Skip to content

Commit 5d35801

Browse files
committed
feat(nx-heroku): return and format updated config vars
1 parent 90d1dbf commit 5d35801

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

packages/nx-heroku/src/executors/common/heroku/config-vars.ts

+29-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { fromPairs } from 'lodash';
2+
13
import { HEROKU_ENV_VARIABLES_PREFIX } from '../constants';
24
import { exec, parseTable } from '../utils';
35

@@ -37,6 +39,16 @@ export function serializeConfigVar(
3739
return `${key}=${quote}${value}${quote}`;
3840
}
3941

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+
4052
export function addConfigVars(
4153
variables: Variables,
4254
source: Variables,
@@ -62,13 +74,26 @@ export function addConfigVars(
6274
export async function setConfigVars(options: {
6375
appName: string;
6476
configVars: SerializedConfigVar[];
65-
}): Promise<void> {
77+
}): Promise<Variables> {
6678
const { appName, configVars = [] } = options;
6779
if (configVars.length > 0) {
6880
// outputs variables set to stdout key1: value1 \n key2: value2
6981
// 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);
7195
}
96+
return undefined;
7297
}
7398

7499
/*
@@ -78,7 +103,7 @@ export async function mergeConfigVars(options: {
78103
appName: string;
79104
variables?: Variables;
80105
excludeKeys?: string[];
81-
}): Promise<void> {
106+
}): Promise<Variables> {
82107
const { appName, variables = {}, excludeKeys = [] } = options;
83108
const currentConfigVars = await getConfigVars(options);
84109
let configVars: SerializedConfigVar[] = [];
@@ -95,5 +120,5 @@ export async function mergeConfigVars(options: {
95120
...configVars,
96121
...addConfigVars(variables, currentConfigVars, excludeKeys),
97122
];
98-
await setConfigVars({ appName, configVars });
123+
return setConfigVars({ appName, configVars });
99124
}

0 commit comments

Comments
 (0)