Skip to content

Commit 6021ec8

Browse files
committed
Add --no-code and question for code pulling
1 parent b9cd545 commit 6021ec8

File tree

2 files changed

+46
-22
lines changed

2 files changed

+46
-22
lines changed

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

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { databasesGet, databasesListCollections, databasesList } = require("./dat
1111
const { storageListBuckets } = require("./storage");
1212
const { localConfig } = require("../config");
1313
const { paginate } = require("../paginate");
14-
const { questionsPullCollection, questionsPullFunctions, questionsPullResources } = require("../questions");
14+
const { questionsPullCollection, questionsPullFunctions, questionsPullFunctionsCode, questionsPullResources } = require("../questions");
1515
const { cliConfig, success, log, warn, actionRunner, commandDescriptions } = require("../parser");
1616

1717
const pullResources = async () => {
@@ -56,7 +56,7 @@ const pullSettings = async () => {
5656
}
5757
}
5858

59-
const pullFunctions = async () => {
59+
const pullFunctions = async ({ code }) => {
6060
log("Fetching functions ...");
6161
let total = 0;
6262

@@ -74,6 +74,8 @@ const pullFunctions = async () => {
7474
? (await paginate(functionsList, { parseOutput: false }, 100, 'functions')).functions
7575
: (await inquirer.prompt(questionsPullFunctions)).functions;
7676

77+
let allowCodePull = cliConfig.force === true ? true : null;
78+
7779
for (let func of functions) {
7880
total++;
7981
log(`Pulling function ${chalk.bold(func['name'])} ...`);
@@ -88,26 +90,38 @@ const pullFunctions = async () => {
8890
if (!fs.existsSync(func['path'])) {
8991
fs.mkdirSync(func['path'], { recursive: true });
9092
}
91-
92-
if(func['deployment']) {
93-
const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz`
94-
await functionsDownloadDeployment({
95-
functionId: func['$id'],
96-
deploymentId: func['deployment'],
97-
destination: compressedFileName,
98-
overrideForCli: true,
99-
parseOutput: false
100-
});
101-
102-
tar.extract({
103-
sync: true,
104-
cwd: func['path'],
105-
file: compressedFileName,
106-
strict: false,
107-
});
108-
109-
fs.rmSync(compressedFileName);
110-
}
93+
94+
if(code === false) {
95+
warn("Source code download skipped.");
96+
} else if(!func['deployment']) {
97+
warn("Source code download skipped because function doesn't have active deployment.");
98+
} else {
99+
if(allowCodePull === null) {
100+
const codeAnswer = await inquirer.prompt(questionsPullFunctionsCode);
101+
allowCodePull = codeAnswer.override;
102+
}
103+
104+
if(allowCodePull) {
105+
log(`Pulling active deployment's code ...`);
106+
107+
const compressedFileName = `${func['$id']}-${+new Date()}.tar.gz`
108+
await functionsDownloadDeployment({
109+
functionId: func['$id'],
110+
deploymentId: func['deployment'],
111+
destination: compressedFileName,
112+
overrideForCli: true,
113+
parseOutput: false
114+
});
115+
116+
tar.extract({
117+
sync: true,
118+
cwd: func['path'],
119+
file: compressedFileName,
120+
strict: false,
121+
});
122+
123+
fs.rmSync(compressedFileName);
124+
}
111125
}
112126

113127
success(`Successfully pulled ${chalk.bold(total)} functions.`);
@@ -261,6 +275,7 @@ pull
261275
.command("function")
262276
.alias("functions")
263277
.description("Pulling your {{ spec.title|caseUcfirst }} cloud function")
278+
.option(`--no-code`, `Don't pull the function's code`)
264279
.action(actionRunner(pullFunctions))
265280

266281
pull

templates/cli/lib/questions.js.twig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ const questionsPullFunctions = [
258258
}
259259
];
260260

261+
const questionsPullFunctionsCode = [
262+
{
263+
type: "confirm",
264+
name: "override",
265+
message: 'Do you want to pull source code of active deployment?'
266+
},
267+
];
268+
261269
const questionsCreateFunction = [
262270
{
263271
type: "input",
@@ -841,6 +849,7 @@ module.exports = {
841849
questionsCreateCollection,
842850
questionsCreateMessagingTopic,
843851
questionsPullFunctions,
852+
questionsPullFunctionsCode,
844853
questionsLogin,
845854
questionsPullResources,
846855
questionsLogout,

0 commit comments

Comments
 (0)