-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctionsDeploy.js
75 lines (62 loc) · 2.1 KB
/
functionsDeploy.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Firebase Batch Functions Deploy (Alisson Enz)
// This script helps firebase users deploy their functions when they have more than 60 functions and
// it's not allowed to deploy all using `firebase deploy --only functions` due deployment quota.
// This script will get your functions export from index.js and deploy in batches of 30 and wait 30 seconds.
// This script will NOT delete your function when removed from index.js.
// Instructions
// 0. This instructions suppose that you already have firebase-tools installed and is logged to your account;
// 1. Install `shelljs` (npm install -g shelljs);
// 2. Change the path to point to your index.js at line 16;
// 3. run `yarn ./functionsDeploy` to deploy your functions;
const shell = require('shelljs');
const myFunctions = require('./functions/index'); // Change here
if (!shell.which('firebase')) {
shell.echo('Sorry, this script requires firebase');
shell.exit(1);
}
const execShellCommand = cmd => {
return new Promise((resolve, reject) => {
shell.exec(cmd, (error, stdout, stderr) => {
if (error) console.warn(error);
resolve(stdout ? stdout : stderr);
});
});
};
const asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
};
let count = 0;
let batchesCount = 0;
let batches = [];
const LIMIT = 10;
batches[batchesCount] = 'firebase deploy --only';
Object.keys(myFunctions).forEach(f => {
if (count === 0) {
batches[batchesCount] += ` functions:${f}`;
count += 1;
} else if (count < LIMIT) {
batches[batchesCount] += `,functions:${f}`;
count += 1;
} else {
count = 1;
batchesCount += 1;
batches[batchesCount] = `firebase deploy --only functions:${f}`;
}
});
console.log('\nTotal: ', Object.keys(myFunctions).length);
const save = async () => {
try {
await asyncForEach(batches, async b => {
console.log(b);
await execShellCommand(`${b} --force`);
await execShellCommand('sleep 30s');
});
} catch (e) {
console.warn(e);
} finally {
console.log('\nDone!\n');
}
};
save();