UNPKG

@tdb/web

Version:

Common condiguration for serving a web-site and testing web-based UI components.

69 lines 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var sizeOf = require("image-size"); var common_1 = require("../common"); function toManifestImage(filePath, urlPath, options) { if (options === void 0) { options = {}; } return tslib_1.__awaiter(this, void 0, void 0, function () { var parts, dir, name, ext, image, file1x, name2x, file2x, _a, width, height; return tslib_1.__generator(this, function (_b) { switch (_b.label) { case 0: parts = common_1.fsPath.parse(filePath); dir = parts.dir; name = parts.name.replace(/\@2x$/, ''); ext = parts.ext.replace(/^\./, ''); image = { type: 'FILE/image', name: name, ext: ext, path: urlPath, }; file1x = common_1.fsPath.join(dir, parts.base); return [4, common_1.fs.pathExists(file1x)]; case 1: if (!(_b.sent())) { return [2]; } if (!!is2x(filePath)) return [3, 3]; name2x = image.name + "@2x." + image.ext; file2x = common_1.fsPath.join(dir, name2x); return [4, common_1.fs.pathExists(file2x)]; case 2: if (_b.sent()) { image.path2x = common_1.fsPath.join(common_1.fsPath.dirname(urlPath), name2x); } _b.label = 3; case 3: if (!(options.size === true)) return [3, 5]; return [4, getSize(file1x)]; case 4: _a = _b.sent(), width = _a.width, height = _a.height; image.width = width; image.height = height; _b.label = 5; case 5: return [2, image]; } }); }); } exports.toManifestImage = toManifestImage; var is2x = function (value) { return value.includes('@2x'); }; function getSize(path) { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { return [2, new Promise(function (resolve, reject) { sizeOf(path, function (err, data) { if (err) { reject(err); } else { resolve(data); } }); })]; }); }); } //# sourceMappingURL=util.image.js.map