Skip to content

Commit cc55943

Browse files
authored
Add behavior and object headers to the registry (#930)
1 parent 960700b commit cc55943

File tree

5 files changed

+146
-13
lines changed

5 files changed

+146
-13
lines changed

extensions/views.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"default": {
3-
"firstExtensionIds": ["Health", "FireBullet", "Gamepads"]
3+
"firstExtensionIds": ["Health", "FireBullet", "Gamepads"],
4+
"firstBehaviorIds": [
5+
{ "extensionName": "Health", "behaviorName": "Health" },
6+
{ "extensionName": "FireBullet", "behaviorName": "FireBullet" }
7+
]
48
}
59
}

scripts/generate-extensions-registry.js

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const {
88
const args = require('minimist')(process.argv.slice(2));
99

1010
/** @typedef {import('./types').ExtensionShortHeader} ExtensionShortHeader */
11+
/** @typedef {import('./types').BehaviorShortHeader} BehaviorShortHeader */
12+
/** @typedef {import('./types').ObjectShortHeader} ObjectShortHeader */
13+
/** @typedef {import('./types').RegistryItem} RegistryItem */
1114
/** @typedef {import('./types').ExtensionsDatabase} ExtensionsDatabase */
1215
/** @typedef {import('./types').ExtensionHeader} ExtensionHeader */
1316
/** @typedef {import('./types').ExtensionWithFileInfo} ExtensionWithFileInfo */
@@ -99,6 +102,10 @@ const readExtensionsFromFolder = async (folderPath, tier) => {
99102

100103
/** @type {ExtensionShortHeader[]} */
101104
const extensionShortHeaders = [];
105+
/** @type {Array<BehaviorShortHeader>} */
106+
const behaviorShortHeaders = [];
107+
/** @type {Array<ObjectShortHeader>} */
108+
const objectShortHeaders = [];
102109

103110
let totalErrors = 0;
104111
let fixableErrors = 0;
@@ -159,11 +166,10 @@ const readExtensionsFromFolder = async (folderPath, tier) => {
159166
}
160167

161168
// Generate the headers of the extension
162-
/** @type {ExtensionShortHeader} */
163-
const extensionShortHeader = {
169+
/** @type {RegistryItem} */
170+
const registryItem = {
164171
tier,
165172
authorIds: extension.authorIds,
166-
shortDescription: extension.shortDescription,
167173
extensionNamespace: extension.extensionNamespace,
168174
fullName: extension.fullName,
169175
name,
@@ -174,6 +180,13 @@ const readExtensionsFromFolder = async (folderPath, tier) => {
174180
tags: extension.tags,
175181
category: extension.category || 'General',
176182
previewIconUrl: extension.previewIconUrl,
183+
};
184+
/** @type {ExtensionShortHeader} */
185+
const extensionShortHeader = {
186+
...registryItem,
187+
shortDescription: extension.shortDescription,
188+
fullName: extension.fullName,
189+
name,
177190
eventsBasedBehaviorsCount: extension.eventsBasedBehaviors.length,
178191
eventsFunctionsCount: extension.eventsFunctions.length,
179192
};
@@ -190,7 +203,40 @@ const readExtensionsFromFolder = async (folderPath, tier) => {
190203
iconUrl: extension.iconUrl,
191204
};
192205

193-
extension.tags.split(',').map(
206+
/** @type {Array<BehaviorShortHeader>} */
207+
behaviorShortHeaders.push.apply(
208+
behaviorShortHeaders,
209+
extension.eventsBasedBehaviors
210+
.map((behavior) =>
211+
behavior.private
212+
? null
213+
: {
214+
...registryItem,
215+
extensionName: name,
216+
name: behavior.name,
217+
fullName: behavior.fullName,
218+
description: behavior.description,
219+
objectType: behavior.objectType,
220+
}
221+
)
222+
.filter(Boolean)
223+
);
224+
225+
/** @type {Array<ObjectShortHeader>} */
226+
objectShortHeaders.push.apply(
227+
objectShortHeaders,
228+
extension.eventsBasedObjects
229+
? extension.eventsBasedObjects.map((object) => ({
230+
...registryItem,
231+
extensionName: name,
232+
name: object.name,
233+
fullName: object.fullName,
234+
description: object.description,
235+
}))
236+
: []
237+
);
238+
239+
extension.tags.split(',').forEach(
194240
/** @param {string} tag */
195241
(tag) => {
196242
allTagsSet.add(tag.trim().toLowerCase());
@@ -240,6 +286,12 @@ const readExtensionsFromFolder = async (folderPath, tier) => {
240286
allTags: Array.from(allTagsSet),
241287
allCategories: Array.from(allCategoriesSet),
242288
extensionShortHeaders,
289+
behavior: {
290+
headers: behaviorShortHeaders,
291+
},
292+
object: {
293+
headers: objectShortHeaders,
294+
},
243295
views,
244296
};
245297

scripts/lib.es5.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Fixes https://github.com/microsoft/TypeScript/issues/16655 for `Array.prototype.filter()`
3+
* For example, using the fix the type of `bar` is `string[]` in the below snippet as it should be.
4+
*
5+
* const foo: (string | null | undefined)[] = [];
6+
* const bar = foo.filter(Boolean);
7+
*
8+
* For related definitions, see https://github.com/microsoft/TypeScript/blob/master/src/lib/es5.d.ts
9+
*
10+
* Original licenses apply, see
11+
* - https://github.com/microsoft/TypeScript/blob/master/LICENSE.txt
12+
* - https://stackoverflow.com/help/licensing
13+
*/
14+
15+
/** See https://stackoverflow.com/a/51390763/1470607 */
16+
type Falsy = false | 0 | '' | null | undefined;
17+
18+
interface Array<T> {
19+
/**
20+
* Returns the elements of an array that meet the condition specified in a callback function.
21+
* @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
22+
* @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
23+
*/
24+
filter<S extends T>(
25+
predicate: BooleanConstructor,
26+
thisArg?: any
27+
): Exclude<S, Falsy>[];
28+
}

scripts/types.d.ts

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,89 @@
1-
interface ExtensionAndShortHeaderFields {
1+
interface ItemExtensionHeaderFields {
22
authorIds: Array<string>;
3-
shortDescription: string;
43
extensionNamespace: string;
5-
fullName: string;
6-
name: string;
74
version: string;
85
gdevelopVersion?: string;
96
tags: Array<string>;
107
category: string;
118
previewIconUrl: string;
129
}
1310

11+
type ExtensionTier = 'community' | 'reviewed';
12+
13+
/**
14+
* An extension, behavior or object.
15+
*/
16+
export interface RegistryItem extends ItemExtensionHeaderFields {
17+
tier: ExtensionTier;
18+
url: string;
19+
headerUrl: string;
20+
}
21+
22+
interface ExtensionAndShortHeaderFields extends ItemExtensionHeaderFields {
23+
shortDescription: string;
24+
fullName: string;
25+
name: string;
26+
}
27+
1428
interface ExtensionAndHeaderFields {
1529
description: string;
1630
helpPath: string;
1731
iconUrl: string;
1832
}
1933

20-
type ExtensionTier = 'community' | 'reviewed';
21-
22-
export interface ExtensionShortHeader extends ExtensionAndShortHeaderFields {
34+
export interface ExtensionShortHeader
35+
extends RegistryItem,
36+
ExtensionAndShortHeaderFields {
2337
tier: ExtensionTier;
2438
url: string;
2539
headerUrl: string;
2640
eventsBasedBehaviorsCount: number;
2741
eventsFunctionsCount: number;
2842
}
2943

44+
interface BehaviorAndShortHeaderFields {
45+
description: string;
46+
fullName: string;
47+
name: string;
48+
objectType: string;
49+
}
50+
51+
export interface BehaviorShortHeader
52+
extends RegistryItem,
53+
BehaviorAndShortHeaderFields {
54+
extensionName: string;
55+
}
56+
57+
interface ObjectAndShortHeaderFields {
58+
description: string;
59+
fullName: string;
60+
name: string;
61+
}
62+
63+
export interface ObjectShortHeader
64+
extends RegistryItem,
65+
ObjectAndShortHeaderFields {
66+
extensionName: string;
67+
}
68+
3069
export interface ExtensionHeader
3170
extends ExtensionShortHeader,
3271
ExtensionAndHeaderFields {}
3372

3473
export interface ExtensionsDatabase {
3574
version: string;
75+
/** @deprecated Tags list should be built by the UI. When only reviewed
76+
* extensions are shown, some tags could lead to no extension. */
3677
allTags: Array<string>;
78+
/** @deprecated Categories list should be built by the UI. */
3779
allCategories: Array<string>;
3880
extensionShortHeaders: Array<ExtensionShortHeader>;
81+
behavior: {
82+
headers: Array<BehaviorShortHeader>;
83+
};
84+
object: {
85+
headers: Array<ObjectShortHeader>;
86+
};
3987
views: {
4088
default: {
4189
firstExtensionIds: Array<string>;
@@ -95,6 +143,7 @@ export interface EventsBasedBehaviors {
95143
fullName: string;
96144
name: string;
97145
objectType: string;
146+
private?: boolean;
98147
eventsFunctions: EventsFunction[];
99148
}
100149

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929
"skipLibCheck": true,
3030
"forceConsistentCasingInFileNames": true
3131
},
32-
"include": ["scripts", "__tests__"]
32+
"include": ["scripts", "__tests__", "lib.es5.d.ts"]
3333
}

0 commit comments

Comments
 (0)