@oak-digital/types-4-strapi-2 0.5.3 → 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 (55) hide show
  1. package/README.md +4 -3
  2. package/lib/content-types/reader.d.ts +2 -2
  3. package/lib/content-types/reader.js +7 -7
  4. package/lib/events/index.d.ts +6 -1
  5. package/lib/events/index.js +5 -0
  6. package/lib/interface/Interface.js +5 -0
  7. package/lib/plugins/PluginManager.d.ts +8 -4
  8. package/lib/plugins/PluginManager.js +11 -6
  9. package/lib/plugins/draft-and-publish/index.d.ts +3 -0
  10. package/lib/plugins/draft-and-publish/index.js +36 -0
  11. package/lib/plugins/i18n/index.d.ts +3 -0
  12. package/lib/plugins/i18n/index.js +41 -0
  13. package/lib/plugins/index.js +7 -0
  14. package/lib/plugins/types.d.ts +3 -1
  15. package/lib/plugins/types.js +1 -0
  16. package/lib/plugins/url-alias/index.d.ts +2 -2
  17. package/lib/plugins/url-alias/index.js +14 -1
  18. package/lib/plugins/url-alias/type.d.ts +8 -0
  19. package/lib/plugins/url-alias/type.js +41 -0
  20. package/lib/program/InterfaceManager.d.ts +4 -2
  21. package/lib/program/InterfaceManager.js +34 -17
  22. package/package.json +9 -8
  23. package/lib/.prettierrc.json +0 -7
  24. package/lib/case/index.d.ts +0 -4
  25. package/lib/case/index.js +0 -47
  26. package/lib/interface/Attributes.d.ts +0 -11
  27. package/lib/interface/Attributes.js +0 -167
  28. package/lib/interface/InterfaceManager.d.ts +0 -39
  29. package/lib/interface/InterfaceManager.js +0 -396
  30. package/lib/interface/interfaceCreator.d.ts +0 -0
  31. package/lib/interface/interfaceCreator.js +0 -7
  32. package/lib/interface/interfaceWriter.d.ts +0 -2
  33. package/lib/interface/interfaceWriter.js +0 -46
  34. package/lib/interface/schemaReader.d.ts +0 -14
  35. package/lib/interface/schemaReader.js +0 -177
  36. package/lib/src/index.d.ts +0 -1
  37. package/lib/src/index.js +0 -25
  38. package/lib/src/interface/Attributes.d.ts +0 -11
  39. package/lib/src/interface/Attributes.js +0 -148
  40. package/lib/src/interface/BuiltinComponentInterface.d.ts +0 -5
  41. package/lib/src/interface/BuiltinComponentInterface.js +0 -36
  42. package/lib/src/interface/BuiltinInterface.d.ts +0 -5
  43. package/lib/src/interface/BuiltinInterface.js +0 -33
  44. package/lib/src/interface/ComponentInterface.d.ts +0 -8
  45. package/lib/src/interface/ComponentInterface.js +0 -58
  46. package/lib/src/interface/Interface.d.ts +0 -31
  47. package/lib/src/interface/Interface.js +0 -112
  48. package/lib/src/interface/InterfaceManager.d.ts +0 -25
  49. package/lib/src/interface/InterfaceManager.js +0 -288
  50. package/lib/src/interface/builtinInterfaces.d.ts +0 -4
  51. package/lib/src/interface/builtinInterfaces.js +0 -81
  52. package/lib/src/interface/schemaReader.d.ts +0 -14
  53. package/lib/src/interface/schemaReader.js +0 -172
  54. package/lib/src/utils/index.d.ts +0 -3
  55. package/lib/src/utils/index.js +0 -67
@@ -1,11 +0,0 @@
1
- import { RelationNames } from './Interface';
2
- export default class Attributes {
3
- Attrs: Record<string, Record<string, any>>;
4
- private RelationNames;
5
- constructor(attr: Record<string, Record<string, any>>, relationNames: RelationNames);
6
- isAttributeOptional(attr: any): boolean;
7
- getDependencies(): any[];
8
- attributeToString(attrName: string, attr: any): string;
9
- toFieldsString(): string;
10
- toString(): string;
11
- }
@@ -1,167 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var Attributes = /** @class */ (function () {
4
- function Attributes(attr, relationNames) {
5
- this.RelationNames = {};
6
- this.Attrs = attr;
7
- this.RelationNames = relationNames;
8
- }
9
- Attributes.prototype.isAttributeOptional = function (attr) {
10
- // If it is a component / relation / dynamiczone it is always optional due to population
11
- switch (attr.type) {
12
- case 'nested':
13
- return attr.nullable === true;
14
- case 'component':
15
- case 'dynamiczone':
16
- case 'relation':
17
- return true;
18
- default:
19
- break;
20
- }
21
- return false;
22
- };
23
- Attributes.prototype.getDependencies = function () {
24
- var dependencies = [];
25
- for (var attrName in this.Attrs) {
26
- var attr = this.Attrs[attrName];
27
- var dependencyNames = [];
28
- switch (attr.type) {
29
- case 'nested':
30
- var attrs = new Attributes(attr.fields, this.RelationNames);
31
- dependencyNames.push.apply(dependencyNames, attrs.getDependencies());
32
- break;
33
- case 'relation':
34
- dependencyNames.push(attr.target);
35
- break;
36
- case 'component':
37
- dependencyNames.push(attr.component);
38
- break;
39
- case 'media':
40
- dependencyNames.push('builtins::Media');
41
- break;
42
- case 'dynamiczone':
43
- dependencyNames.push.apply(dependencyNames, attr.components);
44
- break;
45
- default:
46
- continue;
47
- }
48
- // // If the current dependency is the interface itself, do not report it as a dependency
49
- // if (dependencyName === strapiName) {
50
- // continue;
51
- // }
52
- dependencyNames.forEach(function (dependencyName) {
53
- if (!dependencies.includes(dependencyName)) {
54
- dependencies.push(dependencyName);
55
- }
56
- });
57
- }
58
- return dependencies;
59
- };
60
- Attributes.prototype.attributeToString = function (attrName, attr) {
61
- var _this = this;
62
- var _a, _b, _c, _d;
63
- var optionalString = this.isAttributeOptional(attr) ? '?' : '';
64
- var orNull = ' | null';
65
- var requiredString = attr.required !== true ? orNull : '';
66
- var str = " ".concat(attrName).concat(optionalString, ": ");
67
- var isArray = false;
68
- switch (attr.type) {
69
- // types-4-strapi-2 specific, used for builtin types
70
- case 'nested':
71
- // Be careful with recursion
72
- // console.log(attr);
73
- var nullableString = ((_a = attr === null || attr === void 0 ? void 0 : attr.nullable) !== null && _a !== void 0 ? _a : false) ? ' | null' : '';
74
- var newAttrs = new Attributes(attr.fields, this.RelationNames);
75
- str += newAttrs.toString() + nullableString;
76
- break;
77
- case 'relation':
78
- var apiName = attr.target;
79
- // console.log(this.RelationNames, apiName)
80
- var dependencyName = (_c = (_b = this.RelationNames[apiName]) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : 'any';
81
- var relationMultipleString = attr.relation.endsWith('ToMany') ? '[]' : orNull;
82
- str += "{ data: ".concat(dependencyName).concat(relationMultipleString, "; }");
83
- break;
84
- case 'component':
85
- var componentName = attr.component;
86
- var relationNameObj = this.RelationNames[componentName];
87
- var dependencyComponentName = relationNameObj.name;
88
- isArray = (_d = attr.repeatable) !== null && _d !== void 0 ? _d : false;
89
- str += dependencyComponentName;
90
- break;
91
- case 'media':
92
- var mediaMultipleString = attr.multiple ? '[]' : requiredString;
93
- str += "{ data: ".concat(this.RelationNames['builtins::Media'].name).concat(mediaMultipleString, "; }");
94
- break;
95
- case 'password':
96
- return null;
97
- case 'enumeration':
98
- var hasDefault = 'default' in attr;
99
- var enums = attr.enum.map(function (en) { return "\"".concat(en, "\""); });
100
- enums.push('null');
101
- var typeString = enums.join(' | ');
102
- str += typeString;
103
- break;
104
- case 'dynamiczone':
105
- // console.log(attr.components);
106
- var relations = attr.components
107
- .map(function (componentName) { return _this.RelationNames[componentName].name; });
108
- // console.log(relations);
109
- var relationsString = relations.join(' | ');
110
- // console.log(relationsString);
111
- str += "Array<".concat(relationsString, ">");
112
- break;
113
- case 'string':
114
- case 'text':
115
- case 'richtext':
116
- case 'email':
117
- case 'uid':
118
- str += 'string';
119
- str += requiredString;
120
- break;
121
- case 'integer':
122
- case 'biginteger':
123
- case 'decimal':
124
- case 'float':
125
- str += 'number';
126
- str += requiredString;
127
- break;
128
- case 'date':
129
- case 'datetime':
130
- case 'time':
131
- str += 'string';
132
- str += requiredString;
133
- break;
134
- case 'boolean':
135
- str += attr.type;
136
- str += requiredString;
137
- break;
138
- case 'json':
139
- default:
140
- str += 'any';
141
- break;
142
- }
143
- var isArrayString = isArray ? '[]' : '';
144
- str += "".concat(isArrayString, ";");
145
- return str;
146
- };
147
- Attributes.prototype.toFieldsString = function () {
148
- var strings = [];
149
- for (var attrName in this.Attrs) {
150
- var attr = this.Attrs[attrName];
151
- var attrString = this.attributeToString(attrName, attr);
152
- if (attrString === null) {
153
- continue;
154
- }
155
- strings.push(attrString);
156
- }
157
- return strings.map(function (s) { return "".concat(s, "\n"); }).join('');
158
- };
159
- Attributes.prototype.toString = function () {
160
- var strings = ['{'];
161
- strings.push(this.toFieldsString());
162
- strings.push('}');
163
- return strings.join('\n');
164
- };
165
- return Attributes;
166
- }());
167
- exports.default = Attributes;
@@ -1,39 +0,0 @@
1
- /// <reference types="node" />
2
- import EventEmitter from 'events';
3
- export default class InterfaceManager {
4
- private Interfaces;
5
- private OutRoot;
6
- private StrapiSrcRoot;
7
- private Options;
8
- private PrettierOptions;
9
- eventEmitter: EventEmitter;
10
- static BaseOptions: {
11
- prefix: string;
12
- useCategoryPrefix: boolean;
13
- componentPrefix: string;
14
- componentPrefixOverridesPrefix: boolean;
15
- builtinsPrefix: string;
16
- builtinsPrefixOverridesPrefix: boolean;
17
- deleteOld: boolean;
18
- prettierFile: any;
19
- fileCaseType: "pascal" | "camel" | "capital" | "dot" | "snake" | "constant" | "kebab";
20
- folderCaseType: "pascal" | "camel" | "capital" | "dot" | "snake" | "constant" | "kebab";
21
- enabledPlugins: "url-alias"[];
22
- };
23
- constructor(outRoot: string, strapiSrcRoot: string, options?: Partial<typeof InterfaceManager['BaseOptions']>);
24
- registerPlugins(): void;
25
- validateOptions(): void;
26
- loadPrettierConfig(): Promise<void>;
27
- readSchemas(): Promise<{
28
- apiSchemas: any[];
29
- componentSchemas: any[];
30
- }>;
31
- createInterfaces(): Promise<void>;
32
- createBuiltinInterfaces(): void;
33
- injectDependencies(): void;
34
- deleteOldFolders(): Promise<void>;
35
- makeFolders(): Promise<void>;
36
- writeInterfaces(): Promise<void>;
37
- writeIndexFile(): Promise<void>;
38
- run(): Promise<void>;
39
- }
@@ -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>;