Created
April 26, 2014 06:07
-
-
Save mmmpa/11312981 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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