-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
40 lines (35 loc) · 1.11 KB
/
functions.js
File metadata and controls
40 lines (35 loc) · 1.11 KB
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
const fs = require("fs");
const yaml = require("yaml");
const renameFunctions = (serviceName, basePath, funcs) => {
const keys = Object.keys(funcs);
const functions = {};
keys.forEach((k) => {
const func = funcs[k];
func.handler = `${basePath}${func.handler}`;
if (func.events) {
func.events = func.events.map((e) => {
if (!e.http || !e.http.authorizer) return e;
e.http.authorizer = `${serviceName}-${e.http.authorizer}`;
return e;
});
}
functions[`${serviceName}-${k}`] = funcs[k];
});
return functions;
};
module.exports = () => {
const services = ["service-a", "service-b", "service-c"];
let functions = {};
services.forEach((serviceName) => {
const basePath = `./packages/${serviceName}/`;
let file = fs.readFileSync(`${basePath}functions.yml`, "utf8");
file = file.replace(/\$\{self\:service\}/g, serviceName);
file = file.replace(/\$\{self\:provider.stage\}/g, "local");
const funcs = yaml.parse(file);
functions = {
...functions,
...renameFunctions(serviceName, basePath, funcs),
};
});
return functions;
};