<commit_before>'use strict';
process.env.NODE_ENV = 'production';

const webpack = require('webpack');
const filesize = require('filesize');
const fs = require('fs');
const path = require('path');
const gzipSize = require('gzip-size').sync;
const chalk = require('chalk');
const spawn = require('cross-spawn');
const clientConfig = require('../config/webpack.client.prod');
const serverConfig = require('../config/webpack.server');
const relayCompilerArguments = require('./utils/relayCompilerArguments');

function printFileSizes(stats, config) {
  const outputPath = config.output.path;
  const assets = stats
    .toJson().assets
    .map(asset => {
      const fileContents = fs.readFileSync(path.join(outputPath, asset.name));
      const size = gzipSize(fileContents);
      return {
        name: path.basename(asset.name),
        size: size,
        sizeLabel: filesize(size),
      };
    });
  assets.sort((a, b) => b.size - a.size);
  const longestSizeLabelLength = Math.max.apply(
    null,
    assets.map(a => a.sizeLabel.length)
  );
  assets.forEach(asset => {
    let sizeLabel = asset.sizeLabel;
    const sizeLength = sizeLabel.length;
    if (sizeLength < longestSizeLabelLength) {
      const rightPadding = ' '.repeat(longestSizeLabelLength - sizeLength);
      sizeLabel += rightPadding;
    }
    const dirname = path.relative('', outputPath);
    console.log(
      '  ' + sizeLabel +
      '  ' + chalk.dim(dirname + path.sep) + chalk.cyan(asset.name)
    );
  });
}


function handler(config, err, stats) {
  if (err) {
    console.error(err.message || err);
    process.exit(1);
  }
  if (stats.hasErrors()) {
    console.log(stats.toString('errors-only'));
    process.exit(1);
  } else {
    printFileSizes(stats, config);
  }
}
console.log('Compiling relay queries...');
const relayCompiler = spawn(
  path.resolve('./node_modules/.bin/relay-compiler'),
  relayCompilerArguments,
  { stdio: 'inherit' }
);

relayCompiler.on('close', (code) => {
  if (code) {
    process.exit(code);
    return;
  }

  console.log('Building optimized assets...');
  webpack(clientConfig).run((err, stats) => {
    handler(clientConfig, err, stats);

    console.log();
    console.log('Building server files...');
    webpack(serverConfig).run(handler.bind(null, serverConfig));
  });
});<commit_msg>edit build to use rcp<commit_after>'use strict';
process.env.NODE_ENV = 'production';

const webpack = require('webpack');
const filesize = require('filesize');
const fs = require('fs');
const path = require('path');
const gzipSize = require('gzip-size').sync;
const chalk = require('chalk');
const spawn = require('cross-spawn');
const clientConfig = require('../config/webpack.client.prod');
const serverConfig = require('../config/webpack.server');
const relayCompilerArguments = require('./utils/relayCompilerArguments');

function printFileSizes(stats, config) {
  const outputPath = config.output.path;
  const assets = stats
    .toJson().assets
    .map(asset => {
      const fileContents = fs.readFileSync(path.join(outputPath, asset.name));
      const size = gzipSize(fileContents);
      return {
        name: path.basename(asset.name),
        size: size,
        sizeLabel: filesize(size),
      };
    });
  assets.sort((a, b) => b.size - a.size);
  const longestSizeLabelLength = Math.max.apply(
    null,
    assets.map(a => a.sizeLabel.length)
  );
  assets.forEach(asset => {
    let sizeLabel = asset.sizeLabel;
    const sizeLength = sizeLabel.length;
    if (sizeLength < longestSizeLabelLength) {
      const rightPadding = ' '.repeat(longestSizeLabelLength - sizeLength);
      sizeLabel += rightPadding;
    }
    const dirname = path.relative('', outputPath);
    console.log(
      '  ' + sizeLabel +
      '  ' + chalk.dim(dirname + path.sep) + chalk.cyan(asset.name)
    );
  });
}


function handler(config, err, stats) {
  if (err) {
    console.error(err.message || err);
    process.exit(1);
  }
  if (stats.hasErrors()) {
    console.log(stats.toString('errors-only'));
    process.exit(1);
  } else {
    printFileSizes(stats, config);
  }
}
console.log('Compiling relay queries...');
const relayCompiler = spawn(
  path.resolve('./node_modules/.bin/relay-compiler-plus'),
  relayCompilerArguments,
  { stdio: 'inherit' }
);

relayCompiler.on('close', (code) => {
  if (code) {
    process.exit(code);
    return;
  }

  console.log('Building optimized assets...');
  webpack(clientConfig).run((err, stats) => {
    handler(clientConfig, err, stats);

    console.log();
    console.log('Building server files...');
    webpack(serverConfig).run(handler.bind(null, serverConfig));
  });
});
{'fraction_non_alphanumeric': 0.16224951519069167, 'fraction_numerical': 0.0008618832148243913, 'mean_word_length': 3.5688976377952755, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '2799401', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1433, 'n_words': 284}