@@ -340,7 +340,7 @@ const awaitPools = {
340
340
},
341
341
}
342
342
343
- const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural) => {
343
+ const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural, skipKeys = [] ) => {
344
344
log('Checking for changes');
345
345
const changes = [];
346
346
@@ -352,6 +352,9 @@ const approveChanges = async (resource, resourceGetFunction, keys, resourceName,
352
352
});
353
353
354
354
for (let [key, value] of Object.entries(whitelistKeys(remoteResource, keys))) {
355
+ if (skipKeys.includes(key)) {
356
+ continue;
357
+ }
355
358
if (Array.isArray(value) && Array.isArray(localResource[key])) {
356
359
if (JSON.stringify(value) !== JSON.stringify(localResource[key])) {
357
360
changes.push({
@@ -399,7 +402,7 @@ const getObjectChanges = (remote, local, index, what) => {
399
402
if (remote[index] && local[index]) {
400
403
for (let [service, status] of Object.entries(remote[index])) {
401
404
if (status !== local[index][service]) {
402
- changes.push({ group: what,setting: service, remote: chalk.red(status), local: chalk.green(local[index][service]) })
405
+ changes.push({ group: what, setting: service, remote: chalk.red(status), local: chalk.green(local[index][service]) })
403
406
}
404
407
}
405
408
}
@@ -960,7 +963,7 @@ const pushSettings = async () => {
960
963
}
961
964
}
962
965
963
- const pushFunction = async ({ functionId, async, code } = { returnOnZero: false }) => {
966
+ const pushFunction = async ({ functionId, async, code, withVariables } = { returnOnZero: false }) => {
964
967
const functionIds = [];
965
968
966
969
if (functionId) {
@@ -1009,7 +1012,7 @@ const pushFunction = async ({ functionId, async, code } = { returnOnZero: false
1009
1012
}
1010
1013
}
1011
1014
1012
- if (!(await approveChanges(functions, functionsGet, KeysFunction, 'functionId', 'functions'))) {
1015
+ if (!(await approveChanges(functions, functionsGet, KeysFunction, 'functionId', 'functions', ['vars'] ))) {
1013
1016
return;
1014
1017
}
1015
1018
@@ -1100,6 +1103,39 @@ const pushFunction = async ({ functionId, async, code } = { returnOnZero: false
1100
1103
}
1101
1104
}
1102
1105
1106
+ if (withVariables) {
1107
+ updaterRow.update({ status: 'Updating variables' }).replaceSpinner(SPINNER_ARC);
1108
+
1109
+ const { variables } = await paginate(functionsListVariables, {
1110
+ functionId: func['$id'],
1111
+ parseOutput: false
1112
+ }, 100, 'variables');
1113
+
1114
+ await Promise.all(variables.map(async variable => {
1115
+ await functionsDeleteVariable({
1116
+ functionId: func['$id'],
1117
+ variableId: variable['$id'],
1118
+ parseOutput: false
1119
+ });
1120
+ }));
1121
+
1122
+ let result = await awaitPools.wipeVariables(func['$id']);
1123
+ if (!result) {
1124
+ updaterRow.fail({ errorMessage: `Variable deletion timed out.` })
1125
+ return;
1126
+ }
1127
+
1128
+ // Deploy local variables
1129
+ await Promise.all((func['vars'] ?? []).map(async variable => {
1130
+ await functionsCreateVariable({
1131
+ functionId: func['$id'],
1132
+ key: variable['key'],
1133
+ value: variable['value'],
1134
+ parseOutput: false
1135
+ });
1136
+ }));
1137
+ }
1138
+
1103
1139
if (code === false) {
1104
1140
successfullyPushed++;
1105
1141
successfullyDeployed++;
@@ -1615,6 +1651,7 @@ push
1615
1651
.option(`-f, --function-id <function -id >`, `ID of function to run`)
1616
1652
.option(`-A, --async`, `Don't wait for functions deployments status`)
1617
1653
.option("--no-code", "Don't push the function's code")
1654
+ .option("--with-variables", `Push function variables.`)
1618
1655
.action(actionRunner(pushFunction));
1619
1656
1620
1657
push
0 commit comments