@oak-digital/types-4-strapi-2 0.5.5 → 1.0.0-beta.1
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 +2 -1
- package/CHANGELOG.md +7 -0
- package/README.md +17 -5
- package/lib/attributes/Attributes.d.ts +4 -3
- package/lib/attributes/Attributes.js +102 -78
- package/lib/content-types/reader.js +49 -145
- package/lib/extra-types/ExtraType.d.ts +2 -2
- package/lib/extra-types/ExtraType.js +19 -38
- package/lib/extra-types/createExtraTypes.d.ts +1 -1
- package/lib/extra-types/createExtraTypes.js +11 -12
- package/lib/file/File.d.ts +1 -1
- package/lib/file/File.js +44 -43
- package/lib/index.js +57 -19
- package/lib/interface/BuiltinComponentInterface.js +9 -27
- package/lib/interface/BuiltinInterface.d.ts +0 -1
- package/lib/interface/BuiltinInterface.js +5 -26
- package/lib/interface/ComponentInterface.d.ts +2 -1
- package/lib/interface/ComponentInterface.js +30 -48
- package/lib/interface/Interface.d.ts +6 -2
- package/lib/interface/Interface.js +69 -70
- package/lib/interface/builtinInterfaces.d.ts +1941 -2
- package/lib/interface/builtinInterfaces.js +56 -46
- package/lib/plugins/PluginManager.d.ts +8 -2
- package/lib/plugins/PluginManager.js +28 -35
- package/lib/plugins/draft-and-publish/index.d.ts +1 -1
- package/lib/plugins/draft-and-publish/index.js +17 -21
- package/lib/plugins/i18n/index.d.ts +1 -1
- package/lib/plugins/i18n/index.js +17 -22
- package/lib/plugins/index.js +4 -4
- package/lib/plugins/types.d.ts +1 -1
- package/lib/plugins/types.js +1 -4
- package/lib/plugins/url-alias/index.js +12 -15
- package/lib/plugins/url-alias/type.js +21 -32
- package/lib/program/InterfaceManager.d.ts +374 -24
- package/lib/program/InterfaceManager.js +128 -376
- package/lib/readers/by-file.d.ts +321 -0
- package/lib/readers/by-file.js +116 -0
- package/lib/readers/load-strapi/index.d.ts +319 -0
- package/lib/readers/load-strapi/index.js +106 -0
- package/lib/readers/types/attributes.d.ts +1639 -0
- package/lib/readers/types/attributes.js +144 -0
- package/lib/readers/types/component.d.ts +723 -0
- package/lib/readers/types/component.js +11 -0
- package/lib/readers/types/content-type-reader.d.ts +16 -0
- package/lib/readers/types/content-type-reader.js +2 -0
- package/lib/readers/types/content-type.d.ts +766 -0
- package/lib/readers/types/content-type.js +16 -0
- package/lib/utils/casing/index.js +2 -2
- package/lib/utils/index.js +5 -39
- package/lib/writers/basic-writer.d.ts +24 -0
- package/lib/writers/basic-writer.js +75 -0
- package/lib/writers/types/writer.d.ts +4 -0
- package/lib/writers/types/writer.js +2 -0
- package/package.json +4 -2
- package/tests/strapi-project/.editorconfig +16 -0
- package/tests/strapi-project/.env.example +6 -0
- package/tests/strapi-project/README.md +57 -0
- package/tests/strapi-project/config/admin.ts +13 -0
- package/tests/strapi-project/config/api.ts +7 -0
- package/tests/strapi-project/config/database.ts +93 -0
- package/tests/strapi-project/config/middlewares.ts +12 -0
- package/tests/strapi-project/config/server.ts +10 -0
- package/tests/strapi-project/database/migrations/.gitkeep +0 -0
- package/tests/strapi-project/favicon.png +0 -0
- package/tests/strapi-project/package-lock.json +16125 -0
- package/tests/strapi-project/package.json +30 -0
- package/tests/strapi-project/public/robots.txt +3 -0
- package/tests/strapi-project/public/uploads/.gitkeep +0 -0
- package/tests/strapi-project/src/admin/app.example.tsx +35 -0
- package/tests/strapi-project/src/admin/webpack.config.example.js +9 -0
- package/tests/strapi-project/src/api/.gitkeep +0 -0
- package/tests/strapi-project/src/api/collection-1/content-types/collection-1/schema.json +18 -0
- package/tests/strapi-project/src/api/collection-1/content-types/generated-type/schema.json +18 -0
- package/tests/strapi-project/src/api/collection-1/controllers/collection-1.ts +7 -0
- package/tests/strapi-project/src/api/collection-1/controllers/generated-type.ts +7 -0
- package/tests/strapi-project/src/api/collection-1/routes/collection-1.ts +7 -0
- package/tests/strapi-project/src/api/collection-1/routes/generated-type.ts +7 -0
- package/tests/strapi-project/src/api/collection-1/services/collection-1.ts +7 -0
- package/tests/strapi-project/src/api/collection-1/services/generated-type.ts +7 -0
- package/tests/strapi-project/src/api/standalone-controller/controllers/standalone-controller.ts +13 -0
- package/tests/strapi-project/src/components/my-category/all-types.json +88 -0
- package/tests/strapi-project/src/components/other-category/sub-component.json +12 -0
- package/tests/strapi-project/src/extensions/.gitkeep +0 -0
- package/tests/strapi-project/src/index.ts +18 -0
|
@@ -1,15 +1,4 @@
|
|
|
1
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
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,158 +8,89 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
9
|
});
|
|
21
10
|
};
|
|
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
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
59
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
13
|
};
|
|
61
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var InterfaceManager = /** @class */ (function () {
|
|
78
|
-
function InterfaceManager(outRoot, strapiSrcRoot, options) {
|
|
79
|
-
if (options === void 0) { options = {}; }
|
|
80
|
-
var _this = this;
|
|
15
|
+
const builtinInterfaces_1 = require("../interface/builtinInterfaces");
|
|
16
|
+
const ComponentInterface_1 = __importDefault(require("../interface/ComponentInterface"));
|
|
17
|
+
const Interface_1 = __importDefault(require("../interface/Interface"));
|
|
18
|
+
const change_case_1 = require("change-case");
|
|
19
|
+
const casing_1 = require("../utils/casing/");
|
|
20
|
+
const events_1 = require("../events");
|
|
21
|
+
const plugins_1 = require("../plugins");
|
|
22
|
+
const types_1 = require("../plugins/types");
|
|
23
|
+
const PluginManager_1 = require("../plugins/PluginManager");
|
|
24
|
+
const createExtraTypes_1 = require("../extra-types/createExtraTypes");
|
|
25
|
+
class InterfaceManager {
|
|
26
|
+
constructor(reader, writer, { prefix = 'I', useCategoryPrefix = true, componentPrefix = '', componentPrefixOverridesPrefix = false,
|
|
27
|
+
/* builtinsPrefix = '', */
|
|
28
|
+
/* builtinsPrefixOverridesPrefix = false, */
|
|
29
|
+
fileCaseType = 'pascal', folderCaseType = 'kebab', enabledPlugins = [], } = {}) {
|
|
81
30
|
this.Files = {}; // string = strapi name
|
|
82
31
|
this.dependenciesInjected = false;
|
|
83
|
-
this.
|
|
84
|
-
this.
|
|
85
|
-
this.Options =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
32
|
+
this.contentTypeReader = reader;
|
|
33
|
+
this.interfaceWriter = writer;
|
|
34
|
+
this.Options = {
|
|
35
|
+
prefix,
|
|
36
|
+
useCategoryPrefix,
|
|
37
|
+
componentPrefix,
|
|
38
|
+
componentPrefixOverridesPrefix,
|
|
39
|
+
/* builtinsPrefix, */
|
|
40
|
+
/* builtinsPrefixOverridesPrefix, */
|
|
41
|
+
fileCaseType,
|
|
42
|
+
folderCaseType,
|
|
43
|
+
enabledPlugins,
|
|
44
|
+
};
|
|
92
45
|
this.PluginManager = new PluginManager_1.PluginManager();
|
|
93
46
|
this.validateOptions();
|
|
94
47
|
this.registerBuiltinPlugins();
|
|
95
48
|
}
|
|
96
|
-
|
|
97
|
-
|
|
49
|
+
registerBuiltinPlugins() {
|
|
50
|
+
const pluginNames = new Set(this.Options.enabledPlugins);
|
|
98
51
|
(0, plugins_1.registerBuiltinPlugins)(this.PluginManager, pluginNames);
|
|
99
52
|
this.PluginManager.sortHooks();
|
|
100
|
-
}
|
|
53
|
+
}
|
|
101
54
|
// TODO: this function let's the user register their own plugins
|
|
102
|
-
|
|
55
|
+
registerPlugin() {
|
|
103
56
|
throw new Error('Not implemented');
|
|
104
|
-
}
|
|
105
|
-
|
|
57
|
+
}
|
|
58
|
+
validateOptions() {
|
|
106
59
|
if (!(0, casing_1.checkCaseType)(this.Options.fileCaseType)) {
|
|
107
|
-
throw new Error(
|
|
60
|
+
throw new Error(`${this.Options.fileCaseType} is not a supported type, please use one of the following ${casing_1.caseTypesArray.join(', ')}`);
|
|
108
61
|
}
|
|
109
62
|
if (!(0, casing_1.checkCaseType)(this.Options.folderCaseType)) {
|
|
110
|
-
throw new Error(
|
|
63
|
+
throw new Error(`${this.Options.folderCaseType} is not a supported type, please use one of the following ${casing_1.caseTypesArray.join(', ')}`);
|
|
111
64
|
}
|
|
112
|
-
this.Options.enabledPlugins.forEach(
|
|
65
|
+
this.Options.enabledPlugins.forEach((enabledPlugin) => {
|
|
113
66
|
if (!types_1.supportedPluginNames.includes(enabledPlugin)) {
|
|
114
|
-
throw new Error(
|
|
67
|
+
throw new Error(`plugin: \`${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 [${types_1.supportedPluginNames.join(', ')}]`);
|
|
115
68
|
}
|
|
116
69
|
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (!this.Options.prettierFile) {
|
|
128
|
-
this.PrettierOptions = defaultOptions;
|
|
129
|
-
return [2 /*return*/];
|
|
130
|
-
}
|
|
131
|
-
return [4 /*yield*/, prettier_1.default.resolveConfig(this.Options.prettierFile, {
|
|
132
|
-
editorconfig: true,
|
|
133
|
-
})];
|
|
134
|
-
case 1:
|
|
135
|
-
resolved = _a.sent();
|
|
136
|
-
this.PrettierOptions = Object.assign({}, defaultOptions, resolved);
|
|
137
|
-
return [2 /*return*/];
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
};
|
|
142
|
-
InterfaceManager.prototype.readSchemas = function () {
|
|
143
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
144
|
-
var apiSchemasPre, componentSchemasPre, apiSchemasPromise, componentSchemasPromise, _a, apiSchemas, componentSchemas, newObject;
|
|
145
|
-
return __generator(this, function (_b) {
|
|
146
|
-
switch (_b.label) {
|
|
147
|
-
case 0:
|
|
148
|
-
apiSchemasPre = [];
|
|
149
|
-
componentSchemasPre = [];
|
|
150
|
-
apiSchemasPromise = (0, reader_1.getApiSchemas)(this.StrapiSrcRoot);
|
|
151
|
-
componentSchemasPromise = (0, reader_1.getComponentSchemas)(this.StrapiSrcRoot);
|
|
152
|
-
this.PluginManager.invoke(events_1.Events.BeforeReadSchema, this, {
|
|
153
|
-
apiSchemas: apiSchemasPre,
|
|
154
|
-
componentSchemas: componentSchemasPre,
|
|
155
|
-
});
|
|
156
|
-
return [4 /*yield*/, Promise.all([
|
|
157
|
-
apiSchemasPromise,
|
|
158
|
-
componentSchemasPromise,
|
|
159
|
-
])];
|
|
160
|
-
case 1:
|
|
161
|
-
_a = _b.sent(), apiSchemas = _a[0], componentSchemas = _a[1];
|
|
162
|
-
newObject = {
|
|
163
|
-
apiSchemas: __spreadArray(__spreadArray([], apiSchemasPre, true), apiSchemas, true),
|
|
164
|
-
componentSchemas: __spreadArray(__spreadArray([], componentSchemasPre, true), componentSchemas, true),
|
|
165
|
-
};
|
|
166
|
-
this.PluginManager.invoke(events_1.Events.AfterReadSchema, this, newObject);
|
|
167
|
-
return [2 /*return*/, newObject];
|
|
168
|
-
}
|
|
70
|
+
}
|
|
71
|
+
readSchemas() {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const apiSchemasPre = {};
|
|
74
|
+
const componentSchemasPre = {};
|
|
75
|
+
const apiSchemasPromise = this.contentTypeReader.readContentTypes();
|
|
76
|
+
const componentSchemasPromise = this.contentTypeReader.readComponents();
|
|
77
|
+
this.PluginManager.invoke(events_1.Events.BeforeReadSchema, this, {
|
|
78
|
+
apiSchemas: apiSchemasPre,
|
|
79
|
+
componentSchemas: componentSchemasPre,
|
|
169
80
|
});
|
|
81
|
+
const [apiSchemas, componentSchemas] = yield Promise.all([
|
|
82
|
+
apiSchemasPromise,
|
|
83
|
+
componentSchemasPromise,
|
|
84
|
+
]);
|
|
85
|
+
const newObject = {
|
|
86
|
+
apiSchemas: Object.assign(Object.assign({}, apiSchemasPre), apiSchemas),
|
|
87
|
+
componentSchemas: Object.assign(Object.assign({}, componentSchemasPre), componentSchemas),
|
|
88
|
+
};
|
|
89
|
+
this.PluginManager.invoke(events_1.Events.AfterReadSchema, this, newObject);
|
|
90
|
+
return newObject;
|
|
170
91
|
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (force === void 0) { force = false; }
|
|
92
|
+
}
|
|
93
|
+
addType(name, file, force = false) {
|
|
174
94
|
if (this.dependenciesInjected) {
|
|
175
95
|
console.warn('You should not add types after dependencies have been injected');
|
|
176
96
|
}
|
|
@@ -179,256 +99,88 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
179
99
|
}
|
|
180
100
|
this.Files[name] = file;
|
|
181
101
|
return true;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
_a = _b.sent(), apiSchemas = _a.apiSchemas, componentSchemas = _a.componentSchemas;
|
|
192
|
-
this.PluginManager.invoke(events_1.Events.BeforeReadSchemas, this);
|
|
193
|
-
apiSchemas.forEach(function (schema) {
|
|
194
|
-
var name = schema.name, attributes = schema.schema.attributes;
|
|
195
|
-
var strapiName = "api::".concat(name, ".").concat(name);
|
|
196
|
-
var inter = new Interface_1.default(name, attributes, './', _this.Options.fileCaseType, _this.Options.prefix);
|
|
197
|
-
_this.addType(strapiName, inter);
|
|
198
|
-
});
|
|
199
|
-
componentSchemas.forEach(function (category) {
|
|
200
|
-
var categoryName = category.category;
|
|
201
|
-
category.schemas.forEach(function (_a) {
|
|
202
|
-
var name = _a.name, schema = _a.schema;
|
|
203
|
-
var componentName = name;
|
|
204
|
-
var strapiName = "".concat(categoryName, ".").concat(name);
|
|
205
|
-
var componentPrefix = "".concat(_this.Options.componentPrefix).concat(_this.Options.useCategoryPrefix
|
|
206
|
-
? (0, change_case_1.pascalCase)(categoryName)
|
|
207
|
-
: '');
|
|
208
|
-
var prefix = _this.Options.componentPrefixOverridesPrefix
|
|
209
|
-
? componentPrefix
|
|
210
|
-
: _this.Options.prefix + componentPrefix;
|
|
211
|
-
var categoryFolderName = (0, casing_1.changeCase)(categoryName, _this.Options.folderCaseType);
|
|
212
|
-
// make component interface
|
|
213
|
-
var inter = new ComponentInterface_1.default(componentName, schema.attributes, "./".concat(categoryFolderName), categoryName, _this.Options.fileCaseType, prefix);
|
|
214
|
-
_this.addType(strapiName, inter);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
this.PluginManager.invoke(events_1.Events.AfterReadSchemas, this);
|
|
218
|
-
return [2 /*return*/];
|
|
102
|
+
}
|
|
103
|
+
createInterfaces() {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
const { apiSchemas, componentSchemas } = yield this.readSchemas();
|
|
106
|
+
this.PluginManager.invoke(events_1.Events.BeforeReadSchemas, this);
|
|
107
|
+
Object.entries(apiSchemas).forEach(([name, schema]) => {
|
|
108
|
+
let strapiName = name;
|
|
109
|
+
if (schema.namespace === 'admin') {
|
|
110
|
+
strapiName = `admin::${schema.name}`;
|
|
219
111
|
}
|
|
112
|
+
else {
|
|
113
|
+
/* strapiName = `${schema.namespace}::${schema.collection}.${schema.name}`; */
|
|
114
|
+
}
|
|
115
|
+
const attributes = schema.contentType.attributes;
|
|
116
|
+
const inter = new Interface_1.default(schema.name, schema.namespace, attributes, './', schema.collection, this.Options.fileCaseType, this.Options.prefix);
|
|
117
|
+
this.addType(strapiName, inter);
|
|
118
|
+
});
|
|
119
|
+
Object.entries(componentSchemas).forEach(([name, schema]) => {
|
|
120
|
+
const strapiName = name;
|
|
121
|
+
const componentName = name.split('.')[1];
|
|
122
|
+
const categoryName = name.split('.')[0];
|
|
123
|
+
const attributes = schema.attributes;
|
|
124
|
+
const componentPrefix = `${this.Options.componentPrefix}${this.Options.useCategoryPrefix ? (0, change_case_1.pascalCase)(categoryName) : ''}`;
|
|
125
|
+
const prefix = this.Options.componentPrefixOverridesPrefix
|
|
126
|
+
? componentPrefix
|
|
127
|
+
: this.Options.prefix + componentPrefix;
|
|
128
|
+
const categoryFolderName = (0, casing_1.changeCase)(categoryName, this.Options.folderCaseType);
|
|
129
|
+
// make component interface
|
|
130
|
+
const inter = new ComponentInterface_1.default(componentName, 'api', schema.attributes, `./${categoryFolderName}`, categoryName, this.Options.fileCaseType, prefix);
|
|
131
|
+
this.addType(strapiName, inter);
|
|
220
132
|
});
|
|
133
|
+
this.PluginManager.invoke(events_1.Events.AfterReadSchemas, this);
|
|
221
134
|
});
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
var _this = this;
|
|
135
|
+
}
|
|
136
|
+
createBuiltinInterfaces() {
|
|
225
137
|
// Interfaces
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
builtinInterfaces.push((0, builtinInterfaces_1.createMediaInterface)(
|
|
230
|
-
builtinInterfaces.push((0, builtinInterfaces_1.createMediaFormatInterface)(
|
|
231
|
-
builtinInterfaces.forEach(
|
|
232
|
-
|
|
138
|
+
/* const outDirName = changeCase('builtins', this.Options.folderCaseType); */
|
|
139
|
+
/* const outDir = `./${outDirName}`; */
|
|
140
|
+
const builtinInterfaces = [];
|
|
141
|
+
builtinInterfaces.push((0, builtinInterfaces_1.createMediaInterface)(this.Options.fileCaseType, this.Options.prefix));
|
|
142
|
+
builtinInterfaces.push((0, builtinInterfaces_1.createMediaFormatInterface)(this.Options.fileCaseType, this.Options.prefix));
|
|
143
|
+
builtinInterfaces.forEach((inter) => {
|
|
144
|
+
this.addType(inter.getStrapiName(), inter);
|
|
233
145
|
});
|
|
234
146
|
// Types
|
|
235
|
-
|
|
236
|
-
types.push
|
|
237
|
-
types.forEach(
|
|
238
|
-
|
|
147
|
+
const types = [];
|
|
148
|
+
types.push(...(0, createExtraTypes_1.createExtraTypes)());
|
|
149
|
+
types.forEach((t) => {
|
|
150
|
+
this.addType(t.getStrapiName(), t);
|
|
239
151
|
});
|
|
240
|
-
}
|
|
152
|
+
}
|
|
241
153
|
// Inject dependencies into all interfaces
|
|
242
|
-
|
|
243
|
-
var _this = this;
|
|
154
|
+
injectDependencies() {
|
|
244
155
|
this.PluginManager.invoke(events_1.Events.BeforeInjectDependencies, this);
|
|
245
|
-
Object.keys(this.Files).forEach(
|
|
246
|
-
|
|
247
|
-
|
|
156
|
+
Object.keys(this.Files).forEach((strapiName) => {
|
|
157
|
+
const file = this.Files[strapiName];
|
|
158
|
+
const dependencies = file.getDependencies();
|
|
248
159
|
// console.log(`Interfaces for ${inter.getStrapiName()} are`)
|
|
249
|
-
|
|
250
|
-
.map(
|
|
251
|
-
return
|
|
160
|
+
const interfacesToInject = dependencies
|
|
161
|
+
.map((dependencyStrapiName) => {
|
|
162
|
+
return this.Files[dependencyStrapiName];
|
|
252
163
|
})
|
|
253
|
-
.filter(
|
|
164
|
+
.filter((inter) => inter);
|
|
254
165
|
file.setRelations(interfacesToInject);
|
|
255
166
|
});
|
|
256
167
|
this.dependenciesInjected = true;
|
|
257
168
|
this.PluginManager.invoke(events_1.Events.AfterInjectDependencies, this);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
};
|
|
274
|
-
InterfaceManager.prototype.makeFolders = function () {
|
|
275
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
276
|
-
var componentCategories, promises, componentCategoriesPromises, builintsFolderName, builtinsPath;
|
|
277
|
-
var _this = this;
|
|
278
|
-
return __generator(this, function (_a) {
|
|
279
|
-
switch (_a.label) {
|
|
280
|
-
case 0:
|
|
281
|
-
if (!this.Options.deleteOld) return [3 /*break*/, 2];
|
|
282
|
-
return [4 /*yield*/, this.deleteOldFolders()];
|
|
283
|
-
case 1:
|
|
284
|
-
_a.sent();
|
|
285
|
-
_a.label = 2;
|
|
286
|
-
case 2: return [4 /*yield*/, (0, reader_1.getComponentCategoryFolders)(this.StrapiSrcRoot)];
|
|
287
|
-
case 3:
|
|
288
|
-
componentCategories = _a.sent();
|
|
289
|
-
if (!!(0, fs_1.existsSync)(this.OutRoot)) return [3 /*break*/, 5];
|
|
290
|
-
return [4 /*yield*/, (0, promises_1.mkdir)(this.OutRoot, {
|
|
291
|
-
recursive: true,
|
|
292
|
-
})];
|
|
293
|
-
case 4:
|
|
294
|
-
_a.sent();
|
|
295
|
-
_a.label = 5;
|
|
296
|
-
case 5:
|
|
297
|
-
promises = [];
|
|
298
|
-
componentCategoriesPromises = componentCategories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
|
|
299
|
-
var folderName, path;
|
|
300
|
-
return __generator(this, function (_a) {
|
|
301
|
-
switch (_a.label) {
|
|
302
|
-
case 0:
|
|
303
|
-
folderName = (0, casing_1.changeCase)(category, this.Options.folderCaseType);
|
|
304
|
-
path = (0, posix_1.join)(this.OutRoot, folderName);
|
|
305
|
-
if ((0, fs_1.existsSync)(path)) {
|
|
306
|
-
return [2 /*return*/];
|
|
307
|
-
}
|
|
308
|
-
return [4 /*yield*/, (0, promises_1.mkdir)(path)];
|
|
309
|
-
case 1:
|
|
310
|
-
_a.sent();
|
|
311
|
-
return [2 /*return*/];
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
}); });
|
|
315
|
-
promises.push.apply(promises, componentCategoriesPromises);
|
|
316
|
-
builintsFolderName = (0, casing_1.changeCase)('builtins', this.Options.folderCaseType);
|
|
317
|
-
builtinsPath = (0, posix_1.join)(this.OutRoot, builintsFolderName);
|
|
318
|
-
if (!(0, fs_1.existsSync)(builtinsPath)) {
|
|
319
|
-
promises.push((0, promises_1.mkdir)(builtinsPath));
|
|
320
|
-
}
|
|
321
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
322
|
-
case 6:
|
|
323
|
-
_a.sent();
|
|
324
|
-
return [2 /*return*/];
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
};
|
|
329
|
-
InterfaceManager.prototype.writeInterfaces = function () {
|
|
330
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
331
|
-
var writePromises;
|
|
332
|
-
var _this = this;
|
|
333
|
-
return __generator(this, function (_a) {
|
|
334
|
-
switch (_a.label) {
|
|
335
|
-
case 0:
|
|
336
|
-
writePromises = Object.keys(this.Files).map(function (strapiName) { return __awaiter(_this, void 0, void 0, function () {
|
|
337
|
-
var file, fileData, formattedFileData, filePath;
|
|
338
|
-
return __generator(this, function (_a) {
|
|
339
|
-
switch (_a.label) {
|
|
340
|
-
case 0:
|
|
341
|
-
file = this.Files[strapiName];
|
|
342
|
-
fileData = file.toString();
|
|
343
|
-
formattedFileData = prettier_1.default.format(fileData, this.PrettierOptions);
|
|
344
|
-
filePath = (0, posix_1.join)(this.OutRoot, file.getRelativeRootPathFile());
|
|
345
|
-
return [4 /*yield*/, (0, promises_1.mkdir)((0, posix_1.dirname)(filePath), {
|
|
346
|
-
recursive: true,
|
|
347
|
-
})];
|
|
348
|
-
case 1:
|
|
349
|
-
_a.sent();
|
|
350
|
-
return [4 /*yield*/, (0, promises_1.writeFile)(filePath, formattedFileData)];
|
|
351
|
-
case 2:
|
|
352
|
-
_a.sent();
|
|
353
|
-
return [2 /*return*/];
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
}); });
|
|
357
|
-
return [4 /*yield*/, Promise.all(writePromises)];
|
|
358
|
-
case 1:
|
|
359
|
-
_a.sent();
|
|
360
|
-
return [2 /*return*/];
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
});
|
|
364
|
-
};
|
|
365
|
-
InterfaceManager.prototype.writeIndexFile = function () {
|
|
366
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
367
|
-
var strings, fileData, formattedFileData, filePath;
|
|
368
|
-
var _this = this;
|
|
369
|
-
return __generator(this, function (_a) {
|
|
370
|
-
switch (_a.label) {
|
|
371
|
-
case 0:
|
|
372
|
-
strings = Object.keys(this.Files).map(function (strapiName) {
|
|
373
|
-
var inter = _this.Files[strapiName];
|
|
374
|
-
return "export * from '".concat(inter.getRelativeRootPath(), "'");
|
|
375
|
-
});
|
|
376
|
-
fileData = strings.join('\n');
|
|
377
|
-
formattedFileData = prettier_1.default.format(fileData, this.PrettierOptions);
|
|
378
|
-
filePath = (0, posix_1.join)(this.OutRoot, 'index.ts');
|
|
379
|
-
return [4 /*yield*/, (0, promises_1.writeFile)(filePath, formattedFileData)];
|
|
380
|
-
case 1:
|
|
381
|
-
_a.sent();
|
|
382
|
-
return [2 /*return*/];
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
};
|
|
387
|
-
InterfaceManager.prototype.run = function () {
|
|
388
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
389
|
-
var createInterfacesPromise, makeFoldersPromise, loadPrettierPromise, err_1;
|
|
390
|
-
return __generator(this, function (_a) {
|
|
391
|
-
switch (_a.label) {
|
|
392
|
-
case 0:
|
|
393
|
-
_a.trys.push([0, 4, , 5]);
|
|
394
|
-
createInterfacesPromise = this.createInterfaces();
|
|
395
|
-
makeFoldersPromise = this.makeFolders();
|
|
396
|
-
loadPrettierPromise = this.loadPrettierConfig();
|
|
397
|
-
this.createBuiltinInterfaces();
|
|
398
|
-
return [4 /*yield*/, createInterfacesPromise];
|
|
399
|
-
case 1:
|
|
400
|
-
_a.sent();
|
|
401
|
-
// Create all interfaces before injecting
|
|
402
|
-
this.injectDependencies();
|
|
403
|
-
return [4 /*yield*/, Promise.all([makeFoldersPromise, loadPrettierPromise])];
|
|
404
|
-
case 2:
|
|
405
|
-
_a.sent();
|
|
406
|
-
return [4 /*yield*/, Promise.all([this.writeInterfaces(), this.writeIndexFile()])];
|
|
407
|
-
case 3:
|
|
408
|
-
_a.sent();
|
|
409
|
-
return [3 /*break*/, 5];
|
|
410
|
-
case 4:
|
|
411
|
-
err_1 = _a.sent();
|
|
412
|
-
console.error(err_1);
|
|
413
|
-
return [3 /*break*/, 5];
|
|
414
|
-
case 5: return [2 /*return*/];
|
|
415
|
-
}
|
|
416
|
-
});
|
|
169
|
+
}
|
|
170
|
+
run() {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
try {
|
|
173
|
+
const createInterfacesPromise = this.createInterfaces();
|
|
174
|
+
this.createBuiltinInterfaces();
|
|
175
|
+
yield createInterfacesPromise;
|
|
176
|
+
// Create all interfaces before injecting
|
|
177
|
+
this.injectDependencies();
|
|
178
|
+
yield this.interfaceWriter.write(Object.keys(this.Files).map((key) => this.Files[key]));
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
console.error(err);
|
|
182
|
+
}
|
|
417
183
|
});
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
prefix: 'I',
|
|
421
|
-
useCategoryPrefix: true,
|
|
422
|
-
componentPrefix: '',
|
|
423
|
-
componentPrefixOverridesPrefix: false,
|
|
424
|
-
builtinsPrefix: '',
|
|
425
|
-
builtinsPrefixOverridesPrefix: false,
|
|
426
|
-
deleteOld: false,
|
|
427
|
-
prettierFile: null,
|
|
428
|
-
fileCaseType: 'pascal',
|
|
429
|
-
folderCaseType: 'kebab',
|
|
430
|
-
enabledPlugins: [],
|
|
431
|
-
};
|
|
432
|
-
return InterfaceManager;
|
|
433
|
-
}());
|
|
184
|
+
}
|
|
185
|
+
}
|
|
434
186
|
exports.default = InterfaceManager;
|