@@ -188,6 +188,36 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
188
188
throw new Error(`Runtime missmatch! (local=${func.runtime},remote=${response.runtime}) Please delete remote function or update your appwrite.json`);
189
189
}
190
190
191
+ if(func.variables) {
192
+ // Delete existing variables
193
+
194
+ // TODO: Pagination?
195
+ const { variables: remoteVariables } = await functionsListVariables({
196
+ functionId: func['$id'],
197
+ queries: [ 'limit(100)' ],
198
+ parseOutput: false
199
+ });
200
+
201
+ if(remoteVariables.length > 0) {
202
+ if(!yes) {
203
+ const variableAnswers = await inquirer.prompt(questionsDeployFunctions[1])
204
+
205
+ if (variableAnswers.override !== "YES") {
206
+ log(`Received "${variableAnswers.override}". Skipping ${func.name} ( ${func['$id']} )`);
207
+ continue;
208
+ }
209
+ }
210
+
211
+ await Promise.all(remoteVariables.map(async remoteVariable => {
212
+ await functionsDeleteVariable({
213
+ functionId: func['$id'],
214
+ variableId: remoteVariable['$id'],
215
+ parseOutput: false
216
+ });
217
+ }));
218
+ }
219
+ }
220
+
191
221
response = await functionsUpdate({
192
222
functionId: func['$id'],
193
223
name: func.name,
@@ -224,36 +254,8 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
224
254
}
225
255
}
226
256
227
- // Create function variables
228
- if(func.variables) {
229
- // Delete existing variables
230
-
231
- // TODO: Pagination?
232
- const { variables: remoteVariables } = await functionsListVariables({
233
- functionId: func['$id'],
234
- queries: [ 'limit(100)' ],
235
- parseOutput: false
236
- });
237
-
238
- if(remoteVariables.length > 0) {
239
- if(!yes) {
240
- const variableAnswers = await inquirer.prompt(questionsDeployFunctions[1])
241
-
242
- if (variableAnswers.override !== "YES") {
243
- log(`Received "${variableAnswers.override}". Skipping ${func.name} ( ${func['$id']} )`);
244
- continue;
245
- }
246
- }
247
-
248
- await Promise.all(remoteVariables.map(async remoteVariable => {
249
- await functionsDeleteVariable({
250
- functionId: func['$id'],
251
- variableId: remoteVariable['$id'],
252
- parseOutput: false
253
- });
254
- }));
255
- }
256
-
257
+ // Create variables
258
+ if (func.variables) {
257
259
// Deploy local variables
258
260
await Promise.all(Object.keys(func.variables).map(async localVariableKey => {
259
261
await functionsCreateVariable({
0 commit comments