Skip to content

Commit

Permalink
feat: add thumbnail to samples (#1026)
Browse files Browse the repository at this point in the history
* feat: add thumbnail check to validator

* feat: add thumbnail to samples

* feat: add thumbnail to samples

* fix: redundant gif path

* fix: validation script in CI
  • Loading branch information
tecton authored Sep 14, 2023
1 parent a31531e commit 9b0580f
Show file tree
Hide file tree
Showing 26 changed files with 139 additions and 119 deletions.
30 changes: 24 additions & 6 deletions .config/samples-config-v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"time": "5min to run",
"configuration": "Ready for debug",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": true
},
Expand All @@ -36,6 +37,7 @@
],
"time": "5min to run",
"configuration": "Ready for debug",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": true
},
Expand All @@ -57,6 +59,7 @@
],
"time": "5min to run",
"configuration": "Ready for debug",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": false
},
Expand All @@ -77,6 +80,7 @@
],
"time": "1hr to run",
"configuration": "Manual configurations required",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": false
},
Expand All @@ -96,7 +100,7 @@
],
"time": "30min to run",
"configuration": "Ready for debug",
"gifPath": "images/preview.png",
"thumbnailPath": "images/thumbnail.png",
"suggested": false
},
{
Expand All @@ -118,6 +122,7 @@
],
"time": "30min to run",
"configuration": "Manual configurations required",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": false
},
Expand All @@ -138,6 +143,7 @@
],
"time": "45min to run",
"configuration": "Manual configurations required",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": false
},
Expand All @@ -157,6 +163,7 @@
],
"time": "5min to run",
"configuration": "Ready for debug",
"thumbnailPath": "images/send-proactive-messages.gif",
"gifPath": "images/send-proactive-messages.gif",
"suggested": false,
"downloadUrl": "https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-proactive-messaging-teamsfx"
Expand All @@ -177,6 +184,7 @@
],
"time": "5min to run",
"configuration": "Ready for debug",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": false
},
Expand All @@ -196,6 +204,7 @@
],
"time": "5min to run",
"configuration": "Manual configurations required",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": false
},
Expand All @@ -217,6 +226,7 @@
],
"time": "5min to run",
"configuration": "Ready for debug",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": false
},
Expand All @@ -236,6 +246,7 @@
],
"time": "5min to run",
"configuration": "Ready for debug",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": false
},
Expand All @@ -257,6 +268,7 @@
],
"time": "5min to run",
"configuration": "Ready for debug",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": false
},
Expand All @@ -278,6 +290,7 @@
],
"time": "10min to run",
"configuration": "Manual configurations required",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": false
},
Expand All @@ -299,6 +312,7 @@
],
"time": "5min to run",
"configuration": "Ready for debug",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": false
},
Expand All @@ -321,6 +335,7 @@
],
"time": "30min to run",
"configuration": "Manual configurations required",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": false
},
Expand All @@ -342,6 +357,7 @@
],
"time": "30min to run",
"configuration": "Ready for debug",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": false
},
Expand All @@ -361,7 +377,7 @@
],
"time": "5min to run",
"configuration": "Ready for debug",
"gifPath": "assets/sampleDemo.png",
"thumbnailPath": "assets/thumbnail.png",
"suggested": false
},
{
Expand All @@ -379,7 +395,7 @@
],
"time": "5min to run",
"configuration": "Ready for debug",
"gifPath": "assets/outlook-set-signature-overview.png",
"thumbnailPath": "assets/outlook-set-signature-overview.png",
"suggested": false,
"downloadUrl": "https://github.com/OfficeDev/Office-Add-in-samples/tree/main/Samples/outlook-set-signature"
},
Expand All @@ -400,7 +416,7 @@
],
"time": "15min to run",
"configuration": "Manual configurations required",
"gifPath": "images/preview.png",
"thumbnailPath": "images/preview.png",
"suggested": false
},
{
Expand All @@ -421,6 +437,7 @@
],
"time": "5 min to run",
"configuration": "Manual configurations required",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": false
},
Expand All @@ -441,6 +458,7 @@
],
"time": "5min to run",
"configuration": "Manual configurations required",
"thumbnailPath": "assets/thumbnail.png",
"gifPath": "assets/sampleDemo.gif",
"suggested": false
},
Expand All @@ -462,7 +480,7 @@
],
"time": "5min to run",
"configuration": "Ready for debug",
"gifPath": "src/assets/screenshot.png",
"thumbnailPath": "src/assets/screenshot.png",
"suggested": false
},
{
Expand All @@ -482,7 +500,7 @@
],
"time": "5min to run",
"configuration": "Ready for debug",
"gifPath": "assets/screenshot.png",
"thumbnailPath": "assets/screenshot.png",
"suggested": false
}
]
Expand Down
Binary file added NPM-search-connector-M365/assets/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added adaptive-card-notification/assets/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bot-sso/assets/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graph-connector-app/assets/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added hello-world-tab-with-backend/assets/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added live-share-dice-roller/assets/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added share-now/assets/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added team-central-dashboard/assets/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added teams-chef-bot/assets/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added todo-list-SPFx/assets/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added todo-list-with-Azure-backend/assets/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions validation-tool/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import standard from "figlet/importable-fonts/Standard.js";
import { outputResult } from "./util";
import validateEnvFiles from "./validators/envValidator";
import validateFolderStructure from "./validators/folderStructureValidator";
import validateGif from "./validators/gifValidator";
import validateImage from "./validators/imageValidator";
import validatePackageJson from "./validators/packageJsonValidator";
import validateTeamsAppManifest from "./validators/teamsAppManifestValidator";
import validateTeamsAppYaml from "./validators/teamsAppYamlValidator";
Expand All @@ -22,7 +22,7 @@ const validators = [
validateTeamsAppYaml,
validateTeamsAppManifest,
validateEnvFiles,
validateGif,
validateImage,
validatePackageJson,
];

Expand Down
36 changes: 0 additions & 36 deletions validation-tool/src/validators/gifValidator.ts

This file was deleted.

38 changes: 38 additions & 0 deletions validation-tool/src/validators/imageValidator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import fs from "fs-extra";
import path from "path";
import sizeOf from "image-size";
import { Result } from "../resultType";

/**
* Rule 1: Images should have 1600*920/800*460 resolution or same ratio.
*
* @param projectDir root directory of the project
* @returns validation result
*/
export default async function validateImage(projectDir: string): Promise<Result> {
const result: Result = {
name: "Image Files",
passed: [],
failed: [],
warning: [],
};
const defaultImages = ["thumbnail.png", "sampleDemo.gif"];
for (const image of defaultImages) {
const imageDefaultPath = path.join(projectDir, "assets", image);
const imageName = path.join("assets", image);
if (!await fs.exists(imageDefaultPath)) {
result.warning.push(`${imageName} does not exist.`);
continue;
}
const dimensions = sizeOf(imageDefaultPath);
if (dimensions.width && dimensions.height && dimensions.width / dimensions.height === 40/23) {
result.passed.push(`${imageName} has 1600*920/800*460 resolution or same ratio.`);
} else {
result.failed.push(`${imageName} should have 1600*920/800*460 resolution or same ratio.`);
}
}
return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import mock from "mock-fs";
import fs from "fs-extra";
import path from "path";

import validateGif from "../../src/validators/gifValidator";
import validateImage from "../../src/validators/imageValidator";

describe('validateGif()', () => {
describe('validateImage()', () => {
afterEach(() => {
mock.restore();
});
Expand All @@ -18,11 +18,11 @@ describe('validateGif()', () => {
},
});

const result = await validateGif(path.join(process.cwd(), "testFolder"));
expect(result.name).toEqual("GIF Demo File");
const result = await validateImage(path.join(process.cwd(), "testFolder"));
expect(result.name).toEqual("Image Files");
expect(result.failed.length).toBe(0);
expect(result.passed.length).toBe(0);
expect(result.warning.length).toBe(1);
expect(result.warning.length).toBe(2);
});

test('valid GIF', async () => {
Expand All @@ -35,11 +35,11 @@ describe('validateGif()', () => {
},
});

const result = await validateGif(path.join(process.cwd(), "testFolder"));
expect(result.name).toEqual("GIF Demo File");
const result = await validateImage(path.join(process.cwd(), "testFolder"));
expect(result.name).toEqual("Image Files");
expect(result.failed.length).toBe(0);
expect(result.passed.length).toBe(1);
expect(result.warning.length).toBe(0);
expect(result.warning.length).toBe(1);
});

test('invalid GIF', async () => {
Expand All @@ -52,10 +52,10 @@ describe('validateGif()', () => {
},
});

const result = await validateGif(path.join(process.cwd(), "testFolder"));
expect(result.name).toEqual("GIF Demo File");
const result = await validateImage(path.join(process.cwd(), "testFolder"));
expect(result.name).toEqual("Image Files");
expect(result.failed.length).toBe(1);
expect(result.passed.length).toBe(0);
expect(result.warning.length).toBe(0);
expect(result.warning.length).toBe(1);
});
});
2 changes: 1 addition & 1 deletion validation-tool/validate-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const mandatoryFields = [
"tags",
"time",
"configuration",
"gifPath",
"thumbnailPath",
"suggested",
];

Expand Down
Loading

0 comments on commit 9b0580f

Please sign in to comment.