@oak-digital/types-4-strapi-2 0.3.6 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +0 -4
- package/.prettierrc.json +1 -0
- package/README.md +41 -1
- package/lib/attributes/Attributes.d.ts +13 -0
- package/lib/attributes/Attributes.js +227 -0
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +4 -0
- package/lib/content-types/reader.d.ts +14 -0
- package/lib/content-types/reader.js +177 -0
- package/lib/extra-types/ExtraType.d.ts +11 -0
- package/lib/extra-types/ExtraType.js +47 -0
- package/lib/extra-types/createExtraTypes.d.ts +2 -0
- package/lib/extra-types/createExtraTypes.js +21 -0
- package/lib/file/File.d.ts +26 -0
- package/lib/file/File.js +72 -0
- package/lib/index.js +1 -1
- package/lib/interface/BuiltinComponentInterface.d.ts +1 -1
- package/lib/interface/BuiltinInterface.d.ts +1 -1
- package/lib/interface/ComponentInterface.d.ts +2 -1
- package/lib/interface/ComponentInterface.js +33 -0
- package/lib/interface/Interface.d.ts +7 -23
- package/lib/interface/Interface.js +60 -80
- package/lib/interface/builtinInterfaces.d.ts +1 -1
- package/lib/plugins/PluginManager.d.ts +20 -0
- package/lib/plugins/PluginManager.js +41 -0
- package/lib/plugins/index.d.ts +3 -3
- package/lib/plugins/index.js +4 -4
- package/lib/plugins/url-alias/index.d.ts +2 -2
- package/lib/plugins/url-alias/index.js +11 -3
- package/lib/program/InterfaceManager.d.ts +39 -0
- package/lib/program/InterfaceManager.js +417 -0
- package/lib/utils/casing/index.d.ts +4 -0
- package/lib/utils/casing/index.js +47 -0
- package/package.json +1 -1
package/lib/file/File.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.File = void 0;
|
|
4
|
+
var utils_1 = require("../utils");
|
|
5
|
+
var posix_1 = require("path/posix");
|
|
6
|
+
var casing_1 = require("../utils/casing");
|
|
7
|
+
var File = /** @class */ (function () {
|
|
8
|
+
function File(baseName, relativeDirectoryPath, fileCaseType) {
|
|
9
|
+
if (fileCaseType === void 0) { fileCaseType = 'pascal'; }
|
|
10
|
+
this.Relations = []; // Components and relations
|
|
11
|
+
this.RelationNames = {};
|
|
12
|
+
this.RelationNamesCounter = {};
|
|
13
|
+
this.BaseName = baseName;
|
|
14
|
+
this.StrapiName = '';
|
|
15
|
+
this.FileCase = fileCaseType;
|
|
16
|
+
this.RelativeDirectoryPath = relativeDirectoryPath;
|
|
17
|
+
}
|
|
18
|
+
File.prototype.setRelations = function (relations) {
|
|
19
|
+
var _this = this;
|
|
20
|
+
this.Relations = relations;
|
|
21
|
+
this.RelationNames = {};
|
|
22
|
+
this.RelationNamesCounter = {};
|
|
23
|
+
this.Relations.forEach(function (file) {
|
|
24
|
+
var name = file.getFullName();
|
|
25
|
+
// FIXME: clean up this mess...
|
|
26
|
+
if (file.getStrapiName() !== _this.getStrapiName()) {
|
|
27
|
+
// Avoid duplicate names
|
|
28
|
+
if (name in _this.RelationNamesCounter) {
|
|
29
|
+
name += ++_this.RelationNamesCounter[name];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
_this.RelationNamesCounter[name] = 0;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
_this.RelationNames[file.getStrapiName()] = { name: name, file: file };
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
// For typescript import from index file
|
|
39
|
+
File.prototype.getRelativeRootPath = function () {
|
|
40
|
+
var path = (0, posix_1.join)(this.RelativeDirectoryPath, this.getFileBaseName());
|
|
41
|
+
return (0, utils_1.prefixDotSlash)(path);
|
|
42
|
+
};
|
|
43
|
+
File.prototype.getBaseName = function () {
|
|
44
|
+
return this.BaseName;
|
|
45
|
+
};
|
|
46
|
+
File.prototype.getRelativeRootPathFile = function () {
|
|
47
|
+
return "".concat(this.getRelativeRootPath(), ".ts");
|
|
48
|
+
};
|
|
49
|
+
File.prototype.getRelativeRootDir = function () {
|
|
50
|
+
var path = (0, posix_1.dirname)(this.getRelativeRootPathFile());
|
|
51
|
+
return path;
|
|
52
|
+
};
|
|
53
|
+
File.prototype.getFileBaseName = function () {
|
|
54
|
+
return (0, casing_1.changeCase)(this.getBaseName(), this.FileCase);
|
|
55
|
+
};
|
|
56
|
+
File.prototype.getTsImports = function () {
|
|
57
|
+
var _this = this;
|
|
58
|
+
return Object.keys(this.RelationNames).map(function (strapiName) {
|
|
59
|
+
if (strapiName === _this.getStrapiName()) {
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
var relationName = _this.RelationNames[strapiName].name;
|
|
63
|
+
var inter = _this.RelationNames[strapiName].file;
|
|
64
|
+
var importPath = (0, utils_1.prefixDotSlash)((0, posix_1.relative)(_this.getRelativeRootDir(), inter.getRelativeRootPath()));
|
|
65
|
+
var fullName = inter.getFullName();
|
|
66
|
+
var importNameString = fullName === relationName ? fullName : "".concat(fullName, " as ").concat(relationName);
|
|
67
|
+
return "import { ".concat(importNameString, " } from '").concat(importPath, "';");
|
|
68
|
+
}).filter(function (s) { return s; }).join('\n');
|
|
69
|
+
};
|
|
70
|
+
return File;
|
|
71
|
+
}());
|
|
72
|
+
exports.File = File;
|
package/lib/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
var commander_1 = require("commander");
|
|
7
|
-
var InterfaceManager_1 = __importDefault(require("./
|
|
7
|
+
var InterfaceManager_1 = __importDefault(require("./program/InterfaceManager"));
|
|
8
8
|
commander_1.program
|
|
9
9
|
.name('t4s');
|
|
10
10
|
commander_1.program
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { caseType } from '../
|
|
1
|
+
import { caseType } from '../utils/casing';
|
|
2
2
|
import ComponentInterface from './ComponentInterface';
|
|
3
3
|
export default class BuiltinComponentInterface extends ComponentInterface {
|
|
4
4
|
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, fileCase: caseType, prefix?: string);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { caseType } from '../
|
|
1
|
+
import { caseType } from '../utils/casing';
|
|
2
2
|
import Interface from './Interface';
|
|
3
3
|
export default class BuiltinInterface extends Interface {
|
|
4
4
|
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, fileCase: caseType, prefix?: string);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { caseType } from '../
|
|
1
|
+
import { caseType } from '../utils/casing';
|
|
2
2
|
import Interface from './Interface';
|
|
3
3
|
export default class ComponentInterface extends Interface {
|
|
4
4
|
protected Category: string;
|
|
5
5
|
protected Options: Record<string, any>;
|
|
6
6
|
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, category: string, fileCase: caseType, prefix?: string, options?: Record<string, any>);
|
|
7
7
|
updateStrapiName(): void;
|
|
8
|
+
getInerfaceString(): string;
|
|
8
9
|
getInterfaceFieldsString(): string;
|
|
9
10
|
}
|
|
@@ -18,6 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
var constants_1 = require("../constants");
|
|
21
22
|
var Interface_1 = __importDefault(require("./Interface"));
|
|
22
23
|
var ComponentInterface = /** @class */ (function (_super) {
|
|
23
24
|
__extends(ComponentInterface, _super);
|
|
@@ -41,6 +42,38 @@ var ComponentInterface = /** @class */ (function (_super) {
|
|
|
41
42
|
ComponentInterface.prototype.updateStrapiName = function () {
|
|
42
43
|
this.StrapiName = "".concat(this.Category, ".").concat(this.getBaseName());
|
|
43
44
|
};
|
|
45
|
+
// TODO: make this more dynamic in parent
|
|
46
|
+
ComponentInterface.prototype.getInerfaceString = function () {
|
|
47
|
+
var isPopulatable = this.hasPopulatableAttributes();
|
|
48
|
+
/* const populateString = isPopulatable ? `<${POPULATE_GENERIC_NAME} extends string | never = never>` : ''; */
|
|
49
|
+
var strArr = [];
|
|
50
|
+
if (isPopulatable) {
|
|
51
|
+
strArr.push("export type ".concat(this.getFullName()));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
strArr.push("export interface ".concat(this.getFullName()));
|
|
55
|
+
}
|
|
56
|
+
if (isPopulatable) {
|
|
57
|
+
strArr.push("<".concat(constants_1.POPULATE_GENERIC_NAME, " extends string | never = never>"));
|
|
58
|
+
strArr.push(" = ".concat(this.RelationNames['builtins::RequiredBy'].name, "<"));
|
|
59
|
+
}
|
|
60
|
+
strArr.push(' {\n');
|
|
61
|
+
strArr.push(this.getInterfaceFieldsString());
|
|
62
|
+
strArr.push('}');
|
|
63
|
+
if (isPopulatable) {
|
|
64
|
+
strArr.push(', ');
|
|
65
|
+
strArr.push(this.RelationNames['builtins::ExtractFlat'].name);
|
|
66
|
+
// extract flat start
|
|
67
|
+
strArr.push('<');
|
|
68
|
+
strArr.push(constants_1.POPULATE_GENERIC_NAME);
|
|
69
|
+
// extract flat end
|
|
70
|
+
strArr.push('>');
|
|
71
|
+
// required by end
|
|
72
|
+
strArr.push('>');
|
|
73
|
+
}
|
|
74
|
+
var str = strArr.join('');
|
|
75
|
+
return str;
|
|
76
|
+
};
|
|
44
77
|
ComponentInterface.prototype.getInterfaceFieldsString = function () {
|
|
45
78
|
var attrs = this.getAttributes();
|
|
46
79
|
var str = '';
|
|
@@ -1,31 +1,15 @@
|
|
|
1
|
-
import { caseType } from '../
|
|
2
|
-
import Attributes from '
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
inter: Interface;
|
|
6
|
-
}>;
|
|
7
|
-
export default class Interface {
|
|
8
|
-
protected BaseName: string;
|
|
9
|
-
private Relations;
|
|
10
|
-
private RelationNames;
|
|
11
|
-
private RelationNamesCounter;
|
|
1
|
+
import { caseType } from '../utils/casing';
|
|
2
|
+
import Attributes from '../attributes/Attributes';
|
|
3
|
+
import { File } from '../file/File';
|
|
4
|
+
export default class Interface extends File {
|
|
12
5
|
private NamePrefix;
|
|
13
6
|
protected Attributes: any;
|
|
14
|
-
private RelativeDirectoryPath;
|
|
15
|
-
protected StrapiName: string;
|
|
16
|
-
protected FileCase: caseType;
|
|
17
7
|
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, fileCaseType?: caseType, prefix?: string);
|
|
18
8
|
protected updateStrapiName(): void;
|
|
19
|
-
getBaseName(): string;
|
|
20
9
|
getStrapiName(): string;
|
|
21
|
-
getDependencies():
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
getRelativeRootPath(): any;
|
|
25
|
-
getRelativeRootDir(): string;
|
|
26
|
-
getRelativeRootPathFile(): string;
|
|
27
|
-
setRelations(relations: Interface[]): void;
|
|
28
|
-
private getTsImports;
|
|
10
|
+
getDependencies(): string[];
|
|
11
|
+
getFullName(): string;
|
|
12
|
+
hasPopulatableAttributes(): boolean;
|
|
29
13
|
getAttributes(): Attributes;
|
|
30
14
|
attributesToString(): string;
|
|
31
15
|
getInerfaceString(): string;
|
|
@@ -1,92 +1,54 @@
|
|
|
1
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
|
+
})();
|
|
2
17
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
19
|
};
|
|
5
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var
|
|
7
|
-
var case_1 = require("../case");
|
|
8
|
-
var utils_1 = require("../utils");
|
|
9
|
-
var Attributes_1 = __importDefault(require("./Attributes"));
|
|
21
|
+
var Attributes_1 = __importDefault(require("../attributes/Attributes"));
|
|
10
22
|
var change_case_1 = require("change-case");
|
|
11
|
-
var
|
|
23
|
+
var constants_1 = require("../constants");
|
|
24
|
+
var File_1 = require("../file/File");
|
|
25
|
+
var Interface = /** @class */ (function (_super) {
|
|
26
|
+
__extends(Interface, _super);
|
|
12
27
|
function Interface(baseName, attributes, relativeDirectoryPath, fileCaseType, prefix) {
|
|
13
28
|
if (fileCaseType === void 0) { fileCaseType = 'pascal'; }
|
|
14
29
|
if (prefix === void 0) { prefix = ''; }
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.NamePrefix = prefix;
|
|
22
|
-
this.Attributes = attributes;
|
|
23
|
-
this.RelativeDirectoryPath = relativeDirectoryPath;
|
|
24
|
-
this.FileCase = fileCaseType;
|
|
30
|
+
var _this = _super.call(this, baseName, relativeDirectoryPath, fileCaseType) || this;
|
|
31
|
+
_this.NamePrefix = '';
|
|
32
|
+
_this.updateStrapiName();
|
|
33
|
+
_this.NamePrefix = prefix;
|
|
34
|
+
_this.Attributes = attributes;
|
|
35
|
+
return _this;
|
|
25
36
|
}
|
|
26
37
|
Interface.prototype.updateStrapiName = function () {
|
|
27
38
|
this.StrapiName = "api::".concat(this.BaseName, ".").concat(this.BaseName);
|
|
28
39
|
};
|
|
29
|
-
Interface.prototype.getBaseName = function () {
|
|
30
|
-
return this.BaseName;
|
|
31
|
-
};
|
|
32
40
|
Interface.prototype.getStrapiName = function () {
|
|
33
41
|
return this.StrapiName;
|
|
34
42
|
};
|
|
35
43
|
Interface.prototype.getDependencies = function () {
|
|
36
|
-
|
|
37
|
-
return attrs.getDependencies();
|
|
44
|
+
return this.getAttributes().getDependencies();
|
|
38
45
|
};
|
|
39
|
-
Interface.prototype.
|
|
46
|
+
Interface.prototype.getFullName = function () {
|
|
40
47
|
var pascalName = (0, change_case_1.pascalCase)(this.BaseName);
|
|
41
48
|
return "".concat(this.NamePrefix).concat(pascalName);
|
|
42
49
|
};
|
|
43
|
-
Interface.prototype.
|
|
44
|
-
return
|
|
45
|
-
};
|
|
46
|
-
// For typescript import from index file
|
|
47
|
-
Interface.prototype.getRelativeRootPath = function () {
|
|
48
|
-
var path = (0, posix_1.join)(this.RelativeDirectoryPath, this.getFileBaseName());
|
|
49
|
-
return (0, utils_1.prefixDotSlash)(path);
|
|
50
|
-
};
|
|
51
|
-
Interface.prototype.getRelativeRootDir = function () {
|
|
52
|
-
var path = (0, posix_1.dirname)(this.getRelativeRootPathFile());
|
|
53
|
-
return path;
|
|
54
|
-
};
|
|
55
|
-
Interface.prototype.getRelativeRootPathFile = function () {
|
|
56
|
-
return "".concat(this.getRelativeRootPath(), ".ts");
|
|
57
|
-
};
|
|
58
|
-
Interface.prototype.setRelations = function (relations) {
|
|
59
|
-
var _this = this;
|
|
60
|
-
this.Relations = relations;
|
|
61
|
-
this.RelationNames = {};
|
|
62
|
-
this.Relations.forEach(function (inter) {
|
|
63
|
-
var name = inter.getFullInterfaceName();
|
|
64
|
-
// FIXME: clean up this mess...
|
|
65
|
-
if (inter.getStrapiName() !== _this.getStrapiName()) {
|
|
66
|
-
// Avoid duplicate names
|
|
67
|
-
if (name in _this.RelationNamesCounter) {
|
|
68
|
-
name += ++_this.RelationNamesCounter[name];
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
_this.RelationNamesCounter[name] = 0;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
_this.RelationNames[inter.getStrapiName()] = { name: name, inter: inter };
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
Interface.prototype.getTsImports = function () {
|
|
78
|
-
var _this = this;
|
|
79
|
-
return Object.keys(this.RelationNames).map(function (strapiName) {
|
|
80
|
-
if (strapiName === _this.getStrapiName()) {
|
|
81
|
-
return '';
|
|
82
|
-
}
|
|
83
|
-
var relationName = _this.RelationNames[strapiName].name;
|
|
84
|
-
var inter = _this.RelationNames[strapiName].inter;
|
|
85
|
-
var importPath = (0, utils_1.prefixDotSlash)((0, posix_1.relative)(_this.getRelativeRootDir(), inter.getRelativeRootPath()));
|
|
86
|
-
var fullName = inter.getFullInterfaceName();
|
|
87
|
-
var importNameString = fullName === relationName ? fullName : "".concat(fullName, " as ").concat(relationName);
|
|
88
|
-
return "import { ".concat(importNameString, " } from '").concat(importPath, "';");
|
|
89
|
-
}).filter(function (s) { return s; }).join('\n');
|
|
50
|
+
Interface.prototype.hasPopulatableAttributes = function () {
|
|
51
|
+
return this.getAttributes().hasPopulatableAttributes();
|
|
90
52
|
};
|
|
91
53
|
Interface.prototype.getAttributes = function () {
|
|
92
54
|
return new Attributes_1.default(this.Attributes, this.RelationNames);
|
|
@@ -96,24 +58,42 @@ var Interface = /** @class */ (function () {
|
|
|
96
58
|
return attrs.toString();
|
|
97
59
|
};
|
|
98
60
|
Interface.prototype.getInerfaceString = function () {
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
61
|
+
var isPopulatable = this.hasPopulatableAttributes();
|
|
62
|
+
/* const populateString = isPopulatable ? `<${POPULATE_GENERIC_NAME} extends string | never = never>` : ''; */
|
|
63
|
+
var strArr = ["export interface ".concat(this.getFullName())];
|
|
64
|
+
if (isPopulatable) {
|
|
65
|
+
strArr.push("<".concat(constants_1.POPULATE_GENERIC_NAME, " extends string | never = never>"));
|
|
66
|
+
}
|
|
67
|
+
strArr.push(' {\n');
|
|
68
|
+
strArr.push(this.getInterfaceFieldsString());
|
|
69
|
+
strArr.push('}');
|
|
70
|
+
var str = strArr.join('');
|
|
102
71
|
return str;
|
|
103
72
|
};
|
|
104
73
|
Interface.prototype.getInterfaceFieldsString = function () {
|
|
105
|
-
var
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
74
|
+
var populatable = this.hasPopulatableAttributes();
|
|
75
|
+
var strArr = [];
|
|
76
|
+
strArr.push('id: number;\n');
|
|
77
|
+
strArr.push("attributes: ");
|
|
78
|
+
if (populatable) {
|
|
79
|
+
strArr.push("RequiredBy<");
|
|
80
|
+
}
|
|
81
|
+
strArr.push("".concat(this.attributesToString()));
|
|
82
|
+
if (populatable) {
|
|
83
|
+
// The comma for required by
|
|
84
|
+
strArr.push(', ');
|
|
85
|
+
// second generic for required by
|
|
86
|
+
strArr.push("".concat(this.RelationNames['builtins::ExtractFlat'].name, "<").concat(constants_1.POPULATE_GENERIC_NAME, ">"));
|
|
87
|
+
// close the required by
|
|
88
|
+
strArr.push('>');
|
|
89
|
+
}
|
|
90
|
+
strArr.push("\n");
|
|
91
|
+
return strArr.join('');
|
|
109
92
|
};
|
|
110
93
|
Interface.prototype.toString = function () {
|
|
111
|
-
var strings = [
|
|
112
|
-
this.getTsImports(),
|
|
113
|
-
this.getInerfaceString()
|
|
114
|
-
];
|
|
94
|
+
var strings = [this.getTsImports(), this.getInerfaceString()];
|
|
115
95
|
return strings.join('\n');
|
|
116
96
|
};
|
|
117
97
|
return Interface;
|
|
118
|
-
}());
|
|
98
|
+
}(File_1.File));
|
|
119
99
|
exports.default = Interface;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { caseType } from '../
|
|
1
|
+
import { caseType } from '../utils/casing';
|
|
2
2
|
import BuiltinComponentInterface from './BuiltinComponentInterface';
|
|
3
3
|
import BuiltinInterface from './BuiltinInterface';
|
|
4
4
|
export declare function createMediaInterface(directory: string, caseTypeName: caseType, prefix: string): BuiltinInterface;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import InterfaceManager from '../program/InterfaceManager';
|
|
2
|
+
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;
|
|
7
|
+
};
|
|
8
|
+
export declare type HooksType = {
|
|
9
|
+
[HookType in keyof HookTypes]: {
|
|
10
|
+
fn: HookTypes[HookType];
|
|
11
|
+
priority: number;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
export declare class PluginManager {
|
|
15
|
+
hooks: HooksType;
|
|
16
|
+
registerPlugin(hooks: Partial<HooksType>): void;
|
|
17
|
+
registerHook<Hook extends keyof HookTypes>(hook: Hook, fn: HookTypes[Hook], priority: number): void;
|
|
18
|
+
sortHooks(): void;
|
|
19
|
+
invoke<Hook extends keyof HookTypes>(hook: Hook, ...args: Parameters<HookTypes[Hook]>): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PluginManager = void 0;
|
|
4
|
+
var PluginManager = /** @class */ (function () {
|
|
5
|
+
function PluginManager() {
|
|
6
|
+
this.hooks = {
|
|
7
|
+
BeforeReadSchema: [],
|
|
8
|
+
BeforeReadSchemas: [],
|
|
9
|
+
AfterReadSchema: [],
|
|
10
|
+
AfterReadSchemas: [],
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
PluginManager.prototype.registerPlugin = function (hooks) {
|
|
14
|
+
var _a;
|
|
15
|
+
for (var hook in hooks) {
|
|
16
|
+
if (hooks[hook]) {
|
|
17
|
+
(_a = this.hooks[hook]).push.apply(_a, hooks[hook]);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
PluginManager.prototype.registerHook = function (hook, fn, priority) {
|
|
22
|
+
this.hooks[hook].push({ fn: fn, priority: priority });
|
|
23
|
+
};
|
|
24
|
+
PluginManager.prototype.sortHooks = function () {
|
|
25
|
+
for (var hook in this.hooks) {
|
|
26
|
+
this.hooks[hook].sort(function (a, b) { return a.priority - b.priority; });
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
PluginManager.prototype.invoke = function (hook) {
|
|
30
|
+
var args = [];
|
|
31
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
32
|
+
args[_i - 1] = arguments[_i];
|
|
33
|
+
}
|
|
34
|
+
this.hooks[hook].forEach(function (hook) {
|
|
35
|
+
// @ts-ignore we know that it is the correct type, sunce HooksType is built from HookTypes
|
|
36
|
+
hook.fn.apply(hook, args);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
return PluginManager;
|
|
40
|
+
}());
|
|
41
|
+
exports.PluginManager = PluginManager;
|
package/lib/plugins/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
export declare const
|
|
1
|
+
import { SupportedPluginNamesType } from './types';
|
|
2
|
+
import { PluginManager } from './PluginManager';
|
|
3
|
+
export declare const registerBuiltinPlugins: (pluginManager: PluginManager, pluginNames: Set<SupportedPluginNamesType>) => void;
|
package/lib/plugins/index.js
CHANGED
|
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.registerBuiltinPlugins = void 0;
|
|
7
7
|
var url_alias_1 = __importDefault(require("./url-alias"));
|
|
8
|
-
var
|
|
8
|
+
var registerBuiltinPlugins = function (pluginManager, pluginNames) {
|
|
9
9
|
if (pluginNames.has('url-alias')) {
|
|
10
|
-
(0, url_alias_1.default)(
|
|
10
|
+
pluginManager.registerPlugin((0, url_alias_1.default)());
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
exports.
|
|
13
|
+
exports.registerBuiltinPlugins = registerBuiltinPlugins;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
declare const register: (
|
|
1
|
+
import { HooksType } from '../PluginManager';
|
|
2
|
+
declare const register: () => Partial<HooksType>;
|
|
3
3
|
export default register;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var events_1 = require("../../events");
|
|
4
|
-
var addUrlAliasToAllContentTypes = function (_a) {
|
|
4
|
+
var addUrlAliasToAllContentTypes = function (state, _a) {
|
|
5
5
|
var apiSchemas = _a.apiSchemas;
|
|
6
6
|
apiSchemas.forEach(function (schema) {
|
|
7
7
|
var attributes = schema.attributes;
|
|
@@ -16,7 +16,15 @@ var addUrlAliasToAllContentTypes = function (_a) {
|
|
|
16
16
|
// };
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
|
-
var register = function (
|
|
20
|
-
|
|
19
|
+
var register = function () {
|
|
20
|
+
var _a;
|
|
21
|
+
return _a = {},
|
|
22
|
+
_a[events_1.Events.AfterReadSchema] = [
|
|
23
|
+
{
|
|
24
|
+
fn: addUrlAliasToAllContentTypes,
|
|
25
|
+
priority: 10,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
_a;
|
|
21
29
|
};
|
|
22
30
|
exports.default = register;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export default class InterfaceManager {
|
|
2
|
+
private Interfaces;
|
|
3
|
+
private Files;
|
|
4
|
+
private OutRoot;
|
|
5
|
+
private StrapiSrcRoot;
|
|
6
|
+
private Options;
|
|
7
|
+
private PrettierOptions;
|
|
8
|
+
private PluginManager;
|
|
9
|
+
static BaseOptions: {
|
|
10
|
+
prefix: string;
|
|
11
|
+
useCategoryPrefix: boolean;
|
|
12
|
+
componentPrefix: string;
|
|
13
|
+
componentPrefixOverridesPrefix: boolean;
|
|
14
|
+
builtinsPrefix: string;
|
|
15
|
+
builtinsPrefixOverridesPrefix: boolean;
|
|
16
|
+
deleteOld: boolean;
|
|
17
|
+
prettierFile: any;
|
|
18
|
+
fileCaseType: "camel" | "capital" | "dot" | "snake" | "pascal" | "constant" | "kebab";
|
|
19
|
+
folderCaseType: "camel" | "capital" | "dot" | "snake" | "pascal" | "constant" | "kebab";
|
|
20
|
+
enabledPlugins: "url-alias"[];
|
|
21
|
+
};
|
|
22
|
+
constructor(outRoot: string, strapiSrcRoot: string, options?: Partial<typeof InterfaceManager['BaseOptions']>);
|
|
23
|
+
registerBuiltinPlugins(): void;
|
|
24
|
+
registerPlugin(): 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
|
+
}
|