"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AddFileToManifestJson = void 0;

var _webpack = require("webpack");

var _createManifestJson = require("./createManifestJson");

class AddFileToManifestJson {
  constructor(options) {
    this.options = options;
  }

  apply(compiler) {
    const {
      RawSource
    } = compiler.webpack.sources;
    compiler.hooks.thisCompilation.tap('MyWebpackPlugin', compilation => {
      compilation.hooks.processAssets.tap({
        name: 'MyPlugin',
        stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
      }, assets => {
        const {
          hashDigestLength
        } = compilation.outputOptions;
        this.options.forEach(option => {
          const manifestJson = (0, _createManifestJson.createManifestJson)({
            option,
            hashDigestLength,
            compilation,
            assets
          });
          compilation.emitAsset(option.outputJsonFileName, new RawSource(JSON.stringify(manifestJson)));
        });
      });
    });
  }

}

exports.AddFileToManifestJson = AddFileToManifestJson;