11fs = require ' fs'
22colors = require ' colors'
33
4- # The Notes class holds all the logic needed for crawling a directory of files,
4+ # The Notes class holds all the logic needed for crawling a directory of files,
55# searching for a set of patterns to annotate.
66#
77# Samples:
@@ -11,11 +11,11 @@ colors = require 'colors'
1111# FIXME: Keep up with things to fix.
1212#
1313class Notes
14-
14+
1515 # Defines the patterns that will be checked during file annotating.
16- # If you want to run this on something other than ruby, coffeesciprt, or javascript
17- # files then you may need to change this. The default pattern is looking for a line
18- # beginning with a comment and then followed with "TODO", "NOTE", or "OPTIMIZE" keywords.
16+ # If you want to run this on something other than ruby, coffeesciprt, or javascript
17+ # files then you may need to change this. The default pattern is looking for a line
18+ # beginning with a comment and then followed with "TODO", "NOTE", or "OPTIMIZE" keywords.
1919 #
2020 @patterns =
2121 todo :
@@ -30,33 +30,33 @@ class Notes
3030 fixme :
3131 regexp : / ^ . * (#| \/\/ | \/\* )\s * FIXME\W * /
3232 label : " ☂ FIXME" .underline .red
33-
33+
3434 # You can also customize what types of file extensions will be filtered out of annotation.
3535 @filterExtensions = [
36- " \\ .jpg" , " \\ .jpeg" , " \\ .mov" , " \\ .mp3" , " \\ .gif" , " \\ .png" ,
36+ " \\ .jpg" , " \\ .jpeg" , " \\ .mov" , " \\ .mp3" , " \\ .gif" , " \\ .png" ,
3737 " \\ .log" , " \\ .bin" , " \\ .psd" , " \\ .swf" , " \\ .fla" , " \\ .ico"
3838 ]
39-
39+
4040 # You can filter out full directory trees
41- @filterDirectories = [" node_modules" ]
42-
41+ @filterDirectories = [" node_modules" , " components " , " bower_components " ]
42+
4343 @skipHidden = true
44-
44+
4545 @concurrentFiles = 30
46-
46+
4747 constructor : (@rootDir ) ->
4848 # Constructor must take at least a root directory as first argument
4949 throw " Root directory is required." unless @rootDir
50-
50+
5151 annotate : ->
5252 files = []
5353 filesUnderDirectory @rootDir , (file ) ->
5454 files .push file
55-
55+
5656 # Simple way to control # of files being opened at a time...
5757 concurrency = 0
5858 output = {}
59-
59+
6060 # TODO: Clean this up some. The implementation got much more complex than I originally planned.
6161 run = ->
6262 while files .length > 0 and concurrency < Notes .concurrentFiles
@@ -71,19 +71,19 @@ class Notes
7171 spaces = spaces .substring (0 , spaces .length - 1 ) for n in (lineNum+ 1 ).toString ()
7272 lineNumStr = " Line #{ lineNum} :" .grey
7373 output[filePath] += " #{ lineNumStr}#{ spaces}#{ pattern .label } #{ line} \n "
74-
74+
7575 onCompletion = (filePath ) ->
7676 # Spit out the results for the file
7777 console .log output[filePath] if output[filePath]?
7878 concurrency--
7979 run ()
80-
80+
8181 file = files .shift ()
8282 # Process the file line-by-line
8383 eachLineIn file, onLine, onCompletion
8484 concurrency++
8585 run ()
86-
86+
8787 filesUnderDirectory = (dir , fileCallback ) ->
8888 try
8989 files = fs .readdirSync dir
@@ -101,7 +101,7 @@ class Notes
101101 console .log " #{ error} ... continuing."
102102 else
103103 throw error
104-
104+
105105 eachLineIn = (filePath , onLine , onCompletion ) ->
106106 fs .readFile filePath, (err , data ) ->
107107 throw err if err?
@@ -110,4 +110,4 @@ class Notes
110110 onLine (line, i+ 1 , filePath) for line, i in lines
111111 onCompletion (filePath)
112112
113- module .exports = Notes
113+ module .exports = Notes
0 commit comments