@featurevisor/core 3.0.1 → 3.2.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/tester/testFeature.js +17 -16
- package/lib/tester/testFeature.js.map +1 -1
- package/package.json +10 -7
- package/CHANGELOG.md +0 -2238
- 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
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
import * as path from "path";
|
|
2
|
-
|
|
3
|
-
import { ProjectConfig } from "../config";
|
|
4
|
-
import { Datasource } from "../datasource";
|
|
5
|
-
|
|
6
|
-
import { getNextRevision } from "./revision";
|
|
7
|
-
import { buildDatafile, getCustomDatafile } from "./buildDatafile";
|
|
8
|
-
import { applyContextToDatafile } from "./applyContextToDatafile";
|
|
9
|
-
import { Dependencies } from "../dependencies";
|
|
10
|
-
import { Plugin } from "../cli";
|
|
11
|
-
|
|
12
|
-
import type { DatafileContent, Target } from "@featurevisor/types";
|
|
13
|
-
import { assertProjectSetJsonSelection, getProjectSetExecutions, printSetHeader } from "../sets";
|
|
14
|
-
import { CLI_COLOR_CYAN, CLI_FORMAT_BOLD, CLI_FORMAT_GREEN, colorize } from "../tester/cliFormat";
|
|
15
|
-
import { resolveTargets } from "../targeting";
|
|
16
|
-
|
|
17
|
-
export interface BuildCLIOptions {
|
|
18
|
-
revision?: string;
|
|
19
|
-
revisionFromHash?: boolean;
|
|
20
|
-
|
|
21
|
-
// all three together
|
|
22
|
-
environment?: string;
|
|
23
|
-
feature?: string;
|
|
24
|
-
json?: boolean;
|
|
25
|
-
pretty?: boolean;
|
|
26
|
-
stateFiles?: boolean; // --no-state-files in CLI
|
|
27
|
-
inflate?: number;
|
|
28
|
-
datafilesDir?: string;
|
|
29
|
-
|
|
30
|
-
target?: string | string[];
|
|
31
|
-
set?: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function getFeaturevisorVersion(): string {
|
|
35
|
-
try {
|
|
36
|
-
const cliPackage = require(require.resolve("@featurevisor/cli/package.json"));
|
|
37
|
-
|
|
38
|
-
return cliPackage.version;
|
|
39
|
-
// eslint-disable-next-line
|
|
40
|
-
} catch (error) {
|
|
41
|
-
return "unknown";
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function getEnvironmentLabel(environment: string | false) {
|
|
46
|
-
return environment === false ? "No environment" : `Environment "${environment}"`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async function buildForEnvironment({
|
|
50
|
-
projectConfig,
|
|
51
|
-
datasource,
|
|
52
|
-
nextRevision,
|
|
53
|
-
environment,
|
|
54
|
-
targets,
|
|
55
|
-
cliOptions,
|
|
56
|
-
}: {
|
|
57
|
-
projectConfig: ProjectConfig;
|
|
58
|
-
datasource: Datasource;
|
|
59
|
-
nextRevision: string;
|
|
60
|
-
environment: string | false;
|
|
61
|
-
targets: Array<Target & { key: string }>;
|
|
62
|
-
cliOptions: BuildCLIOptions;
|
|
63
|
-
}) {
|
|
64
|
-
console.log("");
|
|
65
|
-
console.log(CLI_FORMAT_BOLD, getEnvironmentLabel(environment));
|
|
66
|
-
|
|
67
|
-
const existingState = await datasource.readState(environment);
|
|
68
|
-
const featurevisorVersion = getFeaturevisorVersion();
|
|
69
|
-
|
|
70
|
-
for (const target of targets) {
|
|
71
|
-
console.log(` ${colorize("Target", CLI_COLOR_CYAN)}: ${target.key}`);
|
|
72
|
-
|
|
73
|
-
const datafileContent = await buildTargetDatafile({
|
|
74
|
-
projectConfig,
|
|
75
|
-
datasource,
|
|
76
|
-
target,
|
|
77
|
-
environment,
|
|
78
|
-
existingState,
|
|
79
|
-
revision: nextRevision,
|
|
80
|
-
revisionFromHash: cliOptions.revisionFromHash,
|
|
81
|
-
inflate: cliOptions.inflate,
|
|
82
|
-
featurevisorVersion,
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
await datasource.writeDatafile(datafileContent, {
|
|
86
|
-
environment,
|
|
87
|
-
target: target.key,
|
|
88
|
-
datafilesDir: cliOptions.datafilesDir,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (typeof cliOptions.stateFiles === "undefined" || cliOptions.stateFiles) {
|
|
93
|
-
// write state for environment
|
|
94
|
-
await datasource.writeState(environment, existingState);
|
|
95
|
-
|
|
96
|
-
// write revision
|
|
97
|
-
await datasource.writeRevision(nextRevision);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export async function buildTargetDatafile({
|
|
102
|
-
projectConfig,
|
|
103
|
-
datasource,
|
|
104
|
-
target,
|
|
105
|
-
environment,
|
|
106
|
-
existingState,
|
|
107
|
-
revision,
|
|
108
|
-
revisionFromHash,
|
|
109
|
-
inflate,
|
|
110
|
-
featurevisorVersion,
|
|
111
|
-
}: {
|
|
112
|
-
projectConfig: ProjectConfig;
|
|
113
|
-
datasource: Datasource;
|
|
114
|
-
target: Target;
|
|
115
|
-
environment: string | false;
|
|
116
|
-
existingState: Awaited<ReturnType<Datasource["readState"]>>;
|
|
117
|
-
revision: string;
|
|
118
|
-
revisionFromHash?: boolean;
|
|
119
|
-
inflate?: number;
|
|
120
|
-
featurevisorVersion?: string;
|
|
121
|
-
}): Promise<DatafileContent> {
|
|
122
|
-
const datafileContent = await buildDatafile(
|
|
123
|
-
projectConfig,
|
|
124
|
-
datasource,
|
|
125
|
-
{
|
|
126
|
-
revision,
|
|
127
|
-
revisionFromHash,
|
|
128
|
-
environment,
|
|
129
|
-
tag: target.tag,
|
|
130
|
-
tags: target.tags,
|
|
131
|
-
includeFeatures: target.includeFeatures,
|
|
132
|
-
excludeFeatures: target.excludeFeatures,
|
|
133
|
-
inflate,
|
|
134
|
-
featurevisorVersion,
|
|
135
|
-
},
|
|
136
|
-
existingState,
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
if (target.context) {
|
|
140
|
-
return applyContextToDatafile(datafileContent as DatafileContent, target.context);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return datafileContent as DatafileContent;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export async function buildProject(deps: Dependencies, cliOptions: BuildCLIOptions = {}) {
|
|
147
|
-
const { projectConfig, datasource } = deps;
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* This build process does not write to disk, and prints only to stdout.
|
|
151
|
-
*
|
|
152
|
-
* This is ideally for test runners in other languages,
|
|
153
|
-
* when they wish to get datafile for a single feature and/or environment,
|
|
154
|
-
* so they can run tests against their own SDKs in other languages.
|
|
155
|
-
*
|
|
156
|
-
* This way we centralize the datafile generation in one place,
|
|
157
|
-
* while tests can be run anywhere else.
|
|
158
|
-
*/
|
|
159
|
-
if (cliOptions.json) {
|
|
160
|
-
const environment = cliOptions.environment || false;
|
|
161
|
-
|
|
162
|
-
if (Array.isArray(projectConfig.environments) && !cliOptions.environment) {
|
|
163
|
-
throw new Error("Pass --environment=<environment> when printing a datafile.");
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const targets = await resolveTargets(datasource, cliOptions.target, {
|
|
167
|
-
defaultToAll: false,
|
|
168
|
-
requireTargets: false,
|
|
169
|
-
});
|
|
170
|
-
if (targets.length > 1) {
|
|
171
|
-
throw new Error("Only one --target can be used with --json or --print.");
|
|
172
|
-
}
|
|
173
|
-
const target = targets[0];
|
|
174
|
-
|
|
175
|
-
let datafileContent = await getCustomDatafile({
|
|
176
|
-
featureKey: cliOptions.feature,
|
|
177
|
-
environment,
|
|
178
|
-
projectConfig,
|
|
179
|
-
datasource,
|
|
180
|
-
revision: cliOptions.revision,
|
|
181
|
-
inflate: cliOptions.inflate,
|
|
182
|
-
tag: target?.tag,
|
|
183
|
-
tags: target?.tags,
|
|
184
|
-
includeFeatures: target?.includeFeatures,
|
|
185
|
-
excludeFeatures: target?.excludeFeatures,
|
|
186
|
-
featurevisorVersion: getFeaturevisorVersion(),
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
if (target?.context) {
|
|
190
|
-
datafileContent = applyContextToDatafile(datafileContent as DatafileContent, target.context);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (cliOptions.pretty) {
|
|
194
|
-
console.log(JSON.stringify(datafileContent, null, 2));
|
|
195
|
-
} else {
|
|
196
|
-
console.log(JSON.stringify(datafileContent));
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Regular build process that writes to disk.
|
|
204
|
-
*/
|
|
205
|
-
const { environments } = projectConfig;
|
|
206
|
-
const targets = await resolveTargets(datasource, cliOptions.target);
|
|
207
|
-
|
|
208
|
-
const currentRevision = await datasource.readRevision();
|
|
209
|
-
console.log("");
|
|
210
|
-
console.log(CLI_FORMAT_BOLD, "Building Featurevisor datafiles");
|
|
211
|
-
console.log(` Current revision: ${currentRevision}`);
|
|
212
|
-
|
|
213
|
-
const nextRevision =
|
|
214
|
-
(cliOptions.revision && cliOptions.revision.toString()) || getNextRevision(currentRevision);
|
|
215
|
-
|
|
216
|
-
// with environments
|
|
217
|
-
if (Array.isArray(environments)) {
|
|
218
|
-
for (const environment of environments) {
|
|
219
|
-
await buildForEnvironment({
|
|
220
|
-
projectConfig,
|
|
221
|
-
datasource,
|
|
222
|
-
nextRevision,
|
|
223
|
-
environment,
|
|
224
|
-
targets,
|
|
225
|
-
cliOptions,
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// no environment
|
|
231
|
-
if (!Array.isArray(environments)) {
|
|
232
|
-
await buildForEnvironment({
|
|
233
|
-
projectConfig,
|
|
234
|
-
datasource,
|
|
235
|
-
nextRevision,
|
|
236
|
-
environment: false,
|
|
237
|
-
targets,
|
|
238
|
-
cliOptions,
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
console.log("");
|
|
243
|
-
console.log(CLI_FORMAT_GREEN, "Datafiles built");
|
|
244
|
-
console.log(CLI_FORMAT_BOLD, `Latest revision: ${nextRevision}`);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export async function buildProjectSets(deps: Dependencies, cliOptions: BuildCLIOptions = {}) {
|
|
248
|
-
const { projectConfig, datasource } = deps;
|
|
249
|
-
|
|
250
|
-
assertProjectSetJsonSelection(projectConfig, cliOptions.set, cliOptions.json);
|
|
251
|
-
|
|
252
|
-
const executions = await getProjectSetExecutions(projectConfig, datasource, cliOptions.set);
|
|
253
|
-
const currentRevision = await datasource.readRevision();
|
|
254
|
-
const nextRevision =
|
|
255
|
-
(cliOptions.revision && cliOptions.revision.toString()) || getNextRevision(currentRevision);
|
|
256
|
-
|
|
257
|
-
if (projectConfig.sets && !cliOptions.json) {
|
|
258
|
-
console.log("");
|
|
259
|
-
console.log(CLI_FORMAT_BOLD, "Building Featurevisor sets");
|
|
260
|
-
console.log(` Sets: ${executions.map((execution) => execution.set).join(", ")}`);
|
|
261
|
-
console.log(` Current project revision: ${currentRevision}`);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
for (const execution of executions) {
|
|
265
|
-
printSetHeader(projectConfig, execution.set, cliOptions.json);
|
|
266
|
-
|
|
267
|
-
const executionCliOptions =
|
|
268
|
-
projectConfig.sets && cliOptions.datafilesDir
|
|
269
|
-
? {
|
|
270
|
-
...cliOptions,
|
|
271
|
-
datafilesDir: path.join(cliOptions.datafilesDir, execution.set),
|
|
272
|
-
}
|
|
273
|
-
: cliOptions;
|
|
274
|
-
|
|
275
|
-
await buildProject(
|
|
276
|
-
{
|
|
277
|
-
...deps,
|
|
278
|
-
projectConfig: execution.projectConfig,
|
|
279
|
-
datasource: execution.datasource,
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
...executionCliOptions,
|
|
283
|
-
revision: projectConfig.sets ? nextRevision : cliOptions.revision,
|
|
284
|
-
},
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (
|
|
289
|
-
projectConfig.sets &&
|
|
290
|
-
!cliOptions.json &&
|
|
291
|
-
(typeof cliOptions.stateFiles === "undefined" || cliOptions.stateFiles) &&
|
|
292
|
-
!cliOptions.revision
|
|
293
|
-
) {
|
|
294
|
-
await datasource.writeRevision(nextRevision);
|
|
295
|
-
console.log("");
|
|
296
|
-
console.log(CLI_FORMAT_GREEN, "Featurevisor sets built");
|
|
297
|
-
console.log(CLI_FORMAT_BOLD, `Latest project revision: ${nextRevision}`);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
export const buildPlugin: Plugin = {
|
|
302
|
-
command: "build",
|
|
303
|
-
handler: async function ({ rootDirectoryPath, projectConfig, datasource, parsed }) {
|
|
304
|
-
if (parsed.print) {
|
|
305
|
-
parsed.json = true;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
await buildProjectSets(
|
|
309
|
-
{
|
|
310
|
-
rootDirectoryPath,
|
|
311
|
-
projectConfig,
|
|
312
|
-
datasource,
|
|
313
|
-
options: parsed,
|
|
314
|
-
},
|
|
315
|
-
parsed as BuildCLIOptions,
|
|
316
|
-
);
|
|
317
|
-
},
|
|
318
|
-
examples: [
|
|
319
|
-
{
|
|
320
|
-
command: "build",
|
|
321
|
-
description: "build datafiles for all environments and targets",
|
|
322
|
-
},
|
|
323
|
-
{
|
|
324
|
-
command: "build --revision=123",
|
|
325
|
-
description: "build datafiles starting with revision value as 123",
|
|
326
|
-
},
|
|
327
|
-
{
|
|
328
|
-
command: "build --environment=production",
|
|
329
|
-
description: "build datafiles for production environment",
|
|
330
|
-
},
|
|
331
|
-
{
|
|
332
|
-
command: "build --print --environment=production --feature=featureKey --target=web",
|
|
333
|
-
description: "print datafile for a feature in production environment",
|
|
334
|
-
},
|
|
335
|
-
{
|
|
336
|
-
command: "build --print --environment=production --pretty",
|
|
337
|
-
description: "print datafile with pretty print",
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
command: "build --no-state-files",
|
|
341
|
-
description: "build datafiles without writing state files",
|
|
342
|
-
},
|
|
343
|
-
],
|
|
344
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { DatafileContent } from "@featurevisor/types";
|
|
2
|
-
|
|
3
|
-
import type { Dependencies } from "../dependencies";
|
|
4
|
-
import { resolveTargets } from "../targeting";
|
|
5
|
-
import { buildDatafile } from "./buildDatafile";
|
|
6
|
-
import { buildTargetDatafile } from "./buildProject";
|
|
7
|
-
|
|
8
|
-
export interface RuntimeDatafile {
|
|
9
|
-
target?: string;
|
|
10
|
-
datafile: DatafileContent;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function buildRuntimeDatafiles(
|
|
14
|
-
deps: Dependencies,
|
|
15
|
-
options: {
|
|
16
|
-
environment: string | false;
|
|
17
|
-
target?: string | string[];
|
|
18
|
-
revision: string;
|
|
19
|
-
inflate?: number;
|
|
20
|
-
},
|
|
21
|
-
): Promise<RuntimeDatafile[]> {
|
|
22
|
-
const { projectConfig, datasource } = deps;
|
|
23
|
-
const existingState = await datasource.readState(options.environment);
|
|
24
|
-
const targets = await resolveTargets(datasource, options.target, {
|
|
25
|
-
defaultToAll: false,
|
|
26
|
-
requireTargets: false,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
if (targets.length === 0) {
|
|
30
|
-
const datafile = await buildDatafile(
|
|
31
|
-
projectConfig,
|
|
32
|
-
datasource,
|
|
33
|
-
{
|
|
34
|
-
revision: options.revision,
|
|
35
|
-
environment: options.environment,
|
|
36
|
-
inflate: options.inflate,
|
|
37
|
-
},
|
|
38
|
-
existingState,
|
|
39
|
-
);
|
|
40
|
-
return [{ datafile }];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return Promise.all(
|
|
44
|
-
targets.map(async (target) => ({
|
|
45
|
-
target: target.key,
|
|
46
|
-
datafile: await buildTargetDatafile({
|
|
47
|
-
projectConfig,
|
|
48
|
-
datasource,
|
|
49
|
-
target,
|
|
50
|
-
environment: options.environment,
|
|
51
|
-
existingState,
|
|
52
|
-
revision: options.revision,
|
|
53
|
-
inflate: options.inflate,
|
|
54
|
-
}),
|
|
55
|
-
})),
|
|
56
|
-
);
|
|
57
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
|
|
3
|
-
import type { FeatureKey, Group, Range } from "@featurevisor/types";
|
|
4
|
-
|
|
5
|
-
import { ProjectConfig } from "../config";
|
|
6
|
-
import { Datasource } from "../datasource";
|
|
7
|
-
|
|
8
|
-
export type FeatureRanges = Map<FeatureKey, Range[]>;
|
|
9
|
-
|
|
10
|
-
export interface FeatureRangesResult {
|
|
11
|
-
featureRanges: FeatureRanges;
|
|
12
|
-
featureIsInGroup: { [key: string]: boolean };
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export async function getFeatureRanges(
|
|
16
|
-
projectConfig: ProjectConfig,
|
|
17
|
-
datasource: Datasource,
|
|
18
|
-
): Promise<FeatureRangesResult> {
|
|
19
|
-
const featureRanges = new Map<FeatureKey, Range[]>();
|
|
20
|
-
const featureIsInGroup = {}; // featureKey => boolean
|
|
21
|
-
|
|
22
|
-
const groups: Group[] = [];
|
|
23
|
-
if (fs.existsSync(projectConfig.groupsDirectoryPath)) {
|
|
24
|
-
const groupFiles = await datasource.listGroups();
|
|
25
|
-
|
|
26
|
-
for (const groupKey of groupFiles) {
|
|
27
|
-
const parsedGroup = await datasource.readGroup(groupKey);
|
|
28
|
-
|
|
29
|
-
groups.push({
|
|
30
|
-
...parsedGroup,
|
|
31
|
-
key: groupKey,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
let accumulatedPercentage = 0;
|
|
35
|
-
parsedGroup.slots.forEach(function (slot, slotIndex) {
|
|
36
|
-
const isFirstSlot = slotIndex === 0;
|
|
37
|
-
|
|
38
|
-
if (slot.feature) {
|
|
39
|
-
const featureKey = slot.feature;
|
|
40
|
-
|
|
41
|
-
if (typeof featureKey === "string") {
|
|
42
|
-
featureIsInGroup[featureKey] = true;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const featureRangesForFeature = featureRanges.get(featureKey) || [];
|
|
46
|
-
|
|
47
|
-
const start = isFirstSlot ? accumulatedPercentage : accumulatedPercentage + 1;
|
|
48
|
-
const end = accumulatedPercentage + slot.percentage * 1000;
|
|
49
|
-
|
|
50
|
-
featureRangesForFeature.push([start, end]);
|
|
51
|
-
|
|
52
|
-
featureRanges.set(slot.feature, featureRangesForFeature);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
accumulatedPercentage += slot.percentage * 1000;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return { featureRanges, featureIsInGroup };
|
|
61
|
-
}
|
package/src/builder/hashes.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import * as crypto from "crypto";
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
FeatureKey,
|
|
5
|
-
Feature,
|
|
6
|
-
SegmentKey,
|
|
7
|
-
Segment,
|
|
8
|
-
DatafileContent,
|
|
9
|
-
} from "@featurevisor/types";
|
|
10
|
-
|
|
11
|
-
import { extractSegmentsFromFeature } from "../utils";
|
|
12
|
-
|
|
13
|
-
const base62chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
14
|
-
|
|
15
|
-
function generateHashFromString(str: string, length = 10): string {
|
|
16
|
-
const hashBuffer = crypto.createHash("sha256").update(str).digest();
|
|
17
|
-
|
|
18
|
-
// Convert buffer to base62 (alphanumeric)
|
|
19
|
-
let num = BigInt("0x" + hashBuffer.toString("hex"));
|
|
20
|
-
let base62 = "";
|
|
21
|
-
while (num > 0) {
|
|
22
|
-
// Convert the remainder to a number for indexing
|
|
23
|
-
const remainder = Number(num % 62n);
|
|
24
|
-
base62 = base62chars[remainder] + base62;
|
|
25
|
-
num = num / 62n;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Return first 10 chars for a short hash (adjust length as needed)
|
|
29
|
-
return base62.slice(0, length);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function getSegmentHashes(
|
|
33
|
-
segments: Record<SegmentKey, Segment>,
|
|
34
|
-
): Record<SegmentKey, string> {
|
|
35
|
-
const result: Record<SegmentKey, string> = {};
|
|
36
|
-
|
|
37
|
-
for (const segmentKey of Object.keys(segments)) {
|
|
38
|
-
const segment = segments[segmentKey];
|
|
39
|
-
result[segmentKey] = generateHashFromString(
|
|
40
|
-
JSON.stringify({
|
|
41
|
-
conditions: segment.conditions,
|
|
42
|
-
}),
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function generateHashForFeature(
|
|
50
|
-
featureKey: FeatureKey,
|
|
51
|
-
features: Record<FeatureKey, Feature>,
|
|
52
|
-
segmentHashes: Record<SegmentKey, string>,
|
|
53
|
-
): string {
|
|
54
|
-
const feature = features[featureKey];
|
|
55
|
-
|
|
56
|
-
if (!feature) {
|
|
57
|
-
return "";
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const requiredFeatureKeys: string[] = [];
|
|
61
|
-
if (feature.required) {
|
|
62
|
-
for (const r of feature.required) {
|
|
63
|
-
if (typeof r === "string") {
|
|
64
|
-
requiredFeatureKeys.push(r);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (typeof r === "object" && r.key) {
|
|
68
|
-
requiredFeatureKeys.push(r.key);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const requiredFeatureHashes = requiredFeatureKeys.map((key) =>
|
|
74
|
-
generateHashForFeature(key, features, segmentHashes),
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
const usedSegments = extractSegmentsFromFeature(feature);
|
|
78
|
-
const usedSegmentHashes = Object.keys(usedSegments).map(
|
|
79
|
-
(segmentKey) => segmentHashes[segmentKey],
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
return generateHashFromString(
|
|
83
|
-
JSON.stringify({
|
|
84
|
-
featureKey,
|
|
85
|
-
feature,
|
|
86
|
-
requiredFeatureHashes,
|
|
87
|
-
usedSegmentHashes,
|
|
88
|
-
}),
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function generateHashForDatafile(datafileContent: DatafileContent): string {
|
|
93
|
-
const featureHashes = Object.keys(datafileContent.features).reduce(
|
|
94
|
-
(acc, featureKey) => {
|
|
95
|
-
acc[featureKey] = datafileContent.features[featureKey].hash || "";
|
|
96
|
-
return acc;
|
|
97
|
-
},
|
|
98
|
-
{} as Record<FeatureKey, string>,
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
const hash = generateHashFromString(
|
|
102
|
-
JSON.stringify({
|
|
103
|
-
schemaVersion: datafileContent.schemaVersion,
|
|
104
|
-
featureHashes,
|
|
105
|
-
}),
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
return hash;
|
|
109
|
-
}
|
package/src/builder/index.ts
DELETED