UNPKG

@overwolf/ow-app-builder-lib

Version:
48 lines 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.calculateAppUID = void 0; const crypto = require("crypto"); const builder_util_1 = require("builder-util"); // ----------------------------------------------------------------------------- const calculateAppUID = (packageJson, appName) => { let ret = ''; try { let author = ''; let applicationName = ''; if (packageJson.author) { if (packageJson.author.name) { author = packageJson.author.name; } else if (typeof packageJson.author === 'string') { author = packageJson.author; } } if (!author || author === '') { builder_util_1.log.error('missing |author| in package.json'); process.exit(1); } applicationName = packageJson.productName ? packageJson.productName : (packageJson.name ? packageJson.name : appName); // add '.electron' to app name. const key = `{'author':'${author || ''}','name':'${applicationName}.electron'}`; const shasum = crypto.createHash('sha1'); shasum.update(key, 'utf-8'); const hashBuffer = shasum.digest(); const hash = hashBuffer.toString('latin1'); const offsetFromA = 'a'.charCodeAt(0); for (let i = 0; i < hash.length; ++i) { const lo = hash.charCodeAt(i) & 0xf; const hi = hash.charCodeAt(i) >> 4; ret += String.fromCharCode(offsetFromA + lo); ret += String.fromCharCode(offsetFromA + hi); } } catch (err) { builder_util_1.log.error(`Unable to calculate uid ${err.message}`); } return ret; }; exports.calculateAppUID = calculateAppUID; //# sourceMappingURL=overwolfMetadataUtil.js.map