Skip to content

Commit 1a8c87b

Browse files
committed
Updated code to read from .gitignore when available in target directory
For current directories use 'notes .'
1 parent 381dc27 commit 1a8c87b

File tree

5 files changed

+124
-63
lines changed

5 files changed

+124
-63
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
node-notes is a node.js version of Rails' "rake notes" functionality. It allows you
2-
to put comments in your code and then have them annotated across your whole project.
1+
node-notes is a node.js version of Rails' "rake notes" functionality. It allows you
2+
to put comments in your code and then have them annotated across your whole project. Uses local ``.gitignore`` to ignore files or default ignore list.
33

44
### Installation:
55

6-
76
npm install notes -g
87

98
### Usage:
109

1110
$ notes # will search for notes in cwd
11+
$ notes . # will search for notes in cwd considers .gitignore to ignore files
1212
$ notes lib/ test/ # will search only in lib and test
1313

1414
### What It Does:
@@ -18,10 +18,10 @@ For example, if a file contained these lines somewhere in it:
1818
code...
1919
# NOTE: This line should get annoated by Notes.
2020
# OPTIMIZE Make things faster!
21-
21+
2222
more code...
2323
# TODO: Annotate your tasks.
24-
24+
2525
yet more code...
2626
# FIXME: Keep up with things to fix.
2727

lib/notes.js

+78-47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+11-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@
1212
"node": ">= v0.4.7"
1313
},
1414
"contributors": [
15-
{ "name": "Veselin Todorov",
16-
"email": "[email protected]" }
17-
],
15+
{
16+
"name": "Anudeep Potlapally",
17+
"email": "[email protected]"
18+
},
19+
{
20+
"name": "Veselin Todorov",
21+
"email": "[email protected]"
22+
}
23+
],
1824
"dependencies": {
19-
"colors": "*"
25+
"colors": "*",
26+
"minimatch": "https://github.com/isaacs/minimatch/tarball/master"
2027
},
2128
"devDependencies": {
2229
"coffee-script": ">= 1.1.1"

src/notes.coffee

+29-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1+
'use strict';
2+
13
fs = require 'fs'
24
colors = require 'colors'
5+
path = require 'path'
6+
minimatch = require 'minimatch'
7+
8+
getFilterDirectories = (rootDir) ->
9+
defaultPatterns = ["node_modules", "components", "bower_components"]
10+
rootDir = rootDir || '.'
11+
try
12+
data = fs.readFileSync(path.join(rootDir, '.gitignore'), 'utf8')
13+
if data
14+
data.split("\n")
15+
else
16+
defaultPatterns
17+
catch err
18+
defaultPatterns
319

420
# The Notes class holds all the logic needed for crawling a directory of files,
521
# searching for a set of patterns to annotate.
@@ -37,20 +53,18 @@ class Notes
3753
"\\.log", "\\.bin", "\\.psd", "\\.swf", "\\.fla", "\\.ico"
3854
]
3955

40-
# You can filter out full directory trees
41-
@filterDirectories = ["node_modules", "components", "bower_components"]
42-
4356
@skipHidden = true
4457

4558
@concurrentFiles = 30
4659

4760
constructor: (@rootDir) ->
4861
# Constructor must take at least a root directory as first argument
4962
throw "Root directory is required." unless @rootDir
63+
@filterDirectories = getFilterDirectories(@rootDir)
5064

5165
annotate: ->
5266
files = []
53-
filesUnderDirectory @rootDir, (file) ->
67+
@filesUnderDirectory @rootDir, (file) ->
5468
files.push file
5569

5670
# Simple way to control # of files being opened at a time...
@@ -84,14 +98,22 @@ class Notes
8498
concurrency++
8599
run()
86100

87-
filesUnderDirectory = (dir, fileCallback) ->
101+
isInFilteredDirectories: (f) ->
102+
result = false
103+
104+
for pattern in @filterDirectories
105+
result = result || minimatch(f, pattern)
106+
107+
!result
108+
109+
filesUnderDirectory: (dir, fileCallback) ->
88110
try
89111
files = fs.readdirSync dir
90112
# If it's another directory, make a recursive call into it
91113
if files?
92114
files = (f for f in files when !f.match(/^\./)) if Notes.skipHidden # Skip hidden files/directories
93-
files = (f for f in files when Notes.filterDirectories.indexOf(f) < 0) # Skip directories that should be filtered
94-
filesUnderDirectory("#{dir}/#{f}", fileCallback) for f in files
115+
files = (f for f in files when @isInFilteredDirectories(f)) # Skip directories that should be filtered
116+
@filesUnderDirectory("#{dir}/#{f}", fileCallback) for f in files
95117
catch error
96118
if error.code is "ENOTDIR"
97119
filter = ///(#{Notes.filterExtensions.join('|')})$/// # skip files matching filterExtensions

0 commit comments

Comments
 (0)