<commit_before>'use strict';
var fs = require('fs');
var _path = require('path');

var mkdirp = require('mkdirp');
var ncp = require('ncp');
var webpack = require('webpack');
var webpackConfig = require('./webpack.coffee').build;


exports.buildDevIndex = function(config) {
  process.env.NODE_ENV = 'dev';

  webpack(webpackConfig(config), function(err) {
    if(err) {
      return console.error(err);
    }

    var cwd = process.cwd();
    var page = require(_path.join(cwd, './.antwar/build/bundleStaticPage.js'));

    fs.writeFileSync(
      _path.join(cwd, './.antwar/build/index.html'),
      page,
      '/antwar_devindex',
      null
    );

    ncp('./assets', _path.join(cwd, './.antwar/build/assets'));
  });
};

exports.build = function(config) {
  process.env.NODE_ENV = 'production';

  webpack(webpackConfig(config), function(err) {
    if(err) {
      return console.error(err);
    }

    var cwd = process.cwd();

    var assets = _path.join(cwd, './public/assets');
    var renderPage = require(_path.join(cwd, './.antwar/build/bundleStaticPage.js'));
    var paths = require(_path.join(cwd, './.antwar/build/paths.js'));

    mkdirp.sync(assets);
    ncp(_path.join(cwd, './assets'), assets);

    fs.writeFileSync(
      _path.join(assets, '/main.css'),
      fs.readFileSync('./.antwar/build/main.css')
    );

    mkdirp.sync(_path.join(cwd, './public/blog'));

    var allPaths = paths();
    writePages(cwd, renderPage, allPaths);
    writeIndex(cwd, renderPage);
    writePosts(cwd, renderPage, allPaths);

    // TODO: this should be pushed to a plugin
    //var rss = require(_path.join(cwd, './.antwar/build/bundleStaticRss.js'));
    //fs.writeFileSync(_path.join(process.cwd(), './public/atom.xml'), rss(renderPage));
  });
};

function writePages(root, renderPage, allPaths) {
  Object.keys(allPaths).forEach(function(path) {
    if(path !== 'posts') {
      var publicPath;

      if(path === '/') {
        path = '';

        publicPath = _path.join(root, './public');
      }
      else {
        publicPath = _path.join(root, './public/#' + path);

        mkdirp.sync(publicPath);
      }

      fs.writeFileSync(
        _path.join(publicPath, 'index.html'),
        renderPage('/#' + path, null)
      );
    }
  });
}

function writeIndex(root, renderPage) {
  fs.writeFileSync(
    _path.join(root, './public/blog/index.html'),
    renderPage('/blog', null)
  );
}

function writePosts(root, renderPage, allPaths) {
  Object.keys(allPaths.posts).forEach(function(post) {
    fs.writeFileSync(
      _path.join(root, './public/blog/' + post + '.html'),
      renderPage('/blog' + post)
    );
  });
}
<commit_msg>Tidy up<commit_after>'use strict';
var fs = require('fs');
var _path = require('path');

var mkdirp = require('mkdirp');
var ncp = require('ncp');
var webpack = require('webpack');
var webpackConfig = require('./webpack.coffee').build;


exports.buildDevIndex = function(config) {
  process.env.NODE_ENV = 'dev';

  webpack(webpackConfig(config), function(err) {
    if(err) {
      return console.error(err);
    }

    var cwd = process.cwd();
    var page = require(_path.join(cwd, './.antwar/build/bundleStaticPage.js'));

    fs.writeFileSync(
      _path.join(cwd, './.antwar/build/index.html'),
      page,
      '/antwar_devindex',
      null
    );

    ncp('./assets', _path.join(cwd, './.antwar/build/assets'));
  });
};

exports.build = function(config) {
  process.env.NODE_ENV = 'production';

  webpack(webpackConfig(config), function(err) {
    if(err) {
      return console.error(err);
    }

    var cwd = process.cwd();

    var assets = _path.join(cwd, './public/assets');
    var renderPage = require(_path.join(cwd, './.antwar/build/bundleStaticPage.js'));
    var paths = require(_path.join(cwd, './.antwar/build/paths.js'));

    mkdirp.sync(_path.join(cwd, './public/blog'));
    mkdirp.sync(assets);

    ncp(_path.join(cwd, './assets'), assets);

    fs.writeFileSync(
      _path.join(assets, '/main.css'),
      fs.readFileSync('./.antwar/build/main.css')
    );

    var allPaths = paths();
    writePages(cwd, renderPage, allPaths);
    writeIndex(cwd, renderPage);
    writePosts(cwd, renderPage, allPaths);

    // TODO: this should be pushed to a plugin
    //var rss = require(_path.join(cwd, './.antwar/build/bundleStaticRss.js'));
    //fs.writeFileSync(_path.join(process.cwd(), './public/atom.xml'), rss(renderPage));
  });
};

function writePages(root, renderPage, allPaths) {
  Object.keys(allPaths).forEach(function(path) {
    if(path !== 'posts') {
      var publicPath;

      if(path === '/') {
        path = '';

        publicPath = _path.join(root, './public');
      }
      else {
        publicPath = _path.join(root, './public/#' + path);

        mkdirp.sync(publicPath);
      }

      fs.writeFileSync(
        _path.join(publicPath, 'index.html'),
        renderPage('/#' + path, null)
      );
    }
  });
}

function writeIndex(root, renderPage) {
  fs.writeFileSync(
    _path.join(root, './public/blog/index.html'),
    renderPage('/blog', null)
  );
}

function writePosts(root, renderPage, allPaths) {
  Object.keys(allPaths.posts).forEach(function(post) {
    fs.writeFileSync(
      _path.join(root, './public/blog/' + post + '.html'),
      renderPage('/blog' + post)
    );
  });
}

{'fraction_non_alphanumeric': 0.1857573474001507, 'fraction_numerical': 0.0, 'mean_word_length': 2.97976011994003, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2152621', 'n_tokens_mistral': 1841, 'n_tokens_neox': 1788, 'n_words': 303}