-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags.js
103 lines (88 loc) · 2.29 KB
/
flags.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
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
// Copyright 2024 Joseph P Medley
'use strict';
const fs = require('fs');
const { fileURLToPath } = require('url');
const utils = require('./utils.js');
const NO_FLAG = 'No flag found';
let flags;
class _FlagStatus {
constructor(flagPath) {
this._flagPath = flagPath;
this._loadFlags();
}
_loadFlags() {
const flagJSON = utils.getJSON(this._flagPath);
const flagArray = flagJSON.data;
for (let f of flagArray) {
this[f.name] = f;
}
}
getStableAsBoolean(key) {
const flagData = this[key];
if (flagData.status === 'stable') {
return true;
} else {
return false;
}
}
getActualStatus(key) {
if (this[key]) {
if (this[key].status) {
return this[key].status;
}
}
return NO_FLAG;
}
getPlatformStatus(key, platform) {
const actualStatus = this.getActualStatus(key);
if (actualStatus === NO_FLAG) {
return 'stable';
}
if (typeof actualStatus === 'object') {
return actualStatus[platform];
}
}
getHighestResolvedStatus(key) {
const actualStatus = this.getActualStatus(key);
if (actualStatus === NO_FLAG) {
return 'stable';
}
if (typeof actualStatus === 'object') {
// If any part of the interface is stable,
if (Object.values(actualStatus).includes('stable')) {
return 'stable';
};
// If stable isn't found, check if any part is experimental then
if (Object.values(actualStatus).includes('experimental')) {
if (Object.values(actualStatus).includes('origin_trial_feature_name')) {
return 'origintrial'
} else {
return 'experimental';
}
}
if (Object.values(actualStatus).includes('test')) {
return 'test';
}
// If anything is left,
if (Object.values(actualStatus).includes('')) {
return 'stable';
}
} else {
if (this[key]) {
if (this[key].origin_trial_feature_name) {
if (this[key].status === 'experimental') { return 'origintrial'; }
return this[key].status;
}
}
return actualStatus;
}
}
}
function getFlagObject(flagPath) {
if (!flags) {
flags = new _FlagStatus(flagPath);
}
return flags;
}
module.exports.FlagStatus = getFlagObject;
module.exports.NO_FLAG = NO_FLAG;