@blocklet/images 1.16.33-beta-20241107-065332-b20666d2 → 1.16.33-beta-20241108-105022-266cd380
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/lib/logo-validate.d.ts +4 -3
- package/lib/logo-validate.js +19 -12
- package/lib/screenshot-validate.d.ts +1 -1
- package/lib/screenshot-validate.js +18 -14
- package/package.json +10 -3
- package/lib/get-image-size.d.ts +0 -6
- package/lib/get-image-size.js +0 -25
package/lib/logo-validate.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { ImageType } from 'image-type';
|
|
1
2
|
type ISizeKB = number;
|
|
2
3
|
interface ILogoValidateOptions {
|
|
3
4
|
maxSize?: ISizeKB;
|
|
4
|
-
|
|
5
|
-
logoType?:
|
|
5
|
+
minWidth?: number;
|
|
6
|
+
logoType?: ImageType[];
|
|
6
7
|
extractedFilepath: string;
|
|
7
8
|
}
|
|
8
|
-
export declare const validateLogo: (logoName: string, options: ILogoValidateOptions) =>
|
|
9
|
+
export declare const validateLogo: (logoName: string, options: ILogoValidateOptions) => any[];
|
|
9
10
|
export {};
|
package/lib/logo-validate.js
CHANGED
|
@@ -6,14 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.validateLogo = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
9
|
+
const image_size_1 = __importDefault(require("image-size"));
|
|
10
|
+
const image_type_1 = __importDefault(require("image-type"));
|
|
11
|
+
const is_svg_1 = __importDefault(require("is-svg"));
|
|
12
|
+
const validateLogo = (logoName, options) => {
|
|
13
|
+
const { extractedFilepath, maxSize = 1024, minWidth = 256 } = options;
|
|
14
|
+
const logoType = options.logoType || ['png', 'jpg', 'webp'];
|
|
12
15
|
const logoPath = path_1.default.join(extractedFilepath, logoName);
|
|
13
16
|
const preLogoMessage = `The logo(${logoName})`;
|
|
14
17
|
const errorMessages = [];
|
|
15
18
|
if (!logoName) {
|
|
16
|
-
errorMessages.push(
|
|
19
|
+
errorMessages.push('The logo field is required in blocklet.yml.');
|
|
17
20
|
return errorMessages;
|
|
18
21
|
}
|
|
19
22
|
if (!fs_1.default.existsSync(logoPath)) {
|
|
@@ -24,14 +27,18 @@ const validateLogo = async (logoName, options) => {
|
|
|
24
27
|
if (maxSize && logoStats.size > maxSize * 1024) {
|
|
25
28
|
errorMessages.push(`${preLogoMessage} size exceeds ${maxSize} KB, but got ${(logoStats.size / 1024).toFixed(2)} KB.`);
|
|
26
29
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
const imgType = (0, image_type_1.default)(fs_1.default.readFileSync(logoPath));
|
|
31
|
+
const isSvgFile = (0, is_svg_1.default)(fs_1.default.readFileSync(logoPath));
|
|
32
|
+
if (isSvgFile || !logoType.includes(imgType.ext)) {
|
|
33
|
+
errorMessages.push(`${preLogoMessage} format is not supported, expected: [${logoType}].`);
|
|
34
|
+
}
|
|
35
|
+
const imageMeta = (0, image_size_1.default)(logoPath);
|
|
36
|
+
if (imageMeta.width < minWidth || imageMeta.height < minWidth) {
|
|
37
|
+
errorMessages.push(`${preLogoMessage} minimum size must be ${minWidth}x${minWidth}, but got ${imageMeta.width}x${imageMeta.height}.`);
|
|
38
|
+
}
|
|
39
|
+
if (imageMeta.height !== imageMeta.width) {
|
|
40
|
+
errorMessages.push(`${preLogoMessage} aspect ratio must be 1:1, but got 1:${parseFloat((imageMeta.height / imageMeta.width).toFixed(2))}.`);
|
|
41
|
+
}
|
|
35
42
|
return errorMessages;
|
|
36
43
|
};
|
|
37
44
|
exports.validateLogo = validateLogo;
|
|
@@ -7,5 +7,5 @@ interface IScreenshotValidateOptions {
|
|
|
7
7
|
minWidth?: number;
|
|
8
8
|
minHeight?: number;
|
|
9
9
|
}
|
|
10
|
-
export declare const validateScreenshots: (screenshots: string[], options: IScreenshotValidateOptions) =>
|
|
10
|
+
export declare const validateScreenshots: (screenshots: string[], options: IScreenshotValidateOptions) => any[];
|
|
11
11
|
export {};
|
|
@@ -6,11 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.validateScreenshots = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const
|
|
9
|
+
const image_size_1 = __importDefault(require("image-size"));
|
|
10
|
+
const image_type_1 = __importDefault(require("image-type"));
|
|
11
|
+
const is_svg_1 = __importDefault(require("is-svg"));
|
|
10
12
|
const ordinal_suffix_1 = require("./ordinal-suffix");
|
|
11
13
|
const ASPECT_RATIO_16_10 = 16 / 10;
|
|
12
|
-
const ASPECT_RATIO_THRESHOLD = 0.
|
|
13
|
-
const validateScreenshots =
|
|
14
|
+
const ASPECT_RATIO_THRESHOLD = 0.05;
|
|
15
|
+
const validateScreenshots = (screenshots, options) => {
|
|
14
16
|
const { extractedFilepath, minCount, maxCount, maxSize, minWidth, minHeight } = options;
|
|
15
17
|
const errorMessages = [];
|
|
16
18
|
const screenshotList = [];
|
|
@@ -23,29 +25,31 @@ const validateScreenshots = async (screenshots, options) => {
|
|
|
23
25
|
}
|
|
24
26
|
});
|
|
25
27
|
if (minCount && screenshotList.length < minCount) {
|
|
26
|
-
errorMessages.
|
|
28
|
+
errorMessages.unshift(`At least ${minCount} screenshots are required, but just got ${screenshotList.length}.`);
|
|
27
29
|
}
|
|
28
|
-
if (maxCount && screenshotList.length > maxCount) {
|
|
29
|
-
errorMessages.
|
|
30
|
+
else if (maxCount && screenshotList.length > maxCount) {
|
|
31
|
+
errorMessages.unshift(`At most ${maxCount} screenshots are supported, but just got ${screenshotList.length}.`);
|
|
30
32
|
}
|
|
31
33
|
const asyncErrors = {};
|
|
32
|
-
|
|
34
|
+
screenshotList.forEach((screenshot, index) => {
|
|
33
35
|
const screenshotsPath = path_1.default.join(extractedFilepath, 'screenshots', screenshot);
|
|
34
36
|
const preMessage = `The ${(0, ordinal_suffix_1.ordinalSuffix)(index + 1)}[${screenshot}] screenshot`;
|
|
35
37
|
asyncErrors[screenshot] = [];
|
|
36
38
|
if (!fs_1.default.existsSync(screenshotsPath)) {
|
|
37
39
|
asyncErrors[screenshot].push(`${preMessage} file not found.`);
|
|
38
|
-
return
|
|
40
|
+
return;
|
|
39
41
|
}
|
|
40
42
|
const screenshotsStats = fs_1.default.statSync(screenshotsPath);
|
|
41
43
|
if (maxSize && screenshotsStats.size > maxSize * 1024 * 1024) {
|
|
42
44
|
asyncErrors[screenshot].push(`${preMessage} size exceeds ${maxSize} MB, but got ${(screenshotsStats.size / 1024 / 1024).toFixed(2)} MB.`);
|
|
43
45
|
}
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
const imgType = (0, image_type_1.default)(fs_1.default.readFileSync(screenshotsPath));
|
|
47
|
+
const isSvgFile = (0, is_svg_1.default)(fs_1.default.readFileSync(screenshotsPath));
|
|
48
|
+
if (!isSvgFile && !imgType) {
|
|
49
|
+
asyncErrors[screenshot].push(`${preMessage} is not a valid image file.`);
|
|
47
50
|
}
|
|
48
|
-
|
|
51
|
+
if (!isSvgFile) {
|
|
52
|
+
const imageMeta = (0, image_size_1.default)(screenshotsPath);
|
|
49
53
|
const aspectRatio = imageMeta.width / imageMeta.height;
|
|
50
54
|
const width = minWidth || (minHeight && minHeight * ASPECT_RATIO_16_10);
|
|
51
55
|
const height = minHeight || (width && width / ASPECT_RATIO_16_10);
|
|
@@ -55,8 +59,8 @@ const validateScreenshots = async (screenshots, options) => {
|
|
|
55
59
|
if (Math.abs(aspectRatio - ASPECT_RATIO_16_10) > ASPECT_RATIO_THRESHOLD) {
|
|
56
60
|
asyncErrors[screenshot].push(`${preMessage} aspect ratio must be approximately 16:10, but got 16:${parseFloat((imageMeta.height / (imageMeta.width / 16)).toFixed(2))} (${imageMeta.width}x${imageMeta.height}).`);
|
|
57
61
|
}
|
|
58
|
-
}
|
|
59
|
-
})
|
|
62
|
+
}
|
|
63
|
+
});
|
|
60
64
|
screenshotList.forEach((screenshot) => {
|
|
61
65
|
if (asyncErrors[screenshot].length) {
|
|
62
66
|
errorMessages.push(...asyncErrors[screenshot]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/images",
|
|
3
|
-
"version": "1.16.33-beta-
|
|
3
|
+
"version": "1.16.33-beta-20241108-105022-266cd380",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,13 +26,20 @@
|
|
|
26
26
|
"url": "git+https://github.com/ArcBlock/blocklet-server.git"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
|
+
"verify": "npm run lint:fix && npm run coverage && npm run build",
|
|
30
|
+
"lint": "eslint src tests",
|
|
31
|
+
"lint:fix": "npm run lint -- --fix",
|
|
32
|
+
"coverage": "npm run test -- --coverage",
|
|
33
|
+
"clean": "rm -fr lib",
|
|
29
34
|
"build:blocklet-images": "tsc",
|
|
30
35
|
"build": "tsc",
|
|
31
36
|
"test": "jest",
|
|
32
37
|
"watch": "nodemon -w src -e ts -x 'npm run build'"
|
|
33
38
|
},
|
|
34
39
|
"dependencies": {
|
|
35
|
-
"image-size": "^1.0.2"
|
|
40
|
+
"image-size": "^1.0.2",
|
|
41
|
+
"image-type": "^4.1.0",
|
|
42
|
+
"is-svg": "^4.3.2"
|
|
36
43
|
},
|
|
37
44
|
"devDependencies": {
|
|
38
45
|
"@arcblock/eslint-config-ts": "^0.3.3",
|
|
@@ -44,5 +51,5 @@
|
|
|
44
51
|
"ts-node": "^10.9.1",
|
|
45
52
|
"typescript": "^5.6.3"
|
|
46
53
|
},
|
|
47
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "804206007f31a5875d11f0f099b3bc87a4357b83"
|
|
48
55
|
}
|
package/lib/get-image-size.d.ts
DELETED
package/lib/get-image-size.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getImageSize = void 0;
|
|
7
|
-
const image_size_1 = __importDefault(require("image-size"));
|
|
8
|
-
const getImageSize = async (path) => {
|
|
9
|
-
return new Promise((reslove, reject) => {
|
|
10
|
-
try {
|
|
11
|
-
(0, image_size_1.default)(path, (e, res) => {
|
|
12
|
-
if (e) {
|
|
13
|
-
reject(e);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
reslove(res);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
reject(error);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
exports.getImageSize = getImageSize;
|