@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.
- package/README.md +4 -3
- package/lib/content-types/reader.d.ts +2 -2
- package/lib/content-types/reader.js +7 -7
- package/lib/events/index.d.ts +6 -1
- package/lib/events/index.js +5 -0
- package/lib/interface/Interface.js +5 -0
- package/lib/plugins/PluginManager.d.ts +8 -4
- package/lib/plugins/PluginManager.js +11 -6
- package/lib/plugins/draft-and-publish/index.d.ts +3 -0
- package/lib/plugins/draft-and-publish/index.js +36 -0
- package/lib/plugins/i18n/index.d.ts +3 -0
- package/lib/plugins/i18n/index.js +41 -0
- package/lib/plugins/index.js +7 -0
- package/lib/plugins/types.d.ts +3 -1
- package/lib/plugins/types.js +1 -0
- package/lib/plugins/url-alias/index.d.ts +2 -2
- package/lib/plugins/url-alias/index.js +14 -1
- package/lib/plugins/url-alias/type.d.ts +8 -0
- package/lib/plugins/url-alias/type.js +41 -0
- package/lib/program/InterfaceManager.d.ts +4 -2
- package/lib/program/InterfaceManager.js +34 -17
- package/package.json +9 -8
- package/lib/.prettierrc.json +0 -7
- package/lib/case/index.d.ts +0 -4
- package/lib/case/index.js +0 -47
- package/lib/interface/Attributes.d.ts +0 -11
- package/lib/interface/Attributes.js +0 -167
- package/lib/interface/InterfaceManager.d.ts +0 -39
- package/lib/interface/InterfaceManager.js +0 -396
- package/lib/interface/interfaceCreator.d.ts +0 -0
- package/lib/interface/interfaceCreator.js +0 -7
- package/lib/interface/interfaceWriter.d.ts +0 -2
- package/lib/interface/interfaceWriter.js +0 -46
- package/lib/interface/schemaReader.d.ts +0 -14
- package/lib/interface/schemaReader.js +0 -177
- package/lib/src/index.d.ts +0 -1
- package/lib/src/index.js +0 -25
- package/lib/src/interface/Attributes.d.ts +0 -11
- package/lib/src/interface/Attributes.js +0 -148
- package/lib/src/interface/BuiltinComponentInterface.d.ts +0 -5
- package/lib/src/interface/BuiltinComponentInterface.js +0 -36
- package/lib/src/interface/BuiltinInterface.d.ts +0 -5
- package/lib/src/interface/BuiltinInterface.js +0 -33
- package/lib/src/interface/ComponentInterface.d.ts +0 -8
- package/lib/src/interface/ComponentInterface.js +0 -58
- package/lib/src/interface/Interface.d.ts +0 -31
- package/lib/src/interface/Interface.js +0 -112
- package/lib/src/interface/InterfaceManager.d.ts +0 -25
- package/lib/src/interface/InterfaceManager.js +0 -288
- package/lib/src/interface/builtinInterfaces.d.ts +0 -4
- package/lib/src/interface/builtinInterfaces.js +0 -81
- package/lib/src/interface/schemaReader.d.ts +0 -14
- package/lib/src/interface/schemaReader.js +0 -172
- package/lib/src/utils/index.d.ts +0 -3
- package/lib/src/utils/index.js +0 -67
package/README.md
CHANGED
|
@@ -154,12 +154,13 @@ export default (plugin: any) => {
|
|
|
154
154
|
To build this project, use the following command
|
|
155
155
|
|
|
156
156
|
```bash
|
|
157
|
-
|
|
157
|
+
pnpm run build
|
|
158
158
|
```
|
|
159
159
|
|
|
160
160
|
## Publishing
|
|
161
161
|
|
|
162
162
|
```bash
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
pnpm version # major | minor | patch
|
|
164
|
+
pnpm run build
|
|
165
|
+
pnpm publish
|
|
165
166
|
```
|
|
@@ -5,10 +5,10 @@ export declare function getComponentSchemas(strapiSrcRoot: string): Promise<{
|
|
|
5
5
|
category: string;
|
|
6
6
|
schemas: {
|
|
7
7
|
name: string;
|
|
8
|
-
|
|
8
|
+
schema: any;
|
|
9
9
|
}[];
|
|
10
10
|
}[]>;
|
|
11
11
|
export declare function getApiSchemas(strapiSrcRoot: string): Promise<{
|
|
12
12
|
name: string;
|
|
13
|
-
|
|
13
|
+
schema: any;
|
|
14
14
|
}[]>;
|
|
@@ -51,7 +51,7 @@ function readSchema(schemaPath) {
|
|
|
51
51
|
return [4 /*yield*/, (0, promises_1.readFile)(schemaPath)];
|
|
52
52
|
case 1:
|
|
53
53
|
schemaData = _a.sent();
|
|
54
|
-
return [2 /*return*/, JSON.parse(schemaData.toString())
|
|
54
|
+
return [2 /*return*/, JSON.parse(schemaData.toString())];
|
|
55
55
|
case 2:
|
|
56
56
|
e_1 = _a.sent();
|
|
57
57
|
return [2 /*return*/, null];
|
|
@@ -117,16 +117,16 @@ function getComponentSchemas(strapiSrcRoot) {
|
|
|
117
117
|
case 1:
|
|
118
118
|
schemaFiles = _a.sent();
|
|
119
119
|
schemaNamesWithAttributesPromises = schemaFiles.map(function (file) { return __awaiter(_this, void 0, void 0, function () {
|
|
120
|
-
var schemaPath,
|
|
120
|
+
var schemaPath, schema, name;
|
|
121
121
|
return __generator(this, function (_a) {
|
|
122
122
|
switch (_a.label) {
|
|
123
123
|
case 0:
|
|
124
124
|
schemaPath = (0, posix_1.join)(schemaFilesPath, file);
|
|
125
125
|
return [4 /*yield*/, readSchema(schemaPath)];
|
|
126
126
|
case 1:
|
|
127
|
-
|
|
127
|
+
schema = _a.sent();
|
|
128
128
|
name = file.split('.')[0];
|
|
129
|
-
return [2 /*return*/, { name: name,
|
|
129
|
+
return [2 /*return*/, { name: name, schema: schema }];
|
|
130
130
|
}
|
|
131
131
|
});
|
|
132
132
|
}); });
|
|
@@ -156,15 +156,15 @@ function getApiSchemas(strapiSrcRoot) {
|
|
|
156
156
|
case 1:
|
|
157
157
|
apiFolders = _a.sent();
|
|
158
158
|
schemasWithAttributesPromises = apiFolders.map(function (folder) { return __awaiter(_this, void 0, void 0, function () {
|
|
159
|
-
var schemaPath,
|
|
159
|
+
var schemaPath, schema;
|
|
160
160
|
return __generator(this, function (_a) {
|
|
161
161
|
switch (_a.label) {
|
|
162
162
|
case 0:
|
|
163
163
|
schemaPath = (0, posix_1.join)(strapiSrcRoot, 'api', folder, 'content-types', folder, 'schema.json');
|
|
164
164
|
return [4 /*yield*/, readSchema(schemaPath)];
|
|
165
165
|
case 1:
|
|
166
|
-
|
|
167
|
-
return [2 /*return*/, { name: folder,
|
|
166
|
+
schema = _a.sent();
|
|
167
|
+
return [2 /*return*/, { name: folder, schema: schema }];
|
|
168
168
|
}
|
|
169
169
|
});
|
|
170
170
|
}); });
|
package/lib/events/index.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export declare enum Events {
|
|
2
2
|
BeforeReadSchema = "BeforeReadSchema",
|
|
3
|
-
AfterReadSchema = "AfterReadSchema"
|
|
3
|
+
AfterReadSchema = "AfterReadSchema",
|
|
4
|
+
BeforeReadSchemas = "BeforeReadSchemas",
|
|
5
|
+
AfterReadSchemas = "AfterReadSchemas",
|
|
6
|
+
ModifySchemas = "ModifySchemas",
|
|
7
|
+
BeforeInjectDependencies = "BeforeInjectDependencies",
|
|
8
|
+
AfterInjectDependencies = "AfterInjectDependencies"
|
|
4
9
|
}
|
|
5
10
|
export declare type SchemasType = {
|
|
6
11
|
apiSchemas: Record<string, any>[];
|
package/lib/events/index.js
CHANGED
|
@@ -5,4 +5,9 @@ var Events;
|
|
|
5
5
|
(function (Events) {
|
|
6
6
|
Events["BeforeReadSchema"] = "BeforeReadSchema";
|
|
7
7
|
Events["AfterReadSchema"] = "AfterReadSchema";
|
|
8
|
+
Events["BeforeReadSchemas"] = "BeforeReadSchemas";
|
|
9
|
+
Events["AfterReadSchemas"] = "AfterReadSchemas";
|
|
10
|
+
Events["ModifySchemas"] = "ModifySchemas";
|
|
11
|
+
Events["BeforeInjectDependencies"] = "BeforeInjectDependencies";
|
|
12
|
+
Events["AfterInjectDependencies"] = "AfterInjectDependencies";
|
|
8
13
|
})(Events = exports.Events || (exports.Events = {}));
|
|
@@ -32,9 +32,13 @@ var Interface = /** @class */ (function (_super) {
|
|
|
32
32
|
_this.updateStrapiName();
|
|
33
33
|
_this.NamePrefix = prefix;
|
|
34
34
|
_this.Attributes = attributes;
|
|
35
|
+
if (!attributes) {
|
|
36
|
+
console.warn("Warning: attributes for ".concat(_this.getStrapiName(), " is empty!"));
|
|
37
|
+
}
|
|
35
38
|
return _this;
|
|
36
39
|
}
|
|
37
40
|
Interface.prototype.updateStrapiName = function () {
|
|
41
|
+
// TODO: add support for api name
|
|
38
42
|
this.StrapiName = "api::".concat(this.BaseName, ".").concat(this.BaseName);
|
|
39
43
|
};
|
|
40
44
|
Interface.prototype.getStrapiName = function () {
|
|
@@ -44,6 +48,7 @@ var Interface = /** @class */ (function (_super) {
|
|
|
44
48
|
return this.getAttributes().getDependencies();
|
|
45
49
|
};
|
|
46
50
|
Interface.prototype.getFullName = function () {
|
|
51
|
+
// TODO: use correct casing from options
|
|
47
52
|
var pascalName = (0, change_case_1.pascalCase)(this.BaseName);
|
|
48
53
|
return "".concat(this.NamePrefix).concat(pascalName);
|
|
49
54
|
};
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { Events } from '../events';
|
|
1
2
|
import InterfaceManager from '../program/InterfaceManager';
|
|
2
3
|
export declare type HookTypes = {
|
|
3
|
-
BeforeReadSchema: (state: InterfaceManager, schema: any) => void;
|
|
4
|
-
AfterReadSchema: (state: InterfaceManager, schema: any) => void;
|
|
5
|
-
BeforeReadSchemas: (state: InterfaceManager) => void;
|
|
6
|
-
AfterReadSchemas: (state: InterfaceManager) => void;
|
|
4
|
+
[Events.BeforeReadSchema]: (state: InterfaceManager, schema: any) => void;
|
|
5
|
+
[Events.AfterReadSchema]: (state: InterfaceManager, schema: any) => void;
|
|
6
|
+
[Events.BeforeReadSchemas]: (state: InterfaceManager) => void;
|
|
7
|
+
[Events.AfterReadSchemas]: (state: InterfaceManager) => void;
|
|
8
|
+
[Events.ModifySchemas]: (state: InterfaceManager) => void;
|
|
9
|
+
[Events.BeforeInjectDependencies]: (state: InterfaceManager) => void;
|
|
10
|
+
[Events.AfterInjectDependencies]: (state: InterfaceManager) => void;
|
|
7
11
|
};
|
|
8
12
|
export declare type HooksType = {
|
|
9
13
|
[HookType in keyof HookTypes]: {
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PluginManager = void 0;
|
|
4
|
+
var events_1 = require("../events");
|
|
4
5
|
var PluginManager = /** @class */ (function () {
|
|
5
6
|
function PluginManager() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
var _a;
|
|
8
|
+
this.hooks = (_a = {},
|
|
9
|
+
_a[events_1.Events.BeforeReadSchema] = [],
|
|
10
|
+
_a[events_1.Events.BeforeReadSchemas] = [],
|
|
11
|
+
_a[events_1.Events.AfterReadSchema] = [],
|
|
12
|
+
_a[events_1.Events.AfterReadSchemas] = [],
|
|
13
|
+
_a[events_1.Events.ModifySchemas] = [],
|
|
14
|
+
_a[events_1.Events.BeforeInjectDependencies] = [],
|
|
15
|
+
_a[events_1.Events.AfterInjectDependencies] = [],
|
|
16
|
+
_a);
|
|
12
17
|
}
|
|
13
18
|
PluginManager.prototype.registerPlugin = function (hooks) {
|
|
14
19
|
var _a;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var constants_1 = require("../../constants");
|
|
4
|
+
var events_1 = require("../../events");
|
|
5
|
+
var addFieldsToContentTypes = function (state, schema) {
|
|
6
|
+
var apiSchemas = schema.apiSchemas;
|
|
7
|
+
apiSchemas.forEach(function (_a) {
|
|
8
|
+
var name = _a.name, schema = _a.schema;
|
|
9
|
+
var attributes = schema.attributes, _b = schema.options, options = _b === void 0 ? {} : _b;
|
|
10
|
+
if ((options === null || options === void 0 ? void 0 : options.draftAndPublish) !== true) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
var fieldNames = ['publishedAt', 'createdAt', 'updatedAt'];
|
|
14
|
+
fieldNames.forEach(function (fieldName) {
|
|
15
|
+
var _a;
|
|
16
|
+
attributes[fieldName] = (_a = {
|
|
17
|
+
type: 'string',
|
|
18
|
+
required: true
|
|
19
|
+
},
|
|
20
|
+
_a[constants_1.CERTAINLY_REQUIRED_KEY] = true,
|
|
21
|
+
_a);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
var register = function () {
|
|
26
|
+
var _a;
|
|
27
|
+
return _a = {},
|
|
28
|
+
_a[events_1.Events.AfterReadSchema] = [
|
|
29
|
+
{
|
|
30
|
+
fn: addFieldsToContentTypes,
|
|
31
|
+
priority: 10,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
_a;
|
|
35
|
+
};
|
|
36
|
+
exports.default = register;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var constants_1 = require("../../constants");
|
|
4
|
+
var events_1 = require("../../events");
|
|
5
|
+
var addLocaleToLocalizedContentTypes = function (state, _a) {
|
|
6
|
+
var apiSchemas = _a.apiSchemas;
|
|
7
|
+
apiSchemas.forEach(function (_a) {
|
|
8
|
+
var _b;
|
|
9
|
+
var _c, _d;
|
|
10
|
+
var name = _a.name, schema = _a.schema;
|
|
11
|
+
var attributes = schema.attributes;
|
|
12
|
+
if (((_d = (_c = schema === null || schema === void 0 ? void 0 : schema.pluginOptions) === null || _c === void 0 ? void 0 : _c.i18n) === null || _d === void 0 ? void 0 : _d.localized) !== true) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
// Add locale to all localized content types
|
|
16
|
+
attributes.locale = (_b = {
|
|
17
|
+
type: 'string',
|
|
18
|
+
required: true
|
|
19
|
+
},
|
|
20
|
+
_b[constants_1.CERTAINLY_REQUIRED_KEY] = true,
|
|
21
|
+
_b);
|
|
22
|
+
// Add populatable field for localizations
|
|
23
|
+
attributes.localizations = {
|
|
24
|
+
type: 'relation',
|
|
25
|
+
relation: 'oneToMany',
|
|
26
|
+
target: "api::".concat(name, ".").concat(name), // TODO: make this more complete
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var register = function () {
|
|
31
|
+
var _a;
|
|
32
|
+
return _a = {},
|
|
33
|
+
_a[events_1.Events.AfterReadSchema] = [
|
|
34
|
+
{
|
|
35
|
+
fn: addLocaleToLocalizedContentTypes,
|
|
36
|
+
priority: 10,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
_a;
|
|
40
|
+
};
|
|
41
|
+
exports.default = register;
|
package/lib/plugins/index.js
CHANGED
|
@@ -5,9 +5,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.registerBuiltinPlugins = void 0;
|
|
7
7
|
var url_alias_1 = __importDefault(require("./url-alias"));
|
|
8
|
+
var draft_and_publish_1 = __importDefault(require("./draft-and-publish"));
|
|
9
|
+
var i18n_1 = __importDefault(require("./i18n"));
|
|
8
10
|
var registerBuiltinPlugins = function (pluginManager, pluginNames) {
|
|
11
|
+
// Draft and publish is always registered since it is built into Strapi
|
|
12
|
+
pluginManager.registerPlugin((0, draft_and_publish_1.default)());
|
|
9
13
|
if (pluginNames.has('url-alias')) {
|
|
10
14
|
pluginManager.registerPlugin((0, url_alias_1.default)());
|
|
11
15
|
}
|
|
16
|
+
if (pluginNames.has('i18n')) {
|
|
17
|
+
pluginManager.registerPlugin((0, i18n_1.default)());
|
|
18
|
+
}
|
|
12
19
|
};
|
|
13
20
|
exports.registerBuiltinPlugins = registerBuiltinPlugins;
|
package/lib/plugins/types.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { HooksType } from "./PluginManager";
|
|
2
|
+
export declare const supportedPluginNames: readonly ["url-alias", "i18n"];
|
|
2
3
|
export declare type SupportedPluginNamesType = typeof supportedPluginNames[number];
|
|
4
|
+
export declare type PluginRegister = () => Partial<HooksType>;
|
package/lib/plugins/types.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const register:
|
|
1
|
+
import { PluginRegister } from '../types';
|
|
2
|
+
declare const register: PluginRegister;
|
|
3
3
|
export default register;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var events_1 = require("../../events");
|
|
4
|
+
var type_1 = require("./type");
|
|
4
5
|
var addUrlAliasToAllContentTypes = function (state, _a) {
|
|
5
6
|
var apiSchemas = _a.apiSchemas;
|
|
6
|
-
apiSchemas.forEach(function (
|
|
7
|
+
apiSchemas.forEach(function (_a) {
|
|
8
|
+
var name = _a.name, schema = _a.schema;
|
|
7
9
|
var attributes = schema.attributes;
|
|
10
|
+
// TODO: write comment here if it is intentional that it it can be null
|
|
8
11
|
attributes.url_path = {
|
|
9
12
|
type: 'string',
|
|
10
13
|
required: true,
|
|
@@ -16,6 +19,10 @@ var addUrlAliasToAllContentTypes = function (state, _a) {
|
|
|
16
19
|
// };
|
|
17
20
|
});
|
|
18
21
|
};
|
|
22
|
+
var addUrlAliasGetType = function (state) {
|
|
23
|
+
var urlAliasGet = new type_1.UrlAliasGet();
|
|
24
|
+
state.addType(urlAliasGet.getStrapiName(), urlAliasGet);
|
|
25
|
+
};
|
|
19
26
|
var register = function () {
|
|
20
27
|
var _a;
|
|
21
28
|
return _a = {},
|
|
@@ -25,6 +32,12 @@ var register = function () {
|
|
|
25
32
|
priority: 10,
|
|
26
33
|
},
|
|
27
34
|
],
|
|
35
|
+
_a[events_1.Events.AfterReadSchemas] = [
|
|
36
|
+
{
|
|
37
|
+
fn: addUrlAliasGetType,
|
|
38
|
+
priority: 10,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
28
41
|
_a;
|
|
29
42
|
};
|
|
30
43
|
exports.default = register;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.UrlAliasGet = void 0;
|
|
19
|
+
var File_1 = require("../../file/File");
|
|
20
|
+
/* import Interface from "../../interface/Interface"; */
|
|
21
|
+
var UrlAliasGet = /** @class */ (function (_super) {
|
|
22
|
+
__extends(UrlAliasGet, _super);
|
|
23
|
+
function UrlAliasGet() {
|
|
24
|
+
var baseName = 'url-alias';
|
|
25
|
+
return _super.call(this, baseName, 'plugins/url-alias', 'pascal') || this;
|
|
26
|
+
}
|
|
27
|
+
UrlAliasGet.prototype.getStrapiName = function () {
|
|
28
|
+
return 'plugins::url-alias.get';
|
|
29
|
+
};
|
|
30
|
+
UrlAliasGet.prototype.getFullName = function () {
|
|
31
|
+
return 'UrlAliasGet';
|
|
32
|
+
};
|
|
33
|
+
UrlAliasGet.prototype.getDependencies = function () {
|
|
34
|
+
return [];
|
|
35
|
+
};
|
|
36
|
+
UrlAliasGet.prototype.toString = function () {
|
|
37
|
+
return "\n export type ".concat(this.getFullName(), "<ContentType extends { attributes: {} }> = ContentType & {\n attributes: {\n contentType: string;\n },\n }\n ");
|
|
38
|
+
};
|
|
39
|
+
return UrlAliasGet;
|
|
40
|
+
}(File_1.File));
|
|
41
|
+
exports.UrlAliasGet = UrlAliasGet;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { File } from '../file/File';
|
|
1
2
|
export default class InterfaceManager {
|
|
2
|
-
private Interfaces;
|
|
3
3
|
private Files;
|
|
4
4
|
private OutRoot;
|
|
5
5
|
private StrapiSrcRoot;
|
|
6
6
|
private Options;
|
|
7
7
|
private PrettierOptions;
|
|
8
8
|
private PluginManager;
|
|
9
|
+
private dependenciesInjected;
|
|
9
10
|
static BaseOptions: {
|
|
10
11
|
prefix: string;
|
|
11
12
|
useCategoryPrefix: boolean;
|
|
@@ -17,7 +18,7 @@ export default class InterfaceManager {
|
|
|
17
18
|
prettierFile: any;
|
|
18
19
|
fileCaseType: "camel" | "capital" | "dot" | "snake" | "pascal" | "constant" | "kebab";
|
|
19
20
|
folderCaseType: "camel" | "capital" | "dot" | "snake" | "pascal" | "constant" | "kebab";
|
|
20
|
-
enabledPlugins: "url-alias"[];
|
|
21
|
+
enabledPlugins: ("url-alias" | "i18n")[];
|
|
21
22
|
};
|
|
22
23
|
constructor(outRoot: string, strapiSrcRoot: string, options?: Partial<typeof InterfaceManager['BaseOptions']>);
|
|
23
24
|
registerBuiltinPlugins(): void;
|
|
@@ -28,6 +29,7 @@ export default class InterfaceManager {
|
|
|
28
29
|
apiSchemas: any[];
|
|
29
30
|
componentSchemas: any[];
|
|
30
31
|
}>;
|
|
32
|
+
addType(name: string, file: File, force?: boolean): boolean;
|
|
31
33
|
createInterfaces(): Promise<void>;
|
|
32
34
|
createBuiltinInterfaces(): void;
|
|
33
35
|
injectDependencies(): void;
|
|
@@ -67,7 +67,7 @@ var ComponentInterface_1 = __importDefault(require("../interface/ComponentInterf
|
|
|
67
67
|
var Interface_1 = __importDefault(require("../interface/Interface"));
|
|
68
68
|
var reader_1 = require("../content-types/reader");
|
|
69
69
|
var prettier_1 = __importDefault(require("prettier"));
|
|
70
|
-
var
|
|
70
|
+
var change_case_1 = require("change-case");
|
|
71
71
|
var casing_1 = require("../utils/casing/");
|
|
72
72
|
var events_1 = require("../events");
|
|
73
73
|
var plugins_1 = require("../plugins");
|
|
@@ -78,9 +78,8 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
78
78
|
function InterfaceManager(outRoot, strapiSrcRoot, options) {
|
|
79
79
|
if (options === void 0) { options = {}; }
|
|
80
80
|
var _this = this;
|
|
81
|
-
// TODO: remove Interfaces
|
|
82
|
-
this.Interfaces = {}; // string = strapi name
|
|
83
81
|
this.Files = {}; // string = strapi name
|
|
82
|
+
this.dependenciesInjected = false;
|
|
84
83
|
this.OutRoot = outRoot;
|
|
85
84
|
this.StrapiSrcRoot = strapiSrcRoot;
|
|
86
85
|
this.Options = __assign(__assign({}, InterfaceManager.BaseOptions), options);
|
|
@@ -170,6 +169,17 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
170
169
|
});
|
|
171
170
|
});
|
|
172
171
|
};
|
|
172
|
+
InterfaceManager.prototype.addType = function (name, file, force) {
|
|
173
|
+
if (force === void 0) { force = false; }
|
|
174
|
+
if (this.dependenciesInjected) {
|
|
175
|
+
console.warn('You should not add types after dependencies have been injected');
|
|
176
|
+
}
|
|
177
|
+
if (this.Files[name] && !force) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
this.Files[name] = file;
|
|
181
|
+
return true;
|
|
182
|
+
};
|
|
173
183
|
InterfaceManager.prototype.createInterfaces = function () {
|
|
174
184
|
return __awaiter(this, void 0, void 0, function () {
|
|
175
185
|
var _a, apiSchemas, componentSchemas;
|
|
@@ -179,20 +189,21 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
179
189
|
case 0: return [4 /*yield*/, this.readSchemas()];
|
|
180
190
|
case 1:
|
|
181
191
|
_a = _b.sent(), apiSchemas = _a.apiSchemas, componentSchemas = _a.componentSchemas;
|
|
192
|
+
this.PluginManager.invoke(events_1.Events.BeforeReadSchemas, this);
|
|
182
193
|
apiSchemas.forEach(function (schema) {
|
|
183
|
-
var name = schema.name, attributes = schema.attributes;
|
|
194
|
+
var name = schema.name, attributes = schema.schema.attributes;
|
|
184
195
|
var strapiName = "api::".concat(name, ".").concat(name);
|
|
185
196
|
var inter = new Interface_1.default(name, attributes, './', _this.Options.fileCaseType, _this.Options.prefix);
|
|
186
|
-
_this.
|
|
187
|
-
_this.Files[strapiName] = inter;
|
|
197
|
+
_this.addType(strapiName, inter);
|
|
188
198
|
});
|
|
189
199
|
componentSchemas.forEach(function (category) {
|
|
190
200
|
var categoryName = category.category;
|
|
191
|
-
category.schemas.forEach(function (
|
|
192
|
-
var
|
|
193
|
-
var
|
|
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);
|
|
194
205
|
var componentPrefix = "".concat(_this.Options.componentPrefix).concat(_this.Options.useCategoryPrefix
|
|
195
|
-
? (0,
|
|
206
|
+
? (0, change_case_1.pascalCase)(categoryName)
|
|
196
207
|
: '');
|
|
197
208
|
var prefix = _this.Options.componentPrefixOverridesPrefix
|
|
198
209
|
? componentPrefix
|
|
@@ -200,10 +211,10 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
200
211
|
var categoryFolderName = (0, casing_1.changeCase)(categoryName, _this.Options.folderCaseType);
|
|
201
212
|
// make component interface
|
|
202
213
|
var inter = new ComponentInterface_1.default(componentName, schema.attributes, "./".concat(categoryFolderName), categoryName, _this.Options.fileCaseType, prefix);
|
|
203
|
-
_this.
|
|
204
|
-
_this.Files[strapiName] = inter;
|
|
214
|
+
_this.addType(strapiName, inter);
|
|
205
215
|
});
|
|
206
216
|
});
|
|
217
|
+
this.PluginManager.invoke(events_1.Events.AfterReadSchemas, this);
|
|
207
218
|
return [2 /*return*/];
|
|
208
219
|
}
|
|
209
220
|
});
|
|
@@ -218,20 +229,19 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
218
229
|
builtinInterfaces.push((0, builtinInterfaces_1.createMediaInterface)(outDir, this.Options.fileCaseType, this.Options.prefix));
|
|
219
230
|
builtinInterfaces.push((0, builtinInterfaces_1.createMediaFormatInterface)(outDir, this.Options.fileCaseType, this.Options.prefix));
|
|
220
231
|
builtinInterfaces.forEach(function (inter) {
|
|
221
|
-
_this.
|
|
222
|
-
_this.Files[inter.getStrapiName()] = inter;
|
|
232
|
+
_this.addType(inter.getStrapiName(), inter);
|
|
223
233
|
});
|
|
224
234
|
// Types
|
|
225
235
|
var types = [];
|
|
226
236
|
types.push.apply(types, (0, createExtraTypes_1.createExtraTypes)());
|
|
227
237
|
types.forEach(function (t) {
|
|
228
|
-
_this.
|
|
238
|
+
_this.addType(t.getStrapiName(), t);
|
|
229
239
|
});
|
|
230
240
|
};
|
|
231
241
|
// Inject dependencies into all interfaces
|
|
232
242
|
InterfaceManager.prototype.injectDependencies = function () {
|
|
233
243
|
var _this = this;
|
|
234
|
-
|
|
244
|
+
this.PluginManager.invoke(events_1.Events.BeforeInjectDependencies, this);
|
|
235
245
|
Object.keys(this.Files).forEach(function (strapiName) {
|
|
236
246
|
var file = _this.Files[strapiName];
|
|
237
247
|
var dependencies = file.getDependencies();
|
|
@@ -243,6 +253,8 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
243
253
|
.filter(function (inter) { return inter; });
|
|
244
254
|
file.setRelations(interfacesToInject);
|
|
245
255
|
});
|
|
256
|
+
this.dependenciesInjected = true;
|
|
257
|
+
this.PluginManager.invoke(events_1.Events.AfterInjectDependencies, this);
|
|
246
258
|
};
|
|
247
259
|
InterfaceManager.prototype.deleteOldFolders = function () {
|
|
248
260
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -330,8 +342,13 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
330
342
|
fileData = file.toString();
|
|
331
343
|
formattedFileData = prettier_1.default.format(fileData, this.PrettierOptions);
|
|
332
344
|
filePath = (0, posix_1.join)(this.OutRoot, file.getRelativeRootPathFile());
|
|
333
|
-
return [4 /*yield*/, (0, promises_1.
|
|
345
|
+
return [4 /*yield*/, (0, promises_1.mkdir)((0, posix_1.dirname)(filePath), {
|
|
346
|
+
recursive: true,
|
|
347
|
+
})];
|
|
334
348
|
case 1:
|
|
349
|
+
_a.sent();
|
|
350
|
+
return [4 /*yield*/, (0, promises_1.writeFile)(filePath, formattedFileData)];
|
|
351
|
+
case 2:
|
|
335
352
|
_a.sent();
|
|
336
353
|
return [2 /*return*/];
|
|
337
354
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oak-digital/types-4-strapi-2",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "Typescript interface generator for Strapi 4 models",
|
|
5
5
|
"bin": {
|
|
6
6
|
"t4s": "./bin/index.js"
|
|
7
7
|
},
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "tsc -p .",
|
|
10
|
-
"testtypes": "node ./bin/index.js",
|
|
11
|
-
"lint": "eslint src/",
|
|
12
|
-
"t4s": "node ./bin/index.js"
|
|
13
|
-
},
|
|
14
8
|
"repository": {
|
|
15
9
|
"type": "git",
|
|
16
10
|
"url": "git+https://github.com/Oak-Digital/types-4-strapi-2.git"
|
|
@@ -33,11 +27,18 @@
|
|
|
33
27
|
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
|
34
28
|
"@typescript-eslint/parser": "^5.33.1",
|
|
35
29
|
"eslint": "^8.22.0",
|
|
30
|
+
"rimraf": "^4.4.1",
|
|
36
31
|
"typescript": "^4.7.4"
|
|
37
32
|
},
|
|
38
33
|
"dependencies": {
|
|
39
34
|
"change-case": "^4.1.2",
|
|
40
35
|
"commander": "^9.4.0",
|
|
41
36
|
"prettier": "^2.7.1"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "rimraf lib && tsc -p .",
|
|
40
|
+
"testtypes": "node ./bin/index.js",
|
|
41
|
+
"lint": "eslint src/",
|
|
42
|
+
"t4s": "node ./bin/index.js"
|
|
42
43
|
}
|
|
43
|
-
}
|
|
44
|
+
}
|
package/lib/.prettierrc.json
DELETED
package/lib/case/index.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
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;
|
package/lib/case/index.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
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;
|