@featurevisor/core 1.35.3 → 2.0.1

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 (252) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +0 -6
  3. package/coverage/clover.xml +321 -237
  4. package/coverage/coverage-final.json +8 -8
  5. package/coverage/lcov-report/index.html +77 -47
  6. package/coverage/lcov-report/lib/builder/allocator.js.html +14 -14
  7. package/coverage/lcov-report/lib/builder/index.html +16 -16
  8. package/coverage/lcov-report/lib/builder/revision.js.html +3 -3
  9. package/coverage/lcov-report/lib/builder/traffic.js.html +88 -64
  10. package/coverage/lcov-report/lib/list/index.html +116 -0
  11. package/coverage/lcov-report/lib/{tester → list}/matrix.js.html +90 -66
  12. package/coverage/lcov-report/lib/tester/helpers.js.html +295 -0
  13. package/coverage/lcov-report/lib/tester/index.html +20 -35
  14. package/coverage/lcov-report/src/builder/allocator.ts.html +2 -2
  15. package/coverage/lcov-report/src/builder/index.html +15 -15
  16. package/coverage/lcov-report/src/builder/revision.ts.html +1 -1
  17. package/coverage/lcov-report/src/builder/traffic.ts.html +96 -24
  18. package/coverage/lcov-report/src/list/index.html +116 -0
  19. package/coverage/lcov-report/src/{tester → list}/matrix.ts.html +87 -21
  20. package/coverage/lcov-report/src/tester/helpers.ts.html +313 -0
  21. package/coverage/lcov-report/src/tester/index.html +20 -35
  22. package/coverage/lcov.info +592 -436
  23. package/lib/assess-distribution/index.d.ts +1 -1
  24. package/lib/assess-distribution/index.js +102 -162
  25. package/lib/assess-distribution/index.js.map +1 -1
  26. package/lib/benchmark/index.js +87 -143
  27. package/lib/benchmark/index.js.map +1 -1
  28. package/lib/builder/allocator.d.ts +1 -1
  29. package/lib/builder/allocator.js +12 -12
  30. package/lib/builder/allocator.js.map +1 -1
  31. package/lib/builder/allocator.spec.js +22 -22
  32. package/lib/builder/allocator.spec.js.map +1 -1
  33. package/lib/builder/buildDatafile.d.ts +4 -3
  34. package/lib/builder/buildDatafile.js +311 -388
  35. package/lib/builder/buildDatafile.js.map +1 -1
  36. package/lib/builder/buildProject.d.ts +2 -1
  37. package/lib/builder/buildProject.js +96 -183
  38. package/lib/builder/buildProject.js.map +1 -1
  39. package/lib/builder/convertToV1.d.ts +10 -0
  40. package/lib/builder/convertToV1.js +119 -0
  41. package/lib/builder/convertToV1.js.map +1 -0
  42. package/lib/builder/getFeatureRanges.d.ts +1 -1
  43. package/lib/builder/getFeatureRanges.js +32 -105
  44. package/lib/builder/getFeatureRanges.js.map +1 -1
  45. package/lib/builder/hashes.d.ts +4 -0
  46. package/lib/builder/hashes.js +70 -0
  47. package/lib/builder/hashes.js.map +1 -0
  48. package/lib/builder/revision.js +2 -2
  49. package/lib/builder/revision.js.map +1 -1
  50. package/lib/builder/revision.spec.js +1 -1
  51. package/lib/builder/revision.spec.js.map +1 -1
  52. package/lib/builder/traffic.d.ts +1 -1
  53. package/lib/builder/traffic.js +57 -49
  54. package/lib/builder/traffic.js.map +1 -1
  55. package/lib/builder/traffic.spec.js +14 -14
  56. package/lib/builder/traffic.spec.js.map +1 -1
  57. package/lib/cli/cli.js +60 -129
  58. package/lib/cli/cli.js.map +1 -1
  59. package/lib/cli/plugins.js +14 -16
  60. package/lib/cli/plugins.js.map +1 -1
  61. package/lib/config/parsers.js +1 -1
  62. package/lib/config/parsers.js.map +1 -1
  63. package/lib/config/projectConfig.d.ts +8 -6
  64. package/lib/config/projectConfig.js +31 -72
  65. package/lib/config/projectConfig.js.map +1 -1
  66. package/lib/datasource/adapter.d.ts +1 -1
  67. package/lib/datasource/adapter.js +2 -5
  68. package/lib/datasource/adapter.js.map +1 -1
  69. package/lib/datasource/datasource.d.ts +2 -1
  70. package/lib/datasource/datasource.js +107 -148
  71. package/lib/datasource/datasource.js.map +1 -1
  72. package/lib/datasource/filesystemAdapter.d.ts +1 -1
  73. package/lib/datasource/filesystemAdapter.js +224 -360
  74. package/lib/datasource/filesystemAdapter.js.map +1 -1
  75. package/lib/evaluate/index.d.ts +1 -1
  76. package/lib/evaluate/index.js +120 -188
  77. package/lib/evaluate/index.js.map +1 -1
  78. package/lib/find-duplicate-segments/findDuplicateSegments.d.ts +1 -1
  79. package/lib/find-duplicate-segments/findDuplicateSegments.js +40 -128
  80. package/lib/find-duplicate-segments/findDuplicateSegments.js.map +1 -1
  81. package/lib/find-duplicate-segments/index.js +27 -82
  82. package/lib/find-duplicate-segments/index.js.map +1 -1
  83. package/lib/find-usage/index.d.ts +7 -5
  84. package/lib/find-usage/index.js +333 -507
  85. package/lib/find-usage/index.js.map +1 -1
  86. package/lib/generate-code/index.js +36 -91
  87. package/lib/generate-code/index.js.map +1 -1
  88. package/lib/generate-code/typescript.js +117 -157
  89. package/lib/generate-code/typescript.js.map +1 -1
  90. package/lib/index.d.ts +0 -1
  91. package/lib/index.js +0 -1
  92. package/lib/index.js.map +1 -1
  93. package/lib/info/index.js +45 -133
  94. package/lib/info/index.js.map +1 -1
  95. package/lib/init/index.d.ts +1 -1
  96. package/lib/init/index.js +16 -64
  97. package/lib/init/index.js.map +1 -1
  98. package/lib/linter/attributeSchema.d.ts +21 -6
  99. package/lib/linter/attributeSchema.js +18 -4
  100. package/lib/linter/attributeSchema.js.map +1 -1
  101. package/lib/linter/checkCircularDependency.d.ts +1 -1
  102. package/lib/linter/checkCircularDependency.js +22 -80
  103. package/lib/linter/checkCircularDependency.js.map +1 -1
  104. package/lib/linter/checkPercentageExceedingSlot.d.ts +1 -1
  105. package/lib/linter/checkPercentageExceedingSlot.js +36 -76
  106. package/lib/linter/checkPercentageExceedingSlot.js.map +1 -1
  107. package/lib/linter/conditionSchema.d.ts +1 -1
  108. package/lib/linter/conditionSchema.js +89 -41
  109. package/lib/linter/conditionSchema.js.map +1 -1
  110. package/lib/linter/featureSchema.d.ts +345 -197
  111. package/lib/linter/featureSchema.js +313 -172
  112. package/lib/linter/featureSchema.js.map +1 -1
  113. package/lib/linter/groupSchema.js +6 -6
  114. package/lib/linter/groupSchema.js.map +1 -1
  115. package/lib/linter/lintProject.js +306 -480
  116. package/lib/linter/lintProject.js.map +1 -1
  117. package/lib/linter/printError.js +7 -7
  118. package/lib/linter/printError.js.map +1 -1
  119. package/lib/linter/segmentSchema.js +2 -2
  120. package/lib/linter/segmentSchema.js.map +1 -1
  121. package/lib/linter/testSchema.d.ts +155 -3
  122. package/lib/linter/testSchema.js +47 -17
  123. package/lib/linter/testSchema.js.map +1 -1
  124. package/lib/list/index.d.ts +1 -0
  125. package/lib/list/index.js +349 -517
  126. package/lib/list/index.js.map +1 -1
  127. package/lib/{tester → list}/matrix.d.ts +1 -1
  128. package/lib/{tester → list}/matrix.js +50 -42
  129. package/lib/list/matrix.js.map +1 -0
  130. package/lib/{tester → list}/matrix.spec.js +7 -7
  131. package/lib/list/matrix.spec.js.map +1 -0
  132. package/lib/site/exportSite.js +25 -71
  133. package/lib/site/exportSite.js.map +1 -1
  134. package/lib/site/generateHistory.d.ts +1 -1
  135. package/lib/site/generateHistory.js +26 -82
  136. package/lib/site/generateHistory.js.map +1 -1
  137. package/lib/site/generateSiteSearchIndex.d.ts +1 -1
  138. package/lib/site/generateSiteSearchIndex.js +182 -259
  139. package/lib/site/generateSiteSearchIndex.js.map +1 -1
  140. package/lib/site/getLastModifiedFromHistory.d.ts +1 -1
  141. package/lib/site/getLastModifiedFromHistory.js +2 -2
  142. package/lib/site/getLastModifiedFromHistory.js.map +1 -1
  143. package/lib/site/getOwnerAndRepoFromUrl.js +6 -6
  144. package/lib/site/getOwnerAndRepoFromUrl.js.map +1 -1
  145. package/lib/site/getRelativePaths.js +7 -7
  146. package/lib/site/getRelativePaths.js.map +1 -1
  147. package/lib/site/getRepoDetails.js +20 -20
  148. package/lib/site/getRepoDetails.js.map +1 -1
  149. package/lib/site/index.js +25 -73
  150. package/lib/site/index.js.map +1 -1
  151. package/lib/site/serveSite.js +10 -10
  152. package/lib/site/serveSite.js.map +1 -1
  153. package/lib/tester/helpers.d.ts +2 -0
  154. package/lib/tester/helpers.js +71 -0
  155. package/lib/tester/helpers.js.map +1 -0
  156. package/lib/tester/helpers.spec.js +115 -0
  157. package/lib/tester/helpers.spec.js.map +1 -0
  158. package/lib/tester/index.d.ts +0 -1
  159. package/lib/tester/index.js +0 -1
  160. package/lib/tester/index.js.map +1 -1
  161. package/lib/tester/prettyDuration.js +11 -11
  162. package/lib/tester/prettyDuration.js.map +1 -1
  163. package/lib/tester/printTestResult.d.ts +1 -1
  164. package/lib/tester/printTestResult.js +35 -15
  165. package/lib/tester/printTestResult.js.map +1 -1
  166. package/lib/tester/testFeature.d.ts +4 -2
  167. package/lib/tester/testFeature.js +264 -226
  168. package/lib/tester/testFeature.js.map +1 -1
  169. package/lib/tester/testProject.d.ts +3 -7
  170. package/lib/tester/testProject.js +145 -246
  171. package/lib/tester/testProject.js.map +1 -1
  172. package/lib/tester/testSegment.d.ts +5 -2
  173. package/lib/tester/testSegment.js +65 -102
  174. package/lib/tester/testSegment.js.map +1 -1
  175. package/lib/utils/extractKeys.d.ts +2 -1
  176. package/lib/utils/extractKeys.js +57 -12
  177. package/lib/utils/extractKeys.js.map +1 -1
  178. package/lib/utils/git.d.ts +1 -1
  179. package/lib/utils/git.js +23 -23
  180. package/lib/utils/git.js.map +1 -1
  181. package/lib/utils/pretty.js +2 -4
  182. package/lib/utils/pretty.js.map +1 -1
  183. package/package.json +5 -6
  184. package/src/assess-distribution/index.ts +3 -2
  185. package/src/benchmark/index.ts +3 -3
  186. package/src/builder/allocator.spec.ts +1 -1
  187. package/src/builder/allocator.ts +1 -1
  188. package/src/builder/buildDatafile.ts +161 -124
  189. package/src/builder/buildProject.ts +6 -3
  190. package/src/builder/convertToV1.ts +166 -0
  191. package/src/builder/getFeatureRanges.ts +1 -1
  192. package/src/builder/hashes.ts +109 -0
  193. package/src/builder/traffic.ts +40 -16
  194. package/src/cli/cli.ts +1 -1
  195. package/src/cli/plugins.ts +0 -2
  196. package/src/config/projectConfig.ts +13 -10
  197. package/src/datasource/adapter.ts +1 -1
  198. package/src/datasource/datasource.ts +23 -2
  199. package/src/datasource/filesystemAdapter.ts +11 -12
  200. package/src/evaluate/index.ts +7 -6
  201. package/src/find-duplicate-segments/findDuplicateSegments.ts +1 -1
  202. package/src/find-usage/index.ts +111 -44
  203. package/src/generate-code/index.ts +1 -3
  204. package/src/generate-code/typescript.ts +7 -29
  205. package/src/index.ts +0 -1
  206. package/src/info/index.ts +2 -2
  207. package/src/init/index.ts +2 -2
  208. package/src/linter/attributeSchema.ts +18 -2
  209. package/src/linter/checkCircularDependency.ts +1 -1
  210. package/src/linter/checkPercentageExceedingSlot.ts +28 -8
  211. package/src/linter/conditionSchema.ts +66 -10
  212. package/src/linter/featureSchema.ts +312 -116
  213. package/src/linter/lintProject.ts +9 -4
  214. package/src/linter/testSchema.ts +42 -3
  215. package/src/list/index.ts +18 -30
  216. package/src/{tester → list}/matrix.ts +33 -11
  217. package/src/site/exportSite.ts +2 -4
  218. package/src/site/generateHistory.ts +1 -1
  219. package/src/site/generateSiteSearchIndex.ts +58 -50
  220. package/src/site/getLastModifiedFromHistory.ts +1 -1
  221. package/src/tester/helpers.spec.ts +149 -0
  222. package/src/tester/helpers.ts +76 -0
  223. package/src/tester/index.ts +0 -1
  224. package/src/tester/printTestResult.ts +25 -3
  225. package/src/tester/testFeature.ts +270 -124
  226. package/src/tester/testProject.ts +28 -49
  227. package/src/tester/testSegment.ts +48 -40
  228. package/src/utils/extractKeys.ts +58 -1
  229. package/src/utils/git.ts +1 -1
  230. package/tsconfig.cjs.json +1 -0
  231. package/coverage/lcov-report/lib/tester/checkIfObjectsAreEqual.js.html +0 -151
  232. package/coverage/lcov-report/src/tester/checkIfObjectsAreEqual.ts.html +0 -157
  233. package/lib/restore/index.d.ts +0 -4
  234. package/lib/restore/index.js +0 -91
  235. package/lib/restore/index.js.map +0 -1
  236. package/lib/tester/checkIfArraysAreEqual.d.ts +0 -1
  237. package/lib/tester/checkIfArraysAreEqual.js +0 -18
  238. package/lib/tester/checkIfArraysAreEqual.js.map +0 -1
  239. package/lib/tester/checkIfObjectsAreEqual.d.ts +0 -1
  240. package/lib/tester/checkIfObjectsAreEqual.js +0 -23
  241. package/lib/tester/checkIfObjectsAreEqual.js.map +0 -1
  242. package/lib/tester/checkIfObjectsAreEqual.spec.js +0 -26
  243. package/lib/tester/checkIfObjectsAreEqual.spec.js.map +0 -1
  244. package/lib/tester/matrix.js.map +0 -1
  245. package/lib/tester/matrix.spec.js.map +0 -1
  246. package/src/restore/index.ts +0 -42
  247. package/src/tester/checkIfArraysAreEqual.ts +0 -16
  248. package/src/tester/checkIfObjectsAreEqual.spec.ts +0 -31
  249. package/src/tester/checkIfObjectsAreEqual.ts +0 -24
  250. /package/lib/{tester → list}/matrix.spec.d.ts +0 -0
  251. /package/lib/tester/{checkIfObjectsAreEqual.spec.d.ts → helpers.spec.d.ts} +0 -0
  252. /package/src/{tester → list}/matrix.spec.ts +0 -0
@@ -1,102 +1,47 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
28
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
2
  Object.defineProperty(exports, "__esModule", { value: true });
54
3
  exports.FilesystemAdapter = void 0;
55
4
  exports.getExistingStateFilePath = getExistingStateFilePath;
56
5
  exports.getRevisionFilePath = getRevisionFilePath;
57
6
  exports.getAllEntityFilePathsRecursively = getAllEntityFilePathsRecursively;
58
- var fs = require("fs");
59
- var path = require("path");
60
- var child_process_1 = require("child_process");
61
- var mkdirp = require("mkdirp");
62
- var adapter_1 = require("./adapter");
63
- var git_1 = require("../utils/git");
64
- var commitRegex = /^commit (\w+)\nAuthor: (.+) <(.+)>\nDate: (.+)\n\n(.+)/gm;
7
+ const fs = require("fs");
8
+ const path = require("path");
9
+ const child_process_1 = require("child_process");
10
+ const adapter_1 = require("./adapter");
11
+ const git_1 = require("../utils/git");
65
12
  function getExistingStateFilePath(projectConfig, environment) {
66
- var fileName = environment ? "existing-state-".concat(environment, ".json") : "existing-state.json";
13
+ const fileName = environment ? `existing-state-${environment}.json` : `existing-state.json`;
67
14
  return path.join(projectConfig.stateDirectoryPath, fileName);
68
15
  }
69
16
  function getRevisionFilePath(projectConfig) {
70
- return path.join(projectConfig.stateDirectoryPath, "REVISION");
17
+ return path.join(projectConfig.stateDirectoryPath, `REVISION`);
71
18
  }
72
19
  function getAllEntityFilePathsRecursively(directoryPath, extension) {
73
- var entities = [];
20
+ let entities = [];
74
21
  if (!fs.existsSync(directoryPath)) {
75
22
  return entities;
76
23
  }
77
- var files = fs.readdirSync(directoryPath);
78
- for (var i = 0; i < files.length; i++) {
79
- var file = files[i];
80
- var filePath = path.join(directoryPath, file);
24
+ const files = fs.readdirSync(directoryPath);
25
+ for (let i = 0; i < files.length; i++) {
26
+ const file = files[i];
27
+ const filePath = path.join(directoryPath, file);
81
28
  if (fs.statSync(filePath).isDirectory()) {
82
29
  entities = entities.concat(getAllEntityFilePathsRecursively(filePath, extension));
83
30
  }
84
- else if (file.endsWith(".".concat(extension))) {
31
+ else if (file.endsWith(`.${extension}`)) {
85
32
  entities.push(filePath);
86
33
  }
87
34
  }
88
35
  return entities;
89
36
  }
90
- var FilesystemAdapter = /** @class */ (function (_super) {
91
- __extends(FilesystemAdapter, _super);
92
- function FilesystemAdapter(config, rootDirectoryPath) {
93
- var _this = _super.call(this) || this;
94
- _this.config = config;
95
- _this.rootDirectoryPath = rootDirectoryPath;
96
- _this.parser = config.parser;
97
- return _this;
37
+ class FilesystemAdapter extends adapter_1.Adapter {
38
+ constructor(config, rootDirectoryPath) {
39
+ super();
40
+ this.config = config;
41
+ this.rootDirectoryPath = rootDirectoryPath;
42
+ this.parser = config.parser;
98
43
  }
99
- FilesystemAdapter.prototype.getEntityDirectoryPath = function (entityType) {
44
+ getEntityDirectoryPath(entityType) {
100
45
  if (entityType === "feature") {
101
46
  return this.config.featuresDirectoryPath;
102
47
  }
@@ -110,226 +55,161 @@ var FilesystemAdapter = /** @class */ (function (_super) {
110
55
  return this.config.testsDirectoryPath;
111
56
  }
112
57
  return this.config.attributesDirectoryPath;
113
- };
114
- FilesystemAdapter.prototype.getEntityPath = function (entityType, entityKey) {
115
- var basePath = this.getEntityDirectoryPath(entityType);
58
+ }
59
+ getEntityPath(entityType, entityKey) {
60
+ const basePath = this.getEntityDirectoryPath(entityType);
116
61
  // taking care of windows paths
117
- var relativeEntityPath = entityKey.replace(/\//g, path.sep);
118
- return path.join(basePath, "".concat(relativeEntityPath, ".").concat(this.parser.extension));
119
- };
120
- FilesystemAdapter.prototype.listEntities = function (entityType) {
121
- return __awaiter(this, void 0, void 0, function () {
122
- var directoryPath, filePaths;
123
- var _this = this;
124
- return __generator(this, function (_a) {
125
- directoryPath = this.getEntityDirectoryPath(entityType);
126
- filePaths = getAllEntityFilePathsRecursively(directoryPath, this.parser.extension);
127
- return [2 /*return*/, (filePaths
128
- // keep only the files with the right extension
129
- .filter(function (filterPath) { return filterPath.endsWith(".".concat(_this.parser.extension)); })
130
- // remove the entity directory path from beginning
131
- .map(function (filePath) { return filePath.replace(directoryPath + path.sep, ""); })
132
- // remove the extension from the end
133
- .map(function (filterPath) { return filterPath.replace(".".concat(_this.parser.extension), ""); })
134
- // take care of windows paths
135
- .map(function (filterPath) { return filterPath.replace(/\\/g, "/"); }))];
136
- });
137
- });
138
- };
139
- FilesystemAdapter.prototype.entityExists = function (entityType, entityKey) {
140
- return __awaiter(this, void 0, void 0, function () {
141
- var entityPath;
142
- return __generator(this, function (_a) {
143
- entityPath = this.getEntityPath(entityType, entityKey);
144
- return [2 /*return*/, fs.existsSync(entityPath)];
145
- });
146
- });
147
- };
148
- FilesystemAdapter.prototype.readEntity = function (entityType, entityKey) {
149
- return __awaiter(this, void 0, void 0, function () {
150
- var filePath, entityContent;
151
- return __generator(this, function (_a) {
152
- filePath = this.getEntityPath(entityType, entityKey);
153
- entityContent = fs.readFileSync(filePath, "utf8");
154
- return [2 /*return*/, this.parser.parse(entityContent, filePath)];
155
- });
156
- });
157
- };
158
- FilesystemAdapter.prototype.writeEntity = function (entityType, entityKey, entity) {
159
- return __awaiter(this, void 0, void 0, function () {
160
- var filePath;
161
- return __generator(this, function (_a) {
162
- filePath = this.getEntityPath(entityType, entityKey);
163
- if (!fs.existsSync(this.getEntityDirectoryPath(entityType))) {
164
- mkdirp.sync(this.getEntityDirectoryPath(entityType));
165
- }
166
- fs.writeFileSync(filePath, this.parser.stringify(entity));
167
- return [2 /*return*/, entity];
168
- });
169
- });
170
- };
171
- FilesystemAdapter.prototype.deleteEntity = function (entityType, entityKey) {
172
- return __awaiter(this, void 0, void 0, function () {
173
- var filePath;
174
- return __generator(this, function (_a) {
175
- filePath = this.getEntityPath(entityType, entityKey);
176
- if (!fs.existsSync(filePath)) {
177
- return [2 /*return*/];
178
- }
179
- fs.unlinkSync(filePath);
180
- return [2 /*return*/];
181
- });
182
- });
183
- };
62
+ const relativeEntityPath = entityKey.replace(/\//g, path.sep);
63
+ return path.join(basePath, `${relativeEntityPath}.${this.parser.extension}`);
64
+ }
65
+ async listEntities(entityType) {
66
+ const directoryPath = this.getEntityDirectoryPath(entityType);
67
+ const filePaths = getAllEntityFilePathsRecursively(directoryPath, this.parser.extension);
68
+ return (filePaths
69
+ // keep only the files with the right extension
70
+ .filter((filterPath) => filterPath.endsWith(`.${this.parser.extension}`))
71
+ // remove the entity directory path from beginning
72
+ .map((filePath) => filePath.replace(directoryPath + path.sep, ""))
73
+ // remove the extension from the end
74
+ .map((filterPath) => filterPath.replace(`.${this.parser.extension}`, ""))
75
+ // take care of windows paths
76
+ .map((filterPath) => filterPath.replace(/\\/g, "/")));
77
+ }
78
+ async entityExists(entityType, entityKey) {
79
+ const entityPath = this.getEntityPath(entityType, entityKey);
80
+ return fs.existsSync(entityPath);
81
+ }
82
+ async readEntity(entityType, entityKey) {
83
+ const filePath = this.getEntityPath(entityType, entityKey);
84
+ const entityContent = fs.readFileSync(filePath, "utf8");
85
+ return this.parser.parse(entityContent, filePath);
86
+ }
87
+ async writeEntity(entityType, entityKey, entity) {
88
+ const filePath = this.getEntityPath(entityType, entityKey);
89
+ if (!fs.existsSync(this.getEntityDirectoryPath(entityType))) {
90
+ fs.mkdirSync(this.getEntityDirectoryPath(entityType), { recursive: true });
91
+ }
92
+ fs.writeFileSync(filePath, this.parser.stringify(entity));
93
+ return entity;
94
+ }
95
+ async deleteEntity(entityType, entityKey) {
96
+ const filePath = this.getEntityPath(entityType, entityKey);
97
+ if (!fs.existsSync(filePath)) {
98
+ return;
99
+ }
100
+ fs.unlinkSync(filePath);
101
+ }
184
102
  /**
185
103
  * State
186
104
  */
187
- FilesystemAdapter.prototype.readState = function (environment) {
188
- return __awaiter(this, void 0, void 0, function () {
189
- var filePath;
190
- return __generator(this, function (_a) {
191
- filePath = getExistingStateFilePath(this.config, environment);
192
- if (!fs.existsSync(filePath)) {
193
- return [2 /*return*/, {
194
- features: {},
195
- }];
196
- }
197
- return [2 /*return*/, require(filePath)];
198
- });
199
- });
200
- };
201
- FilesystemAdapter.prototype.writeState = function (environment, existingState) {
202
- return __awaiter(this, void 0, void 0, function () {
203
- var filePath;
204
- return __generator(this, function (_a) {
205
- filePath = getExistingStateFilePath(this.config, environment);
206
- if (!fs.existsSync(this.config.stateDirectoryPath)) {
207
- mkdirp.sync(this.config.stateDirectoryPath);
208
- }
209
- fs.writeFileSync(filePath, this.config.prettyState
210
- ? JSON.stringify(existingState, null, 2)
211
- : JSON.stringify(existingState));
212
- fs.writeFileSync(filePath, JSON.stringify(existingState, null, 2));
213
- return [2 /*return*/];
214
- });
215
- });
216
- };
105
+ async readState(environment) {
106
+ const filePath = getExistingStateFilePath(this.config, environment);
107
+ if (!fs.existsSync(filePath)) {
108
+ return {
109
+ features: {},
110
+ };
111
+ }
112
+ return require(filePath);
113
+ }
114
+ async writeState(environment, existingState) {
115
+ const filePath = getExistingStateFilePath(this.config, environment);
116
+ if (!fs.existsSync(this.config.stateDirectoryPath)) {
117
+ fs.mkdirSync(this.config.stateDirectoryPath, { recursive: true });
118
+ }
119
+ fs.writeFileSync(filePath, this.config.prettyState
120
+ ? JSON.stringify(existingState, null, 2)
121
+ : JSON.stringify(existingState));
122
+ fs.writeFileSync(filePath, JSON.stringify(existingState, null, 2));
123
+ }
217
124
  /**
218
125
  * Revision
219
126
  */
220
- FilesystemAdapter.prototype.readRevision = function () {
221
- return __awaiter(this, void 0, void 0, function () {
222
- var filePath, pkg, pkgVersion;
223
- return __generator(this, function (_a) {
224
- filePath = getRevisionFilePath(this.config);
225
- if (fs.existsSync(filePath)) {
226
- return [2 /*return*/, fs.readFileSync(filePath, "utf8")];
227
- }
228
- // maintain backwards compatibility
229
- try {
230
- pkg = require(path.join(this.rootDirectoryPath, "package.json"));
231
- pkgVersion = pkg.version;
232
- if (pkgVersion) {
233
- return [2 /*return*/, pkgVersion];
234
- }
235
- return [2 /*return*/, "0"];
236
- }
237
- catch (e) {
238
- return [2 /*return*/, "0"];
239
- }
240
- return [2 /*return*/];
241
- });
242
- });
243
- };
244
- FilesystemAdapter.prototype.writeRevision = function (revision) {
245
- return __awaiter(this, void 0, void 0, function () {
246
- var filePath;
247
- return __generator(this, function (_a) {
248
- filePath = getRevisionFilePath(this.config);
249
- if (!fs.existsSync(this.config.stateDirectoryPath)) {
250
- mkdirp.sync(this.config.stateDirectoryPath);
251
- }
252
- fs.writeFileSync(filePath, revision);
253
- return [2 /*return*/];
254
- });
255
- });
256
- };
127
+ async readRevision() {
128
+ const filePath = getRevisionFilePath(this.config);
129
+ if (fs.existsSync(filePath)) {
130
+ return fs.readFileSync(filePath, "utf8");
131
+ }
132
+ // maintain backwards compatibility
133
+ try {
134
+ const pkg = require(path.join(this.rootDirectoryPath, "package.json"));
135
+ const pkgVersion = pkg.version;
136
+ if (pkgVersion) {
137
+ return pkgVersion;
138
+ }
139
+ return "0";
140
+ // eslint-disable-next-line
141
+ }
142
+ catch (e) {
143
+ return "0";
144
+ }
145
+ }
146
+ async writeRevision(revision) {
147
+ const filePath = getRevisionFilePath(this.config);
148
+ if (!fs.existsSync(this.config.stateDirectoryPath)) {
149
+ fs.mkdirSync(this.config.stateDirectoryPath, { recursive: true });
150
+ }
151
+ fs.writeFileSync(filePath, revision);
152
+ }
257
153
  /**
258
154
  * Datafile
259
155
  */
260
- FilesystemAdapter.prototype.getDatafilePath = function (options) {
261
- var fileName = "datafile-tag-".concat(options.tag, ".json");
262
- var dir = options.datafilesDir || this.config.outputDirectoryPath;
156
+ getDatafilePath(options) {
157
+ const pattern = this.config.datafileNamePattern || "featurevisor-%s.json";
158
+ const fileName = pattern.replace("%s", `tag-${options.tag}`);
159
+ const dir = options.datafilesDir || this.config.datafilesDirectoryPath;
263
160
  if (options.environment) {
264
161
  return path.join(dir, options.environment, fileName);
265
162
  }
266
163
  return path.join(dir, fileName);
267
- };
268
- FilesystemAdapter.prototype.readDatafile = function (options) {
269
- return __awaiter(this, void 0, void 0, function () {
270
- var filePath, content, datafileContent;
271
- return __generator(this, function (_a) {
272
- filePath = this.getDatafilePath(options);
273
- content = fs.readFileSync(filePath, "utf8");
274
- datafileContent = JSON.parse(content);
275
- return [2 /*return*/, datafileContent];
276
- });
277
- });
278
- };
279
- FilesystemAdapter.prototype.writeDatafile = function (datafileContent, options) {
280
- return __awaiter(this, void 0, void 0, function () {
281
- var dir, outputEnvironmentDirPath, outputFilePath, root, shortPath;
282
- return __generator(this, function (_a) {
283
- dir = options.datafilesDir || this.config.outputDirectoryPath;
284
- outputEnvironmentDirPath = options.environment
285
- ? path.join(dir, options.environment)
286
- : dir;
287
- mkdirp.sync(outputEnvironmentDirPath);
288
- outputFilePath = this.getDatafilePath(options);
289
- fs.writeFileSync(outputFilePath, this.config.prettyDatafile
290
- ? JSON.stringify(datafileContent, null, 2)
291
- : JSON.stringify(datafileContent));
292
- root = path.resolve(dir, "..");
293
- shortPath = outputFilePath.replace(root + path.sep, "");
294
- console.log(" Datafile generated: ".concat(shortPath));
295
- return [2 /*return*/];
296
- });
297
- });
298
- };
164
+ }
165
+ async readDatafile(options) {
166
+ const filePath = this.getDatafilePath(options);
167
+ const content = fs.readFileSync(filePath, "utf8");
168
+ const datafileContent = JSON.parse(content);
169
+ return datafileContent;
170
+ }
171
+ async writeDatafile(datafileContent, options) {
172
+ const dir = options.datafilesDir || this.config.datafilesDirectoryPath;
173
+ const outputEnvironmentDirPath = options.environment
174
+ ? path.join(dir, options.environment)
175
+ : dir;
176
+ fs.mkdirSync(outputEnvironmentDirPath, { recursive: true });
177
+ const outputFilePath = this.getDatafilePath(options);
178
+ fs.writeFileSync(outputFilePath, this.config.prettyDatafile
179
+ ? JSON.stringify(datafileContent, null, 2)
180
+ : JSON.stringify(datafileContent));
181
+ const root = path.resolve(dir, "..");
182
+ const shortPath = outputFilePath.replace(root + path.sep, "");
183
+ console.log(` Datafile generated: ${shortPath}`);
184
+ }
299
185
  /**
300
186
  * History
301
187
  */
302
- FilesystemAdapter.prototype.getRawHistory = function (pathPatterns) {
303
- return __awaiter(this, void 0, void 0, function () {
304
- var gitPaths, logCommand, fullCommand;
305
- return __generator(this, function (_a) {
306
- gitPaths = pathPatterns.join(" ");
307
- logCommand = "git log --name-only --pretty=format:\"%h|%an|%aI\" --relative --no-merges -- ".concat(gitPaths);
308
- fullCommand = "(cd ".concat(this.rootDirectoryPath, " && ").concat(logCommand, ")");
309
- return [2 /*return*/, new Promise(function (resolve, reject) {
310
- var child = (0, child_process_1.spawn)(fullCommand, { shell: true });
311
- var result = "";
312
- child.stdout.on("data", function (data) {
313
- result += data.toString();
314
- });
315
- child.stderr.on("data", function (data) {
316
- console.error(data.toString());
317
- });
318
- child.on("close", function (code) {
319
- if (code === 0) {
320
- resolve(result);
321
- }
322
- else {
323
- reject(code);
324
- }
325
- });
326
- })];
188
+ async getRawHistory(pathPatterns) {
189
+ const gitPaths = pathPatterns.join(" ");
190
+ const logCommand = `git log --name-only --pretty=format:"%h|%an|%aI" --relative --no-merges -- ${gitPaths}`;
191
+ const fullCommand = `(cd ${this.rootDirectoryPath} && ${logCommand})`;
192
+ return new Promise(function (resolve, reject) {
193
+ const child = (0, child_process_1.spawn)(fullCommand, { shell: true });
194
+ let result = "";
195
+ child.stdout.on("data", function (data) {
196
+ result += data.toString();
197
+ });
198
+ child.stderr.on("data", function (data) {
199
+ console.error(data.toString());
200
+ });
201
+ child.on("close", function (code) {
202
+ if (code === 0) {
203
+ resolve(result);
204
+ }
205
+ else {
206
+ reject(code);
207
+ }
327
208
  });
328
209
  });
329
- };
330
- FilesystemAdapter.prototype.getPathPatterns = function (entityType, entityKey) {
331
- var _this = this;
332
- var pathPatterns = [];
210
+ }
211
+ getPathPatterns(entityType, entityKey) {
212
+ let pathPatterns = [];
333
213
  if (entityType && entityKey) {
334
214
  pathPatterns = [this.getEntityPath(entityType, entityKey)];
335
215
  }
@@ -359,93 +239,77 @@ var FilesystemAdapter = /** @class */ (function (_super) {
359
239
  this.config.testsDirectoryPath,
360
240
  ];
361
241
  }
362
- return pathPatterns.map(function (p) { return p.replace(_this.rootDirectoryPath + path.sep, ""); });
363
- };
364
- FilesystemAdapter.prototype.listHistoryEntries = function (entityType, entityKey) {
365
- return __awaiter(this, void 0, void 0, function () {
366
- var pathPatterns, rawHistory, fullHistory, blocks, i, block, lines, commitLine, _a, commitHash, author, timestamp, entities, filePathLines, j, relativePath, absolutePath, fileName, relativeDir, key, type;
367
- return __generator(this, function (_b) {
368
- switch (_b.label) {
369
- case 0:
370
- pathPatterns = this.getPathPatterns(entityType, entityKey);
371
- return [4 /*yield*/, this.getRawHistory(pathPatterns)];
372
- case 1:
373
- rawHistory = _b.sent();
374
- fullHistory = [];
375
- blocks = rawHistory.split("\n\n");
376
- for (i = 0; i < blocks.length; i++) {
377
- block = blocks[i];
378
- if (block.length === 0) {
379
- continue;
380
- }
381
- lines = block.split("\n");
382
- commitLine = lines[0];
383
- _a = commitLine.split("|"), commitHash = _a[0], author = _a[1], timestamp = _a[2];
384
- entities = [];
385
- filePathLines = lines.slice(1);
386
- for (j = 0; j < filePathLines.length; j++) {
387
- relativePath = filePathLines[j];
388
- absolutePath = path.join(this.rootDirectoryPath, relativePath);
389
- fileName = absolutePath.split(path.sep).pop();
390
- relativeDir = path.dirname(absolutePath);
391
- key = fileName.replace("." + this.parser.extension, "");
392
- type = "attribute";
393
- if (relativeDir === this.config.attributesDirectoryPath) {
394
- type = "attribute";
395
- }
396
- else if (relativeDir === this.config.segmentsDirectoryPath) {
397
- type = "segment";
398
- }
399
- else if (relativeDir === this.config.featuresDirectoryPath) {
400
- type = "feature";
401
- }
402
- else if (relativeDir === this.config.groupsDirectoryPath) {
403
- type = "group";
404
- }
405
- else if (relativeDir === this.config.testsDirectoryPath) {
406
- type = "test";
407
- }
408
- else {
409
- continue;
410
- }
411
- entities.push({
412
- type: type,
413
- key: key,
414
- });
415
- }
416
- if (entities.length === 0) {
417
- continue;
418
- }
419
- fullHistory.push({
420
- commit: commitHash,
421
- author: author,
422
- timestamp: timestamp,
423
- entities: entities,
424
- });
425
- }
426
- return [2 /*return*/, fullHistory];
242
+ return pathPatterns.map((p) => p.replace(this.rootDirectoryPath + path.sep, ""));
243
+ }
244
+ async listHistoryEntries(entityType, entityKey) {
245
+ const pathPatterns = this.getPathPatterns(entityType, entityKey);
246
+ const rawHistory = await this.getRawHistory(pathPatterns);
247
+ const fullHistory = [];
248
+ const blocks = rawHistory.split("\n\n");
249
+ for (let i = 0; i < blocks.length; i++) {
250
+ const block = blocks[i];
251
+ if (block.length === 0) {
252
+ continue;
253
+ }
254
+ const lines = block.split("\n");
255
+ const commitLine = lines[0];
256
+ const [commitHash, author, timestamp] = commitLine.split("|");
257
+ const entities = [];
258
+ const filePathLines = lines.slice(1);
259
+ for (let j = 0; j < filePathLines.length; j++) {
260
+ const relativePath = filePathLines[j];
261
+ const absolutePath = path.join(this.rootDirectoryPath, relativePath);
262
+ const fileName = absolutePath.split(path.sep).pop();
263
+ const relativeDir = path.dirname(absolutePath);
264
+ const key = fileName.replace("." + this.parser.extension, "");
265
+ let type = "attribute";
266
+ if (relativeDir === this.config.attributesDirectoryPath) {
267
+ type = "attribute";
427
268
  }
428
- });
429
- });
430
- };
431
- FilesystemAdapter.prototype.readCommit = function (commitHash, entityType, entityKey) {
432
- return __awaiter(this, void 0, void 0, function () {
433
- var pathPatterns, gitPaths, logCommand, fullCommand, gitShowOutput, commit;
434
- return __generator(this, function (_a) {
435
- pathPatterns = this.getPathPatterns(entityType, entityKey);
436
- gitPaths = pathPatterns.join(" ");
437
- logCommand = "git show ".concat(commitHash, " --relative -- ").concat(gitPaths);
438
- fullCommand = "(cd ".concat(this.rootDirectoryPath, " && ").concat(logCommand, ")");
439
- gitShowOutput = (0, child_process_1.execSync)(fullCommand, { encoding: "utf8" }).toString();
440
- commit = (0, git_1.getCommit)(gitShowOutput, {
441
- rootDirectoryPath: this.rootDirectoryPath,
442
- projectConfig: this.config,
269
+ else if (relativeDir === this.config.segmentsDirectoryPath) {
270
+ type = "segment";
271
+ }
272
+ else if (relativeDir === this.config.featuresDirectoryPath) {
273
+ type = "feature";
274
+ }
275
+ else if (relativeDir === this.config.groupsDirectoryPath) {
276
+ type = "group";
277
+ }
278
+ else if (relativeDir === this.config.testsDirectoryPath) {
279
+ type = "test";
280
+ }
281
+ else {
282
+ continue;
283
+ }
284
+ entities.push({
285
+ type,
286
+ key,
443
287
  });
444
- return [2 /*return*/, commit];
288
+ }
289
+ if (entities.length === 0) {
290
+ continue;
291
+ }
292
+ fullHistory.push({
293
+ commit: commitHash,
294
+ author,
295
+ timestamp,
296
+ entities,
445
297
  });
298
+ }
299
+ return fullHistory;
300
+ }
301
+ async readCommit(commitHash, entityType, entityKey) {
302
+ const pathPatterns = this.getPathPatterns(entityType, entityKey);
303
+ const gitPaths = pathPatterns.join(" ");
304
+ const logCommand = `git show ${commitHash} --relative -- ${gitPaths}`;
305
+ const fullCommand = `(cd ${this.rootDirectoryPath} && ${logCommand})`;
306
+ const gitShowOutput = (0, child_process_1.execSync)(fullCommand, { encoding: "utf8" }).toString();
307
+ const commit = (0, git_1.getCommit)(gitShowOutput, {
308
+ rootDirectoryPath: this.rootDirectoryPath,
309
+ projectConfig: this.config,
446
310
  });
447
- };
448
- return FilesystemAdapter;
449
- }(adapter_1.Adapter));
311
+ return commit;
312
+ }
313
+ }
450
314
  exports.FilesystemAdapter = FilesystemAdapter;
451
315
  //# sourceMappingURL=filesystemAdapter.js.map