1
1
fs = require ' fs'
2
2
colors = require ' colors'
3
3
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,
5
5
# searching for a set of patterns to annotate.
6
6
#
7
7
# Samples:
@@ -11,11 +11,11 @@ colors = require 'colors'
11
11
# FIXME: Keep up with things to fix.
12
12
#
13
13
class Notes
14
-
14
+
15
15
# 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.
19
19
#
20
20
@patterns =
21
21
todo :
@@ -30,33 +30,33 @@ class Notes
30
30
fixme :
31
31
regexp : / ^ . * (#| \/\/ | \/\* )\s * FIXME\W * /
32
32
label : " ☂ FIXME" .underline .red
33
-
33
+
34
34
# You can also customize what types of file extensions will be filtered out of annotation.
35
35
@filterExtensions = [
36
- " \\ .jpg" , " \\ .jpeg" , " \\ .mov" , " \\ .mp3" , " \\ .gif" , " \\ .png" ,
36
+ " \\ .jpg" , " \\ .jpeg" , " \\ .mov" , " \\ .mp3" , " \\ .gif" , " \\ .png" ,
37
37
" \\ .log" , " \\ .bin" , " \\ .psd" , " \\ .swf" , " \\ .fla" , " \\ .ico"
38
38
]
39
-
39
+
40
40
# You can filter out full directory trees
41
- @filterDirectories = [" node_modules" ]
42
-
41
+ @filterDirectories = [" node_modules" , " components " , " bower_components " ]
42
+
43
43
@skipHidden = true
44
-
44
+
45
45
@concurrentFiles = 30
46
-
46
+
47
47
constructor : (@rootDir ) ->
48
48
# Constructor must take at least a root directory as first argument
49
49
throw " Root directory is required." unless @rootDir
50
-
50
+
51
51
annotate : ->
52
52
files = []
53
53
filesUnderDirectory @rootDir , (file ) ->
54
54
files .push file
55
-
55
+
56
56
# Simple way to control # of files being opened at a time...
57
57
concurrency = 0
58
58
output = {}
59
-
59
+
60
60
# TODO: Clean this up some. The implementation got much more complex than I originally planned.
61
61
run = ->
62
62
while files .length > 0 and concurrency < Notes .concurrentFiles
@@ -71,19 +71,19 @@ class Notes
71
71
spaces = spaces .substring (0 , spaces .length - 1 ) for n in (lineNum+ 1 ).toString ()
72
72
lineNumStr = " Line #{ lineNum} :" .grey
73
73
output[filePath] += " #{ lineNumStr}#{ spaces}#{ pattern .label } #{ line} \n "
74
-
74
+
75
75
onCompletion = (filePath ) ->
76
76
# Spit out the results for the file
77
77
console .log output[filePath] if output[filePath]?
78
78
concurrency--
79
79
run ()
80
-
80
+
81
81
file = files .shift ()
82
82
# Process the file line-by-line
83
83
eachLineIn file, onLine, onCompletion
84
84
concurrency++
85
85
run ()
86
-
86
+
87
87
filesUnderDirectory = (dir , fileCallback ) ->
88
88
try
89
89
files = fs .readdirSync dir
@@ -101,7 +101,7 @@ class Notes
101
101
console .log " #{ error} ... continuing."
102
102
else
103
103
throw error
104
-
104
+
105
105
eachLineIn = (filePath , onLine , onCompletion ) ->
106
106
fs .readFile filePath, (err , data ) ->
107
107
throw err if err?
@@ -110,4 +110,4 @@ class Notes
110
110
onLine (line, i+ 1 , filePath) for line, i in lines
111
111
onCompletion (filePath)
112
112
113
- module .exports = Notes
113
+ module .exports = Notes
0 commit comments