@polyfill-io-aot/builder
Version:
This is the builder module for polyfill-io-aot.
54 lines • 2.21 kB
JavaScript
"use strict";
const Bluebird = require("bluebird");
const fs = require("fs-extra");
const noop = require("lodash/noop");
const BuildEvent_1 = require("../interfaces/BuildEvent");
const PoolExecutor_1 = require("../PoolExecutor");
const Serialiser_1 = require("../Serialiser");
const symbols_1 = require("../symbols");
/** @internal */
class WritePolyfillCombinationsExecutor extends PoolExecutor_1.PoolExecutor {
execute() {
this._ora.start(`Creating empty output dir ${this.conf.outDir}`);
Bluebird.resolve(fs.emptyDir(this.conf.outDir)) //tslint:disable-line:no-floating-promises
.then(() => {
this._initPool(require.resolve('../workers/polyfill-string-generator'));
this._ora.text = 'Generating bundles';
return this.builder[symbols_1.COMBO_HASHES];
})
.map(this.mapper.bind(this))
.then(() => {
this.emit(BuildEvent_1.BuildEvent.GENERATE_BUNDLES_OK);
this._ora.succeed('Bundles generated');
}, (e) => {
this._ora.fail(`Failed to generate bundles: ${this.formatError(e)}`);
this.onError(e);
})
.finally(() => {
this._terminate().catch(noop);
});
}
mapper(hash) {
const uaString = this.builder[symbols_1.COMBO_HASH_UA_MAP][hash];
this.emit(BuildEvent_1.BuildEvent.GENERATE_BUNDLE_BEGIN, uaString);
return this
._wrap(this._pool.exec('generate', [
this.conf.excludes,
JSON.stringify(this.builder[symbols_1.COMBO_MAP].get(hash), Serialiser_1.replacer),
this.builder[symbols_1.COMBO_HASH_UA_MAP][hash],
this.conf.unknown,
this.conf.outDir,
hash
]))
.then(() => {
this.emit(BuildEvent_1.BuildEvent.GENERATE_BUNDLE_OK, uaString);
this._ora.text = `Generated bundle for ${uaString}`;
})
.catch((e) => {
this.emit(BuildEvent_1.BuildEvent.GENERATE_BUNDLE_ERR, uaString, e);
throw e;
});
}
}
module.exports = WritePolyfillCombinationsExecutor;
//# sourceMappingURL=WritePolyfillCombinationsExecutor.js.map