Skip to content

Commit 9d540cb

Browse files
authored
fix(thumbnail): translate package name and description (#111)
1 parent eb9e1f4 commit 9d540cb

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

src/utils/thumbnail.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { describe, expect, it } from "vitest";
2+
import { fixture } from "../../tests/helper/fs";
3+
import { Thumbnail } from "./thumbnail";
4+
5+
describe("thumbnail Smoke Test", () => {
6+
it("should return localized package thumbnail", async () => {
7+
const thumbnail = await Thumbnail.create(fixture("oo_project_1"), [], "en");
8+
9+
const data = await thumbnail?.provideThumbnail();
10+
11+
expect(data).toEqual(expect.objectContaining({
12+
title: "Project 1",
13+
description: "This is the description for Project 1.",
14+
}));
15+
});
16+
});

src/utils/thumbnail.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export class Thumbnail implements ThumbnailProvider {
278278

279279
async provideThumbnail(): Promise<PackageThumbnail | undefined> {
280280
const result: PackageThumbnail = {
281-
title: this.wsPkgData.packageName,
281+
title: this.wsPkgData.displayName,
282282
icon: this.wsPkgData.icon,
283283
description: this.wsPkgData.description,
284284
flows: await this._provideFlowsThumbnail(),
@@ -343,7 +343,7 @@ export class Thumbnail implements ThumbnailProvider {
343343
private async _provideFlowsThumbnail(): Promise<FlowThumbnail[]> {
344344
const result: FlowThumbnail[] = [];
345345
const flowsDir = path.join(this.wsPkgData.packageDir, "flows");
346-
const flowNames = await fs.readdir(flowsDir);
346+
const flowNames = await fs.readdir(flowsDir).catch(() => []);
347347
for (const flowName of flowNames) {
348348
const flowData = await FlowLikeData.create(this.wsPkgData, flowName, path.join(flowsDir, flowName), "flow");
349349
if (flowData) {
@@ -563,7 +563,7 @@ class PkgData {
563563

564564
public readonly searchPaths: string[];
565565

566-
public readonly title: string | undefined;
566+
public readonly displayName: string | undefined;
567567
public readonly description: string | undefined;
568568
public readonly icon: string | undefined;
569569
public readonly blocksOrder: string[] | undefined;
@@ -582,8 +582,8 @@ class PkgData {
582582
) {
583583
this.searchPaths = depsQuery.searchPaths;
584584
this.icon = this.resolveResourceURI(data.icon, packageDir);
585-
this.title = data.title || data.name;
586-
this.description = data.description;
585+
this.displayName = this.localize(data.displayName) || data.name;
586+
this.description = this.localize(data.description);
587587
this.blocksOrder = data.ui?.blocks;
588588
this.dependencies = isPlainObject(data.dependencies) ? data.dependencies : {};
589589
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"displayName": "Project 1",
3+
"description": "This is the description for Project 1."
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: project-1
2+
version: 1.0.0
3+
displayName: "%displayName%"
4+
description: "%description%"

0 commit comments

Comments
 (0)