@@ -4,8 +4,19 @@ const { Command } = require("commander");
4
4
const { localConfig, globalConfig } = require("../config");
5
5
const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner');
6
6
const { paginate } = require('../paginate');
7
- const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionsConfirmPushCollections, questionsPushMessagingTopics } = require("../questions");
8
- const { cliConfig, actionRunner, success, log, error, commandDescriptions } = require("../parser");
7
+ const {
8
+ questionsPushBuckets,
9
+ questionsPushTeams,
10
+ questionsPushFunctions,
11
+ questionsGetEntrypoint,
12
+ questionsPushCollections,
13
+ questionsPushResources,
14
+ questionsPushMessagingTopics
15
+ } = require("../questions");
16
+ const {
17
+ cliConfig, actionRunner,
18
+ success, log, error, commandDescriptions
19
+ } = require("../parser");
9
20
const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsUpdateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions');
10
21
const {
11
22
databasesGet,
@@ -241,43 +252,29 @@ const pushResources = async () => {
241
252
messages: pushMessagingTopic
242
253
}
243
254
244
- if (cliConfig.all) {
245
- Object.values(actions).forEach(action => action());
246
- } else {
247
- const answers = await inquirer.prompt(questionsPushResources[0]);
255
+ const answers = await inquirer.prompt(questionsPushResources);
248
256
249
- answers.resources.forEach((resource) => {
250
- const action = actions[resource];
251
- if (action !== undefined) {
252
- action();
257
+ for (const resource of answers.resources) {
258
+ const method = resource.value ? resource.value : resource;
259
+ const action = actions[method];
260
+ if (action !== undefined) {
261
+ try {
262
+ await action();
263
+ } catch (e) {
264
+ error(e);
253
265
}
254
- })
266
+ }
255
267
}
256
268
};
257
269
258
- const pushFunction = async ({ functionId, async } = {}) => {
270
+ const pushFunction = async ({ async } = {}) => {
259
271
let response = {};
260
272
261
- const functionIds = [] ;
273
+ const functionIds = (await inquirer.prompt(questionsPushFunctions.slice(0, 2))).functions ;
262
274
263
- if (functionId) {
264
- functionIds.push(functionId);
265
- } else if (cliConfig.all) {
266
- const functions = localConfig.getFunctions();
267
- if (functions.length === 0) {
268
- throw new Error("No functions found in the current directory.");
269
- }
270
- functionIds.push(...functions.map((func, idx) => {
271
- return func.$id;
272
- }));
273
- }
275
+ let functions = functionIds.map((functionId) => {
276
+ const id = functionId.value ? functionId.value : functionId;
274
277
275
- if (functionIds.length < = 0) {
276
- const answers = await inquirer.prompt(questionsPushFunctions[0]);
277
- functionIds.push(...answers.functions);
278
- }
279
-
280
- let functions = functionIds.map((id) => {
281
278
const functions = localConfig.getFunctions();
282
279
const func = functions.find((f) => f.$id === id);
283
280
@@ -651,22 +648,19 @@ const pushCollection = async () => {
651
648
652
649
const collections = [];
653
650
654
- if (cliConfig.all) {
655
- if (localConfig.getCollections().length === 0) {
656
- throw new Error("No collections found in the current directory. Run `{{ language .params .executableName }} pull collection` to fetch all your collections.");
657
- }
658
- collections.push(...localConfig.getCollections());
659
- } else {
660
- const answers = await inquirer.prompt(questionsPushCollections[0])
661
- const configCollections = new Map();
662
- localConfig.getCollections().forEach((c) => {
663
- configCollections.set(`${c['databaseId']}|${c['$id']}`, c);
664
- });
665
- answers.collections.forEach((a) => {
666
- const collection = configCollections.get(a);
667
- collections.push(collection);
668
- })
669
- }
651
+ const answers = await inquirer.prompt(questionsPushCollections.slice(0, 2))
652
+
653
+ const configCollections = new Map();
654
+
655
+ localConfig.getCollections().forEach((c) => {
656
+ configCollections.set(`${c['databaseId']}|${c['$id']}`, c);
657
+ });
658
+
659
+ answers.collections.forEach((c) => {
660
+ const id = c.value ? c.value : c;
661
+ const collection = configCollections.get(id);
662
+ collections.push(collection);
663
+ })
670
664
671
665
for (let collection of collections) {
672
666
log(`Pushing collection ${collection.name} ( ${collection['databaseId']} - ${collection['$id']} )`)
@@ -714,7 +708,7 @@ const pushCollection = async () => {
714
708
log(`Collection ${collection.name} ( ${collection['$id']} ) already exists.`);
715
709
716
710
if (!cliConfig.force) {
717
- const answers = await inquirer.prompt(questionsPushCollections[1 ])
711
+ const answers = await inquirer.prompt(questionsPushCollections[2 ])
718
712
if (answers.override.toLowerCase() !== "yes") {
719
713
log(`Received "${answers.override}". Skipping ${collection.name} ( ${collection['$id']} )`);
720
714
continue;
@@ -870,25 +864,13 @@ const pushCollection = async () => {
870
864
const pushBucket = async () => {
871
865
let response = {};
872
866
873
- let bucketIds = [];
867
+ const bucketIds = (await inquirer.prompt(questionsPushBuckets.slice(0, 2))).buckets;
868
+ const buckets = [];
874
869
const configBuckets = localConfig.getBuckets();
875
870
876
- if (cliConfig.all) {
877
- if (configBuckets.length === 0) {
878
- throw new Error("No buckets found in the current directory. Run `appwrite pull bucket` to fetch all your buckets.");
879
- }
880
- bucketIds.push(...configBuckets.map((b) => b.$id));
881
- }
882
-
883
- if (bucketIds.length === 0) {
884
- const answers = await inquirer.prompt(questionsPushBuckets[0])
885
- bucketIds.push(...answers.buckets);
886
- }
887
-
888
- let buckets = [];
889
-
890
871
for (const bucketId of bucketIds) {
891
- const idBuckets = configBuckets.filter((b) => b.$id === bucketId);
872
+ const id = bucketId.value ? bucketId.value : bucketId;
873
+ const idBuckets = configBuckets.filter((b) => b.$id === id);
892
874
buckets.push(...idBuckets);
893
875
}
894
876
@@ -903,7 +885,7 @@ const pushBucket = async () => {
903
885
log(`Bucket ${bucket.name} ( ${bucket['$id']} ) already exists.`);
904
886
905
887
if (!cliConfig.force) {
906
- const answers = await inquirer.prompt(questionsPushBuckets[1 ])
888
+ const answers = await inquirer.prompt(questionsPushBuckets[2 ])
907
889
if (answers.override.toLowerCase() !== "yes") {
908
890
log(`Received "${answers.override}". Skipping ${bucket.name} ( ${bucket['$id']} )`);
909
891
continue;
@@ -957,25 +939,13 @@ const pushBucket = async () => {
957
939
const pushTeam = async () => {
958
940
let response = {};
959
941
960
- let teamIds = [] ;
942
+ const teamIds = (await inquirer.prompt(questionsPushTeams.slice(0, 2))).teams ;
961
943
const configTeams = localConfig.getTeams();
962
-
963
- if (cliConfig.all) {
964
- if (configTeams.length === 0) {
965
- throw new Error("No teams found in the current directory. Run `appwrite pull team` to fetch all your teams.");
966
- }
967
- teamIds.push(...configTeams.map((t) => t.$id));
968
- }
969
-
970
- if (teamIds.length === 0) {
971
- const answers = await inquirer.prompt(questionsPushTeams[0])
972
- teamIds.push(...answers.teams);
973
- }
974
-
975
- let teams = [];
944
+ const teams = [];
976
945
977
946
for (const teamId of teamIds) {
978
- const idTeams = configTeams.filter((t) => t.$id === teamId);
947
+ const id = teamId.value ? teamId.value : teamId
948
+ const idTeams = configTeams.filter((t) => t.$id === id);
979
949
teams.push(...idTeams);
980
950
}
981
951
@@ -990,7 +960,7 @@ const pushTeam = async () => {
990
960
log(`Team ${team.name} ( ${team['$id']} ) already exists.`);
991
961
992
962
if (!cliConfig.force) {
993
- const answers = await inquirer.prompt(questionsPushTeams[1 ])
963
+ const answers = await inquirer.prompt(questionsPushTeams[2 ])
994
964
if (answers.override.toLowerCase() !== "yes") {
995
965
log(`Received "${answers.override}". Skipping ${team.name} ( ${team['$id']} )`);
996
966
continue;
@@ -1027,31 +997,19 @@ const pushTeam = async () => {
1027
997
const pushMessagingTopic = async () => {
1028
998
let response = {};
1029
999
1030
- let topicsIds = [];
1031
1000
const configTopics = localConfig.getMessagingTopics();
1001
+ const topicsIds = (await inquirer.prompt(questionsPushMessagingTopics.slice(0, 2))).topics;
1032
1002
let overrideExisting = cliConfig.force;
1033
-
1034
- if (cliConfig.all) {
1035
- if (configTopics.length === 0) {
1036
- throw new Error("No topics found in the current directory. Run `appwrite pull topics` to pull all your messaging topics.");
1037
- }
1038
- topicsIds.push(...configTopics.map((b) => b.$id));
1039
- }
1040
-
1041
- if (topicsIds.length === 0) {
1042
- const answers = await inquirer.prompt(questionsPushMessagingTopics[0])
1043
- topicsIds.push(...answers.topics);
1044
- }
1045
-
1046
- let topics = [];
1003
+ const topics = [];
1047
1004
1048
1005
for (const topicId of topicsIds) {
1049
- const idTopic = configTopics.filter((b) => b.$id === topicId);
1006
+ const id = topicId.value ? topicId.value : topicId
1007
+ const idTopic = configTopics.filter((b) => b.$id === id);
1050
1008
topics.push(...idTopic);
1051
1009
}
1052
1010
1053
1011
if (!cliConfig.force) {
1054
- const answers = await inquirer.prompt(questionsPushMessagingTopics[1 ])
1012
+ const answers = await inquirer.prompt(questionsPushMessagingTopics[2 ])
1055
1013
if (answers.override.toLowerCase() === "yes") {
1056
1014
overrideExisting = true;
1057
1015
}
0 commit comments