Skip to content

Commit e089e9c

Browse files
committed
feat(cli): Pull all resources
1 parent 9ac316d commit e089e9c

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,34 @@ 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 { success, log, actionRunner, commandDescriptions } = require("../parser");
1515

16+
const pullResources = async ({ all, yes } = {}) => {
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 (all) {
27+
for (let action of Object.values(actions)) {
28+
await action({ all: true, yes });
29+
}
30+
} else {
31+
const answers = await inquirer.prompt(questionsPullResources[0]);
32+
answers.resources.forEach((resource) => {
33+
const action = actions[resource];
34+
if (action !== undefined) {
35+
action({ all: true, yes });
36+
}
37+
})
38+
}
39+
};
40+
1641
const pullProject = async () => {
1742
try {
1843
let response = await projectsGet({
@@ -47,6 +72,7 @@ const pullFunctions = async ({ all } = {}) => {
4772
} else {
4873
func['path'] = `functions/${func['$id']}`;
4974
localConfig.addFunction(func);
75+
localFunctions.push(func);
5076
}
5177

5278
const localFunction = localFunctions.find((localFunc) => localFunc['$id'] === func['$id']);
@@ -65,6 +91,10 @@ const pullFunctions = async ({ all } = {}) => {
6591
parseOutput: false
6692
})
6793

94+
if (!fs.existsSync(localFunction['path'])) {
95+
fs.mkdirSync(localFunction['path'], { recursive: true });
96+
}
97+
6898
tar.extract({
6999
sync: true,
70100
cwd: localFunction['path'],
@@ -169,6 +199,14 @@ const pull = new Command("pull")
169199
helpWidth: process.stdout.columns || 80
170200
});
171201

202+
pull
203+
.command("all")
204+
.description("Push all resource.")
205+
.option(`--all`, `Flag to pull all functions`)
206+
.option(`--yes`, `Flag to confirm all warnings`)
207+
.action(actionRunner(pullResources));
208+
209+
172210
pull
173211
.command("project")
174212
.description("Pulling your {{ spec.title|caseUcfirst }} project name, services and auth settings")

templates/cli/lib/questions.js.twig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,21 @@ const questionsInitProject = [
213213
when: (answer) => answer.start === 'existing'
214214
}
215215
];
216+
const questionsPullResources = [
217+
{
218+
type: "checkbox",
219+
name: "resources",
220+
message: "Which resources would you like to pull?",
221+
choices: [
222+
{ name: 'Project', value: 'project' },
223+
{ name: 'Functions', value: 'functions' },
224+
{ name: 'Collections', value: 'collections' },
225+
{ name: 'Buckets', value: 'buckets' },
226+
{ name: 'Teams', value: 'teams' },
227+
{ name: 'Topics', value: 'messages' }
228+
]
229+
}
230+
]
216231

217232
const questionsPullFunctions = [
218233
{
@@ -648,6 +663,7 @@ module.exports = {
648663
questionsCreateMessagingTopic,
649664
questionsPullFunctions,
650665
questionsLogin,
666+
questionsPullResources,
651667
questionsPullCollection,
652668
questionsPushResources,
653669
questionsPushFunctions,

0 commit comments

Comments
 (0)