@@ -10,9 +10,35 @@ const { databasesGet, databasesListCollections, databasesList } = require("./dat
10
10
const { storageListBuckets } = require("./storage");
11
11
const { localConfig } = require("../config");
12
12
const { paginate } = require("../paginate");
13
- const { questionsPullCollection, questionsPullFunctions } = require("../questions");
13
+ const { questionsPullCollection, questionsPullFunctions, questionsPullResources } = require("../questions");
14
14
const { cliConfig, success, log, actionRunner, commandDescriptions } = require("../parser");
15
15
16
+ const pullResources = async () => {
17
+ const actions = {
18
+ project: pullProject,
19
+ functions: pullFunctions,
20
+ collections: pullCollection,
21
+ buckets: pullBucket,
22
+ teams: pullTeam,
23
+ messages: pullMessagingTopic
24
+ }
25
+
26
+ if (cliConfig.all) {
27
+ for (let action of Object.values(actions)) {
28
+ await action();
29
+ }
30
+ } else {
31
+ const answers = await inquirer.prompt(questionsPullResources[0]);
32
+
33
+ for (let resource of answers.resources) {
34
+ const action = actions[resource];
35
+ if (action !== undefined) {
36
+ await action();
37
+ }
38
+ }
39
+ }
40
+ };
41
+
16
42
const pullProject = async () => {
17
43
try {
18
44
let response = await projectsGet({
@@ -47,6 +73,7 @@ const pullFunctions = async () => {
47
73
} else {
48
74
func['path'] = `functions/${func['$id']}`;
49
75
localConfig.addFunction(func);
76
+ localFunctions.push(func);
50
77
}
51
78
52
79
const localFunction = localFunctions.find((localFunc) => localFunc['$id'] === func['$id']);
@@ -65,6 +92,10 @@ const pullFunctions = async () => {
65
92
parseOutput: false
66
93
})
67
94
95
+ if (!fs.existsSync(localFunction['path'])) {
96
+ fs.mkdirSync(localFunction['path'], { recursive: true });
97
+ }
98
+
68
99
tar.extract({
69
100
sync: true,
70
101
cwd: localFunction['path'],
@@ -82,8 +113,8 @@ const pullCollection = async () => {
82
113
83
114
if (databases.length === 0) {
84
115
if (cliConfig.all) {
85
- databases = (await paginate(databasesList, { parseOutput: false }, 100, 'databases')).databases.map(database=> database.$id);
86
- } else{
116
+ databases = (await paginate(databasesList, { parseOutput: false }, 100, 'databases')).databases.map(database => database.$id);
117
+ } else {
87
118
databases = (await inquirer.prompt(questionsPullCollection)).databases;
88
119
}
89
120
}
@@ -111,21 +142,17 @@ const pullCollection = async () => {
111
142
'$updatedAt': undefined
112
143
});
113
144
});
114
-
115
- success();
116
145
}
117
146
147
+ success();
118
148
}
119
149
120
150
const pullBucket = async () => {
121
151
const { buckets } = await paginate(storageListBuckets, { parseOutput: false }, 100, 'buckets');
122
152
123
153
log(`Found ${buckets.length} buckets`);
124
154
125
- buckets.forEach(async bucket => {
126
- log(`Fetching ${bucket.name} ...`);
127
- localConfig.addBucket(bucket);
128
- });
155
+ buckets.forEach(bucket => localConfig.addBucket(bucket));
129
156
130
157
success();
131
158
}
@@ -135,8 +162,7 @@ const pullTeam = async () => {
135
162
136
163
log(`Found ${teams.length} teams`);
137
164
138
- teams.forEach(async team => {
139
- log(`Fetching ${team.name} ...`);
165
+ teams.forEach(team => {
140
166
const { total, $updatedAt, $createdAt, prefs, ...rest } = team;
141
167
localConfig.addTeam(rest);
142
168
});
@@ -149,8 +175,7 @@ const pullMessagingTopic = async () => {
149
175
150
176
log(`Found ${topics.length} topics`);
151
177
152
- topics.forEach(async topic => {
153
- log(`Pulling ${topic.name} ...`);
178
+ topics.forEach(topic => {
154
179
localConfig.addMessagingTopic(topic);
155
180
});
156
181
@@ -163,34 +188,40 @@ const pull = new Command("pull")
163
188
helpWidth: process.stdout.columns || 80
164
189
});
165
190
191
+ pull
192
+ .command("all")
193
+ .description("Pull all resource.")
194
+ .action(actionRunner(pullResources));
195
+
196
+
166
197
pull
167
198
.command("project")
168
- .description("Pulling your {{ spec .title | caseUcfirst }} project name, services and auth settings")
199
+ .description("Pull your {{ spec .title | caseUcfirst }} project name, services and auth settings")
169
200
.action(actionRunner(pullProject));
170
201
171
202
pull
172
203
.command("functions")
173
- .description(`Pulling your {{ spec .title | caseUcfirst }} functions`)
204
+ .description(`Pull your {{ spec .title | caseUcfirst }} functions`)
174
205
.action(actionRunner(pullFunctions));
175
206
176
207
pull
177
208
.command("collections")
178
- .description("Pulling your {{ spec .title | caseUcfirst }} collections")
209
+ .description("Pull your {{ spec .title | caseUcfirst }} collections")
179
210
.action(actionRunner(pullCollection))
180
211
181
212
pull
182
213
.command("buckets")
183
- .description("Pulling your {{ spec .title | caseUcfirst }} buckets")
214
+ .description("Pull your {{ spec .title | caseUcfirst }} buckets")
184
215
.action(actionRunner(pullBucket))
185
216
186
217
pull
187
218
.command("teams")
188
- .description("Pulling your {{ spec .title | caseUcfirst }} teams")
219
+ .description("Pull your {{ spec .title | caseUcfirst }} teams")
189
220
.action(actionRunner(pullTeam))
190
221
191
222
pull
192
223
.command("topics")
193
- .description("Initialise your Appwrite messaging topics")
224
+ .description("Pull your {{ spec . title | caseUcfirst }} messaging topics")
194
225
.action(actionRunner(pullMessagingTopic))
195
226
196
227
module.exports = {
0 commit comments