-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
106 lines (94 loc) · 3.17 KB
/
index.js
File metadata and controls
106 lines (94 loc) · 3.17 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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"use strict";
const Logger = require("./Logger");
const FQL4DeployCommand = require("./commands/FQL4DeployCommand");
const FQL4RemoveCommand = require("./commands/FQL4RemoveCommand");
const faunaV4Schema = require("./fauna/v4/schema/fauna");
const getV4Client = require("./fauna/v4/client");
const faunaV10Schema = require("./fauna/v10/schema/fauna");
const getV10Client = require("./fauna/v10/client");
const FQL10Commands = require("./commands/FQL10Commands");
const FaunaCommands = require("./commands/FaunaCommands");
class ServerlessFaunaPlugin {
constructor(serverless, options) {
this.serverless = serverless;
this.config = this.serverless.service.initialServerlessConfig;
this.options = options;
this.logger = new Logger(serverless.cli);
this.hooks = {};
this.commands = {
fauna: {
commands: {},
options: {},
},
};
if (options.help) {
// If --help is true, init with noops
const cmd = new FaunaCommands({
deployCommand: async () => {},
removeCommand: async () => {},
});
Object.assign(this.hooks, cmd.hooks);
Object.assign(this.commands.fauna.commands, cmd.command);
} else {
this.config.fauna.version = this.config.fauna.version ?? "4";
if (
this.config.fauna.version === "10" ||
this.config.fauna.version === 10
) {
this.serverless.configSchemaHandler.defineTopLevelProperty(
"fauna",
faunaV10Schema
);
const v10cmd = new FQL10Commands({
faunaClient: getV10Client(this.config.fauna.client),
serverless: this.serverless,
config: this.config.fauna,
options: this.options,
logger: this.logger,
});
const cmd = new FaunaCommands({
config: this.config,
deployCommand: v10cmd,
removeCommand: v10cmd,
});
Object.assign(this.hooks, cmd.hooks);
Object.assign(this.commands.fauna.commands, cmd.command);
} else if (
this.config.fauna.version === "4" ||
this.config.fauna.version === 4
) {
this.serverless.configSchemaHandler.defineTopLevelProperty(
"fauna",
faunaV4Schema
);
const client = getV4Client(this.config.fauna.client);
const v4deploy = new FQL4DeployCommand({
faunaClient: client,
serverless: this.serverless,
config: this.config.fauna,
options: this.options,
logger: this.logger,
});
const v4remove = new FQL4RemoveCommand({
faunaClient: client,
serverless: this.serverless,
config: this.config.fauna,
options: this.options,
logger: this.logger,
});
const cmd = new FaunaCommands({
config: this.config,
deployCommand: v4deploy,
removeCommand: v4remove,
});
Object.assign(this.hooks, cmd.hooks);
Object.assign(this.commands.fauna.commands, cmd.command);
} else {
throw new Error(
`Version must be '4' or '10', but was '${this.config.fauna.version}'`
);
}
}
}
}
module.exports = ServerlessFaunaPlugin;