Skip to content

Commit f4278e0

Browse files
committed
Fix cli function variables deploy
1 parent ed8d3da commit f4278e0

File tree

1 file changed

+41
-40
lines changed

1 file changed

+41
-40
lines changed

templates/cli/lib/commands/deploy.js.twig

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -188,46 +188,6 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
188188
throw new Error(`Runtime missmatch! (local=${func.runtime},remote=${response.runtime}) Please delete remote function or update your appwrite.json`);
189189
}
190190

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-
// Deploy local variables
221-
await Promise.all(Object.keys(func.variables).map(async localVariableKey => {
222-
await functionsCreateVariable({
223-
functionId: func['$id'],
224-
key: localVariableKey,
225-
value: func.variables[localVariableKey],
226-
parseOutput: false
227-
});
228-
}));
229-
}
230-
231191
response = await functionsUpdate({
232192
functionId: func['$id'],
233193
name: func.name,
@@ -264,6 +224,47 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
264224
}
265225
}
266226

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+
// Deploy local variables
258+
await Promise.all(Object.keys(func.variables).map(async localVariableKey => {
259+
await functionsCreateVariable({
260+
functionId: func['$id'],
261+
key: localVariableKey,
262+
value: func.variables[localVariableKey],
263+
parseOutput: false
264+
});
265+
}));
266+
}
267+
267268
// Create tag
268269
if (!func.entrypoint) {
269270
answers = await inquirer.prompt(questionsGetEntrypoint)

0 commit comments

Comments
 (0)