@oak-digital/types-4-strapi-2 0.2.5 → 0.2.8
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 +18 -8
- package/lib/case/index.d.ts +4 -0
- package/lib/case/index.js +47 -0
- package/lib/index.js +9 -1
- package/lib/interface/BuiltinComponentInterface.d.ts +3 -2
- package/lib/interface/BuiltinComponentInterface.js +3 -3
- package/lib/interface/BuiltinInterface.d.ts +3 -2
- package/lib/interface/BuiltinInterface.js +3 -3
- package/lib/interface/ComponentInterface.d.ts +3 -2
- package/lib/interface/ComponentInterface.js +4 -4
- package/lib/interface/Interface.d.ts +4 -1
- package/lib/interface/Interface.js +10 -3
- package/lib/interface/InterfaceManager.d.ts +5 -0
- package/lib/interface/InterfaceManager.js +66 -22
- package/lib/interface/builtinInterfaces.d.ts +5 -4
- package/lib/interface/builtinInterfaces.js +40 -32
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +3 -12
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
# types-4-strapi-2
|
|
2
2
|
|
|
3
|
-
types-4-strapi-2 is a
|
|
4
|
-
This can be useful if you have a frontend written with
|
|
3
|
+
types-4-strapi-2 is a TypeScript program that will generate TypeScript types for your strapi projects.
|
|
4
|
+
This can be useful if you have a frontend written with TypeScript to make sure you are using the correct types and can help report errors at compile time.
|
|
5
5
|
|
|
6
|
-
types-4-strapi-2 is a rewrite of
|
|
6
|
+
types-4-strapi-2 is a rewrite of [francescolorenzetti/types-4-strapi](https://github.com/francescolorenzetti/types-4-strapi) written in TypeScript, with the goal of being much easier to extend and maintain.
|
|
7
7
|
|
|
8
8
|
## Getting started
|
|
9
9
|
|
|
10
10
|
Install the script for your project:
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
|
+
# NPM
|
|
13
14
|
npm install --save-dev @oak-digital/types-4-strapi-2
|
|
15
|
+
# YARN
|
|
16
|
+
yarn add -D @oak-digital/types-4-strapi-2
|
|
14
17
|
```
|
|
15
18
|
|
|
16
19
|
Then set up a script in your `package.json`
|
|
@@ -38,8 +41,8 @@ This can be done with the `--out` flag like in the following example.
|
|
|
38
41
|
|
|
39
42
|
## Features
|
|
40
43
|
|
|
41
|
-
* Generate
|
|
42
|
-
* Generate
|
|
44
|
+
* Generate TypeScript interfaces for all your api content-types and components
|
|
45
|
+
* Generate TypeScript interfaces for builtin types such as `Media` and `MediaFormat`
|
|
43
46
|
* Select input and output directory
|
|
44
47
|
* Prettier formatting and ability to use your own `.prettierrc`.
|
|
45
48
|
|
|
@@ -48,9 +51,16 @@ This can be done with the `--out` flag like in the following example.
|
|
|
48
51
|
* Support for localization
|
|
49
52
|
* Support if you are using other plugins, such as `url-alias`, which should add extra fields for some interfaces.
|
|
50
53
|
|
|
51
|
-
##
|
|
54
|
+
## Flags
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
| **Flag** | **Description** | **Default** |
|
|
57
|
+
|-----------------------------|--------------------------------------------------------------------------------------|-------------|
|
|
58
|
+
| -i, --in <dir> | The src directory for strapi | `./src` |
|
|
59
|
+
| -o, --out <dir> | The output directory to output the types to | `./types` |
|
|
60
|
+
| -prefix | A prefix for all generated interfaces | `I` |
|
|
61
|
+
| --component-prefix <prefix> | A prefix for components | none |
|
|
62
|
+
| -D, --delete-old | CAUTION: This option is equivalent to running `rm -rf` on the output directory first | `false` |
|
|
63
|
+
| --prettier <file> | The prettier config file to use for formatting TypeScript interfaces | none |
|
|
54
64
|
|
|
55
65
|
## Building
|
|
56
66
|
|
|
@@ -60,7 +70,7 @@ To build this project, use the following command
|
|
|
60
70
|
npm run build
|
|
61
71
|
```
|
|
62
72
|
|
|
63
|
-
##
|
|
73
|
+
## Publishing
|
|
64
74
|
|
|
65
75
|
```bash
|
|
66
76
|
npm run build
|
|
@@ -0,0 +1,47 @@
|
|
|
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;
|
package/lib/index.js
CHANGED
|
@@ -10,14 +10,22 @@ commander_1.program
|
|
|
10
10
|
commander_1.program
|
|
11
11
|
.option('-i, --in <dir>', 'The src directory for strapi', './src')
|
|
12
12
|
.option('-o, --out <dir>', 'The output directory to output the types to', './types')
|
|
13
|
+
.option('--prefix <prefix>', 'A prefix for all generated interfaces', 'I')
|
|
13
14
|
.option('--component-prefix <prefix>', 'A prefix for components', '')
|
|
15
|
+
.option('-D, --delete-old', 'CAUTION: This option is equivalent to running rm -rf on the output directory first')
|
|
16
|
+
.option('--file-case <case>', 'Which case to use for generated files', 'pascal')
|
|
17
|
+
.option('--folder-case <case>', 'Which case to use for generated folders', 'kebab')
|
|
14
18
|
.option('--prettier <file>', 'The prettier config file to use for formatting typescript interfaces');
|
|
15
19
|
commander_1.program.parse();
|
|
16
20
|
var options = commander_1.program.opts();
|
|
17
|
-
var input = options.in, out = options.out, componentPrefix = options.componentPrefix, prettierFile = options.prettier;
|
|
21
|
+
var input = options.in, out = options.out, componentPrefix = options.componentPrefix, prefix = options.prefix, prettierFile = options.prettier, deleteOld = options.deleteOld, fileCaseType = options.fileCase, folderCaseType = options.folderCase;
|
|
18
22
|
var manager = new InterfaceManager_1.default(out, input, {
|
|
19
23
|
componentPrefix: componentPrefix,
|
|
24
|
+
prefix: prefix,
|
|
20
25
|
prettierFile: prettierFile,
|
|
26
|
+
deleteOld: deleteOld,
|
|
27
|
+
fileCaseType: fileCaseType,
|
|
28
|
+
folderCaseType: folderCaseType,
|
|
21
29
|
});
|
|
22
30
|
manager.run().catch(function (err) {
|
|
23
31
|
console.error(err);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { caseType } from '../case';
|
|
2
|
+
import ComponentInterface from './ComponentInterface';
|
|
2
3
|
export default class BuiltinComponentInterface extends ComponentInterface {
|
|
3
|
-
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, prefix?: string);
|
|
4
|
+
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, fileCase: caseType, prefix?: string);
|
|
4
5
|
updateStrapiName(): void;
|
|
5
6
|
}
|
|
@@ -21,9 +21,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
21
|
var ComponentInterface_1 = __importDefault(require("./ComponentInterface"));
|
|
22
22
|
var BuiltinComponentInterface = /** @class */ (function (_super) {
|
|
23
23
|
__extends(BuiltinComponentInterface, _super);
|
|
24
|
-
function BuiltinComponentInterface(baseName, attributes, relativeDirectoryPath, prefix) {
|
|
25
|
-
if (prefix === void 0) { prefix =
|
|
26
|
-
return _super.call(this, baseName, attributes, relativeDirectoryPath,
|
|
24
|
+
function BuiltinComponentInterface(baseName, attributes, relativeDirectoryPath, fileCase, prefix) {
|
|
25
|
+
if (prefix === void 0) { prefix = ''; }
|
|
26
|
+
return _super.call(this, baseName, attributes, relativeDirectoryPath, 'builtins', fileCase, prefix, {
|
|
27
27
|
hasId: false,
|
|
28
28
|
hasComponent: false,
|
|
29
29
|
}) || this;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { caseType } from '../case';
|
|
2
|
+
import Interface from './Interface';
|
|
2
3
|
export default class BuiltinInterface extends Interface {
|
|
3
|
-
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, prefix?: string);
|
|
4
|
+
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, fileCase: caseType, prefix?: string);
|
|
4
5
|
updateStrapiName(): void;
|
|
5
6
|
}
|
|
@@ -21,9 +21,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
21
|
var Interface_1 = __importDefault(require("./Interface"));
|
|
22
22
|
var BuiltinInterface = /** @class */ (function (_super) {
|
|
23
23
|
__extends(BuiltinInterface, _super);
|
|
24
|
-
function BuiltinInterface(baseName, attributes, relativeDirectoryPath, prefix) {
|
|
25
|
-
if (prefix === void 0) { prefix =
|
|
26
|
-
return _super.call(this, baseName, attributes, relativeDirectoryPath, prefix) || this;
|
|
24
|
+
function BuiltinInterface(baseName, attributes, relativeDirectoryPath, fileCase, prefix) {
|
|
25
|
+
if (prefix === void 0) { prefix = ''; }
|
|
26
|
+
return _super.call(this, baseName, attributes, relativeDirectoryPath, fileCase, prefix) || this;
|
|
27
27
|
}
|
|
28
28
|
BuiltinInterface.prototype.updateStrapiName = function () {
|
|
29
29
|
this.StrapiName = "builtins::".concat(this.BaseName);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { caseType } from '../case';
|
|
2
|
+
import Interface from './Interface';
|
|
2
3
|
export default class ComponentInterface extends Interface {
|
|
3
4
|
protected Category: string;
|
|
4
5
|
protected Options: Record<string, any>;
|
|
5
|
-
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, category: string, prefix?: string, options?: Record<string, any>);
|
|
6
|
+
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, category: string, fileCase: caseType, prefix?: string, options?: Record<string, any>);
|
|
6
7
|
updateStrapiName(): void;
|
|
7
8
|
getInterfaceFieldsString(): string;
|
|
8
9
|
}
|
|
@@ -21,10 +21,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
21
|
var Interface_1 = __importDefault(require("./Interface"));
|
|
22
22
|
var ComponentInterface = /** @class */ (function (_super) {
|
|
23
23
|
__extends(ComponentInterface, _super);
|
|
24
|
-
function ComponentInterface(baseName, attributes, relativeDirectoryPath, category, prefix, options) {
|
|
25
|
-
if (prefix === void 0) { prefix =
|
|
24
|
+
function ComponentInterface(baseName, attributes, relativeDirectoryPath, category, fileCase, prefix, options) {
|
|
25
|
+
if (prefix === void 0) { prefix = ''; }
|
|
26
26
|
if (options === void 0) { options = {}; }
|
|
27
|
-
var _this = _super.call(this, baseName, attributes, relativeDirectoryPath, prefix) || this;
|
|
27
|
+
var _this = _super.call(this, baseName, attributes, relativeDirectoryPath, fileCase, prefix) || this;
|
|
28
28
|
_this.Options = {
|
|
29
29
|
hasId: true,
|
|
30
30
|
hasComponent: true,
|
|
@@ -46,7 +46,7 @@ var ComponentInterface = /** @class */ (function (_super) {
|
|
|
46
46
|
var str = '';
|
|
47
47
|
var _a = this.Options, hasId = _a.hasId, hasComponent = _a.hasComponent;
|
|
48
48
|
if (hasId) {
|
|
49
|
-
str +=
|
|
49
|
+
str += ' id: number;\n';
|
|
50
50
|
}
|
|
51
51
|
if (hasComponent) {
|
|
52
52
|
str += " __component: \"".concat(this.getStrapiName(), "\";\n");
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { caseType } from '../case';
|
|
1
2
|
import Attributes from './Attributes';
|
|
2
3
|
export declare type RelationNames = Record<string, {
|
|
3
4
|
name: string;
|
|
@@ -12,12 +13,14 @@ export default class Interface {
|
|
|
12
13
|
protected Attributes: any;
|
|
13
14
|
private RelativeDirectoryPath;
|
|
14
15
|
protected StrapiName: string;
|
|
15
|
-
|
|
16
|
+
protected FileCase: caseType;
|
|
17
|
+
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, fileCaseType?: caseType, prefix?: string);
|
|
16
18
|
protected updateStrapiName(): void;
|
|
17
19
|
getBaseName(): string;
|
|
18
20
|
getStrapiName(): string;
|
|
19
21
|
getDependencies(): any[];
|
|
20
22
|
getFullInterfaceName(): string;
|
|
23
|
+
getFileBaseName(): string;
|
|
21
24
|
getRelativeRootPath(): any;
|
|
22
25
|
getRelativeRootDir(): string;
|
|
23
26
|
getRelativeRootPathFile(): string;
|
|
@@ -4,10 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
var posix_1 = require("path/posix");
|
|
7
|
+
var case_1 = require("../case");
|
|
7
8
|
var utils_1 = require("../utils");
|
|
8
9
|
var Attributes_1 = __importDefault(require("./Attributes"));
|
|
10
|
+
var change_case_1 = require("change-case");
|
|
9
11
|
var Interface = /** @class */ (function () {
|
|
10
|
-
function Interface(baseName, attributes, relativeDirectoryPath, prefix) {
|
|
12
|
+
function Interface(baseName, attributes, relativeDirectoryPath, fileCaseType, prefix) {
|
|
13
|
+
if (fileCaseType === void 0) { fileCaseType = "pascal"; }
|
|
11
14
|
if (prefix === void 0) { prefix = ''; }
|
|
12
15
|
this.Relations = []; // Components and relations
|
|
13
16
|
this.RelationNames = {};
|
|
@@ -18,6 +21,7 @@ var Interface = /** @class */ (function () {
|
|
|
18
21
|
this.NamePrefix = prefix;
|
|
19
22
|
this.Attributes = attributes;
|
|
20
23
|
this.RelativeDirectoryPath = relativeDirectoryPath;
|
|
24
|
+
this.FileCase = fileCaseType;
|
|
21
25
|
}
|
|
22
26
|
Interface.prototype.updateStrapiName = function () {
|
|
23
27
|
this.StrapiName = "api::".concat(this.BaseName, ".").concat(this.BaseName);
|
|
@@ -33,12 +37,15 @@ var Interface = /** @class */ (function () {
|
|
|
33
37
|
return attrs.getDependencies();
|
|
34
38
|
};
|
|
35
39
|
Interface.prototype.getFullInterfaceName = function () {
|
|
36
|
-
var pascalName = (0,
|
|
40
|
+
var pascalName = (0, change_case_1.pascalCase)(this.BaseName);
|
|
37
41
|
return "".concat(this.NamePrefix).concat(pascalName);
|
|
38
42
|
};
|
|
43
|
+
Interface.prototype.getFileBaseName = function () {
|
|
44
|
+
return (0, case_1.changeCase)(this.getBaseName(), this.FileCase);
|
|
45
|
+
};
|
|
39
46
|
// For typescript import from index file
|
|
40
47
|
Interface.prototype.getRelativeRootPath = function () {
|
|
41
|
-
var path = (0, posix_1.join)(this.RelativeDirectoryPath, this.
|
|
48
|
+
var path = (0, posix_1.join)(this.RelativeDirectoryPath, this.getFileBaseName());
|
|
42
49
|
return (0, utils_1.prefixDotSlash)(path);
|
|
43
50
|
};
|
|
44
51
|
Interface.prototype.getRelativeRootDir = function () {
|
|
@@ -11,13 +11,18 @@ export default class InterfaceManager {
|
|
|
11
11
|
componentPrefixOverridesPrefix: boolean;
|
|
12
12
|
builtinsPrefix: string;
|
|
13
13
|
builtinsPrefixOverridesPrefix: boolean;
|
|
14
|
+
deleteOld: boolean;
|
|
14
15
|
prettierFile: any;
|
|
16
|
+
fileCaseType: string;
|
|
17
|
+
folderCaseType: string;
|
|
15
18
|
};
|
|
16
19
|
constructor(outRoot: string, strapiSrcRoot: string, options?: any);
|
|
20
|
+
validateOptions(): void;
|
|
17
21
|
loadPrettierConfig(): Promise<void>;
|
|
18
22
|
createInterfaces(): Promise<void>;
|
|
19
23
|
createBuiltinInterfaces(): void;
|
|
20
24
|
injectDependencies(): void;
|
|
25
|
+
deleteOldFolders(): Promise<void>;
|
|
21
26
|
makeFolders(): Promise<void>;
|
|
22
27
|
writeInterfaces(): Promise<void>;
|
|
23
28
|
writeIndexFile(): Promise<void>;
|
|
@@ -42,12 +42,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
42
42
|
var fs_1 = require("fs");
|
|
43
43
|
var promises_1 = require("fs/promises");
|
|
44
44
|
var posix_1 = require("path/posix");
|
|
45
|
-
var utils_1 = require("../utils");
|
|
46
45
|
var builtinInterfaces_1 = require("./builtinInterfaces");
|
|
47
46
|
var ComponentInterface_1 = __importDefault(require("./ComponentInterface"));
|
|
48
47
|
var Interface_1 = __importDefault(require("./Interface"));
|
|
49
48
|
var schemaReader_1 = require("./schemaReader");
|
|
50
49
|
var prettier_1 = __importDefault(require("prettier"));
|
|
50
|
+
var pascal_case_1 = require("pascal-case");
|
|
51
|
+
var case_1 = require("../case");
|
|
51
52
|
var InterfaceManager = /** @class */ (function () {
|
|
52
53
|
function InterfaceManager(outRoot, strapiSrcRoot, options) {
|
|
53
54
|
if (options === void 0) { options = {}; }
|
|
@@ -55,7 +56,16 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
55
56
|
this.OutRoot = outRoot;
|
|
56
57
|
this.StrapiSrcRoot = strapiSrcRoot;
|
|
57
58
|
this.Options = Object.assign({}, InterfaceManager.BaseOptions, options);
|
|
59
|
+
this.validateOptions();
|
|
58
60
|
}
|
|
61
|
+
InterfaceManager.prototype.validateOptions = function () {
|
|
62
|
+
if (!(0, case_1.checkCaseType)(this.Options.fileCaseType)) {
|
|
63
|
+
throw new Error("".concat(this.Options.fileCaseType, " is not a supported type, please use one of the following ").concat(case_1.caseTypesArray.join(', ')));
|
|
64
|
+
}
|
|
65
|
+
if (!(0, case_1.checkCaseType)(this.Options.folderCaseType)) {
|
|
66
|
+
throw new Error("".concat(this.Options.folderCaseType, " is not a supported type, please use one of the following ").concat(case_1.caseTypesArray.join(', ')));
|
|
67
|
+
}
|
|
68
|
+
};
|
|
59
69
|
InterfaceManager.prototype.loadPrettierConfig = function () {
|
|
60
70
|
return __awaiter(this, void 0, void 0, function () {
|
|
61
71
|
var defaultOptions, resolved;
|
|
@@ -93,7 +103,7 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
93
103
|
apiSchemas.forEach(function (schema) {
|
|
94
104
|
var name = schema.name, attributes = schema.attributes;
|
|
95
105
|
var strapiName = "api::".concat(name, ".").concat(name);
|
|
96
|
-
var inter = new Interface_1.default(name, attributes, './', _this.Options.prefix);
|
|
106
|
+
var inter = new Interface_1.default(name, attributes, './', _this.Options.fileCaseType, _this.Options.prefix);
|
|
97
107
|
_this.Interfaces[strapiName] = inter;
|
|
98
108
|
});
|
|
99
109
|
return [4 /*yield*/, componentSchemasPromise];
|
|
@@ -104,10 +114,15 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
104
114
|
category.schemas.forEach(function (schema) {
|
|
105
115
|
var componentName = schema.name;
|
|
106
116
|
var strapiName = "".concat(categoryName, ".").concat(schema.name);
|
|
107
|
-
var componentPrefix = "".concat(_this.Options.componentPrefix).concat(_this.Options.useCategoryPrefix
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
var
|
|
117
|
+
var componentPrefix = "".concat(_this.Options.componentPrefix).concat(_this.Options.useCategoryPrefix
|
|
118
|
+
? (0, pascal_case_1.pascalCase)(categoryName)
|
|
119
|
+
: '');
|
|
120
|
+
var prefix = _this.Options.componentPrefixOverridesPrefix
|
|
121
|
+
? componentPrefix
|
|
122
|
+
: _this.Options.prefix + componentPrefix;
|
|
123
|
+
var categoryFolderName = (0, case_1.changeCase)(categoryName, _this.Options.folderCaseType);
|
|
124
|
+
// make component interface
|
|
125
|
+
var inter = new ComponentInterface_1.default(componentName, schema.attributes, "./".concat(categoryFolderName), categoryName, _this.Options.fileCaseType, prefix);
|
|
111
126
|
_this.Interfaces[strapiName] = inter;
|
|
112
127
|
});
|
|
113
128
|
});
|
|
@@ -118,10 +133,11 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
118
133
|
};
|
|
119
134
|
InterfaceManager.prototype.createBuiltinInterfaces = function () {
|
|
120
135
|
var _this = this;
|
|
121
|
-
var
|
|
136
|
+
var outDirName = (0, case_1.changeCase)('builtins', this.Options.folderCaseType);
|
|
137
|
+
var outDir = "./".concat(outDirName);
|
|
122
138
|
var builtinInterfaces = [];
|
|
123
|
-
builtinInterfaces.push((0, builtinInterfaces_1.createMediaInterface)(outDir, this.Options.prefix));
|
|
124
|
-
builtinInterfaces.push((0, builtinInterfaces_1.createMediaFormatInterface)(outDir, this.Options.prefix));
|
|
139
|
+
builtinInterfaces.push((0, builtinInterfaces_1.createMediaInterface)(outDir, this.Options.fileCaseType, this.Options.prefix));
|
|
140
|
+
builtinInterfaces.push((0, builtinInterfaces_1.createMediaFormatInterface)(outDir, this.Options.fileCaseType, this.Options.prefix));
|
|
125
141
|
builtinInterfaces.forEach(function (inter) {
|
|
126
142
|
_this.Interfaces[inter.getStrapiName()] = inter;
|
|
127
143
|
});
|
|
@@ -134,36 +150,60 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
134
150
|
var inter = _this.Interfaces[strapiName];
|
|
135
151
|
var dependencies = inter.getDependencies();
|
|
136
152
|
// console.log(`Interfaces for ${inter.getStrapiName()} are`)
|
|
137
|
-
var interfacesToInject = dependencies
|
|
153
|
+
var interfacesToInject = dependencies
|
|
154
|
+
.map(function (dependencyStrapiName) {
|
|
138
155
|
return _this.Interfaces[dependencyStrapiName];
|
|
139
|
-
})
|
|
156
|
+
})
|
|
157
|
+
.filter(function (inter) { return inter; });
|
|
140
158
|
inter.setRelations(interfacesToInject);
|
|
141
159
|
});
|
|
142
160
|
};
|
|
161
|
+
InterfaceManager.prototype.deleteOldFolders = function () {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
163
|
+
return __generator(this, function (_a) {
|
|
164
|
+
switch (_a.label) {
|
|
165
|
+
case 0: return [4 /*yield*/, (0, promises_1.rm)(this.OutRoot, {
|
|
166
|
+
force: true,
|
|
167
|
+
recursive: true,
|
|
168
|
+
})];
|
|
169
|
+
case 1:
|
|
170
|
+
_a.sent();
|
|
171
|
+
return [2 /*return*/];
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
};
|
|
143
176
|
InterfaceManager.prototype.makeFolders = function () {
|
|
144
177
|
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
-
var componentCategories, promises, componentCategoriesPromises, builtinsPath;
|
|
178
|
+
var componentCategories, promises, componentCategoriesPromises, builintsFolderName, builtinsPath;
|
|
146
179
|
var _this = this;
|
|
147
180
|
return __generator(this, function (_a) {
|
|
148
181
|
switch (_a.label) {
|
|
149
|
-
case 0:
|
|
182
|
+
case 0:
|
|
183
|
+
if (!this.Options.deleteOld) return [3 /*break*/, 2];
|
|
184
|
+
return [4 /*yield*/, this.deleteOldFolders()];
|
|
150
185
|
case 1:
|
|
186
|
+
_a.sent();
|
|
187
|
+
_a.label = 2;
|
|
188
|
+
case 2: return [4 /*yield*/, (0, schemaReader_1.getComponentCategoryFolders)(this.StrapiSrcRoot)];
|
|
189
|
+
case 3:
|
|
151
190
|
componentCategories = _a.sent();
|
|
152
|
-
if (!!(0, fs_1.existsSync)(this.OutRoot)) return [3 /*break*/,
|
|
191
|
+
if (!!(0, fs_1.existsSync)(this.OutRoot)) return [3 /*break*/, 5];
|
|
153
192
|
return [4 /*yield*/, (0, promises_1.mkdir)(this.OutRoot, {
|
|
154
193
|
recursive: true,
|
|
155
194
|
})];
|
|
156
|
-
case
|
|
195
|
+
case 4:
|
|
157
196
|
_a.sent();
|
|
158
|
-
_a.label =
|
|
159
|
-
case
|
|
197
|
+
_a.label = 5;
|
|
198
|
+
case 5:
|
|
160
199
|
promises = [];
|
|
161
200
|
componentCategoriesPromises = componentCategories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
|
|
162
|
-
var path;
|
|
201
|
+
var folderName, path;
|
|
163
202
|
return __generator(this, function (_a) {
|
|
164
203
|
switch (_a.label) {
|
|
165
204
|
case 0:
|
|
166
|
-
|
|
205
|
+
folderName = (0, case_1.changeCase)(category, this.Options.folderCaseType);
|
|
206
|
+
path = (0, posix_1.join)(this.OutRoot, folderName);
|
|
167
207
|
if ((0, fs_1.existsSync)(path)) {
|
|
168
208
|
return [2 /*return*/];
|
|
169
209
|
}
|
|
@@ -175,12 +215,13 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
175
215
|
});
|
|
176
216
|
}); });
|
|
177
217
|
promises.push.apply(promises, componentCategoriesPromises);
|
|
178
|
-
|
|
218
|
+
builintsFolderName = (0, case_1.changeCase)('builtins', this.Options.folderCaseType);
|
|
219
|
+
builtinsPath = (0, posix_1.join)(this.OutRoot, builintsFolderName);
|
|
179
220
|
if (!(0, fs_1.existsSync)(builtinsPath)) {
|
|
180
|
-
promises.push((0, promises_1.mkdir)(
|
|
221
|
+
promises.push((0, promises_1.mkdir)(builtinsPath));
|
|
181
222
|
}
|
|
182
223
|
return [4 /*yield*/, Promise.all(promises)];
|
|
183
|
-
case
|
|
224
|
+
case 6:
|
|
184
225
|
_a.sent();
|
|
185
226
|
return [2 /*return*/];
|
|
186
227
|
}
|
|
@@ -279,7 +320,10 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
279
320
|
componentPrefixOverridesPrefix: false,
|
|
280
321
|
builtinsPrefix: '',
|
|
281
322
|
builtinsPrefixOverridesPrefix: false,
|
|
323
|
+
deleteOld: false,
|
|
282
324
|
prettierFile: null,
|
|
325
|
+
fileCaseType: 'pascal',
|
|
326
|
+
folderCaseType: 'kebab',
|
|
283
327
|
};
|
|
284
328
|
return InterfaceManager;
|
|
285
329
|
}());
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
1
|
+
import { caseType } from '../case';
|
|
2
|
+
import BuiltinComponentInterface from './BuiltinComponentInterface';
|
|
3
|
+
import BuiltinInterface from './BuiltinInterface';
|
|
4
|
+
export declare function createMediaInterface(directory: string, caseTypeName: caseType, prefix: string): BuiltinInterface;
|
|
5
|
+
export declare function createMediaFormatInterface(directory: string, caseTypeName: caseType, prefix: string): BuiltinComponentInterface;
|
|
@@ -6,32 +6,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createMediaFormatInterface = exports.createMediaInterface = void 0;
|
|
7
7
|
var BuiltinComponentInterface_1 = __importDefault(require("./BuiltinComponentInterface"));
|
|
8
8
|
var BuiltinInterface_1 = __importDefault(require("./BuiltinInterface"));
|
|
9
|
-
function createMediaInterface(directory, prefix) {
|
|
9
|
+
function createMediaInterface(directory, caseTypeName, prefix) {
|
|
10
10
|
var stringFields = [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
'name',
|
|
12
|
+
'alternativeText',
|
|
13
|
+
'caption',
|
|
14
|
+
'hash',
|
|
15
|
+
'ext',
|
|
16
|
+
'mime',
|
|
17
|
+
'url',
|
|
18
|
+
'previewUrl',
|
|
19
|
+
'provider',
|
|
20
20
|
];
|
|
21
21
|
var numberFields = [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
'width',
|
|
23
|
+
'height',
|
|
24
|
+
'size',
|
|
25
25
|
];
|
|
26
26
|
var mediaFormat = {
|
|
27
|
-
type:
|
|
27
|
+
type: 'component',
|
|
28
28
|
repeatable: false,
|
|
29
|
-
component:
|
|
29
|
+
component: 'builtins::MediaFormat',
|
|
30
30
|
};
|
|
31
31
|
var mediaAttrs = {
|
|
32
32
|
formats: {
|
|
33
33
|
// types-4-strapi-2 specific
|
|
34
|
-
type:
|
|
34
|
+
type: 'nested',
|
|
35
35
|
fields: {
|
|
36
36
|
thumbnail: mediaFormat,
|
|
37
37
|
medium: mediaFormat,
|
|
@@ -39,8 +39,12 @@ function createMediaInterface(directory, prefix) {
|
|
|
39
39
|
},
|
|
40
40
|
},
|
|
41
41
|
};
|
|
42
|
-
stringFields.forEach(function (s) {
|
|
43
|
-
|
|
42
|
+
stringFields.forEach(function (s) {
|
|
43
|
+
mediaAttrs[s] = { type: 'string' };
|
|
44
|
+
});
|
|
45
|
+
numberFields.forEach(function (s) {
|
|
46
|
+
mediaAttrs[s] = { type: 'integer' };
|
|
47
|
+
});
|
|
44
48
|
// const dataAttrs = {
|
|
45
49
|
// data: {
|
|
46
50
|
// type: "nested",
|
|
@@ -48,26 +52,30 @@ function createMediaInterface(directory, prefix) {
|
|
|
48
52
|
// nullable: true,
|
|
49
53
|
// },
|
|
50
54
|
// };
|
|
51
|
-
return new BuiltinInterface_1.default(
|
|
55
|
+
return new BuiltinInterface_1.default('Media', mediaAttrs, directory, caseTypeName, prefix);
|
|
52
56
|
}
|
|
53
57
|
exports.createMediaInterface = createMediaInterface;
|
|
54
|
-
function createMediaFormatInterface(directory, prefix) {
|
|
58
|
+
function createMediaFormatInterface(directory, caseTypeName, prefix) {
|
|
55
59
|
var stringFields = [
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
'name',
|
|
61
|
+
'hash',
|
|
62
|
+
'ext',
|
|
63
|
+
'mime',
|
|
64
|
+
'path',
|
|
65
|
+
'url',
|
|
62
66
|
];
|
|
63
67
|
var numberFields = [
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
'width',
|
|
69
|
+
'height',
|
|
70
|
+
'size',
|
|
67
71
|
];
|
|
68
72
|
var mediaAttrs = {};
|
|
69
|
-
stringFields.forEach(function (s) {
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
stringFields.forEach(function (s) {
|
|
74
|
+
mediaAttrs[s] = { type: 'string' };
|
|
75
|
+
});
|
|
76
|
+
numberFields.forEach(function (s) {
|
|
77
|
+
mediaAttrs[s] = { type: 'integer' };
|
|
78
|
+
});
|
|
79
|
+
return new BuiltinComponentInterface_1.default('MediaFormat', mediaAttrs, directory, caseTypeName, prefix);
|
|
72
80
|
}
|
|
73
81
|
exports.createMediaFormatInterface = createMediaFormatInterface;
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -36,17 +36,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.prefixDotSlash = exports.readDirFiltered =
|
|
39
|
+
exports.prefixDotSlash = exports.readDirFiltered = void 0;
|
|
40
40
|
var promises_1 = require("fs/promises");
|
|
41
|
-
function pascalCase(name) {
|
|
42
|
-
var words = name.match(/[a-z]+/gi);
|
|
43
|
-
var pascalName = words.map(function (word) {
|
|
44
|
-
return word.charAt(0).toUpperCase() + word.substring(1).toLowerCase();
|
|
45
|
-
}).join("");
|
|
46
|
-
// console.log(pascalName)
|
|
47
|
-
return pascalName;
|
|
48
|
-
}
|
|
49
|
-
exports.pascalCase = pascalCase;
|
|
50
41
|
function readDirFiltered(dir) {
|
|
51
42
|
return __awaiter(this, void 0, void 0, function () {
|
|
52
43
|
var folders;
|
|
@@ -55,13 +46,13 @@ function readDirFiltered(dir) {
|
|
|
55
46
|
case 0: return [4 /*yield*/, (0, promises_1.readdir)(dir)];
|
|
56
47
|
case 1:
|
|
57
48
|
folders = _a.sent();
|
|
58
|
-
return [2 /*return*/, folders.filter(function (folder) { return !folder.startsWith(
|
|
49
|
+
return [2 /*return*/, folders.filter(function (folder) { return !folder.startsWith('.'); })];
|
|
59
50
|
}
|
|
60
51
|
});
|
|
61
52
|
});
|
|
62
53
|
}
|
|
63
54
|
exports.readDirFiltered = readDirFiltered;
|
|
64
55
|
function prefixDotSlash(path) {
|
|
65
|
-
return (/^\.?\.\//).test(path) ? path :
|
|
56
|
+
return (/^\.?\.\//).test(path) ? path : './' + path;
|
|
66
57
|
}
|
|
67
58
|
exports.prefixDotSlash = prefixDotSlash;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oak-digital/types-4-strapi-2",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Typescript interface generator for Strapi 4 models",
|
|
5
5
|
"bin": {
|
|
6
6
|
"t4s": "./bin/index.js"
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"typescript": "^4.7.4"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"change-case": "^4.1.2",
|
|
39
40
|
"commander": "^9.4.0",
|
|
40
41
|
"prettier": "^2.7.1"
|
|
41
42
|
}
|