@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.
- package/.eslintcache +1 -1
- package/CHANGELOG.md +19 -0
- package/coverage/clover.xml +2 -2
- package/coverage/lcov-report/index.html +1 -1
- package/coverage/lcov-report/lib/builder/allocator.js.html +1 -1
- package/coverage/lcov-report/lib/builder/index.html +1 -1
- package/coverage/lcov-report/lib/builder/traffic.js.html +1 -1
- package/coverage/lcov-report/src/builder/allocator.ts.html +1 -1
- package/coverage/lcov-report/src/builder/index.html +1 -1
- package/coverage/lcov-report/src/builder/traffic.ts.html +1 -1
- package/lib/builder/buildProject.d.ts +2 -1
- package/lib/builder/buildProject.js +3 -4
- package/lib/builder/buildProject.js.map +1 -1
- package/lib/config/index.d.ts +2 -0
- package/lib/config/index.js +19 -0
- package/lib/config/index.js.map +1 -0
- package/lib/{datasource → config}/parsers.d.ts +3 -3
- package/lib/config/parsers.js +32 -0
- package/lib/config/parsers.js.map +1 -0
- package/lib/{config.d.ts → config/projectConfig.d.ts} +2 -1
- package/lib/{config.js → config/projectConfig.js} +16 -5
- package/lib/config/projectConfig.js.map +1 -0
- package/lib/datasource/adapter.d.ts +10 -0
- package/lib/datasource/adapter.js +10 -0
- package/lib/datasource/adapter.js.map +1 -0
- package/lib/datasource/datasource.d.ts +11 -18
- package/lib/datasource/datasource.js +32 -130
- package/lib/datasource/datasource.js.map +1 -1
- package/lib/datasource/filesystemAdapter.d.ts +20 -0
- package/lib/datasource/filesystemAdapter.js +173 -0
- package/lib/datasource/filesystemAdapter.js.map +1 -0
- package/lib/datasource/index.d.ts +2 -1
- package/lib/datasource/index.js +2 -1
- package/lib/datasource/index.js.map +1 -1
- package/lib/dependencies.d.ts +11 -0
- package/lib/dependencies.js +3 -0
- package/lib/dependencies.js.map +1 -0
- package/lib/find-duplicate-segments/index.d.ts +2 -2
- package/lib/find-duplicate-segments/index.js +2 -3
- package/lib/find-duplicate-segments/index.js.map +1 -1
- package/lib/generate-code/index.d.ts +2 -2
- package/lib/generate-code/index.js +4 -5
- package/lib/generate-code/index.js.map +1 -1
- package/lib/generate-code/typescript.d.ts +2 -3
- package/lib/generate-code/typescript.js +3 -2
- package/lib/generate-code/typescript.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/{init.js → init/index.js} +1 -1
- package/lib/init/index.js.map +1 -0
- package/lib/linter/checkCircularDependency.js +1 -1
- package/lib/linter/checkCircularDependency.js.map +1 -1
- package/lib/linter/lintProject.d.ts +2 -2
- package/lib/linter/lintProject.js +3 -4
- package/lib/linter/lintProject.js.map +1 -1
- package/lib/restore/index.d.ts +2 -0
- package/lib/{restore.js → restore/index.js} +4 -3
- package/lib/restore/index.js.map +1 -0
- package/lib/site/exportSite.d.ts +2 -2
- package/lib/site/exportSite.js +4 -3
- package/lib/site/exportSite.js.map +1 -1
- package/lib/site/generateSiteSearchIndex.d.ts +2 -2
- package/lib/site/generateSiteSearchIndex.js +3 -4
- package/lib/site/generateSiteSearchIndex.js.map +1 -1
- package/lib/site/serveSite.d.ts +2 -2
- package/lib/site/serveSite.js +2 -2
- package/lib/site/serveSite.js.map +1 -1
- package/lib/tester/testProject.d.ts +2 -2
- package/lib/tester/testProject.js +4 -5
- package/lib/tester/testProject.js.map +1 -1
- package/lib/tester/testSegment.js +1 -1
- package/lib/tester/testSegment.js.map +1 -1
- package/package.json +5 -5
- package/src/builder/buildProject.ts +4 -7
- package/src/config/index.ts +2 -0
- package/src/config/parsers.ts +40 -0
- package/src/{config.ts → config/projectConfig.ts} +20 -5
- package/src/datasource/adapter.ts +15 -0
- package/src/datasource/datasource.ts +44 -131
- package/src/datasource/filesystemAdapter.ts +108 -0
- package/src/datasource/index.ts +2 -1
- package/src/dependencies.ts +13 -0
- package/src/find-duplicate-segments/index.ts +3 -8
- package/src/generate-code/index.ts +5 -12
- package/src/generate-code/typescript.ts +4 -8
- package/src/index.ts +2 -0
- package/src/linter/checkCircularDependency.ts +1 -1
- package/src/linter/lintProject.ts +4 -5
- package/src/{restore.ts → restore/index.ts} +4 -2
- package/src/site/exportSite.ts +5 -9
- package/src/site/generateSiteSearchIndex.ts +4 -5
- package/src/site/serveSite.ts +4 -6
- package/src/tester/testProject.ts +5 -9
- package/src/tester/testSegment.ts +1 -1
- package/lib/config.js.map +0 -1
- package/lib/datasource/parsers.js +0 -19
- package/lib/datasource/parsers.js.map +0 -1
- package/lib/init.js.map +0 -1
- package/lib/restore.d.ts +0 -2
- package/lib/restore.js.map +0 -1
- package/src/datasource/parsers.ts +0 -26
- /package/lib/{init.d.ts → init/index.d.ts} +0 -0
- /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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"datasource.js","sourceRoot":"","sources":["../../src/datasource/datasource.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;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C;IAC9D,CAAC;IAED,kCAAa,GAAb,UAAc,YAA0B;QACtC,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAY,WAAW,EAAE,YAAY,CAAC,CAAC;IACxE,CAAC;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
|
|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;;;KAC5C;IAED;;OAEG;IACG,qCAAS,GAAf,UAAgB,WAA2B;;;;gBACnC,QAAQ,GAAG,wBAAwB,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;gBAEpE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;oBAC5B,sBAAO;4BACL,QAAQ,EAAE,EAAE;yBACb,EAAC;iBACH;gBAED,sBAAO,OAAO,CAAC,QAAQ,CAAC,EAAC;;;KAC1B;IAEK,sCAAU,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"}
|
package/lib/datasource/index.js
CHANGED
|
@@ -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("./
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../src/dependencies.ts"],"names":[],"mappings":""}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function findDuplicateSegmentsInProject(
|
|
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(
|
|
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 =
|
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/find-duplicate-segments/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iEAAgE;AAGhE,SAAsB,8BAA8B,CAAC,IAAkB;;;;;;oBAC7D,UAAU,GAAK,IAAI,WAAT,CAAU;oBAET,qBAAM,IAAA,6CAAqB,EAAC,UAAU,CAAC,EAAA;;oBAApD,UAAU,GAAG,SAAuC;oBAE1D,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;wBAC3B,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;wBAC3C,sBAAO;qBACR;oBAED,OAAO,CAAC,GAAG,CAAC,gBAAS,UAAU,CAAC,MAAM,mBAAgB,CAAC,CAAC;oBAExD,UAAU,CAAC,OAAO,CAAC,UAAC,WAAW;wBAC7B,OAAO,CAAC,GAAG,CAAC,cAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAE,CAAC,CAAC;oBAC/C,CAAC,CAAC,CAAC;;;;;CACJ;AAfD,wEAeC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
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(
|
|
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(
|
|
45
|
+
function generateCodeForProject(deps, cliOptions) {
|
|
47
46
|
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var
|
|
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)(
|
|
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;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generate-code/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uBAAyB;AACzB,2BAA6B;AAE7B,+BAAiC;AAEjC,2CAAgE;AAGnD,QAAA,qCAAqC,GAAG,CAAC,YAAY,CAAC,CAAC;AAOpE,SAAsB,sBAAsB,CAC1C,IAAkB,EAClB,UAAkC;;;;;;oBAE1B,iBAAiB,GAAK,IAAI,kBAAT,CAAU;oBAEnC,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,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,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 {
|
|
2
|
-
|
|
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(
|
|
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);
|