@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/find-usage/index.ts
DELETED
|
@@ -1,565 +0,0 @@
|
|
|
1
|
-
import type { Condition, FeatureKey, SegmentKey, AttributeKey } from "@featurevisor/types";
|
|
2
|
-
|
|
3
|
-
import { Dependencies } from "../dependencies";
|
|
4
|
-
import { Plugin } from "../cli";
|
|
5
|
-
import {
|
|
6
|
-
extractAttributeKeysFromConditions,
|
|
7
|
-
extractSegmentKeysFromGroupSegments,
|
|
8
|
-
} from "../utils/extractKeys";
|
|
9
|
-
import { getProjectSetExecutions, printSetHeader } from "../sets";
|
|
10
|
-
import {
|
|
11
|
-
CLI_COLOR_CYAN,
|
|
12
|
-
CLI_COLOR_DIM,
|
|
13
|
-
CLI_FORMAT_BOLD,
|
|
14
|
-
CLI_FORMAT_GREEN,
|
|
15
|
-
CLI_FORMAT_YELLOW,
|
|
16
|
-
colorize,
|
|
17
|
-
} from "../tester/cliFormat";
|
|
18
|
-
|
|
19
|
-
export interface UsageInFeatures {
|
|
20
|
-
[featureKey: string]: {
|
|
21
|
-
features: Set<FeatureKey>;
|
|
22
|
-
segments: Set<SegmentKey>;
|
|
23
|
-
attributes: Set<AttributeKey>;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export async function findAllUsageInFeatures(deps: Dependencies): Promise<UsageInFeatures> {
|
|
28
|
-
const { datasource, projectConfig } = deps;
|
|
29
|
-
const usageInFeatures: UsageInFeatures = {};
|
|
30
|
-
|
|
31
|
-
const featureKeys = await datasource.listFeatures();
|
|
32
|
-
|
|
33
|
-
for (const featureKey of featureKeys) {
|
|
34
|
-
const feature = await datasource.readFeature(featureKey);
|
|
35
|
-
usageInFeatures[featureKey] = {
|
|
36
|
-
features: new Set<FeatureKey>(),
|
|
37
|
-
segments: new Set<SegmentKey>(),
|
|
38
|
-
attributes: new Set<AttributeKey>(),
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// required
|
|
42
|
-
if (feature.required) {
|
|
43
|
-
feature.required.forEach((required) => {
|
|
44
|
-
if (typeof required === "string") {
|
|
45
|
-
usageInFeatures[featureKey].features.add(required);
|
|
46
|
-
} else if (typeof required === "object" && required.key) {
|
|
47
|
-
usageInFeatures[featureKey].features.add(required.key);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// bucketBy
|
|
53
|
-
if (feature.bucketBy) {
|
|
54
|
-
if (typeof feature.bucketBy === "string") {
|
|
55
|
-
usageInFeatures[featureKey].attributes.add(feature.bucketBy);
|
|
56
|
-
} else if (Array.isArray(feature.bucketBy)) {
|
|
57
|
-
feature.bucketBy.forEach((b) => usageInFeatures[featureKey].attributes.add(b));
|
|
58
|
-
} else if (typeof feature.bucketBy === "object" && feature.bucketBy.or) {
|
|
59
|
-
feature.bucketBy.or.forEach((b) => usageInFeatures[featureKey].attributes.add(b));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// variable overrides inside variations
|
|
64
|
-
if (feature.variations) {
|
|
65
|
-
feature.variations.forEach((variation) => {
|
|
66
|
-
if (variation.variableOverrides) {
|
|
67
|
-
Object.keys(variation.variableOverrides).forEach((variableKey) => {
|
|
68
|
-
const overrides = variation.variableOverrides?.[variableKey];
|
|
69
|
-
|
|
70
|
-
if (overrides) {
|
|
71
|
-
overrides.forEach((override) => {
|
|
72
|
-
if (override.segments) {
|
|
73
|
-
extractSegmentKeysFromGroupSegments(override.segments).forEach((segmentKey) =>
|
|
74
|
-
usageInFeatures[featureKey].segments.add(segmentKey),
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (override.conditions) {
|
|
79
|
-
extractAttributeKeysFromConditions(override.conditions).forEach((attributeKey) =>
|
|
80
|
-
usageInFeatures[featureKey].attributes.add(attributeKey),
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// with environments
|
|
91
|
-
if (Array.isArray(projectConfig.environments)) {
|
|
92
|
-
projectConfig.environments.forEach((environment) => {
|
|
93
|
-
// force
|
|
94
|
-
if (feature.force && feature.force[environment]) {
|
|
95
|
-
feature.force[environment].forEach((force) => {
|
|
96
|
-
if (force.segments) {
|
|
97
|
-
extractSegmentKeysFromGroupSegments(force.segments).forEach((segmentKey) =>
|
|
98
|
-
usageInFeatures[featureKey].segments.add(segmentKey),
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (force.conditions) {
|
|
103
|
-
extractAttributeKeysFromConditions(force.conditions).forEach((attributeKey) =>
|
|
104
|
-
usageInFeatures[featureKey].attributes.add(attributeKey),
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// rules
|
|
111
|
-
if (feature.rules && feature.rules[environment]) {
|
|
112
|
-
feature.rules[environment].forEach((rule) => {
|
|
113
|
-
extractSegmentKeysFromGroupSegments(rule.segments).forEach((segmentKey) =>
|
|
114
|
-
usageInFeatures[featureKey].segments.add(segmentKey),
|
|
115
|
-
);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// no environments
|
|
122
|
-
if (!Array.isArray(projectConfig.environments)) {
|
|
123
|
-
// force
|
|
124
|
-
if (Array.isArray(feature.force)) {
|
|
125
|
-
feature.force.forEach((force) => {
|
|
126
|
-
if (force.segments) {
|
|
127
|
-
extractSegmentKeysFromGroupSegments(force.segments).forEach((segmentKey) =>
|
|
128
|
-
usageInFeatures[featureKey].segments.add(segmentKey),
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (force.conditions) {
|
|
133
|
-
extractAttributeKeysFromConditions(force.conditions).forEach((attributeKey) =>
|
|
134
|
-
usageInFeatures[featureKey].attributes.add(attributeKey),
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// rules
|
|
141
|
-
if (Array.isArray(feature.rules)) {
|
|
142
|
-
feature.rules.forEach((rule) => {
|
|
143
|
-
extractSegmentKeysFromGroupSegments(rule.segments).forEach((segmentKey) =>
|
|
144
|
-
usageInFeatures[featureKey].segments.add(segmentKey),
|
|
145
|
-
);
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return usageInFeatures;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export interface UsageInSegments {
|
|
155
|
-
[segmentKey: string]: {
|
|
156
|
-
attributes: Set<AttributeKey>;
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export async function findAllUsageInSegments(deps: Dependencies): Promise<UsageInSegments> {
|
|
161
|
-
const { datasource } = deps;
|
|
162
|
-
const usageInSegments: UsageInSegments = {};
|
|
163
|
-
|
|
164
|
-
const segmentKeys = await datasource.listSegments();
|
|
165
|
-
|
|
166
|
-
for (const segmentKey of segmentKeys) {
|
|
167
|
-
const segment = await datasource.readSegment(segmentKey);
|
|
168
|
-
usageInSegments[segmentKey] = {
|
|
169
|
-
attributes: new Set<AttributeKey>(),
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
extractAttributeKeysFromConditions(segment.conditions as Condition | Condition[]).forEach(
|
|
173
|
-
(attributeKey) => {
|
|
174
|
-
usageInSegments[segmentKey].attributes.add(attributeKey);
|
|
175
|
-
},
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return usageInSegments;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export async function findFeatureUsage(
|
|
183
|
-
usageInFeatures: UsageInFeatures,
|
|
184
|
-
searchFeatureKey: FeatureKey,
|
|
185
|
-
): Promise<Set<FeatureKey>> {
|
|
186
|
-
const usedInFeatures = new Set<FeatureKey>();
|
|
187
|
-
|
|
188
|
-
for (const featureKey in usageInFeatures) {
|
|
189
|
-
if (usageInFeatures[featureKey].features.has(searchFeatureKey)) {
|
|
190
|
-
usedInFeatures.add(featureKey);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return usedInFeatures;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export async function findSegmentUsage(
|
|
198
|
-
usageInFeatures: UsageInFeatures,
|
|
199
|
-
segmentKey: SegmentKey,
|
|
200
|
-
): Promise<Set<FeatureKey>> {
|
|
201
|
-
const usedInFeatures = new Set<FeatureKey>();
|
|
202
|
-
|
|
203
|
-
for (const featureKey in usageInFeatures) {
|
|
204
|
-
if (usageInFeatures[featureKey].segments.has(segmentKey)) {
|
|
205
|
-
usedInFeatures.add(featureKey);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return usedInFeatures;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export interface AttributeUsage {
|
|
213
|
-
features: Set<FeatureKey>;
|
|
214
|
-
segments: Set<SegmentKey>;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export async function findAttributeUsage(
|
|
218
|
-
usageInFeatures: UsageInFeatures,
|
|
219
|
-
usageInSegments: UsageInSegments,
|
|
220
|
-
attributeKey: AttributeKey,
|
|
221
|
-
): Promise<AttributeUsage> {
|
|
222
|
-
const usedIn: AttributeUsage = {
|
|
223
|
-
features: new Set<FeatureKey>(),
|
|
224
|
-
segments: new Set<SegmentKey>(),
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
for (const featureKey in usageInFeatures) {
|
|
228
|
-
if (usageInFeatures[featureKey].attributes.has(attributeKey)) {
|
|
229
|
-
usedIn.features.add(featureKey);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
for (const segmentKey in usageInSegments) {
|
|
234
|
-
if (usageInSegments[segmentKey].attributes.has(attributeKey)) {
|
|
235
|
-
usedIn.segments.add(segmentKey);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return usedIn;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export async function findUnusedSegments(
|
|
243
|
-
deps: Dependencies,
|
|
244
|
-
usageInFeatures: UsageInFeatures,
|
|
245
|
-
): Promise<Set<SegmentKey>> {
|
|
246
|
-
const { datasource } = deps;
|
|
247
|
-
const unusedSegments = new Set<SegmentKey>();
|
|
248
|
-
|
|
249
|
-
const allSegmentKeys = await datasource.listSegments();
|
|
250
|
-
const usedSegmentKeys = new Set<SegmentKey>();
|
|
251
|
-
|
|
252
|
-
for (const featureKey in usageInFeatures) {
|
|
253
|
-
usageInFeatures[featureKey].segments.forEach((segmentKey) => {
|
|
254
|
-
usedSegmentKeys.add(segmentKey);
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
allSegmentKeys.forEach((segmentKey) => {
|
|
259
|
-
if (!usedSegmentKeys.has(segmentKey)) {
|
|
260
|
-
unusedSegments.add(segmentKey);
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
return unusedSegments;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
export async function findUnusedAttributes(
|
|
268
|
-
deps: Dependencies,
|
|
269
|
-
usageInFeatures: UsageInFeatures,
|
|
270
|
-
usageInSegments: UsageInSegments,
|
|
271
|
-
): Promise<Set<AttributeKey>> {
|
|
272
|
-
const { datasource } = deps;
|
|
273
|
-
const unusedAttributes = new Set<AttributeKey>();
|
|
274
|
-
|
|
275
|
-
const allAttributeKeys = await datasource.listAttributes();
|
|
276
|
-
const usedAttributeKeys = new Set<AttributeKey>();
|
|
277
|
-
|
|
278
|
-
for (const featureKey in usageInFeatures) {
|
|
279
|
-
usageInFeatures[featureKey].attributes.forEach((attributeKey) => {
|
|
280
|
-
usedAttributeKeys.add(attributeKey);
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
for (const segmentKey in usageInSegments) {
|
|
285
|
-
usageInSegments[segmentKey].attributes.forEach((attributeKey) => {
|
|
286
|
-
usedAttributeKeys.add(attributeKey);
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
allAttributeKeys.forEach((attributeKey) => {
|
|
291
|
-
if (!usedAttributeKeys.has(attributeKey)) {
|
|
292
|
-
unusedAttributes.add(attributeKey);
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
return unusedAttributes;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export interface FindUsageOptions {
|
|
300
|
-
feature?: string;
|
|
301
|
-
segment?: string;
|
|
302
|
-
attribute?: string;
|
|
303
|
-
|
|
304
|
-
unusedSegments?: boolean;
|
|
305
|
-
unusedAttributes?: boolean;
|
|
306
|
-
|
|
307
|
-
authors?: boolean;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
export async function findUsageInProject(deps: Dependencies, options: FindUsageOptions) {
|
|
311
|
-
const { datasource } = deps;
|
|
312
|
-
|
|
313
|
-
console.log("");
|
|
314
|
-
console.log(CLI_FORMAT_BOLD, "Finding Featurevisor usage");
|
|
315
|
-
console.log("");
|
|
316
|
-
|
|
317
|
-
const usageInFeatures = await findAllUsageInFeatures(deps);
|
|
318
|
-
const usageInSegments = await findAllUsageInSegments(deps);
|
|
319
|
-
|
|
320
|
-
// feature
|
|
321
|
-
if (options.feature) {
|
|
322
|
-
const usedInFeatures = await findFeatureUsage(usageInFeatures, options.feature);
|
|
323
|
-
|
|
324
|
-
if (usedInFeatures.size === 0) {
|
|
325
|
-
console.log(CLI_FORMAT_GREEN, `Feature "${options.feature}" is not used in any features.`);
|
|
326
|
-
} else {
|
|
327
|
-
console.log(CLI_FORMAT_BOLD, `Feature "${options.feature}" is used in these features`);
|
|
328
|
-
console.log("");
|
|
329
|
-
|
|
330
|
-
for (const featureKey of Array.from(usedInFeatures)) {
|
|
331
|
-
if (options.authors) {
|
|
332
|
-
const entries = await datasource.listHistoryEntries("feature", featureKey);
|
|
333
|
-
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
334
|
-
|
|
335
|
-
console.log(
|
|
336
|
-
` ${colorize("•", CLI_COLOR_CYAN)} ${featureKey} ${colorize(`(Authors: ${authors.join(", ")})`, CLI_COLOR_DIM)}`,
|
|
337
|
-
);
|
|
338
|
-
} else {
|
|
339
|
-
console.log(` ${colorize("•", CLI_COLOR_CYAN)} ${featureKey}`);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// segment
|
|
348
|
-
if (options.segment) {
|
|
349
|
-
const usedInFeatures = await findSegmentUsage(usageInFeatures, options.segment);
|
|
350
|
-
|
|
351
|
-
if (usedInFeatures.size === 0) {
|
|
352
|
-
console.log(CLI_FORMAT_GREEN, `Segment "${options.segment}" is not used in any features.`);
|
|
353
|
-
} else {
|
|
354
|
-
console.log(CLI_FORMAT_BOLD, `Segment "${options.segment}" is used in these features`);
|
|
355
|
-
console.log("");
|
|
356
|
-
|
|
357
|
-
for (const featureKey of Array.from(usedInFeatures)) {
|
|
358
|
-
if (options.authors) {
|
|
359
|
-
const entries = await datasource.listHistoryEntries("feature", featureKey);
|
|
360
|
-
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
361
|
-
|
|
362
|
-
console.log(
|
|
363
|
-
` ${colorize("•", CLI_COLOR_CYAN)} ${featureKey} ${colorize(`(Authors: ${authors.join(", ")})`, CLI_COLOR_DIM)}`,
|
|
364
|
-
);
|
|
365
|
-
} else {
|
|
366
|
-
console.log(` ${colorize("•", CLI_COLOR_CYAN)} ${featureKey}`);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// attribute
|
|
375
|
-
if (options.attribute) {
|
|
376
|
-
const usedIn = await findAttributeUsage(usageInFeatures, usageInSegments, options.attribute);
|
|
377
|
-
|
|
378
|
-
if (usedIn.features.size === 0 && usedIn.segments.size === 0) {
|
|
379
|
-
console.log(
|
|
380
|
-
CLI_FORMAT_GREEN,
|
|
381
|
-
`Attribute "${options.attribute}" is not used in any features or segments.`,
|
|
382
|
-
);
|
|
383
|
-
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
if (usedIn.segments.size > 0) {
|
|
388
|
-
console.log(CLI_FORMAT_BOLD, `Attribute "${options.attribute}" is used in these segments`);
|
|
389
|
-
console.log("");
|
|
390
|
-
|
|
391
|
-
for (const segmentKey of Array.from(usedIn.segments)) {
|
|
392
|
-
if (options.authors) {
|
|
393
|
-
const entries = await datasource.listHistoryEntries("segment", segmentKey);
|
|
394
|
-
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
395
|
-
|
|
396
|
-
console.log(
|
|
397
|
-
` ${colorize("•", CLI_COLOR_CYAN)} ${segmentKey} ${colorize(`(Authors: ${authors.join(", ")})`, CLI_COLOR_DIM)}`,
|
|
398
|
-
);
|
|
399
|
-
} else {
|
|
400
|
-
console.log(` ${colorize("•", CLI_COLOR_CYAN)} ${segmentKey}`);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
// features affected by above segments
|
|
405
|
-
const affectedFeatures = new Set<FeatureKey>();
|
|
406
|
-
|
|
407
|
-
for (const segmentKey of Array.from(usedIn.segments)) {
|
|
408
|
-
const featureKeys = await findSegmentUsage(usageInFeatures, segmentKey);
|
|
409
|
-
featureKeys.forEach((featureKey) => affectedFeatures.add(featureKey));
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
if (affectedFeatures.size > 0) {
|
|
413
|
-
console.log("");
|
|
414
|
-
console.log(CLI_FORMAT_BOLD, "Segments above are used in these features");
|
|
415
|
-
console.log("");
|
|
416
|
-
|
|
417
|
-
for (const featureKey of Array.from(affectedFeatures)) {
|
|
418
|
-
if (options.authors) {
|
|
419
|
-
const entries = await datasource.listHistoryEntries("feature", featureKey);
|
|
420
|
-
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
421
|
-
|
|
422
|
-
console.log(
|
|
423
|
-
` ${colorize("•", CLI_COLOR_CYAN)} ${featureKey} ${colorize(`(Authors: ${authors.join(", ")})`, CLI_COLOR_DIM)}`,
|
|
424
|
-
);
|
|
425
|
-
} else {
|
|
426
|
-
console.log(` ${colorize("•", CLI_COLOR_CYAN)} ${featureKey}`);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
console.log("");
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
if (usedIn.features.size > 0) {
|
|
435
|
-
console.log(
|
|
436
|
-
CLI_FORMAT_BOLD,
|
|
437
|
-
`Attribute "${options.attribute}" is used directly in these features`,
|
|
438
|
-
);
|
|
439
|
-
console.log("");
|
|
440
|
-
|
|
441
|
-
for (const featureKey of Array.from(usedIn.features)) {
|
|
442
|
-
if (options.authors) {
|
|
443
|
-
const entries = await datasource.listHistoryEntries("feature", featureKey);
|
|
444
|
-
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
445
|
-
|
|
446
|
-
console.log(
|
|
447
|
-
` ${colorize("•", CLI_COLOR_CYAN)} ${featureKey} ${colorize(`(Authors: ${authors.join(", ")})`, CLI_COLOR_DIM)}`,
|
|
448
|
-
);
|
|
449
|
-
} else {
|
|
450
|
-
console.log(` ${colorize("•", CLI_COLOR_CYAN)} ${featureKey}`);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
console.log("");
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
// unused segments
|
|
461
|
-
if (options.unusedSegments) {
|
|
462
|
-
const unusedSegments = await findUnusedSegments(deps, usageInFeatures);
|
|
463
|
-
|
|
464
|
-
if (unusedSegments.size === 0) {
|
|
465
|
-
console.log(CLI_FORMAT_GREEN, "No unused segments found.");
|
|
466
|
-
} else {
|
|
467
|
-
console.log(CLI_FORMAT_YELLOW, "Unused segments");
|
|
468
|
-
console.log("");
|
|
469
|
-
|
|
470
|
-
for (const segmentKey of Array.from(unusedSegments)) {
|
|
471
|
-
if (options.authors) {
|
|
472
|
-
const entries = await datasource.listHistoryEntries("segment", segmentKey);
|
|
473
|
-
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
474
|
-
|
|
475
|
-
console.log(
|
|
476
|
-
` ${colorize("•", CLI_COLOR_CYAN)} ${segmentKey} ${colorize(`(Authors: ${authors.join(", ")})`, CLI_COLOR_DIM)}`,
|
|
477
|
-
);
|
|
478
|
-
} else {
|
|
479
|
-
console.log(` ${colorize("•", CLI_COLOR_CYAN)} ${segmentKey}`);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
// unused attributes
|
|
488
|
-
if (options.unusedAttributes) {
|
|
489
|
-
const unusedAttributes = await findUnusedAttributes(deps, usageInFeatures, usageInSegments);
|
|
490
|
-
|
|
491
|
-
if (unusedAttributes.size === 0) {
|
|
492
|
-
console.log(CLI_FORMAT_GREEN, "No unused attributes found.");
|
|
493
|
-
} else {
|
|
494
|
-
console.log(CLI_FORMAT_YELLOW, "Unused attributes");
|
|
495
|
-
console.log("");
|
|
496
|
-
|
|
497
|
-
for (const attributeKey of Array.from(unusedAttributes)) {
|
|
498
|
-
if (options.authors) {
|
|
499
|
-
const entries = await datasource.listHistoryEntries("attribute", attributeKey);
|
|
500
|
-
const authors = Array.from(new Set(entries.map((entry) => entry.author)));
|
|
501
|
-
|
|
502
|
-
console.log(
|
|
503
|
-
` ${colorize("•", CLI_COLOR_CYAN)} ${attributeKey} ${colorize(`(Authors: ${authors.join(", ")})`, CLI_COLOR_DIM)}`,
|
|
504
|
-
);
|
|
505
|
-
} else {
|
|
506
|
-
console.log(` ${colorize("•", CLI_COLOR_CYAN)} ${attributeKey}`);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
console.log(CLI_FORMAT_YELLOW, "Please specify a feature, segment, attribute, or unused query.");
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
export const findUsagePlugin: Plugin = {
|
|
518
|
-
command: "find-usage",
|
|
519
|
-
handler: async ({ rootDirectoryPath, projectConfig, datasource, parsed }) => {
|
|
520
|
-
const executions = await getProjectSetExecutions(projectConfig, datasource, parsed.set);
|
|
521
|
-
|
|
522
|
-
for (const execution of executions) {
|
|
523
|
-
printSetHeader(projectConfig, execution.set);
|
|
524
|
-
|
|
525
|
-
await findUsageInProject(
|
|
526
|
-
{
|
|
527
|
-
rootDirectoryPath,
|
|
528
|
-
projectConfig: execution.projectConfig,
|
|
529
|
-
datasource: execution.datasource,
|
|
530
|
-
options: parsed,
|
|
531
|
-
},
|
|
532
|
-
{
|
|
533
|
-
feature: parsed.feature,
|
|
534
|
-
segment: parsed.segment,
|
|
535
|
-
attribute: parsed.attribute,
|
|
536
|
-
unusedSegments: parsed.unusedSegments,
|
|
537
|
-
unusedAttributes: parsed.unusedAttributes,
|
|
538
|
-
authors: parsed.authors,
|
|
539
|
-
},
|
|
540
|
-
);
|
|
541
|
-
}
|
|
542
|
-
},
|
|
543
|
-
examples: [
|
|
544
|
-
{
|
|
545
|
-
command: "find-usage --segment=<segmentKey>",
|
|
546
|
-
description: "Find usage of a segment",
|
|
547
|
-
},
|
|
548
|
-
{
|
|
549
|
-
command: "find-usage --attribute=<attributeKey>",
|
|
550
|
-
description: "Find usage of an attribute",
|
|
551
|
-
},
|
|
552
|
-
{
|
|
553
|
-
command: "find-usage --unused-segments",
|
|
554
|
-
description: "Find unused segments",
|
|
555
|
-
},
|
|
556
|
-
{
|
|
557
|
-
command: "find-usage --unused-attributes",
|
|
558
|
-
description: "Find unused attributes",
|
|
559
|
-
},
|
|
560
|
-
{
|
|
561
|
-
command: "find-usage --authors",
|
|
562
|
-
description: "List authors of the usage",
|
|
563
|
-
},
|
|
564
|
-
],
|
|
565
|
-
};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
|
|
4
|
-
import { generateTypeScriptCodeForProject } from "./typescript";
|
|
5
|
-
import { Dependencies } from "../dependencies";
|
|
6
|
-
import { Plugin } from "../cli";
|
|
7
|
-
import { getProjectSetExecutions, printSetHeader } from "../sets";
|
|
8
|
-
import { CLI_COLOR_CYAN, CLI_FORMAT_BOLD, colorize } from "../tester/cliFormat";
|
|
9
|
-
|
|
10
|
-
export const ALLOWED_LANGUAGES_FOR_CODE_GENERATION = ["typescript"];
|
|
11
|
-
|
|
12
|
-
export interface GenerateCodeCLIOptions {
|
|
13
|
-
language: string;
|
|
14
|
-
outDir: string;
|
|
15
|
-
tag?: string | string[];
|
|
16
|
-
target?: string | string[];
|
|
17
|
-
react?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export async function generateCodeForProject(
|
|
21
|
-
deps: Dependencies,
|
|
22
|
-
cliOptions: GenerateCodeCLIOptions,
|
|
23
|
-
) {
|
|
24
|
-
const { rootDirectoryPath } = deps;
|
|
25
|
-
|
|
26
|
-
if (!cliOptions.language) {
|
|
27
|
-
throw new Error("Option `--language` is required");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!cliOptions.outDir) {
|
|
31
|
-
throw new Error("Option `--out-dir` is required");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const absolutePath = path.resolve(rootDirectoryPath, cliOptions.outDir);
|
|
35
|
-
|
|
36
|
-
if (!fs.existsSync(absolutePath)) {
|
|
37
|
-
console.log(`Creating output directory: ${colorize(absolutePath, CLI_COLOR_CYAN)}`);
|
|
38
|
-
fs.mkdirSync(absolutePath, { recursive: true });
|
|
39
|
-
} else {
|
|
40
|
-
console.log(`Output directory already exists at: ${colorize(absolutePath, CLI_COLOR_CYAN)}`);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!ALLOWED_LANGUAGES_FOR_CODE_GENERATION.includes(cliOptions.language)) {
|
|
44
|
-
console.log(CLI_FORMAT_BOLD, "Unsupported language");
|
|
45
|
-
console.log(
|
|
46
|
-
`Only these languages are supported: ${ALLOWED_LANGUAGES_FOR_CODE_GENERATION.join(", ")}`,
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
throw new Error(`Language ${cliOptions.language} is not supported for code generation`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (cliOptions.language === "typescript") {
|
|
53
|
-
return await generateTypeScriptCodeForProject(deps, absolutePath, {
|
|
54
|
-
tag: cliOptions.tag,
|
|
55
|
-
target: cliOptions.target,
|
|
56
|
-
react: cliOptions.react,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
throw new Error(`Language ${cliOptions.language} is not supported`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export const generateCodePlugin: Plugin = {
|
|
64
|
-
command: "generate-code",
|
|
65
|
-
handler: async function ({ rootDirectoryPath, projectConfig, datasource, parsed }) {
|
|
66
|
-
if (projectConfig.sets && !parsed.set) {
|
|
67
|
-
throw new Error("Pass --set=<set> when generating code in a project with sets enabled.");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const executions = await getProjectSetExecutions(projectConfig, datasource, parsed.set);
|
|
71
|
-
|
|
72
|
-
for (const execution of executions) {
|
|
73
|
-
printSetHeader(projectConfig, execution.set);
|
|
74
|
-
|
|
75
|
-
await generateCodeForProject(
|
|
76
|
-
{
|
|
77
|
-
rootDirectoryPath,
|
|
78
|
-
projectConfig: execution.projectConfig,
|
|
79
|
-
datasource: execution.datasource,
|
|
80
|
-
options: parsed,
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
language: parsed.language,
|
|
84
|
-
outDir: parsed.outDir,
|
|
85
|
-
tag: parsed.tag,
|
|
86
|
-
target: parsed.target,
|
|
87
|
-
react: parsed.react,
|
|
88
|
-
},
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
examples: [
|
|
93
|
-
{
|
|
94
|
-
command: "generate-code --language typescript --out-dir src/generated",
|
|
95
|
-
description: "Generate TypeScript code for the project",
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
command: "generate-code --language typescript --out-dir src/generated --tag web --react",
|
|
99
|
-
description: "Generate TypeScript and React helper code for tagged features",
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
command: "generate-code --language typescript --out-dir src/generated --target web",
|
|
103
|
-
description: "Generate TypeScript code for features selected by a target",
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
};
|