@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.
Files changed (213) hide show
  1. package/lib/datasource/datasource.d.ts +1 -1
  2. package/lib/datasource/datasource.js +4 -14
  3. package/lib/datasource/datasource.js.map +1 -1
  4. package/lib/datasource/requiredFeatures.d.ts +7 -0
  5. package/lib/datasource/requiredFeatures.js +38 -0
  6. package/lib/datasource/requiredFeatures.js.map +1 -0
  7. package/lib/linter/checkCircularDependency.d.ts +1 -1
  8. package/lib/linter/checkCircularDependency.js +3 -22
  9. package/lib/linter/checkCircularDependency.js.map +1 -1
  10. package/lib/linter/conditionSchema.js +27 -3
  11. package/lib/linter/conditionSchema.js.map +1 -1
  12. package/lib/linter/testSchema.d.ts +4 -0
  13. package/lib/linter/testSchema.js +46 -4
  14. package/lib/linter/testSchema.js.map +1 -1
  15. package/lib/promoter/index.js +62 -1
  16. package/lib/promoter/index.js.map +1 -1
  17. package/lib/tester/testFeature.js +17 -16
  18. package/lib/tester/testFeature.js.map +1 -1
  19. package/package.json +10 -7
  20. package/CHANGELOG.md +0 -2246
  21. package/coverage/clover.xml +0 -5456
  22. package/coverage/coverage-final.json +0 -64
  23. package/coverage/lcov-report/base.css +0 -224
  24. package/coverage/lcov-report/block-navigation.js +0 -87
  25. package/coverage/lcov-report/favicon.png +0 -0
  26. package/coverage/lcov-report/index.html +0 -371
  27. package/coverage/lcov-report/prettify.css +0 -1
  28. package/coverage/lcov-report/prettify.js +0 -2
  29. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  30. package/coverage/lcov-report/sorter.js +0 -210
  31. package/coverage/lcov-report/src/assess-distribution/index.html +0 -116
  32. package/coverage/lcov-report/src/assess-distribution/index.ts.html +0 -754
  33. package/coverage/lcov-report/src/benchmark/index.html +0 -116
  34. package/coverage/lcov-report/src/benchmark/index.ts.html +0 -793
  35. package/coverage/lcov-report/src/builder/allocator.ts.html +0 -220
  36. package/coverage/lcov-report/src/builder/applyContextToConditions.ts.html +0 -502
  37. package/coverage/lcov-report/src/builder/applyContextToDatafile.ts.html +0 -772
  38. package/coverage/lcov-report/src/builder/applyContextToSegments.ts.html +0 -580
  39. package/coverage/lcov-report/src/builder/buildDatafile.ts.html +0 -2053
  40. package/coverage/lcov-report/src/builder/buildProject.ts.html +0 -1117
  41. package/coverage/lcov-report/src/builder/buildRuntimeDatafiles.ts.html +0 -256
  42. package/coverage/lcov-report/src/builder/getFeatureRanges.ts.html +0 -268
  43. package/coverage/lcov-report/src/builder/hashes.ts.html +0 -412
  44. package/coverage/lcov-report/src/builder/index.html +0 -311
  45. package/coverage/lcov-report/src/builder/index.ts.html +0 -91
  46. package/coverage/lcov-report/src/builder/mutateVariables.ts.html +0 -421
  47. package/coverage/lcov-report/src/builder/mutator.ts.html +0 -796
  48. package/coverage/lcov-report/src/builder/revision.ts.html +0 -151
  49. package/coverage/lcov-report/src/builder/traffic.ts.html +0 -661
  50. package/coverage/lcov-report/src/cli/cli.ts.html +0 -400
  51. package/coverage/lcov-report/src/cli/index.html +0 -131
  52. package/coverage/lcov-report/src/cli/plugins.ts.html +0 -214
  53. package/coverage/lcov-report/src/config/index.html +0 -131
  54. package/coverage/lcov-report/src/config/index.ts.html +0 -88
  55. package/coverage/lcov-report/src/config/projectConfig.ts.html +0 -925
  56. package/coverage/lcov-report/src/datasource/adapter.ts.html +0 -253
  57. package/coverage/lcov-report/src/datasource/datasource.ts.html +0 -1000
  58. package/coverage/lcov-report/src/datasource/filesystemAdapter.ts.html +0 -1576
  59. package/coverage/lcov-report/src/datasource/index.html +0 -161
  60. package/coverage/lcov-report/src/datasource/index.ts.html +0 -94
  61. package/coverage/lcov-report/src/evaluate/index.html +0 -116
  62. package/coverage/lcov-report/src/evaluate/index.ts.html +0 -814
  63. package/coverage/lcov-report/src/find-duplicate-segments/findDuplicateSegments.ts.html +0 -313
  64. package/coverage/lcov-report/src/find-duplicate-segments/index.html +0 -131
  65. package/coverage/lcov-report/src/find-duplicate-segments/index.ts.html +0 -307
  66. package/coverage/lcov-report/src/find-usage/index.html +0 -116
  67. package/coverage/lcov-report/src/find-usage/index.ts.html +0 -1780
  68. package/coverage/lcov-report/src/generate-code/index.html +0 -131
  69. package/coverage/lcov-report/src/generate-code/index.ts.html +0 -403
  70. package/coverage/lcov-report/src/generate-code/typescript.ts.html +0 -1909
  71. package/coverage/lcov-report/src/index.html +0 -131
  72. package/coverage/lcov-report/src/info/index.html +0 -116
  73. package/coverage/lcov-report/src/info/index.ts.html +0 -472
  74. package/coverage/lcov-report/src/init/index.html +0 -116
  75. package/coverage/lcov-report/src/init/index.ts.html +0 -280
  76. package/coverage/lcov-report/src/linter/attributeSchema.ts.html +0 -1963
  77. package/coverage/lcov-report/src/linter/checkCircularDependency.ts.html +0 -220
  78. package/coverage/lcov-report/src/linter/checkPercentageExceedingSlot.ts.html +0 -268
  79. package/coverage/lcov-report/src/linter/conditionSchema.ts.html +0 -2224
  80. package/coverage/lcov-report/src/linter/featureSchema.ts.html +0 -5851
  81. package/coverage/lcov-report/src/linter/groupSchema.ts.html +0 -226
  82. package/coverage/lcov-report/src/linter/index.html +0 -326
  83. package/coverage/lcov-report/src/linter/index.ts.html +0 -88
  84. package/coverage/lcov-report/src/linter/lintProject.ts.html +0 -2704
  85. package/coverage/lcov-report/src/linter/mutationNotation.ts.html +0 -1411
  86. package/coverage/lcov-report/src/linter/printError.ts.html +0 -289
  87. package/coverage/lcov-report/src/linter/schema.ts.html +0 -1558
  88. package/coverage/lcov-report/src/linter/segmentSchema.ts.html +0 -139
  89. package/coverage/lcov-report/src/linter/targetSchema.ts.html +0 -223
  90. package/coverage/lcov-report/src/linter/testSchema.ts.html +0 -529
  91. package/coverage/lcov-report/src/linter/zodHelpers.ts.html +0 -133
  92. package/coverage/lcov-report/src/list/index.html +0 -131
  93. package/coverage/lcov-report/src/list/index.ts.html +0 -2065
  94. package/coverage/lcov-report/src/list/matrix.ts.html +0 -721
  95. package/coverage/lcov-report/src/promoter/index.html +0 -116
  96. package/coverage/lcov-report/src/promoter/index.ts.html +0 -3883
  97. package/coverage/lcov-report/src/sets.ts.html +0 -313
  98. package/coverage/lcov-report/src/targeting.ts.html +0 -403
  99. package/coverage/lcov-report/src/tester/cliFormat.ts.html +0 -133
  100. package/coverage/lcov-report/src/tester/helpers.ts.html +0 -313
  101. package/coverage/lcov-report/src/tester/index.html +0 -206
  102. package/coverage/lcov-report/src/tester/prettyDuration.ts.html +0 -187
  103. package/coverage/lcov-report/src/tester/printTestResult.ts.html +0 -337
  104. package/coverage/lcov-report/src/tester/testFeature.ts.html +0 -1186
  105. package/coverage/lcov-report/src/tester/testProject.ts.html +0 -1018
  106. package/coverage/lcov-report/src/tester/testSegment.ts.html +0 -316
  107. package/coverage/lcov-report/src/utils/extractKeys.ts.html +0 -493
  108. package/coverage/lcov-report/src/utils/git.ts.html +0 -559
  109. package/coverage/lcov-report/src/utils/index.html +0 -161
  110. package/coverage/lcov-report/src/utils/index.ts.html +0 -94
  111. package/coverage/lcov-report/src/utils/pretty.ts.html +0 -121
  112. package/coverage/lcov.info +0 -11615
  113. package/jest.config.js +0 -22
  114. package/json-schema/README.md +0 -5
  115. package/json-schema/attribute.json +0 -40
  116. package/json-schema/feature.json +0 -394
  117. package/json-schema/segment.json +0 -137
  118. package/src/assess-distribution/index.ts +0 -223
  119. package/src/benchmark/index.ts +0 -236
  120. package/src/builder/allocator.spec.ts +0 -105
  121. package/src/builder/allocator.ts +0 -45
  122. package/src/builder/applyContextToConditions.spec.ts +0 -2677
  123. package/src/builder/applyContextToConditions.ts +0 -139
  124. package/src/builder/applyContextToDatafile.spec.ts +0 -2626
  125. package/src/builder/applyContextToDatafile.ts +0 -229
  126. package/src/builder/applyContextToSegments.spec.ts +0 -1593
  127. package/src/builder/applyContextToSegments.ts +0 -165
  128. package/src/builder/buildDatafile.spec.ts +0 -445
  129. package/src/builder/buildDatafile.ts +0 -656
  130. package/src/builder/buildProject.ts +0 -344
  131. package/src/builder/buildRuntimeDatafiles.ts +0 -57
  132. package/src/builder/getFeatureRanges.ts +0 -61
  133. package/src/builder/hashes.ts +0 -109
  134. package/src/builder/index.ts +0 -2
  135. package/src/builder/mutateVariables.spec.ts +0 -1179
  136. package/src/builder/mutateVariables.ts +0 -112
  137. package/src/builder/mutator.spec.ts +0 -413
  138. package/src/builder/mutator.ts +0 -237
  139. package/src/builder/revision.spec.ts +0 -22
  140. package/src/builder/revision.ts +0 -22
  141. package/src/builder/traffic.spec.ts +0 -946
  142. package/src/builder/traffic.ts +0 -192
  143. package/src/cli/cli.ts +0 -105
  144. package/src/cli/index.ts +0 -2
  145. package/src/cli/plugins.ts +0 -43
  146. package/src/config/index.ts +0 -1
  147. package/src/config/projectConfig.spec.ts +0 -194
  148. package/src/config/projectConfig.ts +0 -280
  149. package/src/datasource/adapter.ts +0 -56
  150. package/src/datasource/datasource.ts +0 -305
  151. package/src/datasource/filesystemAdapter.spec.ts +0 -212
  152. package/src/datasource/filesystemAdapter.ts +0 -497
  153. package/src/datasource/index.ts +0 -3
  154. package/src/dependencies.ts +0 -13
  155. package/src/evaluate/index.ts +0 -243
  156. package/src/find-duplicate-segments/findDuplicateSegments.ts +0 -76
  157. package/src/find-duplicate-segments/index.ts +0 -74
  158. package/src/find-usage/index.ts +0 -565
  159. package/src/generate-code/index.ts +0 -106
  160. package/src/generate-code/typescript.spec.ts +0 -214
  161. package/src/generate-code/typescript.ts +0 -608
  162. package/src/index.ts +0 -20
  163. package/src/info/index.ts +0 -129
  164. package/src/init/index.ts +0 -65
  165. package/src/linter/attributeSchema.spec.ts +0 -342
  166. package/src/linter/attributeSchema.ts +0 -626
  167. package/src/linter/checkCircularDependency.ts +0 -45
  168. package/src/linter/checkPercentageExceedingSlot.ts +0 -61
  169. package/src/linter/conditionSchema.spec.ts +0 -510
  170. package/src/linter/conditionSchema.ts +0 -713
  171. package/src/linter/featureSchema.spec.ts +0 -1985
  172. package/src/linter/featureSchema.ts +0 -1922
  173. package/src/linter/groupSchema.ts +0 -47
  174. package/src/linter/index.ts +0 -1
  175. package/src/linter/lintProject.spec.ts +0 -336
  176. package/src/linter/lintProject.ts +0 -873
  177. package/src/linter/mutationNotation.spec.ts +0 -704
  178. package/src/linter/mutationNotation.ts +0 -442
  179. package/src/linter/printError.ts +0 -68
  180. package/src/linter/schema.spec.ts +0 -690
  181. package/src/linter/schema.ts +0 -491
  182. package/src/linter/segmentSchema.spec.ts +0 -358
  183. package/src/linter/segmentSchema.ts +0 -18
  184. package/src/linter/targetSchema.spec.ts +0 -159
  185. package/src/linter/targetSchema.ts +0 -46
  186. package/src/linter/testSchema.spec.ts +0 -258
  187. package/src/linter/testSchema.ts +0 -148
  188. package/src/linter/zodHelpers.ts +0 -16
  189. package/src/list/index.spec.ts +0 -135
  190. package/src/list/index.ts +0 -660
  191. package/src/list/matrix.spec.ts +0 -49
  192. package/src/list/matrix.ts +0 -212
  193. package/src/promoter/index.spec.ts +0 -617
  194. package/src/promoter/index.ts +0 -1266
  195. package/src/sets.ts +0 -76
  196. package/src/targeting.spec.ts +0 -74
  197. package/src/targeting.ts +0 -106
  198. package/src/tester/cliFormat.ts +0 -16
  199. package/src/tester/helpers.spec.ts +0 -149
  200. package/src/tester/helpers.ts +0 -76
  201. package/src/tester/index.ts +0 -2
  202. package/src/tester/prettyDuration.ts +0 -34
  203. package/src/tester/printTestResult.ts +0 -84
  204. package/src/tester/testFeature.ts +0 -367
  205. package/src/tester/testProject.spec.ts +0 -50
  206. package/src/tester/testProject.ts +0 -311
  207. package/src/tester/testSegment.ts +0 -77
  208. package/src/utils/extractKeys.ts +0 -136
  209. package/src/utils/git.ts +0 -158
  210. package/src/utils/index.ts +0 -3
  211. package/src/utils/pretty.ts +0 -12
  212. package/tsconfig.cjs.json +0 -13
  213. package/tsconfig.typecheck.json +0 -9
package/src/list/index.ts DELETED
@@ -1,660 +0,0 @@
1
- import type {
2
- ParsedFeature,
3
- Segment,
4
- Attribute,
5
- TestFeature,
6
- TestSegment,
7
- FeatureAssertion,
8
- SegmentAssertion,
9
- Target,
10
- } from "@featurevisor/types";
11
-
12
- import { Dependencies } from "../dependencies";
13
- import type { DatafileFile } from "../datasource";
14
- import { Plugin } from "../cli";
15
- import { getFeatureAssertionsFromMatrix, getSegmentAssertionsFromMatrix } from "./matrix";
16
- import { assertProjectSetJsonSelection, getProjectSetExecutions, printSetHeader } from "../sets";
17
- import { getTargetFeatureKeys, resolveTargets } from "../targeting";
18
- import {
19
- CLI_COLOR_CYAN,
20
- CLI_COLOR_GREEN,
21
- CLI_COLOR_YELLOW,
22
- CLI_FORMAT_BOLD,
23
- CLI_FORMAT_GREEN,
24
- CLI_FORMAT_YELLOW,
25
- colorize,
26
- } from "../tester/cliFormat";
27
-
28
- async function getEntitiesWithTests(
29
- deps: Dependencies,
30
- ): Promise<{ features: string[]; segments: string[] }> {
31
- const { datasource } = deps;
32
-
33
- const featuresWithTests = new Set<string>();
34
- const segmentsWithTests = new Set<string>();
35
-
36
- const tests = await datasource.listTests();
37
- for (const testKey of tests) {
38
- const test = await datasource.readTest(testKey);
39
-
40
- if ((test as TestFeature).feature) {
41
- featuresWithTests.add((test as TestFeature).feature);
42
- }
43
-
44
- if ((test as TestSegment).segment) {
45
- segmentsWithTests.add((test as TestSegment).segment);
46
- }
47
- }
48
-
49
- return {
50
- features: Array.from(featuresWithTests),
51
- segments: Array.from(segmentsWithTests),
52
- };
53
- }
54
-
55
- export async function listEntities<T>(deps: Dependencies, entityType): Promise<T[]> {
56
- const { datasource, options } = deps;
57
-
58
- const result: T[] = [];
59
- let entityKeys: string[] = [];
60
-
61
- if (entityType === "feature") {
62
- entityKeys = await datasource.listFeatures();
63
- } else if (entityType === "segment") {
64
- entityKeys = await datasource.listSegments();
65
- } else if (entityType === "attribute") {
66
- entityKeys = await datasource.listAttributes();
67
- } else if (entityType === "test") {
68
- entityKeys = await datasource.listTests();
69
- } else if (entityType === "target") {
70
- entityKeys = await datasource.listTargets();
71
- }
72
-
73
- if (entityKeys.length === 0) {
74
- return result;
75
- }
76
-
77
- let entitiesWithTests: { features: string[]; segments: string[] } = {
78
- features: [],
79
- segments: [],
80
- };
81
- let entitiesWithTestsInitialized = false;
82
- let targetFeatureKeys: Set<string> | undefined;
83
-
84
- if (entityType === "feature" && options.target) {
85
- const targets = await resolveTargets(datasource, options.target, { defaultToAll: false });
86
- targetFeatureKeys = await getTargetFeatureKeys(datasource, targets);
87
- }
88
-
89
- async function initializeEntitiesWithTests() {
90
- if (entitiesWithTestsInitialized) {
91
- return;
92
- }
93
-
94
- entitiesWithTests = await getEntitiesWithTests(deps);
95
- entitiesWithTestsInitialized = true;
96
- }
97
-
98
- for (const key of entityKeys) {
99
- let entity = {} as T;
100
-
101
- if (entityType === "feature") {
102
- entity = (await datasource.readFeature(key)) as T;
103
- } else if (entityType === "segment") {
104
- entity = (await datasource.readSegment(key)) as T;
105
- } else if (entityType === "attribute") {
106
- entity = (await datasource.readAttribute(key)) as T;
107
- } else if (entityType === "test") {
108
- entity = (await datasource.readTest(key)) as T;
109
- } else if (entityType === "target") {
110
- entity = (await datasource.readTarget(key)) as T;
111
- }
112
-
113
- // filter
114
- if (entityType === "feature") {
115
- const parsedFeature = entity as ParsedFeature;
116
-
117
- if (targetFeatureKeys && !targetFeatureKeys.has(key)) {
118
- continue;
119
- }
120
-
121
- // --archived=true|false
122
- if (parsedFeature.archived) {
123
- const archivedStatus = options.archived === "false";
124
-
125
- if (parsedFeature.archived !== archivedStatus) {
126
- continue;
127
- }
128
- }
129
-
130
- // --description=<pattern>
131
- if (options.description) {
132
- const description = parsedFeature.description || "";
133
-
134
- const regex = new RegExp(options.description, "i");
135
- if (!regex.test(description)) {
136
- continue;
137
- }
138
- }
139
-
140
- // --disabledIn=<environment>
141
- if (options.disabledIn && parsedFeature.rules && parsedFeature.rules[options.disabledIn]) {
142
- const disabledInEnvironment = parsedFeature.rules[options.disabledIn].every((rule) => {
143
- return rule.percentage === 0;
144
- });
145
-
146
- if (!disabledInEnvironment) {
147
- continue;
148
- }
149
- }
150
-
151
- // --enabledIn=<environment>
152
- if (options.enabledIn && parsedFeature.rules && parsedFeature.rules[options.enabledIn]) {
153
- const enabledInEnvironment = parsedFeature.rules[options.enabledIn].some((rule) => {
154
- return rule.percentage > 0;
155
- });
156
-
157
- if (!enabledInEnvironment) {
158
- continue;
159
- }
160
- }
161
-
162
- // --keyPattern=<pattern>
163
- if (options.keyPattern) {
164
- const regex = new RegExp(options.keyPattern, "i");
165
- if (!regex.test(key)) {
166
- continue;
167
- }
168
- }
169
-
170
- // --tag=<tag>
171
- if (options.tag) {
172
- const tags = Array.isArray(options.tag) ? options.tag : [options.tag];
173
- const featureTags = parsedFeature.tags || [];
174
- const hasTags = tags.every((tag) => featureTags.includes(tag));
175
-
176
- if (!hasTags) {
177
- continue;
178
- }
179
- }
180
-
181
- // --variable=<variableKey>
182
- if (options.variable) {
183
- const lookForVariables = Array.isArray(options.variable)
184
- ? options.variable
185
- : [options.variable];
186
-
187
- let variablesInFeature: string[] = Object.keys(parsedFeature.variablesSchema || {});
188
-
189
- const hasVariables = lookForVariables.every((variable) =>
190
- variablesInFeature.includes(variable),
191
- );
192
-
193
- if (!hasVariables) {
194
- continue;
195
- }
196
- }
197
-
198
- // --variation=<variationValue>
199
- if (options.variation) {
200
- const lookForVariations = Array.isArray(options.variation)
201
- ? options.variation
202
- : [options.variation];
203
-
204
- let variationsInFeature: string[] = parsedFeature.variations
205
- ? parsedFeature.variations.map((v) => v.value)
206
- : [];
207
-
208
- const hasVariations = lookForVariations.every((variation) =>
209
- variationsInFeature.includes(variation),
210
- );
211
-
212
- if (!hasVariations) {
213
- continue;
214
- }
215
- }
216
-
217
- // --with-tests
218
- if (options.withTests) {
219
- await initializeEntitiesWithTests();
220
-
221
- if (!entitiesWithTests.features.includes(key)) {
222
- continue;
223
- }
224
- }
225
-
226
- // --with-variables
227
- if (options.withVariables) {
228
- const hasVariables = parsedFeature.variablesSchema;
229
-
230
- if (!hasVariables) {
231
- continue;
232
- }
233
- }
234
-
235
- // --with-variations
236
- if (options.withVariations) {
237
- const hasVariations = parsedFeature.variations;
238
-
239
- if (!hasVariations) {
240
- continue;
241
- }
242
- }
243
-
244
- // --without-tests
245
- if (options.withoutTests) {
246
- await initializeEntitiesWithTests();
247
-
248
- if (entitiesWithTests.features.includes(key)) {
249
- continue;
250
- }
251
- }
252
-
253
- // --without-variables
254
- if (options.withoutVariables) {
255
- const hasVariables = parsedFeature.variablesSchema;
256
-
257
- if (hasVariables) {
258
- continue;
259
- }
260
- }
261
-
262
- // --without-variations
263
- if (options.withoutVariations) {
264
- const hasVariations = parsedFeature.variations;
265
-
266
- if (hasVariations) {
267
- continue;
268
- }
269
- }
270
- } else if (entityType === "segment") {
271
- const segment = entity as Segment;
272
-
273
- // --archived=true|false
274
- if (segment.archived) {
275
- const archivedStatus = options.archived === "false";
276
-
277
- if (segment.archived !== archivedStatus) {
278
- continue;
279
- }
280
- }
281
-
282
- // --description=<pattern>
283
- if (options.description) {
284
- const description = segment.description || "";
285
-
286
- const regex = new RegExp(options.description, "i");
287
- if (!regex.test(description)) {
288
- continue;
289
- }
290
- }
291
-
292
- // --keyPattern=<pattern>
293
- if (options.keyPattern) {
294
- const regex = new RegExp(options.keyPattern, "i");
295
- if (!regex.test(key)) {
296
- continue;
297
- }
298
- }
299
-
300
- // --with-tests
301
- if (options.withTests) {
302
- await initializeEntitiesWithTests();
303
-
304
- if (!entitiesWithTests.segments.includes(key)) {
305
- continue;
306
- }
307
- }
308
-
309
- // --without-tests
310
- if (options.withoutTests) {
311
- await initializeEntitiesWithTests();
312
-
313
- if (entitiesWithTests.segments.includes(key)) {
314
- continue;
315
- }
316
- }
317
- } else if (entityType === "attribute") {
318
- const attribute = entity as Attribute;
319
-
320
- // --archived=true|false
321
- if (options.archived) {
322
- const archivedStatus = options.archived === "false";
323
-
324
- if (attribute.archived !== archivedStatus) {
325
- continue;
326
- }
327
- }
328
-
329
- // --description=<pattern>
330
- if (options.description) {
331
- const description = attribute.description || "";
332
-
333
- const regex = new RegExp(options.description, "i");
334
- if (!regex.test(description)) {
335
- continue;
336
- }
337
- }
338
-
339
- // --keyPattern=<pattern>
340
- if (options.keyPattern) {
341
- const regex = new RegExp(options.keyPattern, "i");
342
- if (!regex.test(key)) {
343
- continue;
344
- }
345
- }
346
- } else if (entityType === "test") {
347
- let test = entity as TestFeature | TestSegment;
348
- const testEntityKey = (test as TestFeature).feature || (test as TestSegment).segment;
349
- const testEntityType = (test as TestSegment).segment ? "segment" : "feature";
350
- let testAssertions = test.assertions;
351
-
352
- // --entityType=<type>
353
- if (options.entityType && options.entityType !== testEntityType) {
354
- continue;
355
- }
356
-
357
- // --apply-matrix
358
- if (options.applyMatrix) {
359
- if (testEntityType === "feature") {
360
- let assertionsAfterApplyingMatrix: FeatureAssertion[] = [];
361
- for (let aIndex = 0; aIndex < testAssertions.length; aIndex++) {
362
- const processedAssertions = getFeatureAssertionsFromMatrix(
363
- aIndex,
364
- testAssertions[aIndex] as FeatureAssertion,
365
- );
366
- assertionsAfterApplyingMatrix =
367
- assertionsAfterApplyingMatrix.concat(processedAssertions);
368
- }
369
-
370
- testAssertions = assertionsAfterApplyingMatrix;
371
- } else if (testEntityType === "segment") {
372
- let assertionsAfterApplyingMatrix: SegmentAssertion[] = [];
373
- for (let aIndex = 0; aIndex < testAssertions.length; aIndex++) {
374
- const processedAssertions = getSegmentAssertionsFromMatrix(
375
- aIndex,
376
- testAssertions[aIndex] as SegmentAssertion,
377
- );
378
- assertionsAfterApplyingMatrix =
379
- assertionsAfterApplyingMatrix.concat(processedAssertions);
380
- }
381
-
382
- testAssertions = assertionsAfterApplyingMatrix;
383
- }
384
- }
385
-
386
- // --keyPattern=<pattern>
387
- if (options.keyPattern) {
388
- const regex = new RegExp(options.keyPattern, "i");
389
- if (!regex.test(testEntityKey)) {
390
- continue;
391
- }
392
- }
393
-
394
- // --assertionPattern=<pattern>
395
- if (options.assertionPattern) {
396
- const regex = new RegExp(options.assertionPattern, "i");
397
- testAssertions = testAssertions.filter((assertion) => {
398
- if (!assertion.description) {
399
- return false;
400
- }
401
-
402
- return regex.test(assertion.description);
403
- }) as FeatureAssertion[] | SegmentAssertion[];
404
-
405
- if (testAssertions.length === 0) {
406
- continue;
407
- }
408
- }
409
-
410
- (entity as TestFeature | TestSegment).assertions = testAssertions;
411
- }
412
-
413
- result.push({
414
- ...entity,
415
- key,
416
- });
417
- }
418
-
419
- return result;
420
- }
421
-
422
- function ucfirst(str: string) {
423
- return str.charAt(0).toUpperCase() + str.slice(1);
424
- }
425
-
426
- function printResult({ result, entityType, options }) {
427
- if (options.json) {
428
- console.log(options.pretty ? JSON.stringify(result, null, 2) : JSON.stringify(result));
429
- return;
430
- }
431
-
432
- if (result.length === 0) {
433
- console.log(CLI_FORMAT_YELLOW, `No ${entityType}s found.`);
434
- return;
435
- }
436
-
437
- console.log("");
438
- console.log(CLI_FORMAT_BOLD, `${ucfirst(entityType)}s`);
439
- console.log("");
440
-
441
- for (const item of result) {
442
- console.log(` ${colorize("•", CLI_COLOR_CYAN)} ${item.key}`);
443
- }
444
-
445
- console.log("");
446
- console.log(CLI_FORMAT_GREEN, `Found ${result.length} ${entityType}s.`);
447
- }
448
-
449
- function getDatafileSizeParts(size: number): { value: string; unit: string; color: number } {
450
- if (size < 1024) {
451
- return { value: size.toFixed(2), unit: "B", color: CLI_COLOR_YELLOW };
452
- }
453
-
454
- if (size < 1024 * 1024) {
455
- return { value: (size / 1024).toFixed(2), unit: "kB", color: CLI_COLOR_CYAN };
456
- }
457
-
458
- return { value: (size / (1024 * 1024)).toFixed(2), unit: "mB", color: CLI_COLOR_GREEN };
459
- }
460
-
461
- export function formatDatafileSize(size: number): string {
462
- const { value, unit, color } = getDatafileSizeParts(size);
463
-
464
- return `${value} ${colorize(unit, color)}`;
465
- }
466
-
467
- function formatDatafileSizeColumn(size: number, valueWidth: number): string {
468
- const { value, unit, color } = getDatafileSizeParts(size);
469
-
470
- return `${value.padStart(valueWidth)} ${" ".repeat(2 - unit.length)}${colorize(unit, color)}`;
471
- }
472
-
473
- function getDatafileDirectory(datafilePath: string): string {
474
- const lastSlashIndex = datafilePath.lastIndexOf("/");
475
-
476
- return lastSlashIndex === -1 ? "" : datafilePath.slice(0, lastSlashIndex);
477
- }
478
-
479
- function getDatafileDirectoryPriority(datafilePath: string): number {
480
- const directory = datafilePath.split("/", 1)[0].toLowerCase();
481
-
482
- if (directory.startsWith("dev")) {
483
- return 0;
484
- }
485
-
486
- if (directory.startsWith("prod")) {
487
- return 2;
488
- }
489
-
490
- return 1;
491
- }
492
-
493
- function sortDatafiles(datafiles: DatafileFile[]): DatafileFile[] {
494
- return datafiles.slice().sort((a, b) => {
495
- const priorityDifference =
496
- getDatafileDirectoryPriority(a.path) - getDatafileDirectoryPriority(b.path);
497
-
498
- return priorityDifference || a.path.localeCompare(b.path);
499
- });
500
- }
501
-
502
- function printDatafiles({ result, options }: { result: DatafileFile[]; options: any }) {
503
- const sortedResult = sortDatafiles(result);
504
-
505
- if (options.json) {
506
- console.log(
507
- options.pretty ? JSON.stringify(sortedResult, null, 2) : JSON.stringify(sortedResult),
508
- );
509
- return;
510
- }
511
-
512
- if (sortedResult.length === 0) {
513
- console.log(CLI_FORMAT_YELLOW, "No datafiles found.");
514
- return;
515
- }
516
-
517
- console.log("");
518
-
519
- const pathWidth = Math.max(
520
- "Datafile".length,
521
- ...sortedResult.map((datafile) => datafile.path.length),
522
- );
523
- const sizeValueWidth = Math.max(
524
- ...sortedResult.map((datafile) => {
525
- const { value } = getDatafileSizeParts(datafile.size);
526
- return value.length;
527
- }),
528
- );
529
- const gzipSizeValueWidth = Math.max(
530
- ...sortedResult.map((datafile) => {
531
- const { value } = getDatafileSizeParts(datafile.gzipSize);
532
- return value.length;
533
- }),
534
- );
535
- const sizeWidth = Math.max("Size".length, sizeValueWidth + 3);
536
- const gzipSizeWidth = Math.max("Gzip".length, gzipSizeValueWidth + 3);
537
-
538
- console.log(
539
- ` ${colorize("Datafile".padEnd(pathWidth), CLI_COLOR_CYAN)} ${colorize(
540
- "Size".padStart(sizeWidth),
541
- CLI_COLOR_CYAN,
542
- )} ${colorize("Gzip".padStart(gzipSizeWidth), CLI_COLOR_CYAN)}`,
543
- );
544
- console.log(` ${"-".repeat(pathWidth)} ${"-".repeat(sizeWidth)} ${"-".repeat(gzipSizeWidth)}`);
545
-
546
- let previousDirectory: string | undefined;
547
- for (const datafile of sortedResult) {
548
- const directory = getDatafileDirectory(datafile.path);
549
- if (previousDirectory !== undefined && directory !== previousDirectory) {
550
- console.log("");
551
- }
552
-
553
- const formattedSize = formatDatafileSizeColumn(datafile.size, sizeValueWidth);
554
- const formattedGzipSize = formatDatafileSizeColumn(datafile.gzipSize, gzipSizeValueWidth);
555
- console.log(` ${datafile.path.padEnd(pathWidth)} ${formattedSize} ${formattedGzipSize}`);
556
- previousDirectory = directory;
557
- }
558
-
559
- console.log("");
560
- console.log(CLI_FORMAT_GREEN, `Found ${sortedResult.length} datafiles.`);
561
- }
562
-
563
- export async function listProject(deps: Dependencies) {
564
- const { options } = deps;
565
-
566
- // datafiles
567
- if (options.datafiles) {
568
- const result = await deps.datasource.listDatafiles();
569
-
570
- return printDatafiles({ result, options });
571
- }
572
-
573
- // features
574
- if (options.features) {
575
- const result = await listEntities<ParsedFeature>(deps, "feature");
576
-
577
- return printResult({
578
- result,
579
- entityType: "feature",
580
- options,
581
- });
582
- }
583
-
584
- // segments
585
- if (options.segments) {
586
- const result = await listEntities<Segment>(deps, "segment");
587
-
588
- return printResult({
589
- result,
590
- entityType: "segment",
591
- options,
592
- });
593
- }
594
-
595
- // attributes
596
- if (options.attributes) {
597
- const result = await listEntities<Attribute>(deps, "attribute");
598
-
599
- return printResult({
600
- result,
601
- entityType: "attribute",
602
- options,
603
- });
604
- }
605
-
606
- // tests
607
- if (options.tests) {
608
- const result = await listEntities<Attribute>(deps, "test");
609
-
610
- return printResult({
611
- result,
612
- entityType: "test",
613
- options,
614
- });
615
- }
616
-
617
- // targets
618
- if (options.targets) {
619
- const result = await listEntities<Target>(deps, "target");
620
-
621
- return printResult({
622
- result,
623
- entityType: "target",
624
- options,
625
- });
626
- }
627
-
628
- console.log("");
629
- console.log(CLI_FORMAT_YELLOW, "Nothing to list.");
630
- console.log("");
631
- console.log(
632
- "Please pass `--datafiles`, `--features`, `--segments`, `--attributes`, or `--targets`.",
633
- );
634
- }
635
-
636
- export const listPlugin: Plugin = {
637
- command: "list",
638
- handler: async function ({ rootDirectoryPath, projectConfig, datasource, parsed }) {
639
- assertProjectSetJsonSelection(projectConfig, parsed.set, parsed.json);
640
-
641
- const executions = await getProjectSetExecutions(projectConfig, datasource, parsed.set);
642
-
643
- for (const execution of executions) {
644
- printSetHeader(projectConfig, execution.set, parsed.json);
645
-
646
- await listProject({
647
- rootDirectoryPath,
648
- projectConfig: execution.projectConfig,
649
- datasource: execution.datasource,
650
- options: parsed,
651
- });
652
- }
653
- },
654
- examples: [
655
- {
656
- command: "list",
657
- description: "list entities",
658
- },
659
- ],
660
- };
@@ -1,49 +0,0 @@
1
- import { getMatrixCombinations } from "./matrix";
2
-
3
- describe("core :: tester :: matrix", function () {
4
- test("should empty array when no keys are available", function () {
5
- const matrix = {};
6
- const combinations = getMatrixCombinations(matrix);
7
-
8
- expect(combinations).toEqual([]);
9
- });
10
-
11
- test("should get combinations from matrix with two keys", function () {
12
- const matrix = {
13
- a: [1, 2],
14
- b: ["x", "y"],
15
- };
16
- const combinations = getMatrixCombinations(matrix);
17
-
18
- expect(combinations).toEqual([
19
- { a: 1, b: "x" },
20
- { a: 1, b: "y" },
21
-
22
- { a: 2, b: "x" },
23
- { a: 2, b: "y" },
24
- ]);
25
- });
26
-
27
- test("should get combinations from matrix with three keys", function () {
28
- const matrix = {
29
- a: [1, 2],
30
- b: ["x", "y"],
31
- c: [true, false],
32
- };
33
- const combinations = getMatrixCombinations(matrix);
34
-
35
- expect(combinations).toEqual([
36
- { a: 1, b: "x", c: true },
37
- { a: 1, b: "x", c: false },
38
-
39
- { a: 1, b: "y", c: true },
40
- { a: 1, b: "y", c: false },
41
-
42
- { a: 2, b: "x", c: true },
43
- { a: 2, b: "x", c: false },
44
-
45
- { a: 2, b: "y", c: true },
46
- { a: 2, b: "y", c: false },
47
- ]);
48
- });
49
- });