-
Notifications
You must be signed in to change notification settings - Fork 905
/
triggerParser.js
75 lines (69 loc) · 1.86 KB
/
triggerParser.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
// This is an independently executed script that parses triggers
// from a functions package directory.
"use strict";
var extractTriggers = require("./extractTriggers");
var EXIT = function() {
process.exit(0);
};
(function() {
// wrap in function to allow return without exiting process
var packageDir = process.argv[2];
if (!packageDir) {
process.send({ error: "Must supply package directory for functions trigger parsing." }, EXIT);
return;
}
var mod;
var triggers = [];
try {
mod = require(packageDir);
} catch (e) {
if (e.code === "MODULE_NOT_FOUND") {
process.send(
{
error:
"Error parsing triggers: " +
e.message +
'\n\nTry running "npm install" in your functions directory before deploying.',
},
EXIT
);
return;
}
if (/Firebase config variables are not available/.test(e.message)) {
process.send(
{
error:
"Error occurred while parsing your function triggers. " +
'Please ensure you have the latest firebase-functions SDK by running "npm i --save firebase-functions@latest" inside your functions folder.\n\n' +
e.stack,
},
EXIT
);
return;
}
process.send(
{
error: "Error occurred while parsing your function triggers.\n\n" + e.stack,
},
EXIT
);
return;
}
try {
extractTriggers(mod, triggers);
} catch (err) {
if (/Maximum call stack size exceeded/.test(err.message)) {
process.send(
{
error:
"Error occurred while parsing your function triggers. Please ensure that index.js only " +
"exports cloud functions.\n\n",
},
EXIT
);
return;
}
process.send({ error: err.message }, EXIT);
}
process.send({ triggers: triggers }, EXIT);
})();