Skip to content

Commit f78b368

Browse files
Merge pull request #865 from appwrite/feat-push-pull-all
Feat push pull all
2 parents 705647d + dcea1df commit f78b368

File tree

3 files changed

+486
-417
lines changed

3 files changed

+486
-417
lines changed

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

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,35 @@ const { databasesGet, databasesListCollections, databasesList } = require("./dat
1010
const { storageListBuckets } = require("./storage");
1111
const { localConfig } = require("../config");
1212
const { paginate } = require("../paginate");
13-
const { questionsPullCollection, questionsPullFunctions } = require("../questions");
13+
const { questionsPullCollection, questionsPullFunctions, questionsPullResources } = require("../questions");
1414
const { cliConfig, success, log, actionRunner, commandDescriptions } = require("../parser");
1515

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+
1642
const pullProject = async () => {
1743
try {
1844
let response = await projectsGet({
@@ -47,6 +73,7 @@ const pullFunctions = async () => {
4773
} else {
4874
func['path'] = `functions/${func['$id']}`;
4975
localConfig.addFunction(func);
76+
localFunctions.push(func);
5077
}
5178

5279
const localFunction = localFunctions.find((localFunc) => localFunc['$id'] === func['$id']);
@@ -65,6 +92,10 @@ const pullFunctions = async () => {
6592
parseOutput: false
6693
})
6794

95+
if (!fs.existsSync(localFunction['path'])) {
96+
fs.mkdirSync(localFunction['path'], { recursive: true });
97+
}
98+
6899
tar.extract({
69100
sync: true,
70101
cwd: localFunction['path'],
@@ -82,8 +113,8 @@ const pullCollection = async () => {
82113

83114
if (databases.length === 0) {
84115
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 {
87118
databases = (await inquirer.prompt(questionsPullCollection)).databases;
88119
}
89120
}
@@ -111,21 +142,17 @@ const pullCollection = async () => {
111142
'$updatedAt': undefined
112143
});
113144
});
114-
115-
success();
116145
}
117146

147+
success();
118148
}
119149

120150
const pullBucket = async () => {
121151
const { buckets } = await paginate(storageListBuckets, { parseOutput: false }, 100, 'buckets');
122152

123153
log(`Found ${buckets.length} buckets`);
124154

125-
buckets.forEach(async bucket => {
126-
log(`Fetching ${bucket.name} ...`);
127-
localConfig.addBucket(bucket);
128-
});
155+
buckets.forEach(bucket => localConfig.addBucket(bucket));
129156

130157
success();
131158
}
@@ -135,8 +162,7 @@ const pullTeam = async () => {
135162

136163
log(`Found ${teams.length} teams`);
137164

138-
teams.forEach(async team => {
139-
log(`Fetching ${team.name} ...`);
165+
teams.forEach(team => {
140166
const { total, $updatedAt, $createdAt, prefs, ...rest } = team;
141167
localConfig.addTeam(rest);
142168
});
@@ -149,8 +175,7 @@ const pullMessagingTopic = async () => {
149175

150176
log(`Found ${topics.length} topics`);
151177

152-
topics.forEach(async topic => {
153-
log(`Pulling ${topic.name} ...`);
178+
topics.forEach(topic => {
154179
localConfig.addMessagingTopic(topic);
155180
});
156181

@@ -163,34 +188,40 @@ const pull = new Command("pull")
163188
helpWidth: process.stdout.columns || 80
164189
});
165190

191+
pull
192+
.command("all")
193+
.description("Pull all resource.")
194+
.action(actionRunner(pullResources));
195+
196+
166197
pull
167198
.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")
169200
.action(actionRunner(pullProject));
170201

171202
pull
172203
.command("functions")
173-
.description(`Pulling your {{ spec.title|caseUcfirst }} functions`)
204+
.description(`Pull your {{ spec.title|caseUcfirst }} functions`)
174205
.action(actionRunner(pullFunctions));
175206

176207
pull
177208
.command("collections")
178-
.description("Pulling your {{ spec.title|caseUcfirst }} collections")
209+
.description("Pull your {{ spec.title|caseUcfirst }} collections")
179210
.action(actionRunner(pullCollection))
180211

181212
pull
182213
.command("buckets")
183-
.description("Pulling your {{ spec.title|caseUcfirst }} buckets")
214+
.description("Pull your {{ spec.title|caseUcfirst }} buckets")
184215
.action(actionRunner(pullBucket))
185216

186217
pull
187218
.command("teams")
188-
.description("Pulling your {{ spec.title|caseUcfirst }} teams")
219+
.description("Pull your {{ spec.title|caseUcfirst }} teams")
189220
.action(actionRunner(pullTeam))
190221

191222
pull
192223
.command("topics")
193-
.description("Initialise your Appwrite messaging topics")
224+
.description("Pull your {{ spec.title|caseUcfirst }} messaging topics")
194225
.action(actionRunner(pullMessagingTopic))
195226

196227
module.exports = {

0 commit comments

Comments
 (0)