@overwolf/ow-app-builder-lib
Version:
ow-electron-builder lib
67 lines • 3.15 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.OWPackagesHelper = void 0;
const binDownload_1 = require("../../../binDownload");
const builder_util_1 = require("builder-util");
const kPackagesURL = 'https://electronapi.overwolf.com/packages';
// -----------------------------------------------------------------------------
class OWPackagesHelper {
// ---------------------------------------------------------------------------
constructor(appOutDir, config, packages) {
this.packagesInfo = null;
this.appOutDir = appOutDir;
this.configuration = config;
this.packages = packages || [];
if (this.packages.length > 0 &&
!this.packages.includes('utility')) {
// bundle the utility package if any other package is included
this.packages.push('utility');
}
}
// ---------------------------------------------------------------------------
async downloadRequiredPackages() {
try {
if (this.packages.length === 0) {
builder_util_1.log.info('No ow-electron packages configured in package.json');
return true;
}
this.packagesInfo = await this.obtainPackageInfo();
if (!this.packagesInfo) {
return false;
}
const { packages } = this.packagesInfo;
builder_util_1.log.info(`Downloading and packing ow-electron packages: ${this.packages.join(',')}`);
const downloads = packages === null || packages === void 0 ? void 0 : packages.filter((p) => this.packages.includes(p.name));
const downloadPromises = [];
downloads.forEach((pkg) => {
builder_util_1.log.info(`downloading ow-electron package ${pkg.name} - version: ${pkg.version}`);
const packageOutput = `${this.appOutDir}/packages/${pkg.uid}.owepk`;
downloadPromises.push((0, binDownload_1.download)(pkg.url, packageOutput, null, true));
});
await Promise.all(downloadPromises);
return true;
}
catch (err) {
builder_util_1.log.error(`Error while Packaging owW-electron packages: ${err === null || err === void 0 ? void 0 : err.message}`);
}
return false;
}
// ---------------------------------------------------------------------------
async obtainPackageInfo() {
var _a;
const url = ((_a = this.configuration.overwolf) === null || _a === void 0 ? void 0 : _a.overridePackagesUrl) || kPackagesURL;
try {
const res = await fetch(url);
if (!res.ok) {
throw new Error(`fetch error '${res.status}': ${res.statusText}`);
}
return await res.json();
}
catch (err) {
builder_util_1.log.warn(`Unable to fetch ow-electron packages info from '${url}': ${err === null || err === void 0 ? void 0 : err.message}`);
return null;
}
}
}
exports.OWPackagesHelper = OWPackagesHelper;
//# sourceMappingURL=OWPackagesHelper.js.map
;