@@ -56,7 +56,7 @@ const pullSettings = async () => {
56
56
}
57
57
}
58
58
59
- const pullFunctions = async ({ code }) => {
59
+ const pullFunctions = async ({ code, withVariables }) => {
60
60
log("Fetching functions ...");
61
61
let total = 0;
62
62
@@ -83,27 +83,29 @@ const pullFunctions = async ({ code }) => {
83
83
const localFunction = localConfig.getFunction(func.$id);
84
84
85
85
func['path'] = localFunction['path'];
86
- if(!localFunction['path']) {
86
+ if (!localFunction['path']) {
87
87
func['path'] = `functions/${func.$id}`;
88
88
}
89
-
89
+ if (!withVariables) {
90
+ delete func['vars'];
91
+ }
90
92
localConfig.addFunction(func);
91
93
92
94
if (!fs.existsSync(func['path'])) {
93
95
fs.mkdirSync(func['path'], { recursive: true });
94
96
}
95
97
96
- if(code === false) {
98
+ if (code === false) {
97
99
warn("Source code download skipped.");
98
- } else if(!func['deployment']) {
100
+ } else if (!func['deployment']) {
99
101
warn("Source code download skipped because function doesn't have active deployment.");
100
102
} else {
101
- if(allowCodePull === null) {
103
+ if (allowCodePull === null) {
102
104
const codeAnswer = await inquirer.prompt(questionsPullFunctionsCode);
103
105
allowCodePull = codeAnswer.override;
104
106
}
105
107
106
- if(allowCodePull) {
108
+ if (allowCodePull) {
107
109
log("Pulling active deployment's code ...");
108
110
109
111
const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz`
@@ -123,6 +125,16 @@ const pullFunctions = async ({ code }) => {
123
125
});
124
126
125
127
fs.rmSync(compressedFileName);
128
+
129
+ if (withVariables) {
130
+ const envFileLocation = `${func['path']}/.env`
131
+ try {
132
+ fs.rmSync(envFileLocation);
133
+ } catch {
134
+ }
135
+
136
+ fs.writeFileSync(envFileLocation, func['vars'].map(r => `${r.key}=${r.value}\n`).join(''))
137
+ }
126
138
}
127
139
}
128
140
}
@@ -170,7 +182,7 @@ const pullCollection = async () => {
170
182
parseOutput: false
171
183
}, 100, 'collections');
172
184
173
- for(const collection of collections) {
185
+ for (const collection of collections) {
174
186
localConfig.addCollection({
175
187
...collection,
176
188
'$createdAt': undefined,
@@ -198,7 +210,7 @@ const pullBucket = async () => {
198
210
199
211
const { buckets } = await paginate(storageListBuckets, { parseOutput: false }, 100, 'buckets');
200
212
201
- for(const bucket of buckets) {
213
+ for (const bucket of buckets) {
202
214
total++;
203
215
log(`Pulling bucket ${chalk.bold(bucket['name'])} ...`);
204
216
localConfig.addBucket(bucket);
@@ -223,7 +235,7 @@ const pullTeam = async () => {
223
235
224
236
const { teams } = await paginate(teamsList, { parseOutput: false }, 100, 'teams');
225
237
226
- for(const team of teams) {
238
+ for (const team of teams) {
227
239
total++;
228
240
log(`Pulling team ${chalk.bold(team['name'])} ...`);
229
241
localConfig.addTeam(team);
@@ -248,7 +260,7 @@ const pullMessagingTopic = async () => {
248
260
249
261
const { topics } = await paginate(messagingListTopics, { parseOutput: false }, 100, 'topics');
250
262
251
- for(const topic of topics) {
263
+ for (const topic of topics) {
252
264
total++;
253
265
log(`Pulling topic ${chalk.bold(topic['name'])} ...`);
254
266
localConfig.addMessagingTopic(topic);
279
291
.alias("functions")
280
292
.description("Pulling your {{ spec .title | caseUcfirst }} cloud function")
281
293
.option("--no-code", "Don't pull the function's code")
294
+ .option("--with-variables", `Pull function variables. ${chalk.red('recommend for testing purposes only')}`)
282
295
.action(actionRunner(pullFunctions))
283
296
284
297
pull
0 commit comments