<commit_before>var fs = require("fs");
var fse = require("fs-extra");

var DEFAULT_PARAMS = {
  manifestFile: "../../config/sprockets-manifest.json",
  statsFile: "webpack-stats.json"
};

function WebpackSprocketsRailsManifestPlugin(options) {
  var params = options || {};

  this._manifestFile = params.manifestFile || DEFAULT_PARAMS.manifestFile;
  this._statsFile = params.statsFile || DEFAULT_PARAMS.statsFile;
}

WebpackSprocketsRailsManifestPlugin.prototype.apply = function(compiler) {
  var manifestFile = this._manifestFile;
  var statsFile = this._statsFile;
  var sprockets = {
    files: {},
    assets: {}
  };

  compiler.plugin("done", function(stats) {
    var statsJson = stats.toJson();
    var chunks = statsJson.chunks;
    var webpackContext = compiler.options.context;
    var outputPath = compiler.options.output.path;
    var outputDest = webpackContext + "/" + outputPath;
    var manifestDest = outputDest + "/" + manifestFile;

    chunks.forEach(function(chunk) {
      var bundleName = chunk.names[0];
      var chunkHashFileName = chunk.files[0];
      var logicalPath = bundleName + ".js";
      var chunkDest = outputDest + "/" + chunkHashFileName;
      var mtime = fs.statSync(chunkDest).mtime.toISOString();

      sprockets.assets[logicalPath] = chunkHashFileName;
      sprockets.files[chunkHashFileName] = {
        "logical_path": logicalPath,
        "mtime": mtime,
        "size": chunk.size,
        "digest": chunk.hash,
        // TODO
        // "integrity": "sha256-<KEY>
      };
    });

    fse.outputFileSync(manifestDest, JSON.stringify(sprockets, null, "  "));<commit_msg>Add support for Webpack dev server<commit_after>var fs = require("fs");
var fse = require("fs-extra");

var DEFAULT_PARAMS = {
  manifestFile: "../../config/sprockets-manifest.json",
  statsFile: "webpack-stats.json"
};

function WebpackSprocketsRailsManifestPlugin(options) {
  var params = options || {};

  this._manifestFile = params.manifestFile || DEFAULT_PARAMS.manifestFile;
  this._statsFile = params.statsFile || DEFAULT_PARAMS.statsFile;
}

WebpackSprocketsRailsManifestPlugin.prototype.apply = function(compiler) {
  var manifestFile = this._manifestFile;
  var statsFile = this._statsFile;
  var sprockets = {
    files: {},
    assets: {}
  };

  compiler.plugin("done", function(stats) {
    var statsJson = stats.toJson();
    var chunks = statsJson.chunks;
    var webpackContext = compiler.options.context;
    var devServer = compiler.options.devServer;
    var outputPath;

    if (devServer && devServer.contentBase) {
      outputPath = devServer.contentBase;
    } else {
      outputPath = compiler.options.output.path;
    }

    var outputDest = webpackContext + "/" + outputPath;
    var manifestDest = outputDest + "/" + manifestFile;

    chunks.forEach(function(chunk) {
      var bundleName = chunk.names[0];
      var chunkHashFileName = chunk.files[0];
      var logicalPath = bundleName + ".js";
      var chunkDest = outputDest + "/" + chunkHashFileName;
      var mtime = fs.statSync(chunkDest).mtime.toISOString();

      sprockets.assets[logicalPath] = chunkHashFileName;
      sprockets.files[chunkHashFileName] = {
        "logical_path": logicalPath,
        "mtime": mtime,
        "size": chunk.size,
        "digest": chunk.hash,
        // TODO
        // "integrity": "<KEY>
      };
    });

    fse.outputFileSync(manifestDest, JSON.stringify(sprockets, null, "  "));
{'fraction_non_alphanumeric': 0.13077593722755013, 'fraction_numerical': 0.002034292356873002, 'mean_word_length': 3.3680203045685277, 'pattern_counts': {'":': 10, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '840316', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1055, 'n_words': 199}