Skip to content

Instantly share code, notes, and snippets.

@mmmpa
Created April 26, 2014 06:07
Show Gist options
  • Save mmmpa/11312981 to your computer and use it in GitHub Desktop.
Save mmmpa/11312981 to your computer and use it in GitHub Desktop.
var fs = require('fs');
module.exports = function (grunt) {
grunt.registerTask('listTsReference', 'listing .ts', function () {
var def = grunt.config('listTsReference').def;
var starter = grunt.config('listTsReference').src;
var dest = grunt.config('listTsReference').dest;
var ts = def.concat(read('./'));
var ref = ts.map(function (path, i, self) {
if (path === dest) {
return null;
}
return '/// <reference path="' + path + '" />';
});
var txt = ref.join('\n');
fs.writeFileSync(dest, txt);
grunt.log.write(txt).ok();
});
}
function read(start) {
var ts = [];
var list = fs.readdirSync(start);
list.forEach(function (name, i, self) {
var path = start + name;
var stat = fs.statSync(path);
if (stat.isDirectory()) {
ts = ts.concat(read(path + '/'));
} else {
if (name.match(/.*\.ts$/)) {
ts.push(path)
}
}
});
return ts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment