-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdeploy.js
51 lines (48 loc) · 1.3 KB
/
deploy.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
const { spawn } = require('child_process');
const appConfig = require('./app-config');
const deployParams = [];
const params = [
'beta',
'functions',
'deploy'
];
for (let cloudFunction in appConfig.functions) {
const triggerEvent = appConfig.functions[cloudFunction].trigger.event;
const resourceName = appConfig.functions[cloudFunction].trigger.resource;
if (triggerEvent === 'storage') {
let command = [
...params,
cloudFunction,
'--trigger-resource',
appConfig.buckets[resourceName],
'--trigger-event',
'google.storage.object.finalize'
];
deployParams.push(command);
} else if (triggerEvent === 'http') {
let command = [
...params,
cloudFunction,
'--trigger-http'
];
deployParams.push(command);
}
else {
//stub for other triggers
}
}
function deploy() {
if (deployParams.length < 1) {
return;
}
const deployParam = deployParams.shift();
console.log(`gcloud ${deployParam.join(' ')}`);
spawn('gcloud', deployParam, {
stdio: 'inherit',
shell: true
}).on('close', (code) => {
console.log(`child process exited with code ${code}`);
deploy();
});
}
deploy();