I have unforunately ran firebase deploy --only hosting
without specifying a target and deployed to the wrong site too many times. I was wondering if it would be possible to configure the debug tab in VS Code to run a command to make sure I'm deploying to the correct site.
Overall I have found managing multiple hosting sites in Firebase very frustrating as you have to exactly follow the steps to add ALL the targets.
Has anyone found tricks to make life simpler in this department?
You could achieve this using the Firebase predeploy
and postdeploy
hooks. In your project directory (that contains "public/", "functions/" and the like), edit your firebase.json
to contain an assertion that your target matches what you expect.
{
"functions": {
// ...
},
"hosting": {
// ...
"predeploy": [
"node assertMatch.js \"$GCLOUD_PROJECT\" \"your-desired-project-id\"",
]
}
}
assertMatch.js
is just a simple script that compares the first and second command line arguments and returns a non-zero exit code if they don't match. This could probably be installed as a global script somewhere.
let argv = process.argv.slice(2);
let equal = argv[0] == argv[1];
if (equal) {
console.log('Assertion passed.')
} else {
console.log('Assertion failed. "' + argv[0] + '" does not match "' + argv[1] + '".');
}
process.exit(!equal);