@oak-digital/types-4-strapi-2 0.2.1 → 0.2.2

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 ADDED
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ # Unix-style newlines with a newline ending every file
4
+ [*]
5
+ end_of_line = lf
6
+ insert_final_newline = true
7
+ indent_style = space
8
+ indent_size = 4
9
+ trim_trailing_whitespace = true
package/.eslintrc.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "env": {
3
+ "es2021": true,
4
+ "node": true
5
+ },
6
+ "extends": [
7
+ "eslint:recommended",
8
+ "plugin:@typescript-eslint/recommended"
9
+ ],
10
+ "overrides": [
11
+ ],
12
+ "parser": "@typescript-eslint/parser",
13
+ "parserOptions": {
14
+ "ecmaVersion": "latest",
15
+ "sourceType": "module"
16
+ },
17
+ "plugins": [
18
+ "@typescript-eslint"
19
+ ],
20
+ "rules": {
21
+ "@typescript-eslint/no-explicit-any": "off",
22
+ "no-case-declarations": "off",
23
+ "@typescript-eslint/no-unused-vars": "off",
24
+ "default-case-last": ["error"],
25
+ "eqeqeq": ["error", "always"],
26
+ "no-lonely-if": ["error"],
27
+ "no-magic-numbers": ["warn", {
28
+ "ignoreArrayIndexes": true,
29
+ "ignore": [-1, 0, 1]
30
+ }],
31
+ "no-return-assign": ["error", "always"],
32
+ "no-return-await": ["error"],
33
+ "no-var": ["error"],
34
+ "no-cond-assign": ["error", "always"],
35
+ "indent": [
36
+ "error",
37
+ 4
38
+ ],
39
+ "linebreak-style": [
40
+ "error",
41
+ "unix"
42
+ ],
43
+ "quotes": [
44
+ "error",
45
+ "single"
46
+ ],
47
+ "semi": [
48
+ "error",
49
+ "always"
50
+ ]
51
+ }
52
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "parser": "typescript",
3
+ "semi": true,
4
+ "singleQuote": true,
5
+ "bracketSameLine": false,
6
+ "trailingComma": "es5"
7
+ }
package/README.md CHANGED
@@ -41,11 +41,11 @@ This can be done with the `--out` flag like in the following example.
41
41
  * Generate typescript interfaces for all your api content-types and components
42
42
  * Generate typescript interfaces for builtin types such as `Media` and `MediaFormat`
43
43
  * Select input and output directory
44
+ * Prettier formatting and ability to use your own `.prettierrc`.
44
45
 
45
46
  ### Planned features
46
47
 
47
48
  * Support if you are using other plugins, such as `url-alias`, which should add extra fields for some interfaces.
48
- * Nicer formatted interfaces
49
49
 
50
50
  ## Help
51
51
 
@@ -0,0 +1,7 @@
1
+ {
2
+ "parser": "typescript",
3
+ "semi": true,
4
+ "singleQuote": true,
5
+ "bracketSameLine": false,
6
+ "trailingComma": "es5"
7
+ }
package/lib/index.js CHANGED
@@ -6,16 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var commander_1 = require("commander");
7
7
  var InterfaceManager_1 = __importDefault(require("./interface/InterfaceManager"));
8
8
  commander_1.program
9
- .name("t4s");
9
+ .name('t4s');
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('--component-prefix <prefix>', 'A prefix for components', "");
13
+ .option('--component-prefix <prefix>', 'A prefix for components', '')
14
+ .option('--prettier <file>', 'The prettier config file to use for formatting typescript interfaces');
14
15
  commander_1.program.parse();
15
16
  var options = commander_1.program.opts();
16
- var input = options.in, out = options.out, componentPrefix = options.componentPrefix;
17
+ var input = options.in, out = options.out, componentPrefix = options.componentPrefix, prettierFile = options.prettier;
17
18
  var manager = new InterfaceManager_1.default(out, input, {
18
19
  componentPrefix: componentPrefix,
20
+ prettierFile: prettierFile,
19
21
  });
20
22
  manager.run().catch(function (err) {
21
23
  console.error(err);
@@ -3,6 +3,7 @@ export default class InterfaceManager {
3
3
  private OutRoot;
4
4
  private StrapiSrcRoot;
5
5
  private Options;
6
+ private PrettierOptions;
6
7
  static BaseOptions: {
7
8
  prefix: string;
8
9
  useCategoryPrefix: boolean;
@@ -10,8 +11,10 @@ export default class InterfaceManager {
10
11
  componentPrefixOverridesPrefix: boolean;
11
12
  builtinsPrefix: string;
12
13
  builtinsPrefixOverridesPrefix: boolean;
14
+ prettierFile: any;
13
15
  };
14
16
  constructor(outRoot: string, strapiSrcRoot: string, options?: any);
17
+ loadPrettierConfig(): Promise<void>;
15
18
  createInterfaces(): Promise<void>;
16
19
  createBuiltinInterfaces(): void;
17
20
  injectDependencies(): void;
@@ -47,6 +47,7 @@ var builtinInterfaces_1 = require("./builtinInterfaces");
47
47
  var ComponentInterface_1 = __importDefault(require("./ComponentInterface"));
48
48
  var Interface_1 = __importDefault(require("./Interface"));
49
49
  var schemaReader_1 = require("./schemaReader");
50
+ var prettier_1 = __importDefault(require("prettier"));
50
51
  var InterfaceManager = /** @class */ (function () {
51
52
  function InterfaceManager(outRoot, strapiSrcRoot, options) {
52
53
  if (options === void 0) { options = {}; }
@@ -55,6 +56,28 @@ var InterfaceManager = /** @class */ (function () {
55
56
  this.StrapiSrcRoot = strapiSrcRoot;
56
57
  this.Options = Object.assign({}, InterfaceManager.BaseOptions, options);
57
58
  }
59
+ InterfaceManager.prototype.loadPrettierConfig = function () {
60
+ return __awaiter(this, void 0, void 0, function () {
61
+ var defaultOptions, resolved;
62
+ return __generator(this, function (_a) {
63
+ switch (_a.label) {
64
+ case 0:
65
+ defaultOptions = {
66
+ parser: 'typescript',
67
+ };
68
+ if (!this.Options.prettierFile) {
69
+ this.PrettierOptions = defaultOptions;
70
+ return [2 /*return*/];
71
+ }
72
+ return [4 /*yield*/, prettier_1.default.resolveConfig(this.Options.prettierFile)];
73
+ case 1:
74
+ resolved = _a.sent();
75
+ this.PrettierOptions = Object.assign({}, defaultOptions, resolved);
76
+ return [2 /*return*/];
77
+ }
78
+ });
79
+ });
80
+ };
58
81
  InterfaceManager.prototype.createInterfaces = function () {
59
82
  return __awaiter(this, void 0, void 0, function () {
60
83
  var apiSchemasPromise, componentSchemasPromise, apiSchemas, componentSchemas;
@@ -70,7 +93,7 @@ var InterfaceManager = /** @class */ (function () {
70
93
  apiSchemas.forEach(function (schema) {
71
94
  var name = schema.name, attributes = schema.attributes;
72
95
  var strapiName = "api::".concat(name, ".").concat(name);
73
- var inter = new Interface_1.default(name, attributes, "./", _this.Options.prefix);
96
+ var inter = new Interface_1.default(name, attributes, './', _this.Options.prefix);
74
97
  _this.Interfaces[strapiName] = inter;
75
98
  });
76
99
  return [4 /*yield*/, componentSchemasPromise];
@@ -81,7 +104,7 @@ var InterfaceManager = /** @class */ (function () {
81
104
  category.schemas.forEach(function (schema) {
82
105
  var componentName = schema.name;
83
106
  var strapiName = "".concat(categoryName, ".").concat(schema.name);
84
- var componentPrefix = "".concat(_this.Options.componentPrefix).concat(_this.Options.useCategoryPrefix ? (0, utils_1.pascalCase)(categoryName) : "");
107
+ var componentPrefix = "".concat(_this.Options.componentPrefix).concat(_this.Options.useCategoryPrefix ? (0, utils_1.pascalCase)(categoryName) : '');
85
108
  var prefix = _this.Options.componentPrefixOverridesPrefix ? componentPrefix : _this.Options.prefix + componentPrefix;
86
109
  // TODO: make component interface
87
110
  var inter = new ComponentInterface_1.default(componentName, schema.attributes, "./".concat(categoryName), categoryName, prefix);
@@ -95,7 +118,7 @@ var InterfaceManager = /** @class */ (function () {
95
118
  };
96
119
  InterfaceManager.prototype.createBuiltinInterfaces = function () {
97
120
  var _this = this;
98
- var outDir = "./builtins";
121
+ var outDir = './builtins';
99
122
  var builtinInterfaces = [];
100
123
  builtinInterfaces.push((0, builtinInterfaces_1.createMediaInterface)(outDir, this.Options.prefix));
101
124
  builtinInterfaces.push((0, builtinInterfaces_1.createMediaFormatInterface)(outDir, this.Options.prefix));
@@ -152,9 +175,9 @@ var InterfaceManager = /** @class */ (function () {
152
175
  });
153
176
  }); });
154
177
  promises.push.apply(promises, componentCategoriesPromises);
155
- builtinsPath = (0, path_1.join)(this.OutRoot, "builtins");
178
+ builtinsPath = (0, path_1.join)(this.OutRoot, 'builtins');
156
179
  if (!(0, fs_1.existsSync)(builtinsPath)) {
157
- promises.push((0, promises_1.mkdir)((0, path_1.join)(this.OutRoot, "builtins")));
180
+ promises.push((0, promises_1.mkdir)((0, path_1.join)(this.OutRoot, 'builtins')));
158
181
  }
159
182
  return [4 /*yield*/, Promise.all(promises)];
160
183
  case 4:
@@ -172,14 +195,15 @@ var InterfaceManager = /** @class */ (function () {
172
195
  switch (_a.label) {
173
196
  case 0:
174
197
  writePromises = Object.keys(this.Interfaces).map(function (strapiName) { return __awaiter(_this, void 0, void 0, function () {
175
- var inter, fileData, filePath;
198
+ var inter, fileData, formattedFileData, filePath;
176
199
  return __generator(this, function (_a) {
177
200
  switch (_a.label) {
178
201
  case 0:
179
202
  inter = this.Interfaces[strapiName];
180
203
  fileData = inter.toString();
204
+ formattedFileData = prettier_1.default.format(fileData, this.PrettierOptions);
181
205
  filePath = (0, path_1.join)(this.OutRoot, inter.getRelativeRootPathFile());
182
- return [4 /*yield*/, (0, promises_1.writeFile)(filePath, fileData)];
206
+ return [4 /*yield*/, (0, promises_1.writeFile)(filePath, formattedFileData)];
183
207
  case 1:
184
208
  _a.sent();
185
209
  return [2 /*return*/];
@@ -196,7 +220,7 @@ var InterfaceManager = /** @class */ (function () {
196
220
  };
197
221
  InterfaceManager.prototype.writeIndexFile = function () {
198
222
  return __awaiter(this, void 0, void 0, function () {
199
- var strings, fileData, filePath;
223
+ var strings, fileData, formattedFileData, filePath;
200
224
  var _this = this;
201
225
  return __generator(this, function (_a) {
202
226
  switch (_a.label) {
@@ -205,9 +229,10 @@ var InterfaceManager = /** @class */ (function () {
205
229
  var inter = _this.Interfaces[strapiName];
206
230
  return "export * from '".concat(inter.getRelativeRootPath(), "'");
207
231
  });
208
- fileData = strings.join("\n");
209
- filePath = (0, path_1.join)(this.OutRoot, "index.ts");
210
- return [4 /*yield*/, (0, promises_1.writeFile)(filePath, fileData)];
232
+ fileData = strings.join('\n');
233
+ formattedFileData = prettier_1.default.format(fileData, this.PrettierOptions);
234
+ filePath = (0, path_1.join)(this.OutRoot, 'index.ts');
235
+ return [4 /*yield*/, (0, promises_1.writeFile)(filePath, formattedFileData)];
211
236
  case 1:
212
237
  _a.sent();
213
238
  return [2 /*return*/];
@@ -217,20 +242,21 @@ var InterfaceManager = /** @class */ (function () {
217
242
  };
218
243
  InterfaceManager.prototype.run = function () {
219
244
  return __awaiter(this, void 0, void 0, function () {
220
- var createInterfacesPromise, makeFoldersPromise, err_1;
245
+ var createInterfacesPromise, makeFoldersPromise, loadPrettierPromise, err_1;
221
246
  return __generator(this, function (_a) {
222
247
  switch (_a.label) {
223
248
  case 0:
224
249
  _a.trys.push([0, 4, , 5]);
225
250
  createInterfacesPromise = this.createInterfaces();
226
251
  makeFoldersPromise = this.makeFolders();
252
+ loadPrettierPromise = this.loadPrettierConfig();
227
253
  this.createBuiltinInterfaces();
228
254
  return [4 /*yield*/, createInterfacesPromise];
229
255
  case 1:
230
256
  _a.sent();
231
257
  // Create all interfaces before injecting
232
258
  this.injectDependencies();
233
- return [4 /*yield*/, makeFoldersPromise];
259
+ return [4 /*yield*/, Promise.all([makeFoldersPromise, loadPrettierPromise])];
234
260
  case 2:
235
261
  _a.sent();
236
262
  return [4 /*yield*/, Promise.all([this.writeInterfaces(), this.writeIndexFile()])];
@@ -247,12 +273,13 @@ var InterfaceManager = /** @class */ (function () {
247
273
  });
248
274
  };
249
275
  InterfaceManager.BaseOptions = {
250
- prefix: "I",
276
+ prefix: 'I',
251
277
  useCategoryPrefix: true,
252
- componentPrefix: "",
278
+ componentPrefix: '',
253
279
  componentPrefixOverridesPrefix: false,
254
- builtinsPrefix: "",
255
- builtinsPrefixOverridesPrefix: false // TODO: make this work
280
+ builtinsPrefix: '',
281
+ builtinsPrefixOverridesPrefix: false,
282
+ prettierFile: null,
256
283
  };
257
284
  return InterfaceManager;
258
285
  }());
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
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
+ var commander_1 = require("commander");
7
+ var InterfaceManager_1 = __importDefault(require("./interface/InterfaceManager"));
8
+ commander_1.program
9
+ .name('t4s');
10
+ commander_1.program
11
+ .option('-i, --in <dir>', 'The src directory for strapi', './src')
12
+ .option('-o, --out <dir>', 'The output directory to output the types to', './types')
13
+ .option('--component-prefix <prefix>', 'A prefix for components', '')
14
+ .option('--prettier <file>', 'The prettier config file to use for formatting typescript interfaces');
15
+ commander_1.program.parse();
16
+ var options = commander_1.program.opts();
17
+ console.log(options);
18
+ var input = options.in, out = options.out, componentPrefix = options.componentPrefix, prettierFile = options.prettier;
19
+ var manager = new InterfaceManager_1.default(out, input, {
20
+ componentPrefix: componentPrefix,
21
+ prettierFile: prettierFile,
22
+ });
23
+ manager.run().catch(function (err) {
24
+ console.error(err);
25
+ });
@@ -0,0 +1,11 @@
1
+ import { RelationNames } from './Interface';
2
+ export default class Attributes {
3
+ Attrs: Record<string, Record<string, any>>;
4
+ private RelationNames;
5
+ constructor(attr: Record<string, Record<string, any>>, relationNames: RelationNames);
6
+ isAttributeOptional(attr: any): boolean;
7
+ getDependencies(): any[];
8
+ attributeToString(attrName: string, attr: any): string;
9
+ toFieldsString(): string;
10
+ toString(): string;
11
+ }
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var Attributes = /** @class */ (function () {
4
+ function Attributes(attr, relationNames) {
5
+ this.RelationNames = {};
6
+ this.Attrs = attr;
7
+ this.RelationNames = relationNames;
8
+ }
9
+ Attributes.prototype.isAttributeOptional = function (attr) {
10
+ // If it is a component / relation / dynamiczone it is always optional due to population
11
+ switch (attr.type) {
12
+ case 'nested':
13
+ return attr.nullable === true;
14
+ case 'component':
15
+ case 'dynamiczone':
16
+ case 'relation':
17
+ return true;
18
+ default:
19
+ break;
20
+ }
21
+ return false;
22
+ };
23
+ Attributes.prototype.getDependencies = function () {
24
+ var dependencies = [];
25
+ for (var attrName in this.Attrs) {
26
+ var attr = this.Attrs[attrName];
27
+ var dependencyNames = [];
28
+ switch (attr.type) {
29
+ case 'nested':
30
+ var attrs = new Attributes(attr.fields, this.RelationNames);
31
+ dependencyNames.push.apply(dependencyNames, attrs.getDependencies());
32
+ break;
33
+ case 'relation':
34
+ dependencyNames.push(attr.target);
35
+ break;
36
+ case 'component':
37
+ dependencyNames.push(attr.component);
38
+ break;
39
+ case 'media':
40
+ dependencyNames.push('builtins::Media');
41
+ break;
42
+ default:
43
+ continue;
44
+ }
45
+ // // If the current dependency is the interface itself, do not report it as a dependency
46
+ // if (dependencyName === strapiName) {
47
+ // continue;
48
+ // }
49
+ dependencyNames.forEach(function (dependencyName) {
50
+ if (!dependencies.includes(dependencyName)) {
51
+ dependencies.push(dependencyName);
52
+ }
53
+ });
54
+ }
55
+ return dependencies;
56
+ };
57
+ Attributes.prototype.attributeToString = function (attrName, attr) {
58
+ var _a, _b;
59
+ var optionalString = this.isAttributeOptional(attr) ? '?' : '';
60
+ var str = " ".concat(attrName).concat(optionalString, ": ");
61
+ var isArray = false;
62
+ switch (attr.type) {
63
+ // types-4-strapi-2 specific, used for builtin types
64
+ case 'nested':
65
+ // Be careful with recursion
66
+ // console.log(attr);
67
+ var newAttrs = new Attributes(attr.fields, this.RelationNames);
68
+ str += newAttrs.toString();
69
+ break;
70
+ case 'relation':
71
+ var apiName = attr.target;
72
+ // console.log(this.RelationNames, apiName)
73
+ var dependencyName = this.RelationNames[apiName].name;
74
+ isArray = attr.relation.endsWith('ToMany');
75
+ str += dependencyName;
76
+ break;
77
+ case 'component':
78
+ var componentName = attr.component;
79
+ var relationNameObj = this.RelationNames[componentName];
80
+ var dependencyComponentName = relationNameObj.name;
81
+ isArray = (_a = attr.repeatable) !== null && _a !== void 0 ? _a : false;
82
+ str += dependencyComponentName;
83
+ break;
84
+ case 'media':
85
+ var mediaOptional = attr.required !== true ? '?' : '';
86
+ str += "{ data".concat(mediaOptional, ": ").concat(this.RelationNames['builtins::Media'].name, "; }");
87
+ isArray = (_b = attr.multiple) !== null && _b !== void 0 ? _b : false;
88
+ break;
89
+ case 'password':
90
+ return null;
91
+ case 'enumeration':
92
+ var hasDefault = 'default' in attr;
93
+ var enums = attr.enum.map(function (en) { return "\"".concat(en, "\""); });
94
+ enums.push('null');
95
+ var typeString = enums.join(' | ');
96
+ str += typeString;
97
+ break;
98
+ case 'string':
99
+ case 'text':
100
+ case 'richtext':
101
+ case 'email':
102
+ case 'uid':
103
+ str += 'string';
104
+ break;
105
+ case 'integer':
106
+ case 'biginteger':
107
+ case 'decimal':
108
+ case 'float':
109
+ str += 'number';
110
+ break;
111
+ case 'date':
112
+ case 'datetime':
113
+ case 'time':
114
+ str += 'Date';
115
+ break;
116
+ case 'boolean':
117
+ str += attr.type;
118
+ break;
119
+ case 'json':
120
+ default:
121
+ str += 'any';
122
+ break;
123
+ }
124
+ var isArrayString = isArray ? '[]' : '';
125
+ str += "".concat(isArrayString, ";");
126
+ return str;
127
+ };
128
+ Attributes.prototype.toFieldsString = function () {
129
+ var strings = [];
130
+ for (var attrName in this.Attrs) {
131
+ var attr = this.Attrs[attrName];
132
+ var attrString = this.attributeToString(attrName, attr);
133
+ if (attrString === null) {
134
+ continue;
135
+ }
136
+ strings.push(attrString);
137
+ }
138
+ return strings.map(function (s) { return "".concat(s, "\n"); }).join('');
139
+ };
140
+ Attributes.prototype.toString = function () {
141
+ var strings = ['{'];
142
+ strings.push(this.toFieldsString());
143
+ strings.push('}');
144
+ return strings.join('\n');
145
+ };
146
+ return Attributes;
147
+ }());
148
+ exports.default = Attributes;
@@ -0,0 +1,5 @@
1
+ import ComponentInterface from './ComponentInterface';
2
+ export default class BuiltinComponentInterface extends ComponentInterface {
3
+ constructor(baseName: string, attributes: any, relativeDirectoryPath: string, prefix?: string);
4
+ updateStrapiName(): void;
5
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ var ComponentInterface_1 = __importDefault(require("./ComponentInterface"));
22
+ var BuiltinComponentInterface = /** @class */ (function (_super) {
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, 'builtins', prefix, {
27
+ hasId: false,
28
+ hasComponent: false,
29
+ }) || this;
30
+ }
31
+ BuiltinComponentInterface.prototype.updateStrapiName = function () {
32
+ this.StrapiName = "builtins::".concat(this.BaseName);
33
+ };
34
+ return BuiltinComponentInterface;
35
+ }(ComponentInterface_1.default));
36
+ exports.default = BuiltinComponentInterface;
@@ -0,0 +1,5 @@
1
+ import Interface from './Interface';
2
+ export default class BuiltinInterface extends Interface {
3
+ constructor(baseName: string, attributes: any, relativeDirectoryPath: string, prefix?: string);
4
+ updateStrapiName(): void;
5
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ var Interface_1 = __importDefault(require("./Interface"));
22
+ var BuiltinInterface = /** @class */ (function (_super) {
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;
27
+ }
28
+ BuiltinInterface.prototype.updateStrapiName = function () {
29
+ this.StrapiName = "builtins::".concat(this.BaseName);
30
+ };
31
+ return BuiltinInterface;
32
+ }(Interface_1.default));
33
+ exports.default = BuiltinInterface;
@@ -0,0 +1,8 @@
1
+ import Interface from './Interface';
2
+ export default class ComponentInterface extends Interface {
3
+ protected Category: string;
4
+ protected Options: Record<string, any>;
5
+ constructor(baseName: string, attributes: any, relativeDirectoryPath: string, category: string, prefix?: string, options?: Record<string, any>);
6
+ updateStrapiName(): void;
7
+ getInterfaceFieldsString(): string;
8
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ var Interface_1 = __importDefault(require("./Interface"));
22
+ var ComponentInterface = /** @class */ (function (_super) {
23
+ __extends(ComponentInterface, _super);
24
+ function ComponentInterface(baseName, attributes, relativeDirectoryPath, category, prefix, options) {
25
+ if (prefix === void 0) { prefix = ''; }
26
+ if (options === void 0) { options = {}; }
27
+ var _this = _super.call(this, baseName, attributes, relativeDirectoryPath, prefix) || this;
28
+ _this.Options = {
29
+ hasId: true,
30
+ hasComponent: true,
31
+ };
32
+ _this.Category = category;
33
+ // this.Attributes.id = {
34
+ // type: "number", // Components have a id field with a number
35
+ // required: true,
36
+ // };
37
+ _this.updateStrapiName();
38
+ Object.assign(_this.Options, options);
39
+ return _this;
40
+ }
41
+ ComponentInterface.prototype.updateStrapiName = function () {
42
+ this.StrapiName = "".concat(this.Category, ".").concat(this.getBaseName());
43
+ };
44
+ ComponentInterface.prototype.getInterfaceFieldsString = function () {
45
+ var attrs = this.getAttributes();
46
+ var str = '';
47
+ var _a = this.Options, hasId = _a.hasId, hasComponent = _a.hasComponent;
48
+ if (hasId) {
49
+ str += ' id: number;\n';
50
+ }
51
+ if (hasComponent) {
52
+ str += " __component: \"".concat(this.getStrapiName(), "\";\n");
53
+ }
54
+ return str + attrs.toFieldsString();
55
+ };
56
+ return ComponentInterface;
57
+ }(Interface_1.default));
58
+ exports.default = ComponentInterface;