<commit_before>'use strict';

/**
 * Module dependencies.
 */

var path = require('path');
var gutil = require('gulp-util');
var through = require('through2');
var parsePath = require('parse-filepath');
var utils = require('../utils');
var _ = require('lodash');


/**
 * ## Dest path plugin
 *
 * Assemble plugin to calcuate the destination for each file.
 */

module.exports = function destPathPlugin(dest, options) {
  var assemble = this;

  return through.obj(function (file, encoding, cb) {
    var opts = _.extend({}, options);

    try {

      // console.log(dest)
      // get the new dest extension based on the engine extension
      var destExt = opts.ext || utils.getDestExt(file, assemble);

      // calculate the new destination path and parse the path
      var actualDest = path.join(dest, file.relative);
      actualDest = utils.replaceExt(actualDest, destExt);
      var parsed = parsePath(actualDest);

      // update file.data.dest with the new properties
      file.data.dest = file.data.dest || {};

      for (var key in parsed) {
        if (parsed.hasOwnProperty(key)) {
          file.data.dest[key] = parsed[key];
        }
      }

      file.data.dest = _.extend(file.data.dest, {
        path: actualDest,
        ext: parsed.extname
      });

      file.data.dest.dest = dest;

      // push the file along
      this.push(file);
    } catch (err) {
      this.emit('error', new gutil.PluginError('assemble-dest-path', err));
    }
<commit_msg>use rewrite-ext in path plugin<commit_after>'use strict';

/**
 * Module dependencies.
 */

var path = require('path');
var gutil = require('gulp-util');
var through = require('through2');
var parsePath = require('parse-filepath');
var rewrite = require('rewrite-ext');
var utils = require('../utils');
var _ = require('lodash');


/**
 * ## Dest path plugin
 *
 * Assemble plugin to calcuate the destination for each file.
 */

module.exports = function destPathPlugin(dest, options) {
  var assemble = this;

  return through.obj(function (file, encoding, cb) {
    var opts = _.extend({}, options);

    try {

      // console.log(dest)
      // get the new dest extension based on the engine extension
      var destExt = opts.ext || utils.getDestExt(file, assemble);

      // calculate the new destination path and parse the path
      var actualDest = path.join(dest, file.relative);
      actualDest = rewrite(actualDest, destExt);
      var parsed = parsePath(actualDest);

      // update file.data.dest with the new properties
      file.data.dest = file.data.dest || {};

      for (var key in parsed) {
        if (parsed.hasOwnProperty(key)) {
          file.data.dest[key] = parsed[key];
        }
      }

      file.data.dest = _.extend(file.data.dest, {
        path: actualDest,
        ext: parsed.extname
      });

      file.data.dest.dest = dest;

      // push the file along
      this.push(file);
    } catch (err) {
      this.emit('error', new gutil.PluginError('assemble-dest-path', err));
    }

{'fraction_non_alphanumeric': 0.1379654255319149, 'fraction_numerical': 0.0006648936170212766, 'mean_word_length': 2.669512195121951, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5183010', 'n_tokens_mistral': 904, 'n_tokens_neox': 881, 'n_words': 249}