@oak-digital/types-4-strapi-2 0.2.6 → 0.2.7
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/lib/case/index.d.ts +4 -0
- package/lib/case/index.js +47 -0
- package/lib/index.js +5 -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 +3 -0
- package/lib/interface/InterfaceManager.js +38 -16
- 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
|
@@ -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
|
@@ -12,14 +12,18 @@ commander_1.program
|
|
|
12
12
|
.option('-o, --out <dir>', 'The output directory to output the types to', './types')
|
|
13
13
|
.option('--component-prefix <prefix>', 'A prefix for components', '')
|
|
14
14
|
.option('-D, --delete-old', 'CAUTION: This option is equivalent to running rm -rf on the output directory first')
|
|
15
|
+
.option('--file-case <case>', 'Which case to use for generated files', 'pascal')
|
|
16
|
+
.option('--folder-case <case>', 'Which case to use for generated folders', 'kebab')
|
|
15
17
|
.option('--prettier <file>', 'The prettier config file to use for formatting typescript interfaces');
|
|
16
18
|
commander_1.program.parse();
|
|
17
19
|
var options = commander_1.program.opts();
|
|
18
|
-
var input = options.in, out = options.out, componentPrefix = options.componentPrefix, prettierFile = options.prettier, deleteOld = options.deleteOld;
|
|
20
|
+
var input = options.in, out = options.out, componentPrefix = options.componentPrefix, prettierFile = options.prettier, deleteOld = options.deleteOld, fileCaseType = options.fileCase, folderCaseType = options.folderCase;
|
|
19
21
|
var manager = new InterfaceManager_1.default(out, input, {
|
|
20
22
|
componentPrefix: componentPrefix,
|
|
21
23
|
prettierFile: prettierFile,
|
|
22
24
|
deleteOld: deleteOld,
|
|
25
|
+
fileCaseType: fileCaseType,
|
|
26
|
+
folderCaseType: folderCaseType,
|
|
23
27
|
});
|
|
24
28
|
manager.run().catch(function (err) {
|
|
25
29
|
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 () {
|
|
@@ -13,8 +13,11 @@ export default class InterfaceManager {
|
|
|
13
13
|
builtinsPrefixOverridesPrefix: boolean;
|
|
14
14
|
deleteOld: boolean;
|
|
15
15
|
prettierFile: any;
|
|
16
|
+
fileCaseType: string;
|
|
17
|
+
folderCaseType: string;
|
|
16
18
|
};
|
|
17
19
|
constructor(outRoot: string, strapiSrcRoot: string, options?: any);
|
|
20
|
+
validateOptions(): void;
|
|
18
21
|
loadPrettierConfig(): Promise<void>;
|
|
19
22
|
createInterfaces(): Promise<void>;
|
|
20
23
|
createBuiltinInterfaces(): 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,9 +150,11 @@ 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
|
};
|
|
@@ -157,7 +175,7 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
157
175
|
};
|
|
158
176
|
InterfaceManager.prototype.makeFolders = function () {
|
|
159
177
|
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
-
var componentCategories, promises, componentCategoriesPromises, builtinsPath;
|
|
178
|
+
var componentCategories, promises, componentCategoriesPromises, builintsFolderName, builtinsPath;
|
|
161
179
|
var _this = this;
|
|
162
180
|
return __generator(this, function (_a) {
|
|
163
181
|
switch (_a.label) {
|
|
@@ -180,11 +198,12 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
180
198
|
case 5:
|
|
181
199
|
promises = [];
|
|
182
200
|
componentCategoriesPromises = componentCategories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
|
|
183
|
-
var path;
|
|
201
|
+
var folderName, path;
|
|
184
202
|
return __generator(this, function (_a) {
|
|
185
203
|
switch (_a.label) {
|
|
186
204
|
case 0:
|
|
187
|
-
|
|
205
|
+
folderName = (0, case_1.changeCase)(category, this.Options.folderCaseType);
|
|
206
|
+
path = (0, posix_1.join)(this.OutRoot, folderName);
|
|
188
207
|
if ((0, fs_1.existsSync)(path)) {
|
|
189
208
|
return [2 /*return*/];
|
|
190
209
|
}
|
|
@@ -196,9 +215,10 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
196
215
|
});
|
|
197
216
|
}); });
|
|
198
217
|
promises.push.apply(promises, componentCategoriesPromises);
|
|
199
|
-
|
|
218
|
+
builintsFolderName = (0, case_1.changeCase)('builtins', this.Options.folderCaseType);
|
|
219
|
+
builtinsPath = (0, posix_1.join)(this.OutRoot, builintsFolderName);
|
|
200
220
|
if (!(0, fs_1.existsSync)(builtinsPath)) {
|
|
201
|
-
promises.push((0, promises_1.mkdir)(
|
|
221
|
+
promises.push((0, promises_1.mkdir)(builtinsPath));
|
|
202
222
|
}
|
|
203
223
|
return [4 /*yield*/, Promise.all(promises)];
|
|
204
224
|
case 6:
|
|
@@ -302,6 +322,8 @@ var InterfaceManager = /** @class */ (function () {
|
|
|
302
322
|
builtinsPrefixOverridesPrefix: false,
|
|
303
323
|
deleteOld: false,
|
|
304
324
|
prettierFile: null,
|
|
325
|
+
fileCaseType: 'pascal',
|
|
326
|
+
folderCaseType: 'kebab',
|
|
305
327
|
};
|
|
306
328
|
return InterfaceManager;
|
|
307
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.7",
|
|
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
|
}
|