<commit_before>// This script compiles README_template.md 
// into README.md by
//
//  * compiling metadata about examples 
//  * dynamically generating a markdown list of example entries
//  * injecting the list into the template
var _ = require('underscore'),
    fs = require('fs'),
    inputFile = './README_template.md',
    outputFile = './README.md',
    entryDir = 'examples/',
    entryTemplate = _.template(' * [<%= name %>](./examples/<%= name %>) - <%= message %>');

// Read the template for README.md
fs.readFile(inputFile, 'utf8', function (err, template) {

  // Generate the model for the README.md template.
  var model = generateTemplateModel(entryTemplate),

      // Evaluate the README.md template.
      output = _.template(template, model);

  // Write README.md
  fs.writeFile(outputFile, output, function(err) {
    if(err) {
      console.log(err);
    } else {
      console.log("Wrote '" + outputFile + "'!");
    }
  }); 
});

function generateTemplateModel(){
  
  var snapshotsPath = entryDir + 'snapshots/',
      files = fs.readdirSync(snapshotsPath),
      entries = files.map(function(file){
        var msgFile = snapshotsPath + file + '/message.txt',
            message = fs.readFileSync(msgFile, 'utf8');
        message = message.replace('\n','');
        return {
          name: file,
          message: message
        };
      });

  return {
    examples: entries.map(entryTemplate).join('\n')
  };
}
<commit_msg>Added snapshot mechanism for Angular screencast examples. Cleaned up directories (removed half-baked screencast stubs)<commit_after>// This script compiles README_template.md 
// into README.md by
//
//  * compiling metadata about examples 
//  * dynamically generating a markdown list of example entries
//  * injecting the list into the template
//
//  <NAME> 3/2/2014
var _ = require('underscore'),
    fs = require('fs'),
    inputFile = './README_template.md',
    outputFile = './README.md',
    entryDir = 'examples/',
    snapshotsPath = entryDir + 'snapshots/',
    entryTemplate = _.template(' * [<%= name %>](./examples/<%= name %>)<%= message %>');

// Read the template for README.md
fs.readFile(inputFile, 'utf8', function (err, template) {

  // Generate the model for the README.md template.
  var model = generateTemplateModel(entryTemplate),

      // Evaluate the README.md template.
      output = _.template(template, model);

  // Write README.md
  fs.writeFile(outputFile, output, function(err) {
    if(err) {
      console.log(err);
    } else {
      console.log("Wrote '" + outputFile + "'!");
    }
  }); 
});

function generateTemplateModel(){
  
  var files = fs.readdirSync(snapshotsPath),
      entries = files.map(function(file){
        return { name: file, message: getMessage(file) };
      });

  return { examples: entries.map(entryTemplate).join('\n') };
}
function getMessage(file){
  var msgFile = snapshotsPath + file + '/message.txt';
  if(fs.existsSync(msgFile)){
    var msg = fs.readFileSync(msgFile, 'utf8');
    return ' - ' + msg.replace('\n','');
  }
  return '';
}

{'fraction_non_alphanumeric': 0.15414634146341463, 'fraction_numerical': 0.0032520325203252032, 'mean_word_length': 3.0, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '3604857', 'n_tokens_mistral': 964, 'n_tokens_neox': 923, 'n_words': 234}