@polyfill-io-aot/builder
Version:
This is the builder module for polyfill-io-aot.
46 lines • 1.82 kB
JavaScript
"use strict";
const Executor_1 = require("../Executor");
const BuildEvent_1 = require("../interfaces/BuildEvent");
const symbols_1 = require("../symbols");
/** @internal */
class GenerateUserAgentsExecutor extends Executor_1.Executor {
execute() {
this._ora.start('Generating mock user agents');
this.emit(BuildEvent_1.BuildEvent.GENERATE_UAS_ALL_BEGIN);
try {
const all = [];
for (const vendor of Object.keys(this.conf.uaGenerators)) {
this.processVendor(vendor, all);
}
this.builder[symbols_1.USERAGENTS] = all;
this._ora.succeed('Generated mock user agents');
this.emit(BuildEvent_1.BuildEvent.GENERATE_UAS_ALL_OK, this.builder[symbols_1.USERAGENTS].length);
}
catch (e) {
this._ora.fail(`Failed to generate mock user agents: ${this.formatError(e)}`);
this.onError(e);
}
}
processVendor(vendor, all) {
this.emit(BuildEvent_1.BuildEvent.GENERATE_UAS_VENDOR_BEGIN, vendor);
try {
const generator = this.conf.uaGenerators[vendor];
let numUnique = 0;
for (const str of generator()) {
if (!all.includes(str)) {
numUnique++;
all.push(str);
}
}
this._ora.text = `Generated mock user agents for ${vendor}`;
this.emit(BuildEvent_1.BuildEvent.GENERATE_UAS_VENDOR_OK, vendor, numUnique);
}
catch (e) {
this.emit(BuildEvent_1.BuildEvent.GENERATE_UAS_VENDOR_ERR, vendor, e);
// noinspection ExceptionCaughtLocallyJS
throw e;
}
}
}
module.exports = GenerateUserAgentsExecutor;
//# sourceMappingURL=GenerateUserAgentsExecutor.js.map