-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrevert-cert.js
33 lines (23 loc) · 1016 Bytes
/
revert-cert.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* This script reverts the last commit in the repository. This is used for undoing
* the inclusion of firebase.cert.json file after deploying to Heroku.
* @IMPORTANT: Any uncommitted work will be lost. Only run this script with
* `npm run deploy` and only when all work is commited.
*/
const child = require('child_process');
const fs = require('fs');
const path = require('path');
// Get last commit ID
child.exec('git rev-parse HEAD~1', { windowsHide: true }, (error, stdout) => {
if ( error ) return console.error(error);
const lastCommitId = stdout.trim();
// Load certificate into memory
const cert = require(path.resolve(__dirname, 'firebase.cert.json'));
// Rollback
child.exec(`git reset --hard ${lastCommitId}`, { windowsHide: true }, (error, stdout) => {
if ( error ) return console.error(error);
console.log('Hard reset done');
// Write the cert file back
fs.writeFileSync(path.resolve(__dirname, 'firebase.cert.json'), cert, { encoding: 'utf-8' });
});
});