@featurevisor/core 4.3.0 → 4.5.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/cli/cli.d.ts +2 -1
- package/lib/cli/cli.js +9 -6
- package/lib/cli/cli.js.map +1 -1
- package/lib/cli/options.js +69 -0
- package/lib/cli/options.js.map +1 -1
- package/lib/cli/plugins.js +7 -1
- package/lib/cli/plugins.js.map +1 -1
- package/lib/config/projectConfig.d.ts +10 -0
- package/lib/config/projectConfig.js +14 -0
- package/lib/config/projectConfig.js.map +1 -1
- package/lib/convert/check.d.ts +33 -0
- package/lib/convert/check.js +411 -0
- package/lib/convert/check.js.map +1 -0
- package/lib/convert/config.d.ts +20 -0
- package/lib/convert/config.js +147 -0
- package/lib/convert/config.js.map +1 -0
- package/lib/convert/documents.d.ts +40 -0
- package/lib/convert/documents.js +154 -0
- package/lib/convert/documents.js.map +1 -0
- package/lib/convert/index.d.ts +7 -0
- package/lib/convert/index.js +47 -0
- package/lib/convert/index.js.map +1 -0
- package/lib/convert/plan.d.ts +53 -0
- package/lib/convert/plan.js +669 -0
- package/lib/convert/plan.js.map +1 -0
- package/lib/convert/project.d.ts +29 -0
- package/lib/convert/project.js +109 -0
- package/lib/convert/project.js.map +1 -0
- package/lib/convert/run.d.ts +3 -0
- package/lib/convert/run.js +241 -0
- package/lib/convert/run.js.map +1 -0
- package/lib/convert/tests.d.ts +22 -0
- package/lib/convert/tests.js +267 -0
- package/lib/convert/tests.js.map +1 -0
- package/lib/datasource/conditionLocations.d.ts +9 -0
- package/lib/datasource/conditionLocations.js +70 -0
- package/lib/datasource/conditionLocations.js.map +1 -0
- package/lib/datasource/datasource.d.ts +11 -0
- package/lib/datasource/datasource.js +26 -6
- package/lib/datasource/datasource.js.map +1 -1
- package/lib/datasource/expressions.d.ts +36 -0
- package/lib/datasource/expressions.js +118 -0
- package/lib/datasource/expressions.js.map +1 -0
- package/lib/datasource/parseError.d.ts +11 -0
- package/lib/datasource/parseError.js +33 -19
- package/lib/datasource/parseError.js.map +1 -1
- package/lib/diff/conditions.d.ts +23 -0
- package/lib/diff/conditions.js +86 -0
- package/lib/diff/conditions.js.map +1 -0
- package/lib/diff/details.d.ts +7 -1
- package/lib/diff/details.js +54 -25
- package/lib/diff/details.js.map +1 -1
- package/lib/diff/index.d.ts +5 -0
- package/lib/diff/index.js +17 -2
- package/lib/diff/index.js.map +1 -1
- package/lib/evaluate/explain.d.ts +4 -1
- package/lib/evaluate/explain.js +35 -14
- package/lib/evaluate/explain.js.map +1 -1
- package/lib/evaluate/index.js +9 -5
- package/lib/evaluate/index.js.map +1 -1
- package/lib/formatter/expressions.d.ts +21 -0
- package/lib/formatter/expressions.js +79 -0
- package/lib/formatter/expressions.js.map +1 -0
- package/lib/formatter/formatDefinition.d.ts +46 -0
- package/lib/formatter/formatDefinition.js +201 -0
- package/lib/formatter/formatDefinition.js.map +1 -0
- package/lib/formatter/formatProject.d.ts +70 -0
- package/lib/formatter/formatProject.js +186 -0
- package/lib/formatter/formatProject.js.map +1 -0
- package/lib/formatter/index.d.ts +6 -0
- package/lib/formatter/index.js +53 -0
- package/lib/formatter/index.js.map +1 -0
- package/lib/formatter/layout.d.ts +26 -0
- package/lib/formatter/layout.js +175 -0
- package/lib/formatter/layout.js.map +1 -0
- package/lib/formatter/printFormatResult.d.ts +9 -0
- package/lib/formatter/printFormatResult.js +100 -0
- package/lib/formatter/printFormatResult.js.map +1 -0
- package/lib/formatter/run.d.ts +6 -0
- package/lib/formatter/run.js +97 -0
- package/lib/formatter/run.js.map +1 -0
- package/lib/formatter/simplify.d.ts +14 -0
- package/lib/formatter/simplify.js +21 -0
- package/lib/formatter/simplify.js.map +1 -0
- package/lib/formatter/since.d.ts +6 -0
- package/lib/formatter/since.js +80 -0
- package/lib/formatter/since.js.map +1 -0
- package/lib/formatter/style.d.ts +105 -0
- package/lib/formatter/style.js +248 -0
- package/lib/formatter/style.js.map +1 -0
- package/lib/linter/conditionKinds.js +2 -54
- package/lib/linter/conditionKinds.js.map +1 -1
- package/lib/linter/conditionSchema.js +42 -13
- package/lib/linter/conditionSchema.js.map +1 -1
- package/lib/linter/diagnostics.d.ts +14 -14
- package/lib/linter/expressionDiagnostics.d.ts +28 -0
- package/lib/linter/expressionDiagnostics.js +127 -0
- package/lib/linter/expressionDiagnostics.js.map +1 -0
- package/lib/linter/featureSchema.d.ts +2 -2
- package/lib/linter/featureSchema.js +14 -13
- package/lib/linter/featureSchema.js.map +1 -1
- package/lib/linter/lintProject.d.ts +7 -0
- package/lib/linter/lintProject.js +300 -52
- package/lib/linter/lintProject.js.map +1 -1
- package/lib/linter/listTypes.d.ts +7 -0
- package/lib/linter/listTypes.js +19 -0
- package/lib/linter/listTypes.js.map +1 -0
- package/lib/linter/printError.d.ts +2 -0
- package/lib/linter/printError.js +1 -0
- package/lib/linter/printError.js.map +1 -1
- package/lib/linter/requiredVariablesSchema.js +129 -13
- package/lib/linter/requiredVariablesSchema.js.map +1 -1
- package/lib/migrate/definitions.d.ts +46 -0
- package/lib/migrate/definitions.js +488 -0
- package/lib/migrate/definitions.js.map +1 -0
- package/lib/migrate/index.d.ts +6 -0
- package/lib/migrate/index.js +30 -0
- package/lib/migrate/index.js.map +1 -0
- package/lib/migrate/migrateProject.d.ts +33 -0
- package/lib/migrate/migrateProject.js +195 -0
- package/lib/migrate/migrateProject.js.map +1 -0
- package/lib/migrate/project.d.ts +31 -0
- package/lib/migrate/project.js +153 -0
- package/lib/migrate/project.js.map +1 -0
- package/lib/migrate/run.d.ts +3 -0
- package/lib/migrate/run.js +81 -0
- package/lib/migrate/run.js.map +1 -0
- package/lib/migrate/write.d.ts +10 -0
- package/lib/migrate/write.js +150 -0
- package/lib/migrate/write.js.map +1 -0
- package/lib/promoter/index.js +85 -4
- package/lib/promoter/index.js.map +1 -1
- package/lib/rewrite/conditions.d.ts +73 -0
- package/lib/rewrite/conditions.js +485 -0
- package/lib/rewrite/conditions.js.map +1 -0
- package/lib/rewrite/diff.d.ts +2 -0
- package/lib/rewrite/diff.js +76 -0
- package/lib/rewrite/diff.js.map +1 -0
- package/lib/rewrite/documents.d.ts +25 -0
- package/lib/rewrite/documents.js +54 -0
- package/lib/rewrite/documents.js.map +1 -0
- package/lib/rewrite/files.d.ts +6 -0
- package/lib/rewrite/files.js +66 -0
- package/lib/rewrite/files.js.map +1 -0
- package/lib/rewrite/lines.d.ts +56 -0
- package/lib/rewrite/lines.js +205 -0
- package/lib/rewrite/lines.js.map +1 -0
- package/package.json +5 -4
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CustomParser } from "@featurevisor/parsers";
|
|
2
|
+
import { Document, YAMLMap, YAMLSeq } from "yaml";
|
|
3
|
+
import type { Node, Pair } from "yaml";
|
|
4
|
+
import type { EntityType } from "@featurevisor/types";
|
|
5
|
+
import { type FormatDefinitionOptions } from "../formatter/formatDefinition";
|
|
6
|
+
import { load, render } from "../rewrite/documents";
|
|
7
|
+
export { load, render };
|
|
8
|
+
/**
|
|
9
|
+
* Definitions are edited as YAML documents whatever their parser, so one set of edits serves
|
|
10
|
+
* every format. A YAML file keeps its comments, and every file keeps the lines a conversion
|
|
11
|
+
* does not touch.
|
|
12
|
+
*/
|
|
13
|
+
/** Whether fmt leaves a file as it is, so a converted file should be formatted too */
|
|
14
|
+
export declare function isFormatted(entityType: EntityType, text: string, parser: CustomParser, options?: FormatDefinitionOptions): boolean;
|
|
15
|
+
/** The text as fmt writes it, or as it is when fmt cannot format it */
|
|
16
|
+
export declare function formatted(entityType: EntityType, text: string, parser: CustomParser, options?: FormatDefinitionOptions): string;
|
|
17
|
+
export declare function rootMap(doc: Document): YAMLMap | undefined;
|
|
18
|
+
export declare function pairOf(map: YAMLMap, key: string): Pair | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Replaces the map by lane at `key` with one lane's value, keeping the comments above that
|
|
21
|
+
* lane's key. Without one, the key goes, or becomes `empty` when given.
|
|
22
|
+
*/
|
|
23
|
+
export declare function takeLane(map: YAMLMap, key: string, lane: string, empty?: unknown): void;
|
|
24
|
+
/** Whether a map's keys are separated by blank lines, as in a formatted file */
|
|
25
|
+
export declare function isSpaced(map: YAMLMap | undefined): boolean;
|
|
26
|
+
/** Separates a list's items by a blank line, or by none, as `spaced` says */
|
|
27
|
+
export declare function spaceItems(list: {
|
|
28
|
+
items: unknown[];
|
|
29
|
+
}, spaced: boolean): void;
|
|
30
|
+
/** Groups the value at `key` by lane, a copy for each */
|
|
31
|
+
export declare function spreadLanes(map: YAMLMap, key: string, lanes: string[], spaced: boolean): void;
|
|
32
|
+
/** A map from lanes to their nodes, in lane order, leaving out lanes without one */
|
|
33
|
+
export declare function laneMap(values: [string, Node | undefined][], spaced: boolean): YAMLMap | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Sets `key` in a map, keeping its place when it is there already. A new key goes after the
|
|
36
|
+
* last of `after` the map has, and takes a blank line before it when the map's keys have them.
|
|
37
|
+
*/
|
|
38
|
+
export declare function setKey(map: YAMLMap, key: string, node: Node | undefined, after?: string[]): void;
|
|
39
|
+
export declare function nodeAt(map: YAMLMap, key: string): Node | undefined;
|
|
40
|
+
export declare function seqOf(node: unknown): YAMLSeq | undefined;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.render = exports.load = void 0;
|
|
4
|
+
exports.isFormatted = isFormatted;
|
|
5
|
+
exports.formatted = formatted;
|
|
6
|
+
exports.rootMap = rootMap;
|
|
7
|
+
exports.pairOf = pairOf;
|
|
8
|
+
exports.takeLane = takeLane;
|
|
9
|
+
exports.isSpaced = isSpaced;
|
|
10
|
+
exports.spaceItems = spaceItems;
|
|
11
|
+
exports.spreadLanes = spreadLanes;
|
|
12
|
+
exports.laneMap = laneMap;
|
|
13
|
+
exports.setKey = setKey;
|
|
14
|
+
exports.nodeAt = nodeAt;
|
|
15
|
+
exports.seqOf = seqOf;
|
|
16
|
+
const yaml_1 = require("yaml");
|
|
17
|
+
const formatDefinition_1 = require("../formatter/formatDefinition");
|
|
18
|
+
const documents_1 = require("../rewrite/documents");
|
|
19
|
+
Object.defineProperty(exports, "load", { enumerable: true, get: function () { return documents_1.load; } });
|
|
20
|
+
Object.defineProperty(exports, "render", { enumerable: true, get: function () { return documents_1.render; } });
|
|
21
|
+
/**
|
|
22
|
+
* Definitions are edited as YAML documents whatever their parser, so one set of edits serves
|
|
23
|
+
* every format. A YAML file keeps its comments, and every file keeps the lines a conversion
|
|
24
|
+
* does not touch.
|
|
25
|
+
*/
|
|
26
|
+
/** Whether fmt leaves a file as it is, so a converted file should be formatted too */
|
|
27
|
+
function isFormatted(entityType, text, parser, options) {
|
|
28
|
+
try {
|
|
29
|
+
const result = (0, formatDefinition_1.formatDefinition)(entityType, text, parser, undefined, options);
|
|
30
|
+
return !result.changed && !result.declined && !result.ignored;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** The text as fmt writes it, or as it is when fmt cannot format it */
|
|
37
|
+
function formatted(entityType, text, parser, options) {
|
|
38
|
+
try {
|
|
39
|
+
return (0, formatDefinition_1.formatDefinition)(entityType, text, parser, undefined, options).output;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return text;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function rootMap(doc) {
|
|
46
|
+
return (0, yaml_1.isMap)(doc.contents) ? doc.contents : undefined;
|
|
47
|
+
}
|
|
48
|
+
function pairOf(map, key) {
|
|
49
|
+
return map.items.find((pair) => (0, yaml_1.isScalar)(pair.key) && String(pair.key.value) === key);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Replaces the map by lane at `key` with one lane's value, keeping the comments above that
|
|
53
|
+
* lane's key. Without one, the key goes, or becomes `empty` when given.
|
|
54
|
+
*/
|
|
55
|
+
function takeLane(map, key, lane, empty) {
|
|
56
|
+
const pair = pairOf(map, key);
|
|
57
|
+
if (!pair || !(0, yaml_1.isMap)(pair.value))
|
|
58
|
+
return;
|
|
59
|
+
const lanes = pair.value;
|
|
60
|
+
const lanePair = pairOf(lanes, lane);
|
|
61
|
+
if (lanePair && lanePair.value) {
|
|
62
|
+
const node = lanePair.value;
|
|
63
|
+
// a comment above the first lane belongs to the map of lanes
|
|
64
|
+
const above = lanes.items[0] === lanePair ? lanes.commentBefore : undefined;
|
|
65
|
+
const comment = joinComments(above, lanePair.key.commentBefore);
|
|
66
|
+
node.commentBefore = joinComments(comment, node.commentBefore);
|
|
67
|
+
trimTrailingComment(node);
|
|
68
|
+
pair.value = node;
|
|
69
|
+
}
|
|
70
|
+
else if (empty !== undefined) {
|
|
71
|
+
pair.value = new yaml_1.Document(empty).contents;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
map.delete(key);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function joinComments(...comments) {
|
|
78
|
+
const joined = comments.filter(Boolean).join("\n");
|
|
79
|
+
return joined || undefined;
|
|
80
|
+
}
|
|
81
|
+
/** A comment after a value ends at its last line, as blank lines between keys are their own */
|
|
82
|
+
function trimTrailingComment(node) {
|
|
83
|
+
if (node.comment)
|
|
84
|
+
node.comment = node.comment.replace(/\n+$/, "");
|
|
85
|
+
}
|
|
86
|
+
/** Whether a map's keys are separated by blank lines, as in a formatted file */
|
|
87
|
+
function isSpaced(map) {
|
|
88
|
+
return Boolean(map && map.items.slice(1).some((pair) => pair.key?.spaceBefore));
|
|
89
|
+
}
|
|
90
|
+
/** Separates a list's items by a blank line, or by none, as `spaced` says */
|
|
91
|
+
function spaceItems(list, spaced) {
|
|
92
|
+
list.items.forEach((item, index) => {
|
|
93
|
+
if (item && typeof item === "object")
|
|
94
|
+
item.spaceBefore = spaced && index > 0;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** Groups the value at `key` by lane, a copy for each */
|
|
98
|
+
function spreadLanes(map, key, lanes, spaced) {
|
|
99
|
+
const pair = pairOf(map, key);
|
|
100
|
+
if (!pair || pair.value === null || pair.value === undefined)
|
|
101
|
+
return;
|
|
102
|
+
const value = pair.value;
|
|
103
|
+
pair.value = laneMap(lanes.map((lane) => [lane, value.clone()]), spaced);
|
|
104
|
+
}
|
|
105
|
+
/** A map from lanes to their nodes, in lane order, leaving out lanes without one */
|
|
106
|
+
function laneMap(values, spaced) {
|
|
107
|
+
const map = new yaml_1.YAMLMap();
|
|
108
|
+
for (const [lane, node] of values) {
|
|
109
|
+
if (!node)
|
|
110
|
+
continue;
|
|
111
|
+
const key = new yaml_1.Scalar(lane);
|
|
112
|
+
key.spaceBefore = spaced && map.items.length > 0;
|
|
113
|
+
trimTrailingComment(node);
|
|
114
|
+
map.set(key, node);
|
|
115
|
+
}
|
|
116
|
+
return map.items.length > 0 ? map : undefined;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Sets `key` in a map, keeping its place when it is there already. A new key goes after the
|
|
120
|
+
* last of `after` the map has, and takes a blank line before it when the map's keys have them.
|
|
121
|
+
*/
|
|
122
|
+
function setKey(map, key, node, after) {
|
|
123
|
+
const pair = pairOf(map, key);
|
|
124
|
+
if (node === undefined) {
|
|
125
|
+
if (pair)
|
|
126
|
+
map.delete(key);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (pair) {
|
|
130
|
+
pair.value = node;
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const spaced = isSpaced(map);
|
|
134
|
+
const scalar = new yaml_1.Scalar(key);
|
|
135
|
+
map.set(scalar, node);
|
|
136
|
+
const items = map.items;
|
|
137
|
+
if (after) {
|
|
138
|
+
const added = items.pop();
|
|
139
|
+
let index = 0;
|
|
140
|
+
items.forEach((item, at) => {
|
|
141
|
+
if ((0, yaml_1.isScalar)(item.key) && after.includes(String(item.key.value)))
|
|
142
|
+
index = at + 1;
|
|
143
|
+
});
|
|
144
|
+
items.splice(index, 0, added);
|
|
145
|
+
}
|
|
146
|
+
scalar.spaceBefore = spaced && items[0] !== items.find((item) => item.key === scalar);
|
|
147
|
+
}
|
|
148
|
+
function nodeAt(map, key) {
|
|
149
|
+
return pairOf(map, key)?.value || undefined;
|
|
150
|
+
}
|
|
151
|
+
function seqOf(node) {
|
|
152
|
+
return (0, yaml_1.isSeq)(node) ? node : undefined;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=documents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.js","sourceRoot":"","sources":["../../src/convert/documents.ts"],"names":[],"mappings":";;;AAiBA,kCAYC;AAGD,8BAWC;AAED,0BAEC;AAED,wBAEC;AAMD,4BAkBC;AAaD,4BAIC;AAGD,gCAIC;AAGD,kCAQC;AAGD,0BAaC;AAMD,wBAuBC;AAED,wBAEC;AAED,sBAEC;AAlKD,+BAAkF;AAIlF,oEAA+F;AAC/F,oDAAoD;AAE3C,qFAFA,gBAAI,OAEA;AAAE,uFAFA,kBAAM,OAEA;AAErB;;;;GAIG;AAEH,sFAAsF;AACtF,SAAgB,WAAW,CACzB,UAAsB,EACtB,IAAY,EACZ,MAAoB,EACpB,OAAiC;IAEjC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAA,mCAAgB,EAAC,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAC9E,OAAO,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAChE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,uEAAuE;AACvE,SAAgB,SAAS,CACvB,UAAsB,EACtB,IAAY,EACZ,MAAoB,EACpB,OAAiC;IAEjC,IAAI,CAAC;QACH,OAAO,IAAA,mCAAgB,EAAC,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAA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AM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,KAA0B,IAAI,SAAS,CAAC;AACpE,CAAC;AAED,SAAgB,KAAK,CAAC,IAAa;IACjC,OAAO,IAAA,YAAK,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Plugin } from "../cli";
|
|
2
|
+
/**
|
|
3
|
+
* `featurevisor convert` changes a project's shape, between no environments and no sets,
|
|
4
|
+
* environments, and sets, or writes its conditions as expressions or as trees. A project rarely runs it, so the command loads its code only when it
|
|
5
|
+
* runs, and nothing else imports from here.
|
|
6
|
+
*/
|
|
7
|
+
export declare const convertPlugin: Plugin;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertPlugin = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* `featurevisor convert` changes a project's shape, between no environments and no sets,
|
|
6
|
+
* environments, and sets, or writes its conditions as expressions or as trees. A project rarely runs it, so the command loads its code only when it
|
|
7
|
+
* runs, and nothing else imports from here.
|
|
8
|
+
*/
|
|
9
|
+
exports.convertPlugin = {
|
|
10
|
+
command: "convert",
|
|
11
|
+
description: "Convert a project between environments, sets, and neither, or its conditions between trees and expressions",
|
|
12
|
+
handler: async function (options) {
|
|
13
|
+
const { runConversion } = require("./run");
|
|
14
|
+
return runConversion(options);
|
|
15
|
+
},
|
|
16
|
+
examples: [
|
|
17
|
+
{
|
|
18
|
+
command: "convert --to=sets",
|
|
19
|
+
description: "Preview turning each environment into a set",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
command: "convert --to=sets --apply",
|
|
23
|
+
description: "Turn each environment into a set",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
command: "convert --to=environments --environments=staging,production",
|
|
27
|
+
description: "Give a project without environments staging and production",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
command: "convert --to=flat --keep=production --apply",
|
|
31
|
+
description: "Keep only production, without environments or sets",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
command: "convert --to=expressions --apply",
|
|
35
|
+
description: "Write condition trees as expressions, and allow them",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
command: "convert --to=expressions --exact --apply",
|
|
39
|
+
description: "Write condition trees as expressions, keeping datafiles byte identical",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
command: "convert --to=trees --apply",
|
|
43
|
+
description: "Write expressions as condition trees, and stop allowing them",
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/convert/index.ts"],"names":[],"mappings":";;;AAEA;;;;GAIG;AACU,QAAA,aAAa,GAAW;IACnC,OAAO,EAAE,SAAS;IAClB,WAAW,EACT,4GAA4G;IAC9G,OAAO,EAAE,KAAK,WAAW,OAAO;QAC9B,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,OAAO,CAA2B,CAAC;QACrE,OAAO,aAAa,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IACD,QAAQ,EAAE;QACR;YACE,OAAO,EAAE,mBAAmB;YAC5B,WAAW,EAAE,6CAA6C;SAC3D;QACD;YACE,OAAO,EAAE,2BAA2B;YACpC,WAAW,EAAE,kCAAkC;SAChD;QACD;YACE,OAAO,EAAE,6DAA6D;YACtE,WAAW,EAAE,4DAA4D;SAC1E;QACD;YACE,OAAO,EAAE,6CAA6C;YACtD,WAAW,EAAE,oDAAoD;SAClE;QACD;YACE,OAAO,EAAE,kCAAkC;YAC3C,WAAW,EAAE,sDAAsD;SACpE;QACD;YACE,OAAO,EAAE,0CAA0C;YACnD,WAAW,EAAE,wEAAwE;SACtF;QACD;YACE,OAAO,EAAE,4BAA4B;YACrC,WAAW,EAAE,8DAA8D;SAC5E;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type Project, type Shape } from "./project";
|
|
2
|
+
/** How a project writes its conditions, which convert also changes */
|
|
3
|
+
export type ConditionForm = "expressions" | "trees";
|
|
4
|
+
/** What convert changes a project to: a shape, or a way of writing conditions */
|
|
5
|
+
export type Target = Shape | ConditionForm;
|
|
6
|
+
export declare const CONDITION_FORMS: ConditionForm[];
|
|
7
|
+
export declare function isConditionForm(target: unknown): target is ConditionForm;
|
|
8
|
+
export interface Plan {
|
|
9
|
+
from: Project["shape"] | ConditionForm;
|
|
10
|
+
to: Target;
|
|
11
|
+
/** The environments or sets, in order */
|
|
12
|
+
lanes: string[];
|
|
13
|
+
/** The lane a conversion to flat keeps */
|
|
14
|
+
keep?: string;
|
|
15
|
+
/** New contents by absolute path: definitions, specs, state and the configuration */
|
|
16
|
+
writes: Map<string, string>;
|
|
17
|
+
/** Absolute paths to delete */
|
|
18
|
+
removes: Set<string>;
|
|
19
|
+
/** featurevisor.config.js: what convert changes in it, or leaves for the user to change */
|
|
20
|
+
config: ConfigPlan;
|
|
21
|
+
/** What stops the conversion */
|
|
22
|
+
conflicts: string[];
|
|
23
|
+
/** What changes that is not a definition's meaning, or what a conversion to flat drops */
|
|
24
|
+
differences: string[];
|
|
25
|
+
/** What to change outside the project afterwards */
|
|
26
|
+
next: string[];
|
|
27
|
+
/** Conditions written the other way, by a conversion between trees and expressions */
|
|
28
|
+
conditions?: number;
|
|
29
|
+
/** Conditions written in their simplest form, which changes datafiles' shape, not evaluation */
|
|
30
|
+
simplified?: number;
|
|
31
|
+
}
|
|
32
|
+
/** featurevisor.config.js in a plan */
|
|
33
|
+
export interface ConfigPlan {
|
|
34
|
+
/** What convert changed, or what the user changes by hand, as the summary says it */
|
|
35
|
+
edits: string[];
|
|
36
|
+
/** Settings the new shape cannot have */
|
|
37
|
+
remove: string[];
|
|
38
|
+
/** Settings the new shape adds, as JavaScript, with how the summary says it */
|
|
39
|
+
add: [name: string, value: string | string[], says: string][];
|
|
40
|
+
/** Why the user edits it after converting, when convert cannot */
|
|
41
|
+
byHand?: string;
|
|
42
|
+
}
|
|
43
|
+
/** Leaves the configuration for the user to change after converting, saying why */
|
|
44
|
+
export declare function leaveConfigByHand(config: ConfigPlan, reason: string): void;
|
|
45
|
+
export interface ConvertOptions {
|
|
46
|
+
to: Target;
|
|
47
|
+
/** Lanes to create from a flat project, or the order of environments made from sets */
|
|
48
|
+
lanes?: string[];
|
|
49
|
+
keep?: string;
|
|
50
|
+
/** With --to=expressions, writes trees as expressions without simplifying them */
|
|
51
|
+
exact?: boolean;
|
|
52
|
+
}
|
|
53
|
+
export declare function planConversion(project: Project, options: ConvertOptions): Plan;
|