-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode-environment.js
59 lines (53 loc) · 1.63 KB
/
node-environment.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
/**
* This static class exposes the settings of the `NODE_ENV` environmental variable by
* matching the value to the AppKu standardized environments: "development" (default),
* "staging", "review" or production.
*/
class NodeEnvironment {
/**
* Returns the standardized environment name of the current process.
* Can be "development", "staging", "review", or "production".
* @type {String}
*/
static get name() {
if (/^stag|test/i.test(process.env.NODE_ENV)) {
return 'staging';
}
if (/^rev|pre/i.test(process.env.NODE_ENV)) {
return 'review';
}
if (/^prod|live/i.test(process.env.NODE_ENV)) {
return 'production';
}
return 'development';
}
/**
* Returns `true` if within a production environment, `false` if not.
* @type {Boolean}
*/
static get production() {
return /^prod|live/i.test(process.env.NODE_ENV);
}
/**
* Returns `true` if within a review environment, `false` if not.
* @type {Boolean}
*/
static get review() {
return /^rev|pre/i.test(process.env.NODE_ENV);
}
/**
* Returns `true` if within a staging environment, `false` if not.
* @type {Boolean}
*/
static get staging() {
return /^stag|test/i.test(process.env.NODE_ENV);
}
/**
* Returns `true` if within a development environment, `false` if not.
* @type {Boolean}
*/
static get development() {
return !(NodeEnvironment.staging || NodeEnvironment.review || NodeEnvironment.production);
}
}
export default NodeEnvironment;