forked from amplify-education/serverless-domain-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobals.ts
94 lines (80 loc) · 3.09 KB
/
globals.ts
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
import chalk = require("chalk");
import DomainConfig = require("./domain-config");
import {ServerlessInstance, ServerlessOptions} from "./types";
export default class Globals {
public static pluginName = "Serverless Domain Manager";
public static serverless: ServerlessInstance;
public static options: ServerlessOptions;
public static defaultRegion = "us-east-1";
public static endpointTypes = {
edge: "EDGE",
regional: "REGIONAL",
};
public static apiTypes = {
http: "HTTP",
rest: "REST",
websocket: "WEBSOCKET",
};
public static gatewayAPIIdKeys = {
[Globals.apiTypes.rest]: "restApiId",
[Globals.apiTypes.websocket]: "websocketApiId",
};
public static tlsVersions = {
tls_1_0: "TLS_1_0",
tls_1_2: "TLS_1_2",
};
public static cliLog(prefix: string, message: string): void {
Globals.serverless.cli.log(`${prefix} ${message}`, Globals.pluginName);
}
/**
* Logs error message
* @param message: message to be printed
* @param debug: if true then show log only if SLS_DEBUG enabled on else anytime.
* By default debug mode on and a message will be printed for SLS_DEBUG enabled.
* @param domain: domain name
*/
public static logError(message: any, domain?: string, debug?: boolean): void {
if (debug === undefined) {
debug = true;
}
const canLog = debug && process.env.SLS_DEBUG || !debug;
if (canLog) {
const error = chalk.bold.red;
Globals.cliLog(error("Error:"), `${domain ? domain + ": " : ""} ${message}`);
}
}
/**
* Logs info message
* @param message: message to be printed
* @param debug: if true then show log only if SLS_DEBUG enabled on else anytime.
* By default debug mode off and a message printed for each call.
*/
public static logInfo(message: any, debug = false): void {
const canLog = debug && process.env.SLS_DEBUG || !debug;
if (canLog) {
Globals.cliLog(chalk.blue("Info:"), message);
}
}
/**
* Logs warning message
* @param message: message to be printed
* @param debug: if true then show log only if SLS_DEBUG enabled on else anytime.
* By default debug mode off and a message printed for each call.
*/
public static logWarning(message: any, debug = false): void {
const canLog = debug && process.env.SLS_DEBUG || !debug;
if (canLog) {
const warning = chalk.keyword("orange");
Globals.cliLog(warning("WARNING:"), message);
}
}
/**
* Prints out a summary of all domain manager related info
*/
public static printDomainSummary(domain: DomainConfig): void {
Globals.cliLog( chalk.yellow.underline("Summary:"), chalk.yellow("Distribution Domain Name"));
Globals.cliLog("", ` Domain Name: ${domain.givenDomainName}`);
Globals.cliLog("", ` Target Domain: ${domain.domainInfo.domainName}`);
Globals.cliLog("", ` Hosted Zone Id: ${domain.domainInfo.hostedZoneId}`);
}
}