Skip to content

Commit

Permalink
Adds deploy --force command. Fixes #877 (#949)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbleigh committed Oct 15, 2018
1 parent 53f091b commit 3b03183
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 43 deletions.
4 changes: 4 additions & 0 deletions commands/deploy.js
Expand Up @@ -42,6 +42,10 @@ 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 without confirmation"
)
.option(
"--only <targets>",
'only deploy to specified, comma-separated targets (e.g. "hosting,storage"). For functions, ' +
Expand Down
88 changes: 46 additions & 42 deletions lib/deploy/functions/release.js
Expand Up @@ -280,7 +280,7 @@ module.exports = function(context, options, payload) {
return "\t" + helper.getFunctionLabel(func);
}).join("\n");

if (options.nonInteractive) {
if (options.nonInteractive && !options.force) {
var deleteCommands = _.map(functionsToDelete, function(func) {
return (
"\tfirebase functions:delete " +
Expand All @@ -296,54 +296,58 @@ module.exports = function(context, options, payload) {
"\n\nAborting because deletion cannot proceed in non-interactive mode. To fix, manually delete the functions by running:\n" +
clc.bold(deleteCommands)
);
} else 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"
)
);
}

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")
);
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.",
});

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;
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
2 changes: 1 addition & 1 deletion lib/firebaseApi.js
Expand Up @@ -16,7 +16,7 @@ function _list(nextPageToken, projects) {
origin: api.firebaseApiOrigin,
})
.then(response => {
projects = projects.concat(projects, response.body.results);
projects = projects.concat(response.body.results);
if (response.body.nextPageToken) {
return _list(response.body.nextPageToken, projects);
}
Expand Down

0 comments on commit 3b03183

Please sign in to comment.