@oak-digital/types-4-strapi-2 0.3.6 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +0 -4
- package/.prettierrc.json +1 -0
- package/README.md +41 -1
- package/lib/attributes/Attributes.d.ts +13 -0
- package/lib/attributes/Attributes.js +227 -0
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +4 -0
- package/lib/content-types/reader.d.ts +14 -0
- package/lib/content-types/reader.js +177 -0
- package/lib/extra-types/ExtraType.d.ts +11 -0
- package/lib/extra-types/ExtraType.js +47 -0
- package/lib/extra-types/createExtraTypes.d.ts +2 -0
- package/lib/extra-types/createExtraTypes.js +21 -0
- package/lib/file/File.d.ts +26 -0
- package/lib/file/File.js +72 -0
- package/lib/index.js +1 -1
- package/lib/interface/BuiltinComponentInterface.d.ts +1 -1
- package/lib/interface/BuiltinInterface.d.ts +1 -1
- package/lib/interface/ComponentInterface.d.ts +2 -1
- package/lib/interface/ComponentInterface.js +33 -0
- package/lib/interface/Interface.d.ts +7 -23
- package/lib/interface/Interface.js +60 -80
- package/lib/interface/builtinInterfaces.d.ts +1 -1
- package/lib/plugins/PluginManager.d.ts +20 -0
- package/lib/plugins/PluginManager.js +41 -0
- package/lib/plugins/index.d.ts +3 -3
- package/lib/plugins/index.js +4 -4
- package/lib/plugins/url-alias/index.d.ts +2 -2
- package/lib/plugins/url-alias/index.js +11 -3
- package/lib/program/InterfaceManager.d.ts +39 -0
- package/lib/program/InterfaceManager.js +417 -0
- package/lib/utils/casing/index.d.ts +4 -0
- package/lib/utils/casing/index.js +47 -0
- package/package.json +1 -1
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
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;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
+
if (ar || !(i in from)) {
|
|
52
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
+
ar[i] = from[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
+
};
|
|
58
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
59
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
|
+
};
|
|
61
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
+
var fs_1 = require("fs");
|
|
63
|
+
var promises_1 = require("fs/promises");
|
|
64
|
+
var posix_1 = require("path/posix");
|
|
65
|
+
var builtinInterfaces_1 = require("../interface/builtinInterfaces");
|
|
66
|
+
var ComponentInterface_1 = __importDefault(require("../interface/ComponentInterface"));
|
|
67
|
+
var Interface_1 = __importDefault(require("../interface/Interface"));
|
|
68
|
+
var reader_1 = require("../content-types/reader");
|
|
69
|
+
var prettier_1 = __importDefault(require("prettier"));
|
|
70
|
+
var pascal_case_1 = require("pascal-case");
|
|
71
|
+
var casing_1 = require("../utils/casing/");
|
|
72
|
+
var events_1 = require("../events");
|
|
73
|
+
var plugins_1 = require("../plugins");
|
|
74
|
+
var types_1 = require("../plugins/types");
|
|
75
|
+
var PluginManager_1 = require("../plugins/PluginManager");
|
|
76
|
+
var createExtraTypes_1 = require("../extra-types/createExtraTypes");
|
|
77
|
+
var InterfaceManager = /** @class */ (function () {
|
|
78
|
+
function InterfaceManager(outRoot, strapiSrcRoot, options) {
|
|
79
|
+
if (options === void 0) { options = {}; }
|
|
80
|
+
var _this = this;
|
|
81
|
+
// TODO: remove Interfaces
|
|
82
|
+
this.Interfaces = {}; // string = strapi name
|
|
83
|
+
this.Files = {}; // string = strapi name
|
|
84
|
+
this.OutRoot = outRoot;
|
|
85
|
+
this.StrapiSrcRoot = strapiSrcRoot;
|
|
86
|
+
this.Options = __assign(__assign({}, InterfaceManager.BaseOptions), options);
|
|
87
|
+
// Make sure all options are set
|
|
88
|
+
Object.keys(this.Options).map(function (name) {
|
|
89
|
+
if (_this.Options[name] === undefined) {
|
|
90
|
+
_this.Options[name] = InterfaceManager.BaseOptions[name];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
this.PluginManager = new PluginManager_1.PluginManager();
|
|
94
|
+
this.validateOptions();
|
|
95
|
+
this.registerBuiltinPlugins();
|
|
96
|
+
}
|
|
97
|
+
InterfaceManager.prototype.registerBuiltinPlugins = function () {
|
|
98
|
+
var pluginNames = new Set(this.Options.enabledPlugins);
|
|
99
|
+
(0, plugins_1.registerBuiltinPlugins)(this.PluginManager, pluginNames);
|
|
100
|
+
this.PluginManager.sortHooks();
|
|
101
|
+
};
|
|
102
|
+
// TODO: this function let's the user register their own plugins
|
|
103
|
+
InterfaceManager.prototype.registerPlugin = function () {
|
|
104
|
+
throw new Error('Not implemented');
|
|
105
|
+
};
|
|
106
|
+
InterfaceManager.prototype.validateOptions = function () {
|
|
107
|
+
if (!(0, casing_1.checkCaseType)(this.Options.fileCaseType)) {
|
|
108
|
+
throw new Error("".concat(this.Options.fileCaseType, " is not a supported type, please use one of the following ").concat(casing_1.caseTypesArray.join(', ')));
|
|
109
|
+
}
|
|
110
|
+
if (!(0, casing_1.checkCaseType)(this.Options.folderCaseType)) {
|
|
111
|
+
throw new Error("".concat(this.Options.folderCaseType, " is not a supported type, please use one of the following ").concat(casing_1.caseTypesArray.join(', ')));
|
|
112
|
+
}
|
|
113
|
+
this.Options.enabledPlugins.forEach(function (enabledPlugin) {
|
|
114
|
+
if (!types_1.supportedPluginNames.includes(enabledPlugin)) {
|
|
115
|
+
throw new Error("plugin: `".concat(enabledPlugin, "` is not a supported plugin, please open an issue on https://github.com/Oak-Digital/types-4-strapi-2 if you want this included or only use the following plugins [").concat(types_1.supportedPluginNames.join(', '), "]"));
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
InterfaceManager.prototype.loadPrettierConfig = function () {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
+
var defaultOptions, resolved;
|
|
122
|
+
return __generator(this, function (_a) {
|
|
123
|
+
switch (_a.label) {
|
|
124
|
+
case 0:
|
|
125
|
+
defaultOptions = {
|
|
126
|
+
parser: 'typescript',
|
|
127
|
+
};
|
|
128
|
+
if (!this.Options.prettierFile) {
|
|
129
|
+
this.PrettierOptions = defaultOptions;
|
|
130
|
+
return [2 /*return*/];
|
|
131
|
+
}
|
|
132
|
+
return [4 /*yield*/, prettier_1.default.resolveConfig(this.Options.prettierFile, {
|
|
133
|
+
editorconfig: true,
|
|
134
|
+
})];
|
|
135
|
+
case 1:
|
|
136
|
+
resolved = _a.sent();
|
|
137
|
+
this.PrettierOptions = Object.assign({}, defaultOptions, resolved);
|
|
138
|
+
return [2 /*return*/];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
InterfaceManager.prototype.readSchemas = function () {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
+
var apiSchemasPre, componentSchemasPre, apiSchemasPromise, componentSchemasPromise, _a, apiSchemas, componentSchemas, newObject;
|
|
146
|
+
return __generator(this, function (_b) {
|
|
147
|
+
switch (_b.label) {
|
|
148
|
+
case 0:
|
|
149
|
+
apiSchemasPre = [];
|
|
150
|
+
componentSchemasPre = [];
|
|
151
|
+
apiSchemasPromise = (0, reader_1.getApiSchemas)(this.StrapiSrcRoot);
|
|
152
|
+
componentSchemasPromise = (0, reader_1.getComponentSchemas)(this.StrapiSrcRoot);
|
|
153
|
+
this.PluginManager.invoke(events_1.Events.BeforeReadSchema, this, {
|
|
154
|
+
apiSchemas: apiSchemasPre,
|
|
155
|
+
componentSchemas: componentSchemasPre,
|
|
156
|
+
});
|
|
157
|
+
return [4 /*yield*/, Promise.all([
|
|
158
|
+
apiSchemasPromise,
|
|
159
|
+
componentSchemasPromise,
|
|
160
|
+
])];
|
|
161
|
+
case 1:
|
|
162
|
+
_a = _b.sent(), apiSchemas = _a[0], componentSchemas = _a[1];
|
|
163
|
+
newObject = {
|
|
164
|
+
apiSchemas: __spreadArray(__spreadArray([], apiSchemasPre, true), apiSchemas, true),
|
|
165
|
+
componentSchemas: __spreadArray(__spreadArray([], componentSchemasPre, true), componentSchemas, true),
|
|
166
|
+
};
|
|
167
|
+
this.PluginManager.invoke(events_1.Events.AfterReadSchema, this, newObject);
|
|
168
|
+
return [2 /*return*/, newObject];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
InterfaceManager.prototype.createInterfaces = function () {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
+
var _a, apiSchemas, componentSchemas;
|
|
176
|
+
var _this = this;
|
|
177
|
+
return __generator(this, function (_b) {
|
|
178
|
+
switch (_b.label) {
|
|
179
|
+
case 0: return [4 /*yield*/, this.readSchemas()];
|
|
180
|
+
case 1:
|
|
181
|
+
_a = _b.sent(), apiSchemas = _a.apiSchemas, componentSchemas = _a.componentSchemas;
|
|
182
|
+
apiSchemas.forEach(function (schema) {
|
|
183
|
+
var name = schema.name, attributes = schema.attributes;
|
|
184
|
+
var strapiName = "api::".concat(name, ".").concat(name);
|
|
185
|
+
var inter = new Interface_1.default(name, attributes, './', _this.Options.fileCaseType, _this.Options.prefix);
|
|
186
|
+
_this.Interfaces[strapiName] = inter;
|
|
187
|
+
_this.Files[strapiName] = inter;
|
|
188
|
+
});
|
|
189
|
+
componentSchemas.forEach(function (category) {
|
|
190
|
+
var categoryName = category.category;
|
|
191
|
+
category.schemas.forEach(function (schema) {
|
|
192
|
+
var componentName = schema.name;
|
|
193
|
+
var strapiName = "".concat(categoryName, ".").concat(schema.name);
|
|
194
|
+
var componentPrefix = "".concat(_this.Options.componentPrefix).concat(_this.Options.useCategoryPrefix
|
|
195
|
+
? (0, pascal_case_1.pascalCase)(categoryName)
|
|
196
|
+
: '');
|
|
197
|
+
var prefix = _this.Options.componentPrefixOverridesPrefix
|
|
198
|
+
? componentPrefix
|
|
199
|
+
: _this.Options.prefix + componentPrefix;
|
|
200
|
+
var categoryFolderName = (0, casing_1.changeCase)(categoryName, _this.Options.folderCaseType);
|
|
201
|
+
// make component interface
|
|
202
|
+
var inter = new ComponentInterface_1.default(componentName, schema.attributes, "./".concat(categoryFolderName), categoryName, _this.Options.fileCaseType, prefix);
|
|
203
|
+
_this.Interfaces[strapiName] = inter;
|
|
204
|
+
_this.Files[strapiName] = inter;
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
return [2 /*return*/];
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
InterfaceManager.prototype.createBuiltinInterfaces = function () {
|
|
213
|
+
var _this = this;
|
|
214
|
+
// Interfaces
|
|
215
|
+
var outDirName = (0, casing_1.changeCase)('builtins', this.Options.folderCaseType);
|
|
216
|
+
var outDir = "./".concat(outDirName);
|
|
217
|
+
var builtinInterfaces = [];
|
|
218
|
+
builtinInterfaces.push((0, builtinInterfaces_1.createMediaInterface)(outDir, this.Options.fileCaseType, this.Options.prefix));
|
|
219
|
+
builtinInterfaces.push((0, builtinInterfaces_1.createMediaFormatInterface)(outDir, this.Options.fileCaseType, this.Options.prefix));
|
|
220
|
+
builtinInterfaces.forEach(function (inter) {
|
|
221
|
+
_this.Interfaces[inter.getStrapiName()] = inter;
|
|
222
|
+
_this.Files[inter.getStrapiName()] = inter;
|
|
223
|
+
});
|
|
224
|
+
// Types
|
|
225
|
+
var types = [];
|
|
226
|
+
types.push.apply(types, (0, createExtraTypes_1.createExtraTypes)());
|
|
227
|
+
types.forEach(function (t) {
|
|
228
|
+
_this.Files[t.getStrapiName()] = t;
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
// Inject dependencies into all interfaces
|
|
232
|
+
InterfaceManager.prototype.injectDependencies = function () {
|
|
233
|
+
var _this = this;
|
|
234
|
+
// console.log("Injecting dependencies")
|
|
235
|
+
Object.keys(this.Files).forEach(function (strapiName) {
|
|
236
|
+
var file = _this.Files[strapiName];
|
|
237
|
+
var dependencies = file.getDependencies();
|
|
238
|
+
// console.log(`Interfaces for ${inter.getStrapiName()} are`)
|
|
239
|
+
var interfacesToInject = dependencies
|
|
240
|
+
.map(function (dependencyStrapiName) {
|
|
241
|
+
return _this.Files[dependencyStrapiName];
|
|
242
|
+
})
|
|
243
|
+
.filter(function (inter) { return inter; });
|
|
244
|
+
file.setRelations(interfacesToInject);
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
InterfaceManager.prototype.deleteOldFolders = function () {
|
|
248
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
249
|
+
return __generator(this, function (_a) {
|
|
250
|
+
switch (_a.label) {
|
|
251
|
+
case 0: return [4 /*yield*/, (0, promises_1.rm)(this.OutRoot, {
|
|
252
|
+
force: true,
|
|
253
|
+
recursive: true,
|
|
254
|
+
})];
|
|
255
|
+
case 1:
|
|
256
|
+
_a.sent();
|
|
257
|
+
return [2 /*return*/];
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
InterfaceManager.prototype.makeFolders = function () {
|
|
263
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
264
|
+
var componentCategories, promises, componentCategoriesPromises, builintsFolderName, builtinsPath;
|
|
265
|
+
var _this = this;
|
|
266
|
+
return __generator(this, function (_a) {
|
|
267
|
+
switch (_a.label) {
|
|
268
|
+
case 0:
|
|
269
|
+
if (!this.Options.deleteOld) return [3 /*break*/, 2];
|
|
270
|
+
return [4 /*yield*/, this.deleteOldFolders()];
|
|
271
|
+
case 1:
|
|
272
|
+
_a.sent();
|
|
273
|
+
_a.label = 2;
|
|
274
|
+
case 2: return [4 /*yield*/, (0, reader_1.getComponentCategoryFolders)(this.StrapiSrcRoot)];
|
|
275
|
+
case 3:
|
|
276
|
+
componentCategories = _a.sent();
|
|
277
|
+
if (!!(0, fs_1.existsSync)(this.OutRoot)) return [3 /*break*/, 5];
|
|
278
|
+
return [4 /*yield*/, (0, promises_1.mkdir)(this.OutRoot, {
|
|
279
|
+
recursive: true,
|
|
280
|
+
})];
|
|
281
|
+
case 4:
|
|
282
|
+
_a.sent();
|
|
283
|
+
_a.label = 5;
|
|
284
|
+
case 5:
|
|
285
|
+
promises = [];
|
|
286
|
+
componentCategoriesPromises = componentCategories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
|
|
287
|
+
var folderName, path;
|
|
288
|
+
return __generator(this, function (_a) {
|
|
289
|
+
switch (_a.label) {
|
|
290
|
+
case 0:
|
|
291
|
+
folderName = (0, casing_1.changeCase)(category, this.Options.folderCaseType);
|
|
292
|
+
path = (0, posix_1.join)(this.OutRoot, folderName);
|
|
293
|
+
if ((0, fs_1.existsSync)(path)) {
|
|
294
|
+
return [2 /*return*/];
|
|
295
|
+
}
|
|
296
|
+
return [4 /*yield*/, (0, promises_1.mkdir)(path)];
|
|
297
|
+
case 1:
|
|
298
|
+
_a.sent();
|
|
299
|
+
return [2 /*return*/];
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}); });
|
|
303
|
+
promises.push.apply(promises, componentCategoriesPromises);
|
|
304
|
+
builintsFolderName = (0, casing_1.changeCase)('builtins', this.Options.folderCaseType);
|
|
305
|
+
builtinsPath = (0, posix_1.join)(this.OutRoot, builintsFolderName);
|
|
306
|
+
if (!(0, fs_1.existsSync)(builtinsPath)) {
|
|
307
|
+
promises.push((0, promises_1.mkdir)(builtinsPath));
|
|
308
|
+
}
|
|
309
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
310
|
+
case 6:
|
|
311
|
+
_a.sent();
|
|
312
|
+
return [2 /*return*/];
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
InterfaceManager.prototype.writeInterfaces = function () {
|
|
318
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
319
|
+
var writePromises;
|
|
320
|
+
var _this = this;
|
|
321
|
+
return __generator(this, function (_a) {
|
|
322
|
+
switch (_a.label) {
|
|
323
|
+
case 0:
|
|
324
|
+
writePromises = Object.keys(this.Files).map(function (strapiName) { return __awaiter(_this, void 0, void 0, function () {
|
|
325
|
+
var file, fileData, formattedFileData, filePath;
|
|
326
|
+
return __generator(this, function (_a) {
|
|
327
|
+
switch (_a.label) {
|
|
328
|
+
case 0:
|
|
329
|
+
file = this.Files[strapiName];
|
|
330
|
+
fileData = file.toString();
|
|
331
|
+
formattedFileData = prettier_1.default.format(fileData, this.PrettierOptions);
|
|
332
|
+
filePath = (0, posix_1.join)(this.OutRoot, file.getRelativeRootPathFile());
|
|
333
|
+
return [4 /*yield*/, (0, promises_1.writeFile)(filePath, formattedFileData)];
|
|
334
|
+
case 1:
|
|
335
|
+
_a.sent();
|
|
336
|
+
return [2 /*return*/];
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
}); });
|
|
340
|
+
return [4 /*yield*/, Promise.all(writePromises)];
|
|
341
|
+
case 1:
|
|
342
|
+
_a.sent();
|
|
343
|
+
return [2 /*return*/];
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
};
|
|
348
|
+
InterfaceManager.prototype.writeIndexFile = function () {
|
|
349
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
350
|
+
var strings, fileData, formattedFileData, filePath;
|
|
351
|
+
var _this = this;
|
|
352
|
+
return __generator(this, function (_a) {
|
|
353
|
+
switch (_a.label) {
|
|
354
|
+
case 0:
|
|
355
|
+
strings = Object.keys(this.Files).map(function (strapiName) {
|
|
356
|
+
var inter = _this.Files[strapiName];
|
|
357
|
+
return "export * from '".concat(inter.getRelativeRootPath(), "'");
|
|
358
|
+
});
|
|
359
|
+
fileData = strings.join('\n');
|
|
360
|
+
formattedFileData = prettier_1.default.format(fileData, this.PrettierOptions);
|
|
361
|
+
filePath = (0, posix_1.join)(this.OutRoot, 'index.ts');
|
|
362
|
+
return [4 /*yield*/, (0, promises_1.writeFile)(filePath, formattedFileData)];
|
|
363
|
+
case 1:
|
|
364
|
+
_a.sent();
|
|
365
|
+
return [2 /*return*/];
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
};
|
|
370
|
+
InterfaceManager.prototype.run = function () {
|
|
371
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
372
|
+
var createInterfacesPromise, makeFoldersPromise, loadPrettierPromise, err_1;
|
|
373
|
+
return __generator(this, function (_a) {
|
|
374
|
+
switch (_a.label) {
|
|
375
|
+
case 0:
|
|
376
|
+
_a.trys.push([0, 4, , 5]);
|
|
377
|
+
createInterfacesPromise = this.createInterfaces();
|
|
378
|
+
makeFoldersPromise = this.makeFolders();
|
|
379
|
+
loadPrettierPromise = this.loadPrettierConfig();
|
|
380
|
+
this.createBuiltinInterfaces();
|
|
381
|
+
return [4 /*yield*/, createInterfacesPromise];
|
|
382
|
+
case 1:
|
|
383
|
+
_a.sent();
|
|
384
|
+
// Create all interfaces before injecting
|
|
385
|
+
this.injectDependencies();
|
|
386
|
+
return [4 /*yield*/, Promise.all([makeFoldersPromise, loadPrettierPromise])];
|
|
387
|
+
case 2:
|
|
388
|
+
_a.sent();
|
|
389
|
+
return [4 /*yield*/, Promise.all([this.writeInterfaces(), this.writeIndexFile()])];
|
|
390
|
+
case 3:
|
|
391
|
+
_a.sent();
|
|
392
|
+
return [3 /*break*/, 5];
|
|
393
|
+
case 4:
|
|
394
|
+
err_1 = _a.sent();
|
|
395
|
+
console.error(err_1);
|
|
396
|
+
return [3 /*break*/, 5];
|
|
397
|
+
case 5: return [2 /*return*/];
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
};
|
|
402
|
+
InterfaceManager.BaseOptions = {
|
|
403
|
+
prefix: 'I',
|
|
404
|
+
useCategoryPrefix: true,
|
|
405
|
+
componentPrefix: '',
|
|
406
|
+
componentPrefixOverridesPrefix: false,
|
|
407
|
+
builtinsPrefix: '',
|
|
408
|
+
builtinsPrefixOverridesPrefix: false,
|
|
409
|
+
deleteOld: false,
|
|
410
|
+
prettierFile: null,
|
|
411
|
+
fileCaseType: 'pascal',
|
|
412
|
+
folderCaseType: 'kebab',
|
|
413
|
+
enabledPlugins: [],
|
|
414
|
+
};
|
|
415
|
+
return InterfaceManager;
|
|
416
|
+
}());
|
|
417
|
+
exports.default = InterfaceManager;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const caseTypesArray: readonly ["camel", "capital", "dot", "snake", "pascal", "constant", "kebab"];
|
|
2
|
+
export declare type caseType = typeof caseTypesArray[number];
|
|
3
|
+
export declare function checkCaseType(caseName: caseType): caseName is caseType;
|
|
4
|
+
export declare function changeCase(text: string, caseName: caseType): string;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.changeCase = exports.checkCaseType = exports.caseTypesArray = void 0;
|
|
4
|
+
var change_case_1 = require("change-case");
|
|
5
|
+
exports.caseTypesArray = [
|
|
6
|
+
'camel',
|
|
7
|
+
'capital',
|
|
8
|
+
'dot',
|
|
9
|
+
'snake',
|
|
10
|
+
'pascal',
|
|
11
|
+
'constant',
|
|
12
|
+
'kebab',
|
|
13
|
+
];
|
|
14
|
+
function checkCaseType(caseName) {
|
|
15
|
+
return exports.caseTypesArray.includes(caseName);
|
|
16
|
+
}
|
|
17
|
+
exports.checkCaseType = checkCaseType;
|
|
18
|
+
function changeCase(text, caseName) {
|
|
19
|
+
var name = text;
|
|
20
|
+
switch (caseName) {
|
|
21
|
+
case 'dot':
|
|
22
|
+
name = (0, change_case_1.dotCase)(name);
|
|
23
|
+
break;
|
|
24
|
+
case 'camel':
|
|
25
|
+
name = (0, change_case_1.camelCase)(name);
|
|
26
|
+
break;
|
|
27
|
+
case 'snake':
|
|
28
|
+
name = (0, change_case_1.snakeCase)(name);
|
|
29
|
+
break;
|
|
30
|
+
case 'capital':
|
|
31
|
+
name = (0, change_case_1.capitalCase)(name);
|
|
32
|
+
break;
|
|
33
|
+
case 'constant':
|
|
34
|
+
name = (0, change_case_1.constantCase)(name);
|
|
35
|
+
break;
|
|
36
|
+
case 'kebab':
|
|
37
|
+
// paramcase is the same as kebab
|
|
38
|
+
name = (0, change_case_1.paramCase)(name);
|
|
39
|
+
break;
|
|
40
|
+
case 'pascal':
|
|
41
|
+
default:
|
|
42
|
+
name = (0, change_case_1.pascalCase)(name);
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
return name;
|
|
46
|
+
}
|
|
47
|
+
exports.changeCase = changeCase;
|