Skip to content

Commit

Permalink
Adds deploy --force command. Fixes #877
Browse files Browse the repository at this point in the history
  • Loading branch information
mbleigh committed Oct 13, 2018
1 parent 53f091b commit b981922
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 41 deletions.
1 change: 1 addition & 0 deletions commands/deploy.js
Expand Up @@ -42,6 +42,7 @@ module.exports = new Command("deploy")
.description("deploy code and assets to your Firebase project")
.option("-p, --public <path>", "override the Hosting public directory specified in firebase.json")
.option("-m, --message <message>", "an optional message describing this deploy")
.option("-f, --force", "delete Cloud Functions missing from the current working directory")
.option(
"--only <targets>",
'only deploy to specified, comma-separated targets (e.g. "hosting,storage"). For functions, ' +
Expand Down
88 changes: 47 additions & 41 deletions lib/deploy/functions/release.js
Expand Up @@ -298,52 +298,58 @@ module.exports = function(context, options, payload) {
);
}

logger.info(
"\nThe following functions are found in your project but do not exist in your local source code:\n" +
deleteList +
"\n\nIf you are renaming a function or changing its region, it is recommended that you create the new " +
"function first before deleting the old one to prevent event loss. For more info, visit " +
clc.underline("https://firebase.google.com/docs/functions/manage-functions#modify" + "\n")
);
if (!options.force) {
logger.info(
"\nThe following functions are found in your project but do not exist in your local source code:\n" +
deleteList +
"\n\nIf you are renaming a function or changing its region, it is recommended that you create the new " +
"function first before deleting the old one to prevent event loss. For more info, visit " +
clc.underline(
"https://firebase.google.com/docs/functions/manage-functions#modify" + "\n"
)
);
}

return prompt
.once({
type: "confirm",
name: "confirm",
default: false,
message:
"Would you like to proceed with deletion? Selecting no will continue the rest of the deployments.",
})
.then(function(proceed) {
if (!proceed) {
if (deployments.length !== 0) {
utils.logBullet(clc.bold.cyan("functions: ") + "continuing with other deployments.");
}
return;
const next = options.force
? Promise.resolve(true)
: prompt.once({
type: "confirm",
name: "confirm",
default: false,
message:
"Would you like to proceed with deletion? Selecting no will continue the rest of the deployments.",
});

next.then(function(proceed) {
if (!proceed) {
if (deployments.length !== 0) {
utils.logBullet(clc.bold.cyan("functions: ") + "continuing with other deployments.");
}
functionsToDelete.forEach(function(name) {
var functionName = helper.getFunctionName(name);
var region = helper.getRegion(name);
return;
}
functionsToDelete.forEach(function(name) {
var functionName = helper.getFunctionName(name);
var region = helper.getRegion(name);

utils.logBullet(
clc.bold.cyan("functions: ") +
"deleting function " +
clc.bold(helper.getFunctionLabel(name)) +
"..."
);
_startTimer(name, "delete");
deployments.push({
name: name,
retryFunction: function() {
return gcp.cloudfunctions.delete({
projectId: projectId,
region: region,
functionName: functionName,
});
},
});
utils.logBullet(
clc.bold.cyan("functions: ") +
"deleting function " +
clc.bold(helper.getFunctionLabel(name)) +
"..."
);
_startTimer(name, "delete");
deployments.push({
name: name,
retryFunction: function() {
return gcp.cloudfunctions.delete({
projectId: projectId,
region: region,
functionName: functionName,
});
},
});
});
});
})
.then(function() {
return utils.promiseAllSettled(
Expand Down

0 comments on commit b981922

Please sign in to comment.