Skip to content

Instantly share code, notes, and snippets.

@wobsoriano
Last active July 31, 2023 14:59
Show Gist options
  • Save wobsoriano/3634d58ead2e1f80c1dc090d3f5dd8e6 to your computer and use it in GitHub Desktop.
Save wobsoriano/3634d58ead2e1f80c1dc090d3f5dd8e6 to your computer and use it in GitHub Desktop.
Firebase deploy only changed functions
const util = require('util');
const exec = util.promisify(require('child_process').exec);
async function deployOnlyChangedFunctions() {
const { stdout: shaOfLostCommit } = await exec('git rev-parse HEAD');
const { stdout: changedFiles } = await exec(`git log -m -1 --name-only --pretty="format:" ${shaOfLostCommit}`);
const functionsFolder = 'functions/modules/'
const filenames = changedFiles.split('\n')
.filter((line) => line.startsWith(functionsFolder))
.map((line) => line.split('/')[2])
.filter((line) => !line.includes('.'))
.map((line) => {
return line
.replace(/\-[a-z]/g, match => match.toUpperCase())
.split('-').join('')
})
const modules = [...new Set(filenames)].join(',')
const deployScript = `firebase deploy --only functions:${modules}`
await exec(deployScript)
}
deployOnlyChangedFunctions();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment