@featurevisor/core 0.53.4 → 0.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/.eslintcache +1 -1
  2. package/CHANGELOG.md +19 -0
  3. package/coverage/clover.xml +2 -2
  4. package/coverage/lcov-report/index.html +1 -1
  5. package/coverage/lcov-report/lib/builder/allocator.js.html +1 -1
  6. package/coverage/lcov-report/lib/builder/index.html +1 -1
  7. package/coverage/lcov-report/lib/builder/traffic.js.html +1 -1
  8. package/coverage/lcov-report/src/builder/allocator.ts.html +1 -1
  9. package/coverage/lcov-report/src/builder/index.html +1 -1
  10. package/coverage/lcov-report/src/builder/traffic.ts.html +1 -1
  11. package/lib/builder/buildProject.d.ts +2 -1
  12. package/lib/builder/buildProject.js +3 -4
  13. package/lib/builder/buildProject.js.map +1 -1
  14. package/lib/config/index.d.ts +2 -0
  15. package/lib/config/index.js +19 -0
  16. package/lib/config/index.js.map +1 -0
  17. package/lib/{datasource → config}/parsers.d.ts +3 -3
  18. package/lib/config/parsers.js +32 -0
  19. package/lib/config/parsers.js.map +1 -0
  20. package/lib/{config.d.ts → config/projectConfig.d.ts} +2 -1
  21. package/lib/{config.js → config/projectConfig.js} +16 -5
  22. package/lib/config/projectConfig.js.map +1 -0
  23. package/lib/datasource/adapter.d.ts +10 -0
  24. package/lib/datasource/adapter.js +10 -0
  25. package/lib/datasource/adapter.js.map +1 -0
  26. package/lib/datasource/datasource.d.ts +11 -18
  27. package/lib/datasource/datasource.js +32 -130
  28. package/lib/datasource/datasource.js.map +1 -1
  29. package/lib/datasource/filesystemAdapter.d.ts +20 -0
  30. package/lib/datasource/filesystemAdapter.js +173 -0
  31. package/lib/datasource/filesystemAdapter.js.map +1 -0
  32. package/lib/datasource/index.d.ts +2 -1
  33. package/lib/datasource/index.js +2 -1
  34. package/lib/datasource/index.js.map +1 -1
  35. package/lib/dependencies.d.ts +11 -0
  36. package/lib/dependencies.js +3 -0
  37. package/lib/dependencies.js.map +1 -0
  38. package/lib/find-duplicate-segments/index.d.ts +2 -2
  39. package/lib/find-duplicate-segments/index.js +2 -3
  40. package/lib/find-duplicate-segments/index.js.map +1 -1
  41. package/lib/generate-code/index.d.ts +2 -2
  42. package/lib/generate-code/index.js +4 -5
  43. package/lib/generate-code/index.js.map +1 -1
  44. package/lib/generate-code/typescript.d.ts +2 -3
  45. package/lib/generate-code/typescript.js +3 -2
  46. package/lib/generate-code/typescript.js.map +1 -1
  47. package/lib/index.d.ts +2 -0
  48. package/lib/index.js +2 -0
  49. package/lib/index.js.map +1 -1
  50. package/lib/{init.js → init/index.js} +1 -1
  51. package/lib/init/index.js.map +1 -0
  52. package/lib/linter/checkCircularDependency.js +1 -1
  53. package/lib/linter/checkCircularDependency.js.map +1 -1
  54. package/lib/linter/lintProject.d.ts +2 -2
  55. package/lib/linter/lintProject.js +3 -4
  56. package/lib/linter/lintProject.js.map +1 -1
  57. package/lib/restore/index.d.ts +2 -0
  58. package/lib/{restore.js → restore/index.js} +4 -3
  59. package/lib/restore/index.js.map +1 -0
  60. package/lib/site/exportSite.d.ts +2 -2
  61. package/lib/site/exportSite.js +4 -3
  62. package/lib/site/exportSite.js.map +1 -1
  63. package/lib/site/generateSiteSearchIndex.d.ts +2 -2
  64. package/lib/site/generateSiteSearchIndex.js +3 -4
  65. package/lib/site/generateSiteSearchIndex.js.map +1 -1
  66. package/lib/site/serveSite.d.ts +2 -2
  67. package/lib/site/serveSite.js +2 -2
  68. package/lib/site/serveSite.js.map +1 -1
  69. package/lib/tester/testProject.d.ts +2 -2
  70. package/lib/tester/testProject.js +4 -5
  71. package/lib/tester/testProject.js.map +1 -1
  72. package/lib/tester/testSegment.js +1 -1
  73. package/lib/tester/testSegment.js.map +1 -1
  74. package/package.json +5 -5
  75. package/src/builder/buildProject.ts +4 -7
  76. package/src/config/index.ts +2 -0
  77. package/src/config/parsers.ts +40 -0
  78. package/src/{config.ts → config/projectConfig.ts} +20 -5
  79. package/src/datasource/adapter.ts +15 -0
  80. package/src/datasource/datasource.ts +44 -131
  81. package/src/datasource/filesystemAdapter.ts +108 -0
  82. package/src/datasource/index.ts +2 -1
  83. package/src/dependencies.ts +13 -0
  84. package/src/find-duplicate-segments/index.ts +3 -8
  85. package/src/generate-code/index.ts +5 -12
  86. package/src/generate-code/typescript.ts +4 -8
  87. package/src/index.ts +2 -0
  88. package/src/linter/checkCircularDependency.ts +1 -1
  89. package/src/linter/lintProject.ts +4 -5
  90. package/src/{restore.ts → restore/index.ts} +4 -2
  91. package/src/site/exportSite.ts +5 -9
  92. package/src/site/generateSiteSearchIndex.ts +4 -5
  93. package/src/site/serveSite.ts +4 -6
  94. package/src/tester/testProject.ts +5 -9
  95. package/src/tester/testSegment.ts +1 -1
  96. package/lib/config.js.map +0 -1
  97. package/lib/datasource/parsers.js +0 -19
  98. package/lib/datasource/parsers.js.map +0 -1
  99. package/lib/init.js.map +0 -1
  100. package/lib/restore.d.ts +0 -2
  101. package/lib/restore.js.map +0 -1
  102. package/src/datasource/parsers.ts +0 -26
  103. /package/lib/{init.d.ts → init/index.d.ts} +0 -0
  104. /package/src/{init.ts → init/index.ts} +0 -0
@@ -36,143 +36,30 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.Datasource = exports.getExistingStateFilePath = void 0;
40
- var path = require("path");
41
- var fs = require("fs");
42
- var mkdirp = require("mkdirp");
43
- var parsers_1 = require("./parsers");
44
- function getExistingStateFilePath(projectConfig, environment) {
45
- return path.join(projectConfig.stateDirectoryPath, "existing-state-".concat(environment, ".json"));
46
- }
47
- exports.getExistingStateFilePath = getExistingStateFilePath;
39
+ exports.Datasource = void 0;
48
40
  var Datasource = /** @class */ (function () {
49
41
  function Datasource(config) {
50
42
  this.config = config;
51
- if (typeof config.parser === "string") {
52
- // built-in parsers
53
- if (typeof parsers_1.parsers[config.parser] !== "function") {
54
- throw new Error("Invalid parser: ".concat(config.parser));
55
- }
56
- this.extension = config.parser;
57
- this.parse = parsers_1.parsers[config.parser];
58
- }
59
- else if (typeof config.parser === "object") {
60
- // custom parser
61
- if (typeof config.parser.extension !== "string") {
62
- throw new Error("Invalid parser extension: ".concat(config.parser.extension));
63
- }
64
- if (typeof config.parser.parse !== "function") {
65
- throw new Error("Invalid parser parse function: ".concat(config.parser.parse));
66
- }
67
- this.extension = config.parser.extension;
68
- this.parse = config.parser.parse;
69
- }
70
- else {
71
- throw new Error("Invalid parser: ".concat(config.parser));
72
- }
43
+ this.adapter = new config.adapter(config);
73
44
  }
45
+ // @TODO: only site generator needs it, find a way to get it out of here later
74
46
  Datasource.prototype.getExtension = function () {
75
- return this.extension;
76
- };
77
- /**
78
- * Common methods for entities
79
- */
80
- Datasource.prototype.listEntities = function (entityType) {
81
- return __awaiter(this, void 0, void 0, function () {
82
- var directoryPath;
83
- var _this = this;
84
- return __generator(this, function (_a) {
85
- directoryPath = this.getEntityDirectoryPath(entityType);
86
- if (!fs.existsSync(directoryPath)) {
87
- return [2 /*return*/, []];
88
- }
89
- return [2 /*return*/, fs
90
- .readdirSync(directoryPath)
91
- .filter(function (fileName) { return fileName.endsWith(".".concat(_this.extension)); })
92
- .map(function (fileName) { return fileName.replace(".".concat(_this.extension), ""); })];
93
- });
94
- });
95
- };
96
- Datasource.prototype.getEntityDirectoryPath = function (entityType) {
97
- if (entityType === "feature") {
98
- return this.config.featuresDirectoryPath;
99
- }
100
- else if (entityType === "group") {
101
- return this.config.groupsDirectoryPath;
102
- }
103
- else if (entityType === "segment") {
104
- return this.config.segmentsDirectoryPath;
105
- }
106
- else if (entityType === "test") {
107
- return this.config.testsDirectoryPath;
108
- }
109
- return this.config.attributesDirectoryPath;
110
- };
111
- Datasource.prototype.getEntityPath = function (entityType, entityKey) {
112
- var basePath = this.getEntityDirectoryPath(entityType);
113
- return path.join(basePath, "".concat(entityKey, ".").concat(this.extension));
114
- };
115
- Datasource.prototype.entityExists = function (entityType, entityKey) {
116
- return __awaiter(this, void 0, void 0, function () {
117
- var entityPath;
118
- return __generator(this, function (_a) {
119
- entityPath = this.getEntityPath(entityType, entityKey);
120
- return [2 /*return*/, fs.existsSync(entityPath)];
121
- });
122
- });
123
- };
124
- Datasource.prototype.readEntity = function (entityType, entityKey) {
125
- return __awaiter(this, void 0, void 0, function () {
126
- var filePath;
127
- return __generator(this, function (_a) {
128
- filePath = this.getEntityPath(entityType, entityKey);
129
- return [2 /*return*/, fs.readFileSync(filePath, "utf8")];
130
- });
131
- });
132
- };
133
- Datasource.prototype.parseEntity = function (entityType, entityKey) {
134
- return __awaiter(this, void 0, void 0, function () {
135
- var entityContent;
136
- return __generator(this, function (_a) {
137
- switch (_a.label) {
138
- case 0: return [4 /*yield*/, this.readEntity(entityType, entityKey)];
139
- case 1:
140
- entityContent = _a.sent();
141
- return [2 /*return*/, this.parse(entityContent)];
142
- }
143
- });
144
- });
47
+ return this.config.parser.extension;
145
48
  };
146
49
  /**
147
50
  * State
148
51
  */
149
52
  Datasource.prototype.readState = function (environment) {
150
53
  return __awaiter(this, void 0, void 0, function () {
151
- var filePath;
152
54
  return __generator(this, function (_a) {
153
- filePath = getExistingStateFilePath(this.config, environment);
154
- if (!fs.existsSync(filePath)) {
155
- return [2 /*return*/, {
156
- features: {},
157
- }];
158
- }
159
- return [2 /*return*/, require(filePath)];
55
+ return [2 /*return*/, this.adapter.readState(environment)];
160
56
  });
161
57
  });
162
58
  };
163
59
  Datasource.prototype.writeState = function (environment, existingState) {
164
60
  return __awaiter(this, void 0, void 0, function () {
165
- var filePath;
166
61
  return __generator(this, function (_a) {
167
- filePath = getExistingStateFilePath(this.config, environment);
168
- if (!fs.existsSync(this.config.stateDirectoryPath)) {
169
- mkdirp.sync(this.config.stateDirectoryPath);
170
- }
171
- fs.writeFileSync(filePath, this.config.prettyState
172
- ? JSON.stringify(existingState, null, 2)
173
- : JSON.stringify(existingState));
174
- fs.writeFileSync(filePath, JSON.stringify(existingState, null, 2));
175
- return [2 /*return*/];
62
+ return [2 /*return*/, this.adapter.writeState(environment, existingState)];
176
63
  });
177
64
  });
178
65
  };
@@ -184,14 +71,17 @@ var Datasource = /** @class */ (function () {
184
71
  return __awaiter(this, void 0, void 0, function () {
185
72
  return __generator(this, function (_a) {
186
73
  switch (_a.label) {
187
- case 0: return [4 /*yield*/, this.listEntities("feature")];
74
+ case 0: return [4 /*yield*/, this.adapter.listEntities("feature")];
188
75
  case 1: return [2 /*return*/, _a.sent()];
189
76
  }
190
77
  });
191
78
  });
192
79
  };
80
+ Datasource.prototype.featureExists = function (featureKey) {
81
+ return this.adapter.entityExists("feature", featureKey);
82
+ };
193
83
  Datasource.prototype.readFeature = function (featureKey) {
194
- return this.parseEntity("feature", featureKey);
84
+ return this.adapter.parseEntity("feature", featureKey);
195
85
  };
196
86
  Datasource.prototype.getRequiredFeaturesChain = function (featureKey, chain) {
197
87
  if (chain === void 0) { chain = new Set(); }
@@ -201,7 +91,7 @@ var Datasource = /** @class */ (function () {
201
91
  switch (_b.label) {
202
92
  case 0:
203
93
  chain.add(featureKey);
204
- if (!this.entityExists("feature", featureKey)) {
94
+ if (!this.adapter.entityExists("feature", featureKey)) {
205
95
  throw new Error("Feature not found: ".concat(featureKey));
206
96
  }
207
97
  return [4 /*yield*/, this.readFeature(featureKey)];
@@ -233,35 +123,47 @@ var Datasource = /** @class */ (function () {
233
123
  };
234
124
  // segments
235
125
  Datasource.prototype.listSegments = function () {
236
- return this.listEntities("segment");
126
+ return this.adapter.listEntities("segment");
127
+ };
128
+ Datasource.prototype.segmentExists = function (segmentKey) {
129
+ return this.adapter.entityExists("segment", segmentKey);
237
130
  };
238
131
  Datasource.prototype.readSegment = function (segmentKey) {
239
- return this.parseEntity("segment", segmentKey);
132
+ return this.adapter.parseEntity("segment", segmentKey);
240
133
  };
241
134
  // attributes
242
135
  Datasource.prototype.listAttributes = function () {
243
- return this.listEntities("attribute");
136
+ return this.adapter.listEntities("attribute");
137
+ };
138
+ Datasource.prototype.attributeExists = function (attributeKey) {
139
+ return this.adapter.entityExists("attribute", attributeKey);
244
140
  };
245
141
  Datasource.prototype.readAttribute = function (attributeKey) {
246
- return this.parseEntity("attribute", attributeKey);
142
+ return this.adapter.parseEntity("attribute", attributeKey);
247
143
  };
248
144
  // groups
249
145
  Datasource.prototype.listGroups = function () {
250
146
  return __awaiter(this, void 0, void 0, function () {
251
147
  return __generator(this, function (_a) {
252
- return [2 /*return*/, this.listEntities("group")];
148
+ return [2 /*return*/, this.adapter.listEntities("group")];
253
149
  });
254
150
  });
255
151
  };
152
+ Datasource.prototype.groupExists = function (groupKey) {
153
+ return this.adapter.entityExists("group", groupKey);
154
+ };
256
155
  Datasource.prototype.readGroup = function (groupKey) {
257
- return this.parseEntity("group", groupKey);
156
+ return this.adapter.parseEntity("group", groupKey);
258
157
  };
259
158
  // tests
260
159
  Datasource.prototype.listTests = function () {
261
- return this.listEntities("test");
160
+ return this.adapter.listEntities("test");
262
161
  };
263
162
  Datasource.prototype.readTest = function (testKey) {
264
- return this.parseEntity("test", testKey);
163
+ return this.adapter.parseEntity("test", testKey);
164
+ };
165
+ Datasource.prototype.getTestSpecName = function (testKey) {
166
+ return "".concat(testKey, ".").concat(this.getExtension());
265
167
  };
266
168
  return Datasource;
267
169
  }());
@@ -1 +1 @@
1
- {"version":3,"file":"datasource.js","sourceRoot":"","sources":["../../src/datasource/datasource.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2BAA6B;AAC7B,uBAAyB;AAEzB,+BAAiC;AAcjC,qCAAoC;AAIpC,SAAgB,wBAAwB,CACtC,aAA4B,EAC5B,WAA2B;IAE3B,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,kBAAkB,EAAE,yBAAkB,WAAW,UAAO,CAAC,CAAC;AAC3F,CAAC;AALD,4DAKC;AAED;IAIE,oBAAoB,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;QACvC,IAAI,OA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AAC;IAED,SAAS;IACH,+BAAU,GAAhB;;;gBACE,sBAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,EAAC;;;KAC3C;IAED,gCAAW,GAAX,UAAY,QAAgB;QAC1B,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED,8BAAS,GAAT,UAAU,QAAgB;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAQ,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC5D,CAAC;IAED,QAAQ;IACR,8BAAS,GAAT;QACE,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED,6BAAQ,GAAR,UAAS,OAAe;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAO,MAAM,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;IAED,oCAAe,GAAf,UAAgB,OAAe;QAC7B,OAAO,UAAG,OAAO,cAAI,IAAI,CAAC,YAAY,EAAE,CAAE,CAAC;IAC7C,CAAC;IACH,iBAAC;AAAD,CAAC,AAxHD,IAwHC;AAxHY,gCAAU"}
@@ -0,0 +1,20 @@
1
+ import { ExistingState, EnvironmentKey } from "@featurevisor/types";
2
+ import { Adapter, EntityType } from "./adapter";
3
+ import { ProjectConfig } from "../config";
4
+ export declare function getExistingStateFilePath(projectConfig: ProjectConfig, environment: EnvironmentKey): string;
5
+ export declare class FilesystemAdapter extends Adapter {
6
+ private config;
7
+ private parser;
8
+ constructor(config: ProjectConfig);
9
+ getEntityDirectoryPath(entityType: EntityType): string;
10
+ getEntityPath(entityType: EntityType, entityKey: string): string;
11
+ listEntities(entityType: EntityType): Promise<string[]>;
12
+ entityExists(entityType: EntityType, entityKey: string): Promise<boolean>;
13
+ readEntity(entityType: EntityType, entityKey: string): Promise<string>;
14
+ parseEntity<T>(entityType: EntityType, entityKey: string): Promise<T>;
15
+ /**
16
+ * State
17
+ */
18
+ readState(environment: EnvironmentKey): Promise<ExistingState>;
19
+ writeState(environment: EnvironmentKey, existingState: ExistingState): Promise<void>;
20
+ }
@@ -0,0 +1,173 @@
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;
28
+ return g = { next: verb(0), "throw": verb(1), "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
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.FilesystemAdapter = exports.getExistingStateFilePath = void 0;
55
+ var fs = require("fs");
56
+ var path = require("path");
57
+ var mkdirp = require("mkdirp");
58
+ var adapter_1 = require("./adapter");
59
+ function getExistingStateFilePath(projectConfig, environment) {
60
+ return path.join(projectConfig.stateDirectoryPath, "existing-state-".concat(environment, ".json"));
61
+ }
62
+ exports.getExistingStateFilePath = getExistingStateFilePath;
63
+ var FilesystemAdapter = /** @class */ (function (_super) {
64
+ __extends(FilesystemAdapter, _super);
65
+ function FilesystemAdapter(config) {
66
+ var _this = _super.call(this) || this;
67
+ _this.config = config;
68
+ _this.parser = config.parser;
69
+ return _this;
70
+ }
71
+ FilesystemAdapter.prototype.getEntityDirectoryPath = function (entityType) {
72
+ if (entityType === "feature") {
73
+ return this.config.featuresDirectoryPath;
74
+ }
75
+ else if (entityType === "group") {
76
+ return this.config.groupsDirectoryPath;
77
+ }
78
+ else if (entityType === "segment") {
79
+ return this.config.segmentsDirectoryPath;
80
+ }
81
+ else if (entityType === "test") {
82
+ return this.config.testsDirectoryPath;
83
+ }
84
+ return this.config.attributesDirectoryPath;
85
+ };
86
+ FilesystemAdapter.prototype.getEntityPath = function (entityType, entityKey) {
87
+ var basePath = this.getEntityDirectoryPath(entityType);
88
+ return path.join(basePath, "".concat(entityKey, ".").concat(this.parser.extension));
89
+ };
90
+ FilesystemAdapter.prototype.listEntities = function (entityType) {
91
+ return __awaiter(this, void 0, void 0, function () {
92
+ var directoryPath;
93
+ var _this = this;
94
+ return __generator(this, function (_a) {
95
+ directoryPath = this.getEntityDirectoryPath(entityType);
96
+ if (!fs.existsSync(directoryPath)) {
97
+ return [2 /*return*/, []];
98
+ }
99
+ return [2 /*return*/, fs
100
+ .readdirSync(directoryPath)
101
+ .filter(function (fileName) { return fileName.endsWith(".".concat(_this.parser.extension)); })
102
+ .map(function (fileName) { return fileName.replace(".".concat(_this.parser.extension), ""); })];
103
+ });
104
+ });
105
+ };
106
+ FilesystemAdapter.prototype.entityExists = function (entityType, entityKey) {
107
+ return __awaiter(this, void 0, void 0, function () {
108
+ var entityPath;
109
+ return __generator(this, function (_a) {
110
+ entityPath = this.getEntityPath(entityType, entityKey);
111
+ return [2 /*return*/, fs.existsSync(entityPath)];
112
+ });
113
+ });
114
+ };
115
+ FilesystemAdapter.prototype.readEntity = function (entityType, entityKey) {
116
+ return __awaiter(this, void 0, void 0, function () {
117
+ var filePath;
118
+ return __generator(this, function (_a) {
119
+ filePath = this.getEntityPath(entityType, entityKey);
120
+ return [2 /*return*/, fs.readFileSync(filePath, "utf8")];
121
+ });
122
+ });
123
+ };
124
+ FilesystemAdapter.prototype.parseEntity = function (entityType, entityKey) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ var entityContent;
127
+ return __generator(this, function (_a) {
128
+ switch (_a.label) {
129
+ case 0: return [4 /*yield*/, this.readEntity(entityType, entityKey)];
130
+ case 1:
131
+ entityContent = _a.sent();
132
+ return [2 /*return*/, this.parser.parse(entityContent)];
133
+ }
134
+ });
135
+ });
136
+ };
137
+ /**
138
+ * State
139
+ */
140
+ FilesystemAdapter.prototype.readState = function (environment) {
141
+ return __awaiter(this, void 0, void 0, function () {
142
+ var filePath;
143
+ return __generator(this, function (_a) {
144
+ filePath = getExistingStateFilePath(this.config, environment);
145
+ if (!fs.existsSync(filePath)) {
146
+ return [2 /*return*/, {
147
+ features: {},
148
+ }];
149
+ }
150
+ return [2 /*return*/, require(filePath)];
151
+ });
152
+ });
153
+ };
154
+ FilesystemAdapter.prototype.writeState = function (environment, existingState) {
155
+ return __awaiter(this, void 0, void 0, function () {
156
+ var filePath;
157
+ return __generator(this, function (_a) {
158
+ filePath = getExistingStateFilePath(this.config, environment);
159
+ if (!fs.existsSync(this.config.stateDirectoryPath)) {
160
+ mkdirp.sync(this.config.stateDirectoryPath);
161
+ }
162
+ fs.writeFileSync(filePath, this.config.prettyState
163
+ ? JSON.stringify(existingState, null, 2)
164
+ : JSON.stringify(existingState));
165
+ fs.writeFileSync(filePath, JSON.stringify(existingState, null, 2));
166
+ return [2 /*return*/];
167
+ });
168
+ });
169
+ };
170
+ return FilesystemAdapter;
171
+ }(adapter_1.Adapter));
172
+ exports.FilesystemAdapter = FilesystemAdapter;
173
+ //# sourceMappingURL=filesystemAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filesystemAdapter.js","sourceRoot":"","sources":["../../src/datasource/filesystemAdapter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uBAAyB;AACzB,2BAA6B;AAE7B,+BAAiC;AAIjC,qCAAgD;AAGhD,SAAgB,wBAAwB,CACtC,aAA4B,EAC5B,WAA2B;IAE3B,OAAO,IAAI,CAAC,IAAI,CAAC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AU,GAAhB,UAAiB,WAA2B,EAAE,aAA4B;;;;gBAClE,QAAQ,GAAG,wBAAwB,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;gBAEpE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE;oBAClD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;iBAC7C;gBACD,EAAE,CAAC,aAAa,CACd,QAAQ,EACR,IAAI,CAAC,MAAM,CAAC,WAAW;oBACrB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;oBACxC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAClC,CAAC;gBAEF,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;;;;KACpE;IACH,wBAAC;AAAD,CAAC,AA1FD,CAAuC,iBAAO,GA0F7C;AA1FY,8CAAiB"}
@@ -1,2 +1,3 @@
1
1
  export * from "./datasource";
2
- export * from "./parsers";
2
+ export * from "./adapter";
3
+ export * from "./filesystemAdapter";
@@ -15,5 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./datasource"), exports);
18
- __exportStar(require("./parsers"), exports);
18
+ __exportStar(require("./adapter"), exports);
19
+ __exportStar(require("./filesystemAdapter"), exports);
19
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/datasource/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,4CAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/datasource/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,4CAA0B;AAC1B,sDAAoC"}
@@ -0,0 +1,11 @@
1
+ import { ProjectConfig } from "./config";
2
+ import { Datasource } from "./datasource";
3
+ export interface Options {
4
+ [key: string]: any;
5
+ }
6
+ export interface Dependencies {
7
+ rootDirectoryPath: string;
8
+ projectConfig: ProjectConfig;
9
+ datasource: Datasource;
10
+ options: Options;
11
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=dependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../src/dependencies.ts"],"names":[],"mappings":""}
@@ -1,2 +1,2 @@
1
- import { ProjectConfig } from "../config";
2
- export declare function findDuplicateSegmentsInProject(rootDirectoryPath: any, projectConfig: ProjectConfig): Promise<void>;
1
+ import { Dependencies } from "../dependencies";
2
+ export declare function findDuplicateSegmentsInProject(deps: Dependencies): Promise<void>;
@@ -37,15 +37,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.findDuplicateSegmentsInProject = void 0;
40
- var datasource_1 = require("../datasource");
41
40
  var findDuplicateSegments_1 = require("./findDuplicateSegments");
42
- function findDuplicateSegmentsInProject(rootDirectoryPath, projectConfig) {
41
+ function findDuplicateSegmentsInProject(deps) {
43
42
  return __awaiter(this, void 0, void 0, function () {
44
43
  var datasource, duplicates;
45
44
  return __generator(this, function (_a) {
46
45
  switch (_a.label) {
47
46
  case 0:
48
- datasource = new datasource_1.Datasource(projectConfig);
47
+ datasource = deps.datasource;
49
48
  return [4 /*yield*/, (0, findDuplicateSegments_1.findDuplicateSegments)(datasource)];
50
49
  case 1:
51
50
  duplicates = _a.sent();
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/find-duplicate-segments/index.ts"],"names":[],"mappings":";;;;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cAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAE,CAAC,CAAC;oBAC/C,CAAC,CAAC,CAAC;;;;;CACJ;AAfD,wEAeC"}
@@ -1,7 +1,7 @@
1
- import { ProjectConfig } from "../config";
1
+ import { Dependencies } from "../dependencies";
2
2
  export declare const ALLOWED_LANGUAGES_FOR_CODE_GENERATION: string[];
3
3
  export interface GenerateCodeCLIOptions {
4
4
  language: string;
5
5
  outDir: string;
6
6
  }
7
- export declare function generateCodeForProject(rootDirectoryPath: any, projectConfig: ProjectConfig, cliOptions: GenerateCodeCLIOptions): Promise<void>;
7
+ export declare function generateCodeForProject(deps: Dependencies, cliOptions: GenerateCodeCLIOptions): Promise<void>;
@@ -40,22 +40,21 @@ exports.generateCodeForProject = exports.ALLOWED_LANGUAGES_FOR_CODE_GENERATION =
40
40
  var fs = require("fs");
41
41
  var path = require("path");
42
42
  var mkdirp = require("mkdirp");
43
- var datasource_1 = require("../datasource");
44
43
  var typescript_1 = require("./typescript");
45
44
  exports.ALLOWED_LANGUAGES_FOR_CODE_GENERATION = ["typescript"];
46
- function generateCodeForProject(rootDirectoryPath, projectConfig, cliOptions) {
45
+ function generateCodeForProject(deps, cliOptions) {
47
46
  return __awaiter(this, void 0, void 0, function () {
48
- var datasource, absolutePath;
47
+ var rootDirectoryPath, absolutePath;
49
48
  return __generator(this, function (_a) {
50
49
  switch (_a.label) {
51
50
  case 0:
51
+ rootDirectoryPath = deps.rootDirectoryPath;
52
52
  if (!cliOptions.language) {
53
53
  throw new Error("Option `--language` is required");
54
54
  }
55
55
  if (!cliOptions.outDir) {
56
56
  throw new Error("Option `--out-dir` is required");
57
57
  }
58
- datasource = new datasource_1.Datasource(projectConfig);
59
58
  absolutePath = path.resolve(rootDirectoryPath, cliOptions.outDir);
60
59
  if (!fs.existsSync(absolutePath)) {
61
60
  console.log("Creating output directory: ".concat(absolutePath));
@@ -69,7 +68,7 @@ function generateCodeForProject(rootDirectoryPath, projectConfig, cliOptions) {
69
68
  throw new Error("Language ".concat(cliOptions.language, " is not supported for code generation"));
70
69
  }
71
70
  if (!(cliOptions.language === "typescript")) return [3 /*break*/, 2];
72
- return [4 /*yield*/, (0, typescript_1.generateTypeScriptCodeForProject)(rootDirectoryPath, projectConfig, datasource, absolutePath)];
71
+ return [4 /*yield*/, (0, typescript_1.generateTypeScriptCodeForProject)(deps, absolutePath)];
73
72
  case 1: return [2 /*return*/, _a.sent()];
74
73
  case 2: throw new Error("Language ".concat(cliOptions.language, " is not supported"));
75
74
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generate-code/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uBAAyB;AACzB,2BAA6B;AAE7B,+BAAiC;AAGjC,4CAA2C;AAC3C,2CAAgE;AAEnD,QAAA,qCAAqC,GAAG,CAAC,YAAY,CAAC,CAAC;AAOpE,SAAsB,sBAAsB,CAC1C,iBAAiB,EACjB,aAA4B,EAC5B,UAAkC;;;;;;oBAElC,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE;wBACxB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;qBACpD;oBAED,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;wBACtB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;qBACnD;oBAEK,UAAU,GAAG,IAAI,uBAAU,CAAC,aAAa,CAAC,CAAC;oBAE3C,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;oBAExE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;wBAChC,OAAO,CAAC,GAAG,CAAC,qCAA8B,YAAY,CAAE,CAAC,CAAC;wBAC1D,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;qBAC3B;yBAAM;wBACL,OAAO,CAAC,GAAG,CAAC,8CAAu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AU,CAAC,YAAY,CAAC,EAAE;wBAChC,OAAO,CAAC,GAAG,CAAC,qCAA8B,YAAY,CAAE,CAAC,CAAC;wBAC1D,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;qBAC3B;yBAAM;wBACL,OAAO,CAAC,GAAG,CAAC,8CAAuC,YAAY,CAAE,CAAC,CAAC;qBACpE;oBAED,IAAI,CAAC,6CAAqC,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;wBACxE,OAAO,CAAC,GAAG,CACT,8CAAuC,6CAAqC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAE,CAC1F,CAAC;wBAEF,MAAM,IAAI,KAAK,CAAC,mBAAY,UAAU,CAAC,QAAQ,0CAAuC,CAAC,CAAC;qBACzF;yBAEG,CAAA,UAAU,CAAC,QAAQ,KAAK,YAAY,CAAA,EAApC,wBAAoC;oBAC/B,qBAAM,IAAA,6CAAgC,EAAC,IAAI,EAAE,YAAY,CAAC,EAAA;wBAAjE,sBAAO,SAA0D,EAAC;wBAGpE,MAAM,IAAI,KAAK,CAAC,mBAAY,UAAU,CAAC,QAAQ,sBAAmB,CAAC,CAAC;;;;CACrE;AApCD,wDAoCC"}
@@ -1,3 +1,2 @@
1
- import { ProjectConfig } from "../config";
2
- import { Datasource } from "../datasource";
3
- export declare function generateTypeScriptCodeForProject(rootDirectoryPath: string, projectConfig: ProjectConfig, datasource: Datasource, outputPath: string): Promise<void>;
1
+ import { Dependencies } from "../dependencies";
2
+ export declare function generateTypeScriptCodeForProject(deps: Dependencies, outputPath: string): Promise<void>;
@@ -95,12 +95,13 @@ function getFeaturevisorTypeFromValue(value) {
95
95
  throw new Error("Could not detect Featurevisor type from value");
96
96
  }
97
97
  var instanceSnippet = "\nimport { FeaturevisorInstance } from \"@featurevisor/sdk\";\n\nlet _instance: FeaturevisorInstance;\n\nexport function setInstance(instance: FeaturevisorInstance) {\n _instance = instance;\n}\n\nexport function getInstance(): FeaturevisorInstance {\n return _instance as FeaturevisorInstance;\n}\n".trimStart();
98
- function generateTypeScriptCodeForProject(rootDirectoryPath, projectConfig, datasource, outputPath) {
98
+ function generateTypeScriptCodeForProject(deps, outputPath) {
99
99
  return __awaiter(this, void 0, void 0, function () {
100
- var instanceFilePath, attributeFiles, attributes, _i, attributeFiles_1, attributeKey, parsedAttribute, attributeProperties, contextContent, contextTypeFilePath, featureNamespaces, featureFiles, _a, featureFiles_1, featureKey, parsedFeature, namespaceValue, variableMethods, _b, _c, variableSchema, variableKey, variableType, internalMethodName, featureContent, featureNamespaceFilePath, indexContent, indexFilePath;
100
+ var rootDirectoryPath, datasource, instanceFilePath, attributeFiles, attributes, _i, attributeFiles_1, attributeKey, parsedAttribute, attributeProperties, contextContent, contextTypeFilePath, featureNamespaces, featureFiles, _a, featureFiles_1, featureKey, parsedFeature, namespaceValue, variableMethods, _b, _c, variableSchema, variableKey, variableType, internalMethodName, featureContent, featureNamespaceFilePath, indexContent, indexFilePath;
101
101
  return __generator(this, function (_d) {
102
102
  switch (_d.label) {
103
103
  case 0:
104
+ rootDirectoryPath = deps.rootDirectoryPath, datasource = deps.datasource;
104
105
  console.log("\nGenerating TypeScript code...\n");
105
106
  instanceFilePath = path.join(outputPath, "instance.ts");
106
107
  fs.writeFileSync(instanceFilePath, instanceSnippet);