@polyfill-io-aot/builder
Version:
This is the builder module for polyfill-io-aot.
52 lines • 1.94 kB
JavaScript
"use strict";
const Bluebird = require("bluebird");
const noop = require("lodash/noop");
const BuildEvent_1 = require("../interfaces/BuildEvent");
const PoolExecutor_1 = require("../PoolExecutor");
const symbols_1 = require("../symbols");
/** @internal */
class UglifyExecutor extends PoolExecutor_1.PoolExecutor {
get _pct() {
return Math.round(this._complete / this._total * 100);
}
get _progressText() {
return `Minifying compiled bundles: ${this._complete}/${this._total} [${this._pct}%]`;
}
execute() {
this.emit(BuildEvent_1.BuildEvent.UGLIFY_ALL_BEGIN);
this._total = this.builder[symbols_1.COMBO_HASHES].length;
this._complete = 0;
this._ora.start('Minifying compiled bundles');
this._initPool(require.resolve('../workers/terser'));
Bluebird //tslint:disable-line:no-floating-promises
.map(this.builder[symbols_1.COMBO_HASHES], this.map.bind(this))
.then(() => {
this._ora.succeed(`Uglified ${this._complete} bundles`);
this.emit(BuildEvent_1.BuildEvent.UGLIFY_ALL_OK);
}, (e) => {
this._ora.fail(`Failed to uglify bundles: ${this.formatError(e)}`);
this.onError(e);
})
.finally(() => {
this._terminate().catch(noop);
});
}
_inc() {
this._complete++;
this._ora.text = this._progressText;
return this;
}
map(hash) {
this.emit(BuildEvent_1.BuildEvent.UGLIFY_ONE_BEGIN, hash);
return this._wrap(this._pool.exec('uglify', [hash, this.conf.outDir]))
.then(() => {
this._inc().emit(BuildEvent_1.BuildEvent.UGLIFY_ONE_OK, hash);
})
.catch((e) => {
this.emit(BuildEvent_1.BuildEvent.UGLIFY_ONE_ERR, hash, e);
throw e;
});
}
}
module.exports = UglifyExecutor;
//# sourceMappingURL=UglifyExecutor.js.map