Skip to content

Instantly share code, notes, and snippets.

@jonschlinkert
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonschlinkert/9735b4ef4b55b22fdf99 to your computer and use it in GitHub Desktop.
Save jonschlinkert/9735b4ef4b55b22fdf99 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var path = require('path');
var glob = require('globby');
var _ = require('lodash');
var pattern = 'test/fixtures/remarked_pending/**/*.{md,html}';
var len = 'answer_to_life_the_universe_and_everything'.length;
var delim = new Array(len).join('~');
function writeFixtures(filepath) {
var fixtures = _.reduce(glob.sync(filepath), function (acc, fp) {
acc[path.basename(fp)] = fs.readFileSync(fp, 'utf8');
return acc;
}, {});
var pairs = _.reduce(fixtures, function (acc, value, key, o) {
var name = path.basename(key, path.extname(key));
acc[name] = {md: o[name + '.md'].trim(), html: o[name + '.html'].trim()};
return acc;
}, {});
return _.reduce(pairs, function (acc, value, key, o) {
acc.push(delim);
acc.push(key + '\n');
acc.push('.');
acc.push(value['md']);
acc.push('.');
acc.push(value['html']);
acc.push('.' + '\n');
return acc;
}, []).join('\n');
}
console.log(writeFixtures(pattern));
// > test/fixtures/remarked/remarked.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment