@@ -202,49 +202,6 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
202202 throw new Error(`Runtime missmatch! (local=${func.runtime},remote=${response.runtime}) Please delete remote function or update your appwrite.json`);
203203 }
204204
205- if (func.variables) {
206- // Delete existing variables
207-
208- // TODO: Pagination?
209- const { variables: remoteVariables } = await functionsListVariables({
210- functionId: func['$id'],
211- queries: ['limit(100)'],
212- parseOutput: false
213- });
214-
215- if (remoteVariables.length > 0) {
216- let override = yes;
217- if (!yes) {
218- const variableAnswers = await inquirer.prompt(questionsDeployFunctions[1])
219- override = variableAnswers.override === "YES";
220- }
221-
222- if (!override) {
223- log(`Skipping variables for ${func.name} ( ${func['$id']} )`);
224- } else {
225- log(`Deploying variables for ${func.name} ( ${func['$id']} )`);
226-
227- await Promise.all(remoteVariables.map(async remoteVariable => {
228- await functionsDeleteVariable({
229- functionId: func['$id'],
230- variableId: remoteVariable['$id'],
231- parseOutput: false
232- });
233- }));
234-
235- // Deploy local variables
236- await Promise.all(Object.keys(func.variables).map(async localVariableKey => {
237- await functionsCreateVariable({
238- functionId: func['$id'],
239- key: localVariableKey,
240- value: func.variables[localVariableKey],
241- parseOutput: false
242- });
243- }));
244- }
245- }
246- }
247-
248205 response = await functionsUpdate({
249206 functionId: func['$id'],
250207 name: func.name,
@@ -281,6 +238,49 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
281238 }
282239 }
283240
241+ if (func.variables) {
242+ // Delete existing variables
243+
244+ // TODO: Pagination?
245+ const { variables: remoteVariables } = await functionsListVariables({
246+ functionId: func['$id'],
247+ queries: ['limit(100)'],
248+ parseOutput: false
249+ });
250+
251+ let deployVariables = yes;
252+ if (remoteVariables.length == 0) {
253+ deployVariables = true;
254+ } else if (remoteVariables.length > 0 && !yes) {
255+ const variableAnswers = await inquirer.prompt(questionsDeployFunctions[1])
256+ deployVariables = variableAnswers.override === "YES";
257+ }
258+
259+ if (!deployVariables) {
260+ log(`Skipping variables for ${func.name} ( ${func['$id']} )`);
261+ } else {
262+ log(`Deploying variables for ${func.name} ( ${func['$id']} )`);
263+
264+ await Promise.all(remoteVariables.map(async remoteVariable => {
265+ await functionsDeleteVariable({
266+ functionId: func['$id'],
267+ variableId: remoteVariable['$id'],
268+ parseOutput: false
269+ });
270+ }));
271+
272+ // Deploy local variables
273+ await Promise.all(Object.keys(func.variables).map(async localVariableKey => {
274+ await functionsCreateVariable({
275+ functionId: func['$id'],
276+ key: localVariableKey,
277+ value: func.variables[localVariableKey],
278+ parseOutput: false
279+ });
280+ }));
281+ }
282+ }
283+
284284 // Create tag
285285 if (!func.entrypoint) {
286286 answers = await inquirer.prompt(questionsGetEntrypoint)
0 commit comments