@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.
Files changed (34) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintrc.json +52 -0
  3. package/.prettierrc.json +7 -0
  4. package/README.md +67 -0
  5. package/lib/.prettierrc.json +7 -0
  6. package/lib/index.js +9 -4
  7. package/lib/interface/Attributes.js +4 -1
  8. package/lib/interface/Interface.d.ts +1 -1
  9. package/lib/interface/Interface.js +13 -15
  10. package/lib/interface/InterfaceManager.d.ts +3 -0
  11. package/lib/interface/InterfaceManager.js +47 -20
  12. package/lib/interface/builtinInterfaces.js +7 -0
  13. package/lib/interface/schemaReader.js +15 -11
  14. package/lib/src/index.d.ts +1 -0
  15. package/lib/src/index.js +25 -0
  16. package/lib/src/interface/Attributes.d.ts +11 -0
  17. package/lib/src/interface/Attributes.js +148 -0
  18. package/lib/src/interface/BuiltinComponentInterface.d.ts +5 -0
  19. package/lib/src/interface/BuiltinComponentInterface.js +36 -0
  20. package/lib/src/interface/BuiltinInterface.d.ts +5 -0
  21. package/lib/src/interface/BuiltinInterface.js +33 -0
  22. package/lib/src/interface/ComponentInterface.d.ts +8 -0
  23. package/lib/src/interface/ComponentInterface.js +58 -0
  24. package/lib/src/interface/Interface.d.ts +31 -0
  25. package/lib/src/interface/Interface.js +112 -0
  26. package/lib/src/interface/InterfaceManager.d.ts +25 -0
  27. package/lib/src/interface/InterfaceManager.js +288 -0
  28. package/lib/src/interface/builtinInterfaces.d.ts +4 -0
  29. package/lib/src/interface/builtinInterfaces.js +81 -0
  30. package/lib/src/interface/schemaReader.d.ts +14 -0
  31. package/lib/src/interface/schemaReader.js +172 -0
  32. package/lib/src/utils/index.d.ts +3 -0
  33. package/lib/src/utils/index.js +67 -0
  34. package/package.json +8 -2
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 ADDED
@@ -0,0 +1,67 @@
1
+ # types-4-strapi-2
2
+
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
+
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
+
8
+ ## Getting started
9
+
10
+ Install the script for your project:
11
+
12
+ ```bash
13
+ npm install --save-dev @oak-digital/types-4-strapi-2
14
+ ```
15
+
16
+ Then set up a script in your `package.json`
17
+
18
+ ```jsonc
19
+ // package.json
20
+ {
21
+ "scripts": {
22
+ "types": "t4s"
23
+ }
24
+ }
25
+ ```
26
+
27
+ In some cases it is desirable to change the output directory which is `./types` by default.
28
+ This can be done with the `--out` flag like in the following example.
29
+
30
+ ```jsonc
31
+ // package.json
32
+ {
33
+ "scripts": {
34
+ "types": "t4s --out ../frontend/src/lib/types"
35
+ }
36
+ }
37
+ ```
38
+
39
+ ## Features
40
+
41
+ * Generate typescript interfaces for all your api content-types and components
42
+ * Generate typescript interfaces for builtin types such as `Media` and `MediaFormat`
43
+ * Select input and output directory
44
+ * Prettier formatting and ability to use your own `.prettierrc`.
45
+
46
+ ### Planned features
47
+
48
+ * Support if you are using other plugins, such as `url-alias`, which should add extra fields for some interfaces.
49
+
50
+ ## Help
51
+
52
+ use `t4s --help` to display which options are available for you
53
+
54
+ ## Building
55
+
56
+ To build this project, use the following command
57
+
58
+ ```bash
59
+ npm run build
60
+ ```
61
+
62
+ ## Publihsing
63
+
64
+ ```bash
65
+ npm run build
66
+ npm publish
67
+ ```
@@ -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,14 +6,19 @@ 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
- .option('-o, --out <dir>', 'The output directory to output the types to', './types');
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');
13
15
  commander_1.program.parse();
14
16
  var options = commander_1.program.opts();
15
- var input = options.in, out = options.out;
16
- var manager = new InterfaceManager_1.default(out, input);
17
+ var input = options.in, out = options.out, componentPrefix = options.componentPrefix, prettierFile = options.prettier;
18
+ var manager = new InterfaceManager_1.default(out, input, {
19
+ componentPrefix: componentPrefix,
20
+ prettierFile: prettierFile,
21
+ });
17
22
  manager.run().catch(function (err) {
18
23
  console.error(err);
19
24
  });
@@ -9,6 +9,8 @@ var Attributes = /** @class */ (function () {
9
9
  Attributes.prototype.isAttributeOptional = function (attr) {
10
10
  // If it is a component / relation / dynamiczone it is always optional due to population
11
11
  switch (attr.type) {
12
+ case "nested":
13
+ return attr.nullable === true;
12
14
  case "component":
13
15
  case "dynamiczone":
14
16
  case "relation":
@@ -80,7 +82,8 @@ var Attributes = /** @class */ (function () {
80
82
  str += dependencyComponentName;
81
83
  break;
82
84
  case "media":
83
- str += this.RelationNames["builtins::Media"].name;
85
+ var mediaOptional = attr.required !== true ? "?" : "";
86
+ str += "{ data".concat(mediaOptional, ": ").concat(this.RelationNames["builtins::Media"].name, "; }");
84
87
  isArray = (_b = attr.multiple) !== null && _b !== void 0 ? _b : false;
85
88
  break;
86
89
  case "password":
@@ -1,4 +1,4 @@
1
- import Attributes from "./Attributes";
1
+ import Attributes from './Attributes';
2
2
  export declare type RelationNames = Record<string, {
3
3
  name: string;
4
4
  inter: Interface;
@@ -3,16 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var path_1 = require("path");
6
+ var posix_1 = require("path/posix");
7
7
  var utils_1 = require("../utils");
8
8
  var Attributes_1 = __importDefault(require("./Attributes"));
9
9
  var Interface = /** @class */ (function () {
10
10
  function Interface(baseName, attributes, relativeDirectoryPath, prefix) {
11
- if (prefix === void 0) { prefix = ""; }
11
+ if (prefix === void 0) { prefix = ''; }
12
12
  this.Relations = []; // Components and relations
13
13
  this.RelationNames = {};
14
14
  this.RelationNamesCounter = {};
15
- this.NamePrefix = "";
15
+ this.NamePrefix = '';
16
16
  this.BaseName = baseName;
17
17
  this.updateStrapiName();
18
18
  this.NamePrefix = prefix;
@@ -38,11 +38,11 @@ var Interface = /** @class */ (function () {
38
38
  };
39
39
  // For typescript import from index file
40
40
  Interface.prototype.getRelativeRootPath = function () {
41
- var path = (0, path_1.join)(this.RelativeDirectoryPath, this.getBaseName());
41
+ var path = (0, posix_1.join)(this.RelativeDirectoryPath, this.getBaseName());
42
42
  return (0, utils_1.prefixDotSlash)(path);
43
43
  };
44
44
  Interface.prototype.getRelativeRootDir = function () {
45
- var path = (0, path_1.dirname)(this.getRelativeRootPathFile());
45
+ var path = (0, posix_1.dirname)(this.getRelativeRootPathFile());
46
46
  return path;
47
47
  };
48
48
  Interface.prototype.getRelativeRootPathFile = function () {
@@ -55,9 +55,7 @@ var Interface = /** @class */ (function () {
55
55
  this.Relations.forEach(function (inter) {
56
56
  var name = inter.getFullInterfaceName();
57
57
  // FIXME: clean up this mess...
58
- if (inter.getStrapiName() === _this.getStrapiName()) {
59
- }
60
- else {
58
+ if (inter.getStrapiName() !== _this.getStrapiName()) {
61
59
  // Avoid duplicate names
62
60
  if (name in _this.RelationNamesCounter) {
63
61
  name += ++_this.RelationNamesCounter[name];
@@ -73,15 +71,15 @@ var Interface = /** @class */ (function () {
73
71
  var _this = this;
74
72
  return Object.keys(this.RelationNames).map(function (strapiName) {
75
73
  if (strapiName === _this.getStrapiName()) {
76
- return "";
74
+ return '';
77
75
  }
78
76
  var relationName = _this.RelationNames[strapiName].name;
79
77
  var inter = _this.RelationNames[strapiName].inter;
80
- var importPath = (0, utils_1.prefixDotSlash)((0, path_1.relative)(_this.getRelativeRootDir(), inter.getRelativeRootPath()));
78
+ var importPath = (0, utils_1.prefixDotSlash)((0, posix_1.relative)(_this.getRelativeRootDir(), inter.getRelativeRootPath()));
81
79
  var fullName = inter.getFullInterfaceName();
82
80
  var importNameString = fullName === relationName ? fullName : "".concat(fullName, " as ").concat(relationName);
83
81
  return "import { ".concat(importNameString, " } from '").concat(importPath, "';");
84
- }).filter(function (s) { return s; }).join("\n");
82
+ }).filter(function (s) { return s; }).join('\n');
85
83
  };
86
84
  Interface.prototype.getAttributes = function () {
87
85
  return new Attributes_1.default(this.Attributes, this.RelationNames);
@@ -93,13 +91,13 @@ var Interface = /** @class */ (function () {
93
91
  Interface.prototype.getInerfaceString = function () {
94
92
  var str = "export interface ".concat(this.getFullInterfaceName(), " {\n");
95
93
  str += this.getInterfaceFieldsString();
96
- str += "}";
94
+ str += '}';
97
95
  return str;
98
96
  };
99
97
  Interface.prototype.getInterfaceFieldsString = function () {
100
98
  var str = '';
101
- str += " id: number;\n";
102
- str += " attributes: ".concat(this.attributesToString(), "\n");
99
+ str += 'id: number;\n';
100
+ str += "attributes: ".concat(this.attributesToString(), "\n");
103
101
  return str;
104
102
  };
105
103
  Interface.prototype.toString = function () {
@@ -107,7 +105,7 @@ var Interface = /** @class */ (function () {
107
105
  this.getTsImports(),
108
106
  this.getInerfaceString()
109
107
  ];
110
- return strings.join("\n");
108
+ return strings.join('\n');
111
109
  };
112
110
  return Interface;
113
111
  }());
@@ -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;
@@ -41,12 +41,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  var fs_1 = require("fs");
43
43
  var promises_1 = require("fs/promises");
44
- var path_1 = require("path");
44
+ var posix_1 = require("path/posix");
45
45
  var utils_1 = require("../utils");
46
46
  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));
@@ -140,7 +163,7 @@ var InterfaceManager = /** @class */ (function () {
140
163
  return __generator(this, function (_a) {
141
164
  switch (_a.label) {
142
165
  case 0:
143
- path = (0, path_1.join)(this.OutRoot, category);
166
+ path = (0, posix_1.join)(this.OutRoot, category);
144
167
  if ((0, fs_1.existsSync)(path)) {
145
168
  return [2 /*return*/];
146
169
  }
@@ -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, posix_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, posix_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();
181
- filePath = (0, path_1.join)(this.OutRoot, inter.getRelativeRootPathFile());
182
- return [4 /*yield*/, (0, promises_1.writeFile)(filePath, fileData)];
204
+ formattedFileData = prettier_1.default.format(fileData, this.PrettierOptions);
205
+ filePath = (0, posix_1.join)(this.OutRoot, inter.getRelativeRootPathFile());
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, posix_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
  }());
@@ -41,6 +41,13 @@ function createMediaInterface(directory, prefix) {
41
41
  };
42
42
  stringFields.forEach(function (s) { return mediaAttrs[s] = { type: "string" }; });
43
43
  numberFields.forEach(function (s) { return mediaAttrs[s] = { type: "integer" }; });
44
+ // const dataAttrs = {
45
+ // data: {
46
+ // type: "nested",
47
+ // fields: mediaAttrs,
48
+ // nullable: true,
49
+ // },
50
+ // };
44
51
  return new BuiltinInterface_1.default("Media", mediaAttrs, directory, prefix);
45
52
  }
46
53
  exports.createMediaInterface = createMediaInterface;
@@ -38,7 +38,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.getApiSchemas = exports.getComponentSchemas = exports.getComponentCategoryFolders = exports.getApiFolders = exports.readSchema = void 0;
40
40
  var promises_1 = require("node:fs/promises");
41
- var node_path_1 = require("node:path");
41
+ var posix_1 = require("node:path/posix");
42
42
  var utils_1 = require("../utils");
43
43
  function readSchema(schemaPath) {
44
44
  return __awaiter(this, void 0, void 0, function () {
@@ -62,13 +62,15 @@ function readSchema(schemaPath) {
62
62
  exports.readSchema = readSchema;
63
63
  function getApiFolders(strapiSrcRoot) {
64
64
  return __awaiter(this, void 0, void 0, function () {
65
- var path;
65
+ var path, folders;
66
66
  return __generator(this, function (_a) {
67
67
  switch (_a.label) {
68
68
  case 0:
69
- path = (0, node_path_1.join)(strapiSrcRoot, 'api');
69
+ path = (0, posix_1.join)(strapiSrcRoot, 'api');
70
70
  return [4 /*yield*/, (0, utils_1.readDirFiltered)(path)];
71
- case 1: return [2 /*return*/, _a.sent()];
71
+ case 1:
72
+ folders = _a.sent();
73
+ return [2 /*return*/, folders];
72
74
  }
73
75
  });
74
76
  });
@@ -76,13 +78,15 @@ function getApiFolders(strapiSrcRoot) {
76
78
  exports.getApiFolders = getApiFolders;
77
79
  function getComponentCategoryFolders(strapiSrcRoot) {
78
80
  return __awaiter(this, void 0, void 0, function () {
79
- var path;
81
+ var path, folders;
80
82
  return __generator(this, function (_a) {
81
83
  switch (_a.label) {
82
84
  case 0:
83
- path = (0, node_path_1.join)(strapiSrcRoot, "components");
85
+ path = (0, posix_1.join)(strapiSrcRoot, 'components');
84
86
  return [4 /*yield*/, (0, utils_1.readDirFiltered)(path)];
85
- case 1: return [2 /*return*/, _a.sent()];
87
+ case 1:
88
+ folders = _a.sent();
89
+ return [2 /*return*/, folders];
86
90
  }
87
91
  });
88
92
  });
@@ -103,7 +107,7 @@ function getComponentSchemas(strapiSrcRoot) {
103
107
  return __generator(this, function (_a) {
104
108
  switch (_a.label) {
105
109
  case 0:
106
- schemaFilesPath = (0, node_path_1.join)(strapiSrcRoot, "components", category);
110
+ schemaFilesPath = (0, posix_1.join)(strapiSrcRoot, 'components', category);
107
111
  return [4 /*yield*/, (0, utils_1.readDirFiltered)(schemaFilesPath)];
108
112
  case 1:
109
113
  schemaFiles = _a.sent();
@@ -112,11 +116,11 @@ function getComponentSchemas(strapiSrcRoot) {
112
116
  return __generator(this, function (_a) {
113
117
  switch (_a.label) {
114
118
  case 0:
115
- schemaPath = (0, node_path_1.join)(schemaFilesPath, file);
119
+ schemaPath = (0, posix_1.join)(schemaFilesPath, file);
116
120
  return [4 /*yield*/, readSchema(schemaPath)];
117
121
  case 1:
118
122
  attributes = _a.sent();
119
- name = file.split(".")[0];
123
+ name = file.split('.')[0];
120
124
  return [2 /*return*/, { name: name, attributes: attributes }];
121
125
  }
122
126
  });
@@ -151,7 +155,7 @@ function getApiSchemas(strapiSrcRoot) {
151
155
  return __generator(this, function (_a) {
152
156
  switch (_a.label) {
153
157
  case 0:
154
- schemaPath = (0, node_path_1.join)(strapiSrcRoot, "api", folder, "content-types", folder, "schema.json");
158
+ schemaPath = (0, posix_1.join)(strapiSrcRoot, 'api', folder, 'content-types', folder, 'schema.json');
155
159
  return [4 /*yield*/, readSchema(schemaPath)];
156
160
  case 1:
157
161
  attributes = _a.sent();
@@ -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
+ }