Skip to content

Instantly share code, notes, and snippets.

@garbados
Created July 14, 2013 17:51
Show Gist options
  • Save garbados/5995080 to your computer and use it in GitHub Desktop.
Save garbados/5995080 to your computer and use it in GitHub Desktop.
Except from the Yeoman template [generator-couchapp](https://github.com/garbados/generator-couchapp) that recursively copies everything in the template directory accordingly to some simple rules. Cheap time-saver.
CouchappGenerator.prototype.app = function app() {
// copy everything in `templates` based on rules:
// - if dir, this.directory
// - if filename starts with '__', ignore
// - if filename starts with '_', this.template
// - else, this.copy
var files = fs.readdirSync(__dirname + "/templates");
for(var i in files){
var stat = fs.statSync(__dirname + "/templates/" + files[i]);
if(stat.isDirectory()){
this.directory(files[i]);
}else{
if(files[i][0] === '_'){
if(files[i][1] === '_'){
// ignore the file; allow later directives to handle it
}else{
this.template(files[i], files[i].slice(1));
}
}else{
this.copy(files[i], files[i]);
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment