@oak-digital/types-4-strapi-2 0.2.0 → 0.2.3
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/.editorconfig +9 -0
- package/.eslintrc.json +52 -0
- package/.prettierrc.json +7 -0
- package/README.md +67 -0
- package/lib/.prettierrc.json +7 -0
- package/lib/index.js +9 -4
- package/lib/interface/Attributes.js +4 -1
- package/lib/interface/Interface.d.ts +1 -1
- package/lib/interface/Interface.js +13 -15
- package/lib/interface/InterfaceManager.d.ts +3 -0
- package/lib/interface/InterfaceManager.js +47 -20
- package/lib/interface/builtinInterfaces.js +7 -0
- package/lib/interface/schemaReader.js +15 -11
- package/lib/src/index.d.ts +1 -0
- package/lib/src/index.js +25 -0
- package/lib/src/interface/Attributes.d.ts +11 -0
- package/lib/src/interface/Attributes.js +148 -0
- package/lib/src/interface/BuiltinComponentInterface.d.ts +5 -0
- package/lib/src/interface/BuiltinComponentInterface.js +36 -0
- package/lib/src/interface/BuiltinInterface.d.ts +5 -0
- package/lib/src/interface/BuiltinInterface.js +33 -0
- package/lib/src/interface/ComponentInterface.d.ts +8 -0
- package/lib/src/interface/ComponentInterface.js +58 -0
- package/lib/src/interface/Interface.d.ts +31 -0
- package/lib/src/interface/Interface.js +112 -0
- package/lib/src/interface/InterfaceManager.d.ts +25 -0
- package/lib/src/interface/InterfaceManager.js +288 -0
- package/lib/src/interface/builtinInterfaces.d.ts +4 -0
- package/lib/src/interface/builtinInterfaces.js +81 -0
- package/lib/src/interface/schemaReader.d.ts +14 -0
- package/lib/src/interface/schemaReader.js +172 -0
- package/lib/src/utils/index.d.ts +3 -0
- package/lib/src/utils/index.js +67 -0
- package/package.json +8 -2
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var fs_1 = require("fs");
|
|
43
|
+
var promises_1 = require("fs/promises");
|
|
44
|
+
var path_1 = require("path");
|
|
45
|
+
var utils_1 = require("../utils");
|
|
46
|
+
var builtinInterfaces_1 = require("./builtinInterfaces");
|
|
47
|
+
var ComponentInterface_1 = __importDefault(require("./ComponentInterface"));
|
|
48
|
+
var Interface_1 = __importDefault(require("./Interface"));
|
|
49
|
+
var schemaReader_1 = require("./schemaReader");
|
|
50
|
+
var prettier_1 = __importDefault(require("prettier"));
|
|
51
|
+
var _prettierrc_json_1 = __importDefault(require("../../.prettierrc.json"));
|
|
52
|
+
var InterfaceManager = /** @class */ (function () {
|
|
53
|
+
function InterfaceManager(outRoot, strapiSrcRoot, options) {
|
|
54
|
+
if (options === void 0) { options = {}; }
|
|
55
|
+
this.Interfaces = {}; // string = strapi name
|
|
56
|
+
this.OutRoot = outRoot;
|
|
57
|
+
this.StrapiSrcRoot = strapiSrcRoot;
|
|
58
|
+
this.Options = Object.assign({}, InterfaceManager.BaseOptions, options);
|
|
59
|
+
}
|
|
60
|
+
InterfaceManager.prototype.loadPrettierConfig = function () {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
+
var defaultOptions, resolved;
|
|
63
|
+
return __generator(this, function (_a) {
|
|
64
|
+
switch (_a.label) {
|
|
65
|
+
case 0:
|
|
66
|
+
defaultOptions = _prettierrc_json_1.default;
|
|
67
|
+
if (!this.Options.prettierFile) {
|
|
68
|
+
this.PrettierOptions = defaultOptions;
|
|
69
|
+
return [2 /*return*/];
|
|
70
|
+
}
|
|
71
|
+
return [4 /*yield*/, prettier_1.default.resolveConfig(this.Options.prettierFile)];
|
|
72
|
+
case 1:
|
|
73
|
+
resolved = _a.sent();
|
|
74
|
+
this.PrettierOptions = Object.assign({}, defaultOptions, resolved);
|
|
75
|
+
return [2 /*return*/];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
InterfaceManager.prototype.createInterfaces = function () {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
+
var apiSchemasPromise, componentSchemasPromise, apiSchemas, componentSchemas;
|
|
83
|
+
var _this = this;
|
|
84
|
+
return __generator(this, function (_a) {
|
|
85
|
+
switch (_a.label) {
|
|
86
|
+
case 0:
|
|
87
|
+
apiSchemasPromise = (0, schemaReader_1.getApiSchemas)(this.StrapiSrcRoot);
|
|
88
|
+
componentSchemasPromise = (0, schemaReader_1.getComponentSchemas)(this.StrapiSrcRoot);
|
|
89
|
+
return [4 /*yield*/, apiSchemasPromise];
|
|
90
|
+
case 1:
|
|
91
|
+
apiSchemas = _a.sent();
|
|
92
|
+
apiSchemas.forEach(function (schema) {
|
|
93
|
+
var name = schema.name, attributes = schema.attributes;
|
|
94
|
+
var strapiName = "api::".concat(name, ".").concat(name);
|
|
95
|
+
var inter = new Interface_1.default(name, attributes, './', _this.Options.prefix);
|
|
96
|
+
_this.Interfaces[strapiName] = inter;
|
|
97
|
+
});
|
|
98
|
+
return [4 /*yield*/, componentSchemasPromise];
|
|
99
|
+
case 2:
|
|
100
|
+
componentSchemas = _a.sent();
|
|
101
|
+
componentSchemas.forEach(function (category) {
|
|
102
|
+
var categoryName = category.category;
|
|
103
|
+
category.schemas.forEach(function (schema) {
|
|
104
|
+
var componentName = schema.name;
|
|
105
|
+
var strapiName = "".concat(categoryName, ".").concat(schema.name);
|
|
106
|
+
var componentPrefix = "".concat(_this.Options.componentPrefix).concat(_this.Options.useCategoryPrefix ? (0, utils_1.pascalCase)(categoryName) : '');
|
|
107
|
+
var prefix = _this.Options.componentPrefixOverridesPrefix ? componentPrefix : _this.Options.prefix + componentPrefix;
|
|
108
|
+
// TODO: make component interface
|
|
109
|
+
var inter = new ComponentInterface_1.default(componentName, schema.attributes, "./".concat(categoryName), categoryName, prefix);
|
|
110
|
+
_this.Interfaces[strapiName] = inter;
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
return [2 /*return*/];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
InterfaceManager.prototype.createBuiltinInterfaces = function () {
|
|
119
|
+
var _this = this;
|
|
120
|
+
var outDir = './builtins';
|
|
121
|
+
var builtinInterfaces = [];
|
|
122
|
+
builtinInterfaces.push((0, builtinInterfaces_1.createMediaInterface)(outDir, this.Options.prefix));
|
|
123
|
+
builtinInterfaces.push((0, builtinInterfaces_1.createMediaFormatInterface)(outDir, this.Options.prefix));
|
|
124
|
+
builtinInterfaces.forEach(function (inter) {
|
|
125
|
+
_this.Interfaces[inter.getStrapiName()] = inter;
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
// Inject dependencies into all interfaces
|
|
129
|
+
InterfaceManager.prototype.injectDependencies = function () {
|
|
130
|
+
var _this = this;
|
|
131
|
+
// console.log("Injecting dependencies")
|
|
132
|
+
Object.keys(this.Interfaces).forEach(function (strapiName) {
|
|
133
|
+
var inter = _this.Interfaces[strapiName];
|
|
134
|
+
var dependencies = inter.getDependencies();
|
|
135
|
+
// console.log(`Interfaces for ${inter.getStrapiName()} are`)
|
|
136
|
+
var interfacesToInject = dependencies.map(function (dependencyStrapiName) {
|
|
137
|
+
return _this.Interfaces[dependencyStrapiName];
|
|
138
|
+
}).filter(function (inter) { return inter; });
|
|
139
|
+
inter.setRelations(interfacesToInject);
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
InterfaceManager.prototype.makeFolders = function () {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
144
|
+
var componentCategories, promises, componentCategoriesPromises, builtinsPath;
|
|
145
|
+
var _this = this;
|
|
146
|
+
return __generator(this, function (_a) {
|
|
147
|
+
switch (_a.label) {
|
|
148
|
+
case 0: return [4 /*yield*/, (0, schemaReader_1.getComponentCategoryFolders)(this.StrapiSrcRoot)];
|
|
149
|
+
case 1:
|
|
150
|
+
componentCategories = _a.sent();
|
|
151
|
+
if (!!(0, fs_1.existsSync)(this.OutRoot)) return [3 /*break*/, 3];
|
|
152
|
+
return [4 /*yield*/, (0, promises_1.mkdir)(this.OutRoot, {
|
|
153
|
+
recursive: true,
|
|
154
|
+
})];
|
|
155
|
+
case 2:
|
|
156
|
+
_a.sent();
|
|
157
|
+
_a.label = 3;
|
|
158
|
+
case 3:
|
|
159
|
+
promises = [];
|
|
160
|
+
componentCategoriesPromises = componentCategories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
|
|
161
|
+
var path;
|
|
162
|
+
return __generator(this, function (_a) {
|
|
163
|
+
switch (_a.label) {
|
|
164
|
+
case 0:
|
|
165
|
+
path = (0, path_1.join)(this.OutRoot, category);
|
|
166
|
+
if ((0, fs_1.existsSync)(path)) {
|
|
167
|
+
return [2 /*return*/];
|
|
168
|
+
}
|
|
169
|
+
return [4 /*yield*/, (0, promises_1.mkdir)(path)];
|
|
170
|
+
case 1:
|
|
171
|
+
_a.sent();
|
|
172
|
+
return [2 /*return*/];
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}); });
|
|
176
|
+
promises.push.apply(promises, componentCategoriesPromises);
|
|
177
|
+
builtinsPath = (0, path_1.join)(this.OutRoot, 'builtins');
|
|
178
|
+
if (!(0, fs_1.existsSync)(builtinsPath)) {
|
|
179
|
+
promises.push((0, promises_1.mkdir)((0, path_1.join)(this.OutRoot, 'builtins')));
|
|
180
|
+
}
|
|
181
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
182
|
+
case 4:
|
|
183
|
+
_a.sent();
|
|
184
|
+
return [2 /*return*/];
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
InterfaceManager.prototype.writeInterfaces = function () {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
191
|
+
var writePromises;
|
|
192
|
+
var _this = this;
|
|
193
|
+
return __generator(this, function (_a) {
|
|
194
|
+
switch (_a.label) {
|
|
195
|
+
case 0:
|
|
196
|
+
writePromises = Object.keys(this.Interfaces).map(function (strapiName) { return __awaiter(_this, void 0, void 0, function () {
|
|
197
|
+
var inter, fileData, formattedFileData, filePath;
|
|
198
|
+
return __generator(this, function (_a) {
|
|
199
|
+
switch (_a.label) {
|
|
200
|
+
case 0:
|
|
201
|
+
inter = this.Interfaces[strapiName];
|
|
202
|
+
fileData = inter.toString();
|
|
203
|
+
formattedFileData = prettier_1.default.format(fileData, this.PrettierOptions);
|
|
204
|
+
filePath = (0, path_1.join)(this.OutRoot, inter.getRelativeRootPathFile());
|
|
205
|
+
return [4 /*yield*/, (0, promises_1.writeFile)(filePath, formattedFileData)];
|
|
206
|
+
case 1:
|
|
207
|
+
_a.sent();
|
|
208
|
+
return [2 /*return*/];
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}); });
|
|
212
|
+
return [4 /*yield*/, Promise.all(writePromises)];
|
|
213
|
+
case 1:
|
|
214
|
+
_a.sent();
|
|
215
|
+
return [2 /*return*/];
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
InterfaceManager.prototype.writeIndexFile = function () {
|
|
221
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
222
|
+
var strings, fileData, formattedFileData, filePath;
|
|
223
|
+
var _this = this;
|
|
224
|
+
return __generator(this, function (_a) {
|
|
225
|
+
switch (_a.label) {
|
|
226
|
+
case 0:
|
|
227
|
+
strings = Object.keys(this.Interfaces).map(function (strapiName) {
|
|
228
|
+
var inter = _this.Interfaces[strapiName];
|
|
229
|
+
return "export * from '".concat(inter.getRelativeRootPath(), "'");
|
|
230
|
+
});
|
|
231
|
+
fileData = strings.join('\n');
|
|
232
|
+
formattedFileData = prettier_1.default.format(fileData, this.PrettierOptions);
|
|
233
|
+
filePath = (0, path_1.join)(this.OutRoot, 'index.ts');
|
|
234
|
+
return [4 /*yield*/, (0, promises_1.writeFile)(filePath, formattedFileData)];
|
|
235
|
+
case 1:
|
|
236
|
+
_a.sent();
|
|
237
|
+
return [2 /*return*/];
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
InterfaceManager.prototype.run = function () {
|
|
243
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
244
|
+
var createInterfacesPromise, makeFoldersPromise, loadPrettierPromise, err_1;
|
|
245
|
+
return __generator(this, function (_a) {
|
|
246
|
+
switch (_a.label) {
|
|
247
|
+
case 0:
|
|
248
|
+
_a.trys.push([0, 5, , 6]);
|
|
249
|
+
createInterfacesPromise = this.createInterfaces();
|
|
250
|
+
makeFoldersPromise = this.makeFolders();
|
|
251
|
+
loadPrettierPromise = this.loadPrettierConfig();
|
|
252
|
+
return [4 /*yield*/, loadPrettierPromise];
|
|
253
|
+
case 1:
|
|
254
|
+
_a.sent();
|
|
255
|
+
this.createBuiltinInterfaces();
|
|
256
|
+
return [4 /*yield*/, createInterfacesPromise];
|
|
257
|
+
case 2:
|
|
258
|
+
_a.sent();
|
|
259
|
+
// Create all interfaces before injecting
|
|
260
|
+
this.injectDependencies();
|
|
261
|
+
return [4 /*yield*/, Promise.all([makeFoldersPromise,])];
|
|
262
|
+
case 3:
|
|
263
|
+
_a.sent();
|
|
264
|
+
return [4 /*yield*/, Promise.all([this.writeInterfaces(), this.writeIndexFile()])];
|
|
265
|
+
case 4:
|
|
266
|
+
_a.sent();
|
|
267
|
+
return [3 /*break*/, 6];
|
|
268
|
+
case 5:
|
|
269
|
+
err_1 = _a.sent();
|
|
270
|
+
console.error(err_1);
|
|
271
|
+
return [3 /*break*/, 6];
|
|
272
|
+
case 6: return [2 /*return*/];
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
InterfaceManager.BaseOptions = {
|
|
278
|
+
prefix: 'I',
|
|
279
|
+
useCategoryPrefix: true,
|
|
280
|
+
componentPrefix: '',
|
|
281
|
+
componentPrefixOverridesPrefix: false,
|
|
282
|
+
builtinsPrefix: '',
|
|
283
|
+
builtinsPrefixOverridesPrefix: false,
|
|
284
|
+
prettierFile: null,
|
|
285
|
+
};
|
|
286
|
+
return InterfaceManager;
|
|
287
|
+
}());
|
|
288
|
+
exports.default = InterfaceManager;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import BuiltinComponentInterface from './BuiltinComponentInterface';
|
|
2
|
+
import BuiltinInterface from './BuiltinInterface';
|
|
3
|
+
export declare function createMediaInterface(directory: string, prefix: string): BuiltinInterface;
|
|
4
|
+
export declare function createMediaFormatInterface(directory: string, prefix: string): BuiltinComponentInterface;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createMediaFormatInterface = exports.createMediaInterface = void 0;
|
|
7
|
+
var BuiltinComponentInterface_1 = __importDefault(require("./BuiltinComponentInterface"));
|
|
8
|
+
var BuiltinInterface_1 = __importDefault(require("./BuiltinInterface"));
|
|
9
|
+
function createMediaInterface(directory, prefix) {
|
|
10
|
+
var stringFields = [
|
|
11
|
+
'name',
|
|
12
|
+
'alternativeText',
|
|
13
|
+
'caption',
|
|
14
|
+
'hash',
|
|
15
|
+
'ext',
|
|
16
|
+
'mime',
|
|
17
|
+
'url',
|
|
18
|
+
'previewUrl',
|
|
19
|
+
'provider',
|
|
20
|
+
];
|
|
21
|
+
var numberFields = [
|
|
22
|
+
'width',
|
|
23
|
+
'height',
|
|
24
|
+
'size',
|
|
25
|
+
];
|
|
26
|
+
var mediaFormat = {
|
|
27
|
+
type: 'component',
|
|
28
|
+
repeatable: false,
|
|
29
|
+
component: 'builtins::MediaFormat',
|
|
30
|
+
};
|
|
31
|
+
var mediaAttrs = {
|
|
32
|
+
formats: {
|
|
33
|
+
// types-4-strapi-2 specific
|
|
34
|
+
type: 'nested',
|
|
35
|
+
fields: {
|
|
36
|
+
thumbnail: mediaFormat,
|
|
37
|
+
medium: mediaFormat,
|
|
38
|
+
small: mediaFormat,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
stringFields.forEach(function (s) {
|
|
43
|
+
mediaAttrs[s] = { type: 'string' };
|
|
44
|
+
});
|
|
45
|
+
numberFields.forEach(function (s) {
|
|
46
|
+
mediaAttrs[s] = { type: 'integer' };
|
|
47
|
+
});
|
|
48
|
+
// const dataAttrs = {
|
|
49
|
+
// data: {
|
|
50
|
+
// type: "nested",
|
|
51
|
+
// fields: mediaAttrs,
|
|
52
|
+
// nullable: true,
|
|
53
|
+
// },
|
|
54
|
+
// };
|
|
55
|
+
return new BuiltinInterface_1.default('Media', mediaAttrs, directory, prefix);
|
|
56
|
+
}
|
|
57
|
+
exports.createMediaInterface = createMediaInterface;
|
|
58
|
+
function createMediaFormatInterface(directory, prefix) {
|
|
59
|
+
var stringFields = [
|
|
60
|
+
'name',
|
|
61
|
+
'hash',
|
|
62
|
+
'ext',
|
|
63
|
+
'mime',
|
|
64
|
+
'path',
|
|
65
|
+
'url',
|
|
66
|
+
];
|
|
67
|
+
var numberFields = [
|
|
68
|
+
'width',
|
|
69
|
+
'height',
|
|
70
|
+
'size',
|
|
71
|
+
];
|
|
72
|
+
var mediaAttrs = {};
|
|
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, prefix);
|
|
80
|
+
}
|
|
81
|
+
exports.createMediaFormatInterface = createMediaFormatInterface;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function readSchema(schemaPath: string): Promise<any>;
|
|
2
|
+
export declare function getApiFolders(strapiSrcRoot: string): Promise<string[]>;
|
|
3
|
+
export declare function getComponentCategoryFolders(strapiSrcRoot: string): Promise<string[]>;
|
|
4
|
+
export declare function getComponentSchemas(strapiSrcRoot: string): Promise<{
|
|
5
|
+
category: string;
|
|
6
|
+
schemas: {
|
|
7
|
+
name: string;
|
|
8
|
+
attributes: any;
|
|
9
|
+
}[];
|
|
10
|
+
}[]>;
|
|
11
|
+
export declare function getApiSchemas(strapiSrcRoot: string): Promise<{
|
|
12
|
+
name: string;
|
|
13
|
+
attributes: any;
|
|
14
|
+
}[]>;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.getApiSchemas = exports.getComponentSchemas = exports.getComponentCategoryFolders = exports.getApiFolders = exports.readSchema = void 0;
|
|
40
|
+
var promises_1 = require("node:fs/promises");
|
|
41
|
+
var node_path_1 = require("node:path");
|
|
42
|
+
var utils_1 = require("../utils");
|
|
43
|
+
function readSchema(schemaPath) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
+
var schemaData, e_1;
|
|
46
|
+
return __generator(this, function (_a) {
|
|
47
|
+
switch (_a.label) {
|
|
48
|
+
case 0:
|
|
49
|
+
_a.trys.push([0, 2, , 3]);
|
|
50
|
+
return [4 /*yield*/, (0, promises_1.readFile)(schemaPath)];
|
|
51
|
+
case 1:
|
|
52
|
+
schemaData = _a.sent();
|
|
53
|
+
return [2 /*return*/, JSON.parse(schemaData.toString()).attributes];
|
|
54
|
+
case 2:
|
|
55
|
+
e_1 = _a.sent();
|
|
56
|
+
return [2 /*return*/, null];
|
|
57
|
+
case 3: return [2 /*return*/];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
exports.readSchema = readSchema;
|
|
63
|
+
function getApiFolders(strapiSrcRoot) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
+
var path, folders;
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
switch (_a.label) {
|
|
68
|
+
case 0:
|
|
69
|
+
path = (0, node_path_1.join)(strapiSrcRoot, 'api');
|
|
70
|
+
return [4 /*yield*/, (0, utils_1.readDirFiltered)(path)];
|
|
71
|
+
case 1:
|
|
72
|
+
folders = _a.sent();
|
|
73
|
+
return [2 /*return*/, folders];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
exports.getApiFolders = getApiFolders;
|
|
79
|
+
function getComponentCategoryFolders(strapiSrcRoot) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
+
var path, folders;
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
switch (_a.label) {
|
|
84
|
+
case 0:
|
|
85
|
+
path = (0, node_path_1.join)(strapiSrcRoot, 'components');
|
|
86
|
+
return [4 /*yield*/, (0, utils_1.readDirFiltered)(path)];
|
|
87
|
+
case 1:
|
|
88
|
+
folders = _a.sent();
|
|
89
|
+
return [2 /*return*/, folders];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
exports.getComponentCategoryFolders = getComponentCategoryFolders;
|
|
95
|
+
function getComponentSchemas(strapiSrcRoot) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
+
var categories, nestedSchemasPromises, nestedSchemasArr;
|
|
98
|
+
var _this = this;
|
|
99
|
+
return __generator(this, function (_a) {
|
|
100
|
+
switch (_a.label) {
|
|
101
|
+
case 0: return [4 /*yield*/, getComponentCategoryFolders(strapiSrcRoot)];
|
|
102
|
+
case 1:
|
|
103
|
+
categories = _a.sent();
|
|
104
|
+
nestedSchemasPromises = categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
|
|
105
|
+
var schemaFilesPath, schemaFiles, schemaNamesWithAttributesPromises, schemaNamesWithAttributes;
|
|
106
|
+
var _this = this;
|
|
107
|
+
return __generator(this, function (_a) {
|
|
108
|
+
switch (_a.label) {
|
|
109
|
+
case 0:
|
|
110
|
+
schemaFilesPath = (0, node_path_1.join)(strapiSrcRoot, 'components', category);
|
|
111
|
+
return [4 /*yield*/, (0, utils_1.readDirFiltered)(schemaFilesPath)];
|
|
112
|
+
case 1:
|
|
113
|
+
schemaFiles = _a.sent();
|
|
114
|
+
schemaNamesWithAttributesPromises = schemaFiles.map(function (file) { return __awaiter(_this, void 0, void 0, function () {
|
|
115
|
+
var schemaPath, attributes, name;
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
switch (_a.label) {
|
|
118
|
+
case 0:
|
|
119
|
+
schemaPath = (0, node_path_1.join)(schemaFilesPath, file);
|
|
120
|
+
return [4 /*yield*/, readSchema(schemaPath)];
|
|
121
|
+
case 1:
|
|
122
|
+
attributes = _a.sent();
|
|
123
|
+
name = file.split('.')[0];
|
|
124
|
+
return [2 /*return*/, { name: name, attributes: attributes }];
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}); });
|
|
128
|
+
return [4 /*yield*/, Promise.all(schemaNamesWithAttributesPromises)];
|
|
129
|
+
case 2:
|
|
130
|
+
schemaNamesWithAttributes = _a.sent();
|
|
131
|
+
return [2 /*return*/, { category: category, schemas: schemaNamesWithAttributes }];
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}); });
|
|
135
|
+
return [4 /*yield*/, Promise.all(nestedSchemasPromises)];
|
|
136
|
+
case 2:
|
|
137
|
+
nestedSchemasArr = _a.sent();
|
|
138
|
+
return [2 /*return*/, nestedSchemasArr];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
exports.getComponentSchemas = getComponentSchemas;
|
|
144
|
+
function getApiSchemas(strapiSrcRoot) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
+
var apiFolders, schemasWithAttributesPromises, schemasWithAttributes;
|
|
147
|
+
var _this = this;
|
|
148
|
+
return __generator(this, function (_a) {
|
|
149
|
+
switch (_a.label) {
|
|
150
|
+
case 0: return [4 /*yield*/, getApiFolders(strapiSrcRoot)];
|
|
151
|
+
case 1:
|
|
152
|
+
apiFolders = _a.sent();
|
|
153
|
+
schemasWithAttributesPromises = apiFolders.map(function (folder) { return __awaiter(_this, void 0, void 0, function () {
|
|
154
|
+
var schemaPath, attributes;
|
|
155
|
+
return __generator(this, function (_a) {
|
|
156
|
+
switch (_a.label) {
|
|
157
|
+
case 0:
|
|
158
|
+
schemaPath = (0, node_path_1.join)(strapiSrcRoot, 'api', folder, 'content-types', folder, 'schema.json');
|
|
159
|
+
return [4 /*yield*/, readSchema(schemaPath)];
|
|
160
|
+
case 1:
|
|
161
|
+
attributes = _a.sent();
|
|
162
|
+
return [2 /*return*/, { name: folder, attributes: attributes }];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}); });
|
|
166
|
+
schemasWithAttributes = Promise.all(schemasWithAttributesPromises);
|
|
167
|
+
return [2 /*return*/, schemasWithAttributes];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
exports.getApiSchemas = getApiSchemas;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.prefixDotSlash = exports.readDirFiltered = exports.pascalCase = void 0;
|
|
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
|
+
function readDirFiltered(dir) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
+
var folders;
|
|
53
|
+
return __generator(this, function (_a) {
|
|
54
|
+
switch (_a.label) {
|
|
55
|
+
case 0: return [4 /*yield*/, (0, promises_1.readdir)(dir)];
|
|
56
|
+
case 1:
|
|
57
|
+
folders = _a.sent();
|
|
58
|
+
return [2 /*return*/, folders.filter(function (folder) { return !folder.startsWith('.'); })];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
exports.readDirFiltered = readDirFiltered;
|
|
64
|
+
function prefixDotSlash(path) {
|
|
65
|
+
return (/^\.?\.\//).test(path) ? path : './' + path;
|
|
66
|
+
}
|
|
67
|
+
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.3",
|
|
4
4
|
"description": "Typescript interface generator for Strapi 4 models",
|
|
5
5
|
"bin": {
|
|
6
6
|
"t4s": "./bin/index.js"
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsc -p .",
|
|
10
10
|
"testtypes": "node ./bin/index.js",
|
|
11
|
+
"lint": "eslint src/",
|
|
11
12
|
"t4s": "node ./bin/index.js"
|
|
12
13
|
},
|
|
13
14
|
"repository": {
|
|
@@ -28,9 +29,14 @@
|
|
|
28
29
|
"homepage": "https://github.com/Oak-Digital/types-4-strapi-2",
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@types/node": "^18.7.2",
|
|
32
|
+
"@types/prettier": "^2.7.0",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
|
34
|
+
"@typescript-eslint/parser": "^5.33.1",
|
|
35
|
+
"eslint": "^8.22.0",
|
|
31
36
|
"typescript": "^4.7.4"
|
|
32
37
|
},
|
|
33
38
|
"dependencies": {
|
|
34
|
-
"commander": "^9.4.0"
|
|
39
|
+
"commander": "^9.4.0",
|
|
40
|
+
"prettier": "^2.7.1"
|
|
35
41
|
}
|
|
36
42
|
}
|