@oak-digital/types-4-strapi-2 0.2.7 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,16 +1,19 @@
1
1
  # types-4-strapi-2
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.
3
+ types-4-strapi-2 is a TypeScript program that will generate TypeScript types for your strapi projects.
4
+ This can be useful if you have a frontend written with TypeScript to make sure you are using the correct types and can help report errors at compile time.
5
5
 
6
- types-4-strapi-2 is a rewrite of (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.
6
+ types-4-strapi-2 is a rewrite of [francescolorenzetti/types-4-strapi](https://github.com/francescolorenzetti/types-4-strapi) written in TypeScript, with the goal of being much easier to extend and maintain.
7
7
 
8
8
  ## Getting started
9
9
 
10
10
  Install the script for your project:
11
11
 
12
12
  ```bash
13
+ # NPM
13
14
  npm install --save-dev @oak-digital/types-4-strapi-2
15
+ # YARN
16
+ yarn add -D @oak-digital/types-4-strapi-2
14
17
  ```
15
18
 
16
19
  Then set up a script in your `package.json`
@@ -38,8 +41,8 @@ This can be done with the `--out` flag like in the following example.
38
41
 
39
42
  ## Features
40
43
 
41
- * Generate typescript interfaces for all your api content-types and components
42
- * Generate typescript interfaces for builtin types such as `Media` and `MediaFormat`
44
+ * Generate TypeScript interfaces for all your api content-types and components
45
+ * Generate TypeScript interfaces for builtin types such as `Media` and `MediaFormat`
43
46
  * Select input and output directory
44
47
  * Prettier formatting and ability to use your own `.prettierrc`.
45
48
 
@@ -50,13 +53,14 @@ This can be done with the `--out` flag like in the following example.
50
53
 
51
54
  ## Flags
52
55
 
53
- | **flag** | **Description** |
54
- |-----------------------------|------------------------------------------------------------------------------------|
55
- | -i, --in <dir> | The src directory for strapi |
56
- | -o, --out <dir> | The output directory to output the types to |
57
- | --component-prefix <prefix> | A prefix for components |
58
- | -D, --delete-old | CAUTION: This option is equivalent to running rm -rf on the output directory first |
59
- | --prettier <file> | The prettier config file to use for formatting typescript interfaces |
56
+ | **Flag** | **Description** | **Default** |
57
+ |-----------------------------|--------------------------------------------------------------------------------------|-------------|
58
+ | -i, --in <dir> | The src directory for strapi | `./src` |
59
+ | -o, --out <dir> | The output directory to output the types to | `./types` |
60
+ | -prefix | A prefix for all generated interfaces | `I` |
61
+ | --component-prefix <prefix> | A prefix for components | none |
62
+ | -D, --delete-old | CAUTION: This option is equivalent to running `rm -rf` on the output directory first | `false` |
63
+ | --prettier <file> | The prettier config file to use for formatting TypeScript interfaces | none |
60
64
 
61
65
  ## Building
62
66
 
@@ -66,7 +70,7 @@ To build this project, use the following command
66
70
  npm run build
67
71
  ```
68
72
 
69
- ## Publihsing
73
+ ## Publishing
70
74
 
71
75
  ```bash
72
76
  npm run build
package/lib/index.js CHANGED
@@ -10,6 +10,7 @@ commander_1.program
10
10
  commander_1.program
11
11
  .option('-i, --in <dir>', 'The src directory for strapi', './src')
12
12
  .option('-o, --out <dir>', 'The output directory to output the types to', './types')
13
+ .option('--prefix <prefix>', 'A prefix for all generated interfaces', 'I')
13
14
  .option('--component-prefix <prefix>', 'A prefix for components', '')
14
15
  .option('-D, --delete-old', 'CAUTION: This option is equivalent to running rm -rf on the output directory first')
15
16
  .option('--file-case <case>', 'Which case to use for generated files', 'pascal')
@@ -17,9 +18,10 @@ commander_1.program
17
18
  .option('--prettier <file>', 'The prettier config file to use for formatting typescript interfaces');
18
19
  commander_1.program.parse();
19
20
  var options = commander_1.program.opts();
20
- var input = options.in, out = options.out, componentPrefix = options.componentPrefix, prettierFile = options.prettier, deleteOld = options.deleteOld, fileCaseType = options.fileCase, folderCaseType = options.folderCase;
21
+ var input = options.in, out = options.out, componentPrefix = options.componentPrefix, prefix = options.prefix, prettierFile = options.prettier, deleteOld = options.deleteOld, fileCaseType = options.fileCase, folderCaseType = options.folderCase;
21
22
  var manager = new InterfaceManager_1.default(out, input, {
22
23
  componentPrefix: componentPrefix,
24
+ prefix: prefix,
23
25
  prettierFile: prettierFile,
24
26
  deleteOld: deleteOld,
25
27
  fileCaseType: fileCaseType,
@@ -55,7 +55,7 @@ var Attributes = /** @class */ (function () {
55
55
  return dependencies;
56
56
  };
57
57
  Attributes.prototype.attributeToString = function (attrName, attr) {
58
- var _a;
58
+ var _a, _b, _c, _d;
59
59
  var optionalString = this.isAttributeOptional(attr) ? '?' : '';
60
60
  var str = " ".concat(attrName).concat(optionalString, ": ");
61
61
  var isArray = false;
@@ -64,13 +64,14 @@ var Attributes = /** @class */ (function () {
64
64
  case 'nested':
65
65
  // Be careful with recursion
66
66
  // console.log(attr);
67
+ var nullableString = ((_a = attr === null || attr === void 0 ? void 0 : attr.nullable) !== null && _a !== void 0 ? _a : false) ? ' | null' : '';
67
68
  var newAttrs = new Attributes(attr.fields, this.RelationNames);
68
- str += newAttrs.toString();
69
+ str += newAttrs.toString() + nullableString;
69
70
  break;
70
71
  case 'relation':
71
72
  var apiName = attr.target;
72
73
  // console.log(this.RelationNames, apiName)
73
- var dependencyName = this.RelationNames[apiName].name;
74
+ var dependencyName = (_c = (_b = this.RelationNames[apiName]) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : 'any';
74
75
  var relationMultipleString = attr.relation.endsWith('ToMany') ? '[]' : ' | null';
75
76
  str += "{ data: ".concat(dependencyName).concat(relationMultipleString, "; }");
76
77
  break;
@@ -78,7 +79,7 @@ var Attributes = /** @class */ (function () {
78
79
  var componentName = attr.component;
79
80
  var relationNameObj = this.RelationNames[componentName];
80
81
  var dependencyComponentName = relationNameObj.name;
81
- isArray = (_a = attr.repeatable) !== null && _a !== void 0 ? _a : false;
82
+ isArray = (_d = attr.repeatable) !== null && _d !== void 0 ? _d : false;
82
83
  str += dependencyComponentName;
83
84
  break;
84
85
  case 'media':
@@ -32,8 +32,10 @@ function createMediaInterface(directory, caseTypeName, prefix) {
32
32
  formats: {
33
33
  // types-4-strapi-2 specific
34
34
  type: 'nested',
35
+ nullable: true,
35
36
  fields: {
36
37
  thumbnail: mediaFormat,
38
+ large: mediaFormat,
37
39
  medium: mediaFormat,
38
40
  small: mediaFormat,
39
41
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oak-digital/types-4-strapi-2",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "Typescript interface generator for Strapi 4 models",
5
5
  "bin": {
6
6
  "t4s": "./bin/index.js"