@oak-digital/types-4-strapi-2 0.5.4 → 0.5.5

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