Skip to content

Instantly share code, notes, and snippets.

@lowellbander
Last active June 3, 2016 03:29
Show Gist options
  • Select an option

  • Save lowellbander/e4793e6c5b2bdfb5d449d3399d97ae09 to your computer and use it in GitHub Desktop.

Select an option

Save lowellbander/e4793e6c5b2bdfb5d449d3399d97ae09 to your computer and use it in GitHub Desktop.
// run me in the desired directory: `node --harmony genPieces.js`
var fs = require('fs');
var directory = process.cwd();
String.prototype.contains = _ => this.indexOf(_) != -1;
var pieces = fs.readdirSync(directory)
.filter(_ => _.contains('.png') || _.contains('jpg'))
.map(_ => {
var title = _.substring(0, _.indexOf('.'));
return '\nnew Piece({\n\ttitle: \'' + title + '\',\n\t'
+ 'description: \'a description for ' + title + '\',\n\t'
+ 'photoURL: \'photos/' + _ + '\'\n})';
}).join(',');
console.log('[' + pieces + ']');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment