Skip to content

Commit bec7d8b

Browse files
committed
variable creation logic has been updated
1 parent f4278e0 commit bec7d8b

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

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

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,36 @@ 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+
191221
response = await functionsUpdate({
192222
functionId: func['$id'],
193223
name: func.name,
@@ -224,36 +254,8 @@ const deployFunction = async ({ functionId, all, yes } = {}) => {
224254
}
225255
}
226256

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) {
257259
// Deploy local variables
258260
await Promise.all(Object.keys(func.variables).map(async localVariableKey => {
259261
await functionsCreateVariable({

0 commit comments

Comments
 (0)