@featurevisor/core 3.1.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/datasource/datasource.d.ts +1 -1
- package/lib/datasource/datasource.js +4 -14
- package/lib/datasource/datasource.js.map +1 -1
- package/lib/datasource/requiredFeatures.d.ts +7 -0
- package/lib/datasource/requiredFeatures.js +38 -0
- package/lib/datasource/requiredFeatures.js.map +1 -0
- package/lib/linter/checkCircularDependency.d.ts +1 -1
- package/lib/linter/checkCircularDependency.js +3 -22
- package/lib/linter/checkCircularDependency.js.map +1 -1
- package/lib/linter/conditionSchema.js +27 -3
- package/lib/linter/conditionSchema.js.map +1 -1
- package/lib/linter/testSchema.d.ts +4 -0
- package/lib/linter/testSchema.js +46 -4
- package/lib/linter/testSchema.js.map +1 -1
- package/lib/promoter/index.js +62 -1
- package/lib/promoter/index.js.map +1 -1
- package/lib/tester/testFeature.js +17 -16
- package/lib/tester/testFeature.js.map +1 -1
- package/package.json +10 -7
- package/CHANGELOG.md +0 -2246
- package/coverage/clover.xml +0 -5456
- package/coverage/coverage-final.json +0 -64
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -371
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/src/assess-distribution/index.html +0 -116
- package/coverage/lcov-report/src/assess-distribution/index.ts.html +0 -754
- package/coverage/lcov-report/src/benchmark/index.html +0 -116
- package/coverage/lcov-report/src/benchmark/index.ts.html +0 -793
- package/coverage/lcov-report/src/builder/allocator.ts.html +0 -220
- package/coverage/lcov-report/src/builder/applyContextToConditions.ts.html +0 -502
- package/coverage/lcov-report/src/builder/applyContextToDatafile.ts.html +0 -772
- package/coverage/lcov-report/src/builder/applyContextToSegments.ts.html +0 -580
- package/coverage/lcov-report/src/builder/buildDatafile.ts.html +0 -2053
- package/coverage/lcov-report/src/builder/buildProject.ts.html +0 -1117
- package/coverage/lcov-report/src/builder/buildRuntimeDatafiles.ts.html +0 -256
- package/coverage/lcov-report/src/builder/getFeatureRanges.ts.html +0 -268
- package/coverage/lcov-report/src/builder/hashes.ts.html +0 -412
- package/coverage/lcov-report/src/builder/index.html +0 -311
- package/coverage/lcov-report/src/builder/index.ts.html +0 -91
- package/coverage/lcov-report/src/builder/mutateVariables.ts.html +0 -421
- package/coverage/lcov-report/src/builder/mutator.ts.html +0 -796
- package/coverage/lcov-report/src/builder/revision.ts.html +0 -151
- package/coverage/lcov-report/src/builder/traffic.ts.html +0 -661
- package/coverage/lcov-report/src/cli/cli.ts.html +0 -400
- package/coverage/lcov-report/src/cli/index.html +0 -131
- package/coverage/lcov-report/src/cli/plugins.ts.html +0 -214
- package/coverage/lcov-report/src/config/index.html +0 -131
- package/coverage/lcov-report/src/config/index.ts.html +0 -88
- package/coverage/lcov-report/src/config/projectConfig.ts.html +0 -925
- package/coverage/lcov-report/src/datasource/adapter.ts.html +0 -253
- package/coverage/lcov-report/src/datasource/datasource.ts.html +0 -1000
- package/coverage/lcov-report/src/datasource/filesystemAdapter.ts.html +0 -1576
- package/coverage/lcov-report/src/datasource/index.html +0 -161
- package/coverage/lcov-report/src/datasource/index.ts.html +0 -94
- package/coverage/lcov-report/src/evaluate/index.html +0 -116
- package/coverage/lcov-report/src/evaluate/index.ts.html +0 -814
- package/coverage/lcov-report/src/find-duplicate-segments/findDuplicateSegments.ts.html +0 -313
- package/coverage/lcov-report/src/find-duplicate-segments/index.html +0 -131
- package/coverage/lcov-report/src/find-duplicate-segments/index.ts.html +0 -307
- package/coverage/lcov-report/src/find-usage/index.html +0 -116
- package/coverage/lcov-report/src/find-usage/index.ts.html +0 -1780
- package/coverage/lcov-report/src/generate-code/index.html +0 -131
- package/coverage/lcov-report/src/generate-code/index.ts.html +0 -403
- package/coverage/lcov-report/src/generate-code/typescript.ts.html +0 -1909
- package/coverage/lcov-report/src/index.html +0 -131
- package/coverage/lcov-report/src/info/index.html +0 -116
- package/coverage/lcov-report/src/info/index.ts.html +0 -472
- package/coverage/lcov-report/src/init/index.html +0 -116
- package/coverage/lcov-report/src/init/index.ts.html +0 -280
- package/coverage/lcov-report/src/linter/attributeSchema.ts.html +0 -1963
- package/coverage/lcov-report/src/linter/checkCircularDependency.ts.html +0 -220
- package/coverage/lcov-report/src/linter/checkPercentageExceedingSlot.ts.html +0 -268
- package/coverage/lcov-report/src/linter/conditionSchema.ts.html +0 -2224
- package/coverage/lcov-report/src/linter/featureSchema.ts.html +0 -5851
- package/coverage/lcov-report/src/linter/groupSchema.ts.html +0 -226
- package/coverage/lcov-report/src/linter/index.html +0 -326
- package/coverage/lcov-report/src/linter/index.ts.html +0 -88
- package/coverage/lcov-report/src/linter/lintProject.ts.html +0 -2704
- package/coverage/lcov-report/src/linter/mutationNotation.ts.html +0 -1411
- package/coverage/lcov-report/src/linter/printError.ts.html +0 -289
- package/coverage/lcov-report/src/linter/schema.ts.html +0 -1558
- package/coverage/lcov-report/src/linter/segmentSchema.ts.html +0 -139
- package/coverage/lcov-report/src/linter/targetSchema.ts.html +0 -223
- package/coverage/lcov-report/src/linter/testSchema.ts.html +0 -529
- package/coverage/lcov-report/src/linter/zodHelpers.ts.html +0 -133
- package/coverage/lcov-report/src/list/index.html +0 -131
- package/coverage/lcov-report/src/list/index.ts.html +0 -2065
- package/coverage/lcov-report/src/list/matrix.ts.html +0 -721
- package/coverage/lcov-report/src/promoter/index.html +0 -116
- package/coverage/lcov-report/src/promoter/index.ts.html +0 -3883
- package/coverage/lcov-report/src/sets.ts.html +0 -313
- package/coverage/lcov-report/src/targeting.ts.html +0 -403
- package/coverage/lcov-report/src/tester/cliFormat.ts.html +0 -133
- package/coverage/lcov-report/src/tester/helpers.ts.html +0 -313
- package/coverage/lcov-report/src/tester/index.html +0 -206
- package/coverage/lcov-report/src/tester/prettyDuration.ts.html +0 -187
- package/coverage/lcov-report/src/tester/printTestResult.ts.html +0 -337
- package/coverage/lcov-report/src/tester/testFeature.ts.html +0 -1186
- package/coverage/lcov-report/src/tester/testProject.ts.html +0 -1018
- package/coverage/lcov-report/src/tester/testSegment.ts.html +0 -316
- package/coverage/lcov-report/src/utils/extractKeys.ts.html +0 -493
- package/coverage/lcov-report/src/utils/git.ts.html +0 -559
- package/coverage/lcov-report/src/utils/index.html +0 -161
- package/coverage/lcov-report/src/utils/index.ts.html +0 -94
- package/coverage/lcov-report/src/utils/pretty.ts.html +0 -121
- package/coverage/lcov.info +0 -11615
- package/jest.config.js +0 -22
- package/json-schema/README.md +0 -5
- package/json-schema/attribute.json +0 -40
- package/json-schema/feature.json +0 -394
- package/json-schema/segment.json +0 -137
- package/src/assess-distribution/index.ts +0 -223
- package/src/benchmark/index.ts +0 -236
- package/src/builder/allocator.spec.ts +0 -105
- package/src/builder/allocator.ts +0 -45
- package/src/builder/applyContextToConditions.spec.ts +0 -2677
- package/src/builder/applyContextToConditions.ts +0 -139
- package/src/builder/applyContextToDatafile.spec.ts +0 -2626
- package/src/builder/applyContextToDatafile.ts +0 -229
- package/src/builder/applyContextToSegments.spec.ts +0 -1593
- package/src/builder/applyContextToSegments.ts +0 -165
- package/src/builder/buildDatafile.spec.ts +0 -445
- package/src/builder/buildDatafile.ts +0 -656
- package/src/builder/buildProject.ts +0 -344
- package/src/builder/buildRuntimeDatafiles.ts +0 -57
- package/src/builder/getFeatureRanges.ts +0 -61
- package/src/builder/hashes.ts +0 -109
- package/src/builder/index.ts +0 -2
- package/src/builder/mutateVariables.spec.ts +0 -1179
- package/src/builder/mutateVariables.ts +0 -112
- package/src/builder/mutator.spec.ts +0 -413
- package/src/builder/mutator.ts +0 -237
- package/src/builder/revision.spec.ts +0 -22
- package/src/builder/revision.ts +0 -22
- package/src/builder/traffic.spec.ts +0 -946
- package/src/builder/traffic.ts +0 -192
- package/src/cli/cli.ts +0 -105
- package/src/cli/index.ts +0 -2
- package/src/cli/plugins.ts +0 -43
- package/src/config/index.ts +0 -1
- package/src/config/projectConfig.spec.ts +0 -194
- package/src/config/projectConfig.ts +0 -280
- package/src/datasource/adapter.ts +0 -56
- package/src/datasource/datasource.ts +0 -305
- package/src/datasource/filesystemAdapter.spec.ts +0 -212
- package/src/datasource/filesystemAdapter.ts +0 -497
- package/src/datasource/index.ts +0 -3
- package/src/dependencies.ts +0 -13
- package/src/evaluate/index.ts +0 -243
- package/src/find-duplicate-segments/findDuplicateSegments.ts +0 -76
- package/src/find-duplicate-segments/index.ts +0 -74
- package/src/find-usage/index.ts +0 -565
- package/src/generate-code/index.ts +0 -106
- package/src/generate-code/typescript.spec.ts +0 -214
- package/src/generate-code/typescript.ts +0 -608
- package/src/index.ts +0 -20
- package/src/info/index.ts +0 -129
- package/src/init/index.ts +0 -65
- package/src/linter/attributeSchema.spec.ts +0 -342
- package/src/linter/attributeSchema.ts +0 -626
- package/src/linter/checkCircularDependency.ts +0 -45
- package/src/linter/checkPercentageExceedingSlot.ts +0 -61
- package/src/linter/conditionSchema.spec.ts +0 -510
- package/src/linter/conditionSchema.ts +0 -713
- package/src/linter/featureSchema.spec.ts +0 -1985
- package/src/linter/featureSchema.ts +0 -1922
- package/src/linter/groupSchema.ts +0 -47
- package/src/linter/index.ts +0 -1
- package/src/linter/lintProject.spec.ts +0 -336
- package/src/linter/lintProject.ts +0 -873
- package/src/linter/mutationNotation.spec.ts +0 -704
- package/src/linter/mutationNotation.ts +0 -442
- package/src/linter/printError.ts +0 -68
- package/src/linter/schema.spec.ts +0 -690
- package/src/linter/schema.ts +0 -491
- package/src/linter/segmentSchema.spec.ts +0 -358
- package/src/linter/segmentSchema.ts +0 -18
- package/src/linter/targetSchema.spec.ts +0 -159
- package/src/linter/targetSchema.ts +0 -46
- package/src/linter/testSchema.spec.ts +0 -258
- package/src/linter/testSchema.ts +0 -148
- package/src/linter/zodHelpers.ts +0 -16
- package/src/list/index.spec.ts +0 -135
- package/src/list/index.ts +0 -660
- package/src/list/matrix.spec.ts +0 -49
- package/src/list/matrix.ts +0 -212
- package/src/promoter/index.spec.ts +0 -617
- package/src/promoter/index.ts +0 -1266
- package/src/sets.ts +0 -76
- package/src/targeting.spec.ts +0 -74
- package/src/targeting.ts +0 -106
- package/src/tester/cliFormat.ts +0 -16
- package/src/tester/helpers.spec.ts +0 -149
- package/src/tester/helpers.ts +0 -76
- package/src/tester/index.ts +0 -2
- package/src/tester/prettyDuration.ts +0 -34
- package/src/tester/printTestResult.ts +0 -84
- package/src/tester/testFeature.ts +0 -367
- package/src/tester/testProject.spec.ts +0 -50
- package/src/tester/testProject.ts +0 -311
- package/src/tester/testSegment.ts +0 -77
- package/src/utils/extractKeys.ts +0 -136
- package/src/utils/git.ts +0 -158
- package/src/utils/index.ts +0 -3
- package/src/utils/pretty.ts +0 -12
- package/tsconfig.cjs.json +0 -13
- package/tsconfig.typecheck.json +0 -9
package/src/datasource/index.ts
DELETED
package/src/dependencies.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ProjectConfig } from "./config";
|
|
2
|
-
import { Datasource } from "./datasource";
|
|
3
|
-
|
|
4
|
-
export interface Options {
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface Dependencies {
|
|
9
|
-
rootDirectoryPath: string;
|
|
10
|
-
projectConfig: ProjectConfig;
|
|
11
|
-
datasource: Datasource;
|
|
12
|
-
options: Options;
|
|
13
|
-
}
|
package/src/evaluate/index.ts
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import type { Context, DatafileContent } from "@featurevisor/types";
|
|
2
|
-
import { createFeaturevisor } from "@featurevisor/sdk";
|
|
3
|
-
import type { Evaluation, FeaturevisorDiagnostic } from "@featurevisor/sdk";
|
|
4
|
-
|
|
5
|
-
import { Dependencies } from "../dependencies";
|
|
6
|
-
import { buildRuntimeDatafiles } from "../builder/buildRuntimeDatafiles";
|
|
7
|
-
import { Plugin } from "../cli";
|
|
8
|
-
import { assertProjectSetJsonSelection, getProjectSetExecutions, printSetHeader } from "../sets";
|
|
9
|
-
import {
|
|
10
|
-
CLI_COLOR_CYAN,
|
|
11
|
-
CLI_FORMAT_BOLD,
|
|
12
|
-
CLI_FORMAT_GREEN,
|
|
13
|
-
CLI_FORMAT_YELLOW,
|
|
14
|
-
colorize,
|
|
15
|
-
} from "../tester/cliFormat";
|
|
16
|
-
|
|
17
|
-
function printEvaluationDetails(evaluation: Evaluation) {
|
|
18
|
-
const ignoreKeys = ["featureKey", "variableKey", "traffic", "force"];
|
|
19
|
-
|
|
20
|
-
for (const [key, value] of Object.entries(evaluation)) {
|
|
21
|
-
if (ignoreKeys.indexOf(key) !== -1) {
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (key === "variation") {
|
|
26
|
-
console.log(` ${colorize(key, CLI_COLOR_CYAN)}:`, value?.value);
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (key === "variableSchema") {
|
|
31
|
-
console.log(` ${colorize("variableType", CLI_COLOR_CYAN)}:`, value.type);
|
|
32
|
-
console.log(` ${colorize("defaultValue", CLI_COLOR_CYAN)}:`, value.defaultValue);
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
console.log(` ${colorize(key, CLI_COLOR_CYAN)}:`, value);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function printDiagnostics(diagnostics: FeaturevisorDiagnostic[]) {
|
|
41
|
-
diagnostics.forEach((diagnostic) => {
|
|
42
|
-
const levelColor = diagnostic.level === "error" ? 31 : diagnostic.level === "warn" ? 33 : 2;
|
|
43
|
-
console.log(
|
|
44
|
-
`${colorize(`[${diagnostic.level}]`, levelColor)} ${diagnostic.message}`,
|
|
45
|
-
diagnostic,
|
|
46
|
-
);
|
|
47
|
-
console.log("");
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function printHeader(message: string) {
|
|
52
|
-
console.log("");
|
|
53
|
-
console.log(CLI_FORMAT_BOLD, message);
|
|
54
|
-
console.log("");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface EvaluateOptions {
|
|
58
|
-
environment?: string;
|
|
59
|
-
feature: string;
|
|
60
|
-
context: Record<string, unknown>;
|
|
61
|
-
json?: boolean;
|
|
62
|
-
pretty?: boolean;
|
|
63
|
-
verbose?: boolean;
|
|
64
|
-
inflate?: number;
|
|
65
|
-
target?: string | string[];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async function evaluateFeatureWithDatafile(
|
|
69
|
-
datafileContent: DatafileContent,
|
|
70
|
-
options: EvaluateOptions,
|
|
71
|
-
target?: string,
|
|
72
|
-
) {
|
|
73
|
-
let diagnostics: FeaturevisorDiagnostic[] = [];
|
|
74
|
-
const f = createFeaturevisor({
|
|
75
|
-
datafile: datafileContent as DatafileContent,
|
|
76
|
-
logLevel: "debug",
|
|
77
|
-
onDiagnostic: (diagnostic) => diagnostics.push(diagnostic),
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const flagEvaluation = f.evaluateFlag(options.feature, options.context as Context);
|
|
81
|
-
const flagEvaluationDiagnostics = [...diagnostics];
|
|
82
|
-
diagnostics = [];
|
|
83
|
-
|
|
84
|
-
const variationEvaluation = f.evaluateVariation(options.feature, options.context as Context);
|
|
85
|
-
const variationEvaluationDiagnostics = [...diagnostics];
|
|
86
|
-
diagnostics = [];
|
|
87
|
-
|
|
88
|
-
const variableEvaluations: Record<string, Evaluation> = {};
|
|
89
|
-
const variableEvaluationDiagnostics: Record<string, FeaturevisorDiagnostic[]> = {};
|
|
90
|
-
|
|
91
|
-
const feature = f.getFeature(options.feature);
|
|
92
|
-
if (feature?.variablesSchema) {
|
|
93
|
-
const variableKeys = Array.isArray(feature.variablesSchema)
|
|
94
|
-
? feature.variablesSchema
|
|
95
|
-
: Object.keys(feature.variablesSchema);
|
|
96
|
-
|
|
97
|
-
variableKeys.forEach((variableKey) => {
|
|
98
|
-
const variableEvaluation = f.evaluateVariable(
|
|
99
|
-
options.feature,
|
|
100
|
-
variableKey,
|
|
101
|
-
options.context as Context,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
variableEvaluationDiagnostics[variableKey] = [...diagnostics];
|
|
105
|
-
diagnostics = [];
|
|
106
|
-
|
|
107
|
-
variableEvaluations[variableKey] = variableEvaluation;
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const allEvaluations = {
|
|
112
|
-
flag: flagEvaluation,
|
|
113
|
-
variation: variationEvaluation,
|
|
114
|
-
variables: variableEvaluations,
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
if (options.json) {
|
|
118
|
-
return allEvaluations;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
console.log("");
|
|
122
|
-
console.log(CLI_FORMAT_BOLD, "Evaluating Featurevisor feature");
|
|
123
|
-
console.log(` ${colorize("Feature", CLI_COLOR_CYAN)}: ${options.feature}`);
|
|
124
|
-
console.log(` ${colorize("Environment", CLI_COLOR_CYAN)}: ${options.environment || false}`);
|
|
125
|
-
if (target) console.log(` ${colorize("Target", CLI_COLOR_CYAN)}: ${target}`);
|
|
126
|
-
console.log(` ${colorize("Context", CLI_COLOR_CYAN)}: ${JSON.stringify(options.context)}`);
|
|
127
|
-
|
|
128
|
-
// flag
|
|
129
|
-
printHeader("Is enabled?");
|
|
130
|
-
|
|
131
|
-
if (options.verbose) {
|
|
132
|
-
printDiagnostics(flagEvaluationDiagnostics);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
console.log(
|
|
136
|
-
flagEvaluation.enabled ? CLI_FORMAT_GREEN : CLI_FORMAT_YELLOW,
|
|
137
|
-
`Value: ${flagEvaluation.enabled}`,
|
|
138
|
-
);
|
|
139
|
-
console.log("\nDetails:\n");
|
|
140
|
-
|
|
141
|
-
printEvaluationDetails(flagEvaluation);
|
|
142
|
-
|
|
143
|
-
// variation
|
|
144
|
-
printHeader("Variation");
|
|
145
|
-
|
|
146
|
-
if (feature?.variations) {
|
|
147
|
-
if (options.verbose) {
|
|
148
|
-
printDiagnostics(variationEvaluationDiagnostics);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
console.log(CLI_FORMAT_GREEN, `Value: ${JSON.stringify(variationEvaluation.variation?.value)}`);
|
|
152
|
-
console.log("\nDetails:\n");
|
|
153
|
-
|
|
154
|
-
printEvaluationDetails(variationEvaluation);
|
|
155
|
-
} else {
|
|
156
|
-
console.log(CLI_FORMAT_YELLOW, "No variations defined.");
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// variables
|
|
160
|
-
if (feature?.variablesSchema) {
|
|
161
|
-
for (const [key, value] of Object.entries(variableEvaluations)) {
|
|
162
|
-
printHeader(`Variable: ${key}`);
|
|
163
|
-
|
|
164
|
-
if (options.verbose) {
|
|
165
|
-
printDiagnostics(variableEvaluationDiagnostics[key]);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const variableValue =
|
|
169
|
-
typeof value.variableValue !== "undefined"
|
|
170
|
-
? JSON.stringify(value.variableValue)
|
|
171
|
-
: value.variableValue;
|
|
172
|
-
console.log(CLI_FORMAT_GREEN, `Value: ${variableValue}`);
|
|
173
|
-
console.log("\nDetails:\n");
|
|
174
|
-
|
|
175
|
-
printEvaluationDetails(value);
|
|
176
|
-
}
|
|
177
|
-
} else {
|
|
178
|
-
printHeader("Variables");
|
|
179
|
-
|
|
180
|
-
console.log(CLI_FORMAT_YELLOW, "No variables defined.");
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return allEvaluations;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export async function evaluateFeature(deps: Dependencies, options: EvaluateOptions) {
|
|
187
|
-
const datafiles = await buildRuntimeDatafiles(deps, {
|
|
188
|
-
environment: options.environment || false,
|
|
189
|
-
target: options.target,
|
|
190
|
-
revision: "include-all-features",
|
|
191
|
-
inflate: options.inflate,
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
const results = [];
|
|
195
|
-
for (const entry of datafiles) {
|
|
196
|
-
const evaluations = await evaluateFeatureWithDatafile(entry.datafile, options, entry.target);
|
|
197
|
-
results.push({ target: entry.target, evaluations });
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (options.json) {
|
|
201
|
-
const output = results.length === 1 ? results[0].evaluations : results;
|
|
202
|
-
console.log(options.pretty ? JSON.stringify(output, null, 2) : JSON.stringify(output));
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export const evaluatePlugin: Plugin = {
|
|
207
|
-
command: "evaluate",
|
|
208
|
-
handler: async ({ rootDirectoryPath, projectConfig, datasource, parsed }) => {
|
|
209
|
-
assertProjectSetJsonSelection(projectConfig, parsed.set, parsed.json);
|
|
210
|
-
|
|
211
|
-
const executions = await getProjectSetExecutions(projectConfig, datasource, parsed.set);
|
|
212
|
-
|
|
213
|
-
for (const execution of executions) {
|
|
214
|
-
printSetHeader(projectConfig, execution.set, parsed.json);
|
|
215
|
-
|
|
216
|
-
await evaluateFeature(
|
|
217
|
-
{
|
|
218
|
-
rootDirectoryPath,
|
|
219
|
-
projectConfig: execution.projectConfig,
|
|
220
|
-
datasource: execution.datasource,
|
|
221
|
-
options: parsed,
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
environment: parsed.environment,
|
|
225
|
-
feature: parsed.feature,
|
|
226
|
-
context: parsed.context ? JSON.parse(parsed.context) : {},
|
|
227
|
-
// @NOTE: introduce optional --at?
|
|
228
|
-
json: parsed.json,
|
|
229
|
-
pretty: parsed.pretty,
|
|
230
|
-
verbose: parsed.verbose,
|
|
231
|
-
target: parsed.target,
|
|
232
|
-
},
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
examples: [
|
|
237
|
-
{
|
|
238
|
-
command:
|
|
239
|
-
'evaluate --environment=production --feature=my_feature --context=\'{"userId": "123"}\'',
|
|
240
|
-
description: "evaluate a feature against provided context",
|
|
241
|
-
},
|
|
242
|
-
],
|
|
243
|
-
};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import * as crypto from "crypto";
|
|
2
|
-
|
|
3
|
-
import type { HistoryEntry, SegmentKey } from "@featurevisor/types";
|
|
4
|
-
|
|
5
|
-
import { Dependencies } from "../dependencies";
|
|
6
|
-
|
|
7
|
-
export interface DuplicateSegmentsOptions {
|
|
8
|
-
authors?: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface DuplicateSegmentsResult {
|
|
12
|
-
segments: SegmentKey[];
|
|
13
|
-
authors?: string[];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function findDuplicateSegments(
|
|
17
|
-
deps: Dependencies,
|
|
18
|
-
options: DuplicateSegmentsOptions = {},
|
|
19
|
-
): Promise<DuplicateSegmentsResult[]> {
|
|
20
|
-
const { datasource } = deps;
|
|
21
|
-
|
|
22
|
-
const segments = await datasource.listSegments();
|
|
23
|
-
|
|
24
|
-
const segmentsWithHash: { segmentKey: SegmentKey; hash: string }[] = [];
|
|
25
|
-
for (const segmentKey of segments) {
|
|
26
|
-
const segment = await datasource.readSegment(segmentKey);
|
|
27
|
-
const conditions = JSON.stringify(segment.conditions);
|
|
28
|
-
const hash = crypto.createHash("sha256").update(conditions).digest("hex");
|
|
29
|
-
|
|
30
|
-
segmentsWithHash.push({
|
|
31
|
-
segmentKey,
|
|
32
|
-
hash,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const groupedSegments: { [hash: string]: SegmentKey[] } = segmentsWithHash.reduce(
|
|
37
|
-
(acc, { segmentKey, hash }) => {
|
|
38
|
-
if (!acc[hash]) {
|
|
39
|
-
acc[hash] = [];
|
|
40
|
-
}
|
|
41
|
-
acc[hash].push(segmentKey);
|
|
42
|
-
return acc;
|
|
43
|
-
},
|
|
44
|
-
{},
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const duplicateSegments = Object.values(groupedSegments).filter(
|
|
48
|
-
(segmentKeys) => segmentKeys.length > 1,
|
|
49
|
-
);
|
|
50
|
-
const result: DuplicateSegmentsResult[] = [];
|
|
51
|
-
|
|
52
|
-
for (const segmentKeys of duplicateSegments) {
|
|
53
|
-
const entry: DuplicateSegmentsResult = {
|
|
54
|
-
segments: segmentKeys,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
if (options.authors) {
|
|
58
|
-
const historyEntries: HistoryEntry[] = [];
|
|
59
|
-
|
|
60
|
-
for (const segmentKey of segmentKeys) {
|
|
61
|
-
const entries = await datasource.listHistoryEntries("segment", segmentKey);
|
|
62
|
-
|
|
63
|
-
entries.forEach((entry) => {
|
|
64
|
-
historyEntries.push(entry);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const authors = Array.from(new Set(historyEntries.map((entry) => entry.author)));
|
|
69
|
-
entry.authors = authors;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
result.push(entry);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return result;
|
|
76
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { findDuplicateSegments, DuplicateSegmentsOptions } from "./findDuplicateSegments";
|
|
2
|
-
import { Dependencies } from "../dependencies";
|
|
3
|
-
import { Plugin } from "../cli";
|
|
4
|
-
import { getProjectSetExecutions, printSetHeader } from "../sets";
|
|
5
|
-
import {
|
|
6
|
-
CLI_COLOR_CYAN,
|
|
7
|
-
CLI_FORMAT_BOLD,
|
|
8
|
-
CLI_FORMAT_GREEN,
|
|
9
|
-
CLI_FORMAT_YELLOW,
|
|
10
|
-
colorize,
|
|
11
|
-
} from "../tester/cliFormat";
|
|
12
|
-
|
|
13
|
-
export async function findDuplicateSegmentsInProject(
|
|
14
|
-
deps: Dependencies,
|
|
15
|
-
options: DuplicateSegmentsOptions = {},
|
|
16
|
-
) {
|
|
17
|
-
const duplicates = await findDuplicateSegments(deps, options);
|
|
18
|
-
|
|
19
|
-
console.log("");
|
|
20
|
-
console.log(CLI_FORMAT_BOLD, "Finding duplicate Featurevisor segments");
|
|
21
|
-
|
|
22
|
-
if (duplicates.length === 0) {
|
|
23
|
-
console.log(CLI_FORMAT_GREEN, "No duplicate segments found");
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
console.log(CLI_FORMAT_YELLOW, `Found ${duplicates.length} duplicate(s):`);
|
|
28
|
-
console.log("");
|
|
29
|
-
|
|
30
|
-
duplicates.forEach((entry) => {
|
|
31
|
-
if (options.authors) {
|
|
32
|
-
console.log(` ${colorize("•", CLI_COLOR_CYAN)} Segments: ${entry.segments.join(", ")}`);
|
|
33
|
-
console.log(
|
|
34
|
-
` ${colorize("Authors", CLI_COLOR_CYAN)}: ${entry.authors && entry.authors.join(", ")}`,
|
|
35
|
-
);
|
|
36
|
-
console.log("");
|
|
37
|
-
} else {
|
|
38
|
-
console.log(` ${colorize("•", CLI_COLOR_CYAN)} ${entry.segments.join(", ")}`);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const findDuplicateSegmentsPlugin: Plugin = {
|
|
44
|
-
command: "find-duplicate-segments",
|
|
45
|
-
handler: async ({ rootDirectoryPath, projectConfig, datasource, parsed }) => {
|
|
46
|
-
const executions = await getProjectSetExecutions(projectConfig, datasource, parsed.set);
|
|
47
|
-
|
|
48
|
-
for (const execution of executions) {
|
|
49
|
-
printSetHeader(projectConfig, execution.set);
|
|
50
|
-
|
|
51
|
-
await findDuplicateSegmentsInProject(
|
|
52
|
-
{
|
|
53
|
-
rootDirectoryPath,
|
|
54
|
-
projectConfig: execution.projectConfig,
|
|
55
|
-
datasource: execution.datasource,
|
|
56
|
-
options: parsed,
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
authors: parsed.authors,
|
|
60
|
-
},
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
examples: [
|
|
65
|
-
{
|
|
66
|
-
command: "find-duplicate-segments",
|
|
67
|
-
description: "Find duplicate segments in the project",
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
command: "find-duplicate-segments --authors",
|
|
71
|
-
description: "Find duplicate segments in the project and list authors",
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
};
|