@strapi/typescript-utils 5.0.0-beta.1 → 5.0.0-beta.10

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.
@@ -149,6 +149,72 @@ describe('Attributes', () => {
149
149
  expect(addImport).toHaveBeenCalledWith('Schema');
150
150
  };
151
151
 
152
+ describe('Media', () => {
153
+ test('Media with multiple and with no allowedTypes', () => {
154
+ const attribute = { type: 'media', multiple: true };
155
+ const typeNode = getAttributeType('foo', attribute);
156
+
157
+ defaultAssertions(typeNode, 'Schema.Attribute.Media');
158
+
159
+ expect(typeNode.typeArguments).toHaveLength(2);
160
+
161
+ expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.UndefinedKeyword);
162
+
163
+ expect(typeNode.typeArguments[1].kind).toBe(ts.SyntaxKind.TrueKeyword);
164
+ });
165
+
166
+ test('Media without multiple with allowedTypes', () => {
167
+ const attribute = { type: 'media', allowedTypes: ['images', 'videos'] };
168
+ const typeNode = getAttributeType('foo', attribute);
169
+
170
+ defaultAssertions(typeNode, 'Schema.Attribute.Media');
171
+
172
+ expect(typeNode.typeArguments).toHaveLength(1);
173
+
174
+ expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.UnionType);
175
+
176
+ const unionTypes = typeNode.typeArguments[0].types;
177
+
178
+ attribute.allowedTypes.forEach((value, index) => {
179
+ const element = unionTypes[index];
180
+
181
+ expect(element.kind).toBe(ts.SyntaxKind.StringLiteral);
182
+ expect(element.text).toBe(value);
183
+ });
184
+ });
185
+
186
+ test('Media with multiple and with allowedTypes', () => {
187
+ const attribute = { type: 'media', multiple: true, allowedTypes: ['images', 'videos'] };
188
+ const typeNode = getAttributeType('foo', attribute);
189
+
190
+ defaultAssertions(typeNode, 'Schema.Attribute.Media');
191
+
192
+ expect(typeNode.typeArguments).toHaveLength(2);
193
+
194
+ expect(typeNode.typeArguments[0].kind).toBe(ts.SyntaxKind.UnionType);
195
+
196
+ const unionTypes = typeNode.typeArguments[0].types;
197
+
198
+ attribute.allowedTypes.forEach((value, index) => {
199
+ const element = unionTypes[index];
200
+
201
+ expect(element.kind).toBe(ts.SyntaxKind.StringLiteral);
202
+ expect(element.text).toBe(value);
203
+ });
204
+
205
+ expect(typeNode.typeArguments[1].kind).toBe(ts.SyntaxKind.TrueKeyword);
206
+ });
207
+
208
+ test('Media without multiple and with no allowedTypes', () => {
209
+ const attribute = { type: 'media' };
210
+ const typeNode = getAttributeType('foo', attribute);
211
+
212
+ defaultAssertions(typeNode, 'Schema.Attribute.Media');
213
+
214
+ expect(typeNode.typeArguments).toBeUndefined();
215
+ });
216
+ });
217
+
152
218
  describe('Enumeration', () => {
153
219
  test('Enumeration with an enum property', () => {
154
220
  const attribute = { type: 'enumeration', enum: ['a', 'b', 'c'] };
@@ -87,8 +87,26 @@ module.exports = {
87
87
  blocks() {
88
88
  return [withAttributeNamespace('Blocks')];
89
89
  },
90
- media() {
91
- return [withAttributeNamespace('Media')];
90
+ media({ attribute }) {
91
+ const { allowedTypes, multiple } = attribute;
92
+
93
+ const params = [];
94
+
95
+ const typesParam = allowedTypes
96
+ ? factory.createUnionTypeNode(
97
+ allowedTypes.map((allowedType) => factory.createStringLiteral(allowedType))
98
+ )
99
+ : factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword);
100
+
101
+ if (allowedTypes || multiple) {
102
+ params.push(typesParam);
103
+ }
104
+
105
+ if (multiple) {
106
+ params.push(factory.createTrue());
107
+ }
108
+
109
+ return [withAttributeNamespace('Media'), params];
92
110
  },
93
111
  relation({ attribute }) {
94
112
  const { relation, target } = attribute;
@@ -3,7 +3,6 @@
3
3
  const path = require('path');
4
4
  const assert = require('assert');
5
5
  const ts = require('typescript');
6
- const prettier = require('prettier');
7
6
  const fse = require('fs-extra');
8
7
  const chalk = require('chalk');
9
8
 
@@ -61,6 +60,9 @@ const saveDefinitionToFileSystem = async (dir, file, content) => {
61
60
  * @returns {Promise<string>}
62
61
  */
63
62
  const format = async (content) => {
63
+ // eslint-disable-next-line node/no-unsupported-features/es-syntax
64
+ const prettier = await import('prettier'); // ESM-only
65
+
64
66
  const configFile = await prettier.resolveConfigFile();
65
67
  const config = configFile
66
68
  ? await prettier.resolveConfig(configFile)
package/lib/index.js CHANGED
@@ -2,15 +2,12 @@
2
2
 
3
3
  const compile = require('./compile');
4
4
  const compilers = require('./compilers');
5
- const admin = require('./admin');
6
5
  const utils = require('./utils');
7
6
  const generators = require('./generators');
8
7
 
9
8
  module.exports = {
10
9
  compile,
11
10
  compilers,
12
- admin,
13
11
  generators,
14
-
15
12
  ...utils,
16
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/typescript-utils",
3
- "version": "5.0.0-beta.1",
3
+ "version": "5.0.0-beta.10",
4
4
  "description": "Typescript support for Strapi",
5
5
  "keywords": [
6
6
  "strapi",
@@ -37,14 +37,17 @@
37
37
  "dependencies": {
38
38
  "chalk": "4.1.2",
39
39
  "cli-table3": "0.6.2",
40
- "fs-extra": "10.1.0",
40
+ "fs-extra": "11.2.0",
41
41
  "lodash": "4.17.21",
42
- "prettier": "2.8.4",
42
+ "prettier": "3.2.5",
43
43
  "typescript": "5.3.2"
44
44
  },
45
+ "devDependencies": {
46
+ "@types/fs-extra": "11.0.4"
47
+ },
45
48
  "engines": {
46
49
  "node": ">=18.0.0 <=20.x.x",
47
50
  "npm": ">=6.0.0"
48
51
  },
49
- "gitHead": "ae773621dfcbc67c49dc6fa52ac41ea5de676ecb"
52
+ "gitHead": "d4542f0dccfa2eecb55026dbd795042e7d0004ba"
50
53
  }
@@ -11,6 +11,7 @@
11
11
  "skipLibCheck": true,
12
12
  "forceConsistentCasingInFileNames": true,
13
13
 
14
+ "tsBuildInfoFile": "./.tsbuildinfo",
14
15
  "incremental": true,
15
16
  "esModuleInterop": true,
16
17
  "resolveJsonModule": true,
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const fs = require('fs-extra');
5
- const adminTsConfig = require('../../tsconfigs/admin.json');
6
-
7
- module.exports = async (dest) => {
8
- const tsConfig = {
9
- ...adminTsConfig,
10
- include: ['../../../src/admin/*', '../../../src/**/**/admin/src/*'],
11
- exclude: ['node_modules', '**/*.test.js', '*.js'],
12
- };
13
-
14
- const filePath = path.join(dest, 'admin', 'src', 'tsconfig.json');
15
-
16
- try {
17
- await fs.ensureFile(filePath);
18
-
19
- await fs.writeJSON(filePath, tsConfig, { spaces: 2 });
20
- } catch (err) {
21
- console.log(err);
22
- }
23
- };
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- const createTSConfigFile = require('./create-tsconfig-file');
4
-
5
- module.exports = { createTSConfigFile };
@@ -1,19 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "compilerOptions": {
4
- "target": "ESNext",
5
- "module": "ESNext",
6
- "moduleResolution": "Bundler",
7
- "useDefineForClassFields": true,
8
- "lib": ["DOM", "DOM.Iterable", "ESNext"],
9
- "allowJs": false,
10
- "skipLibCheck": true,
11
- "esModuleInterop": true,
12
- "allowSyntheticDefaultImports": true,
13
- "strict": true,
14
- "forceConsistentCasingInFileNames": true,
15
- "resolveJsonModule": true,
16
- "noEmit": true,
17
- "jsx": "react-jsx"
18
- }
19
- }