+39
-36
| (function() { | ||
| var Notes, colors, fs; | ||
| fs = require('fs'); | ||
| colors = require('colors'); | ||
| Notes = (function() { | ||
| var eachLineIn, filesUnderDirectory; | ||
| Notes.patterns = { | ||
@@ -25,12 +29,16 @@ todo: { | ||
| }; | ||
| Notes.filterExtensions = ["\\.jpg", "\\.jpeg", "\\.mov", "\\.mp3", "\\.gif", "\\.png", "\\.log", "\\.bin", "\\.psd", "\\.swf", "\\.fla", "\\.ico"]; | ||
| Notes.filterDirectories = []; | ||
| Notes.filterDirectories = ["node_modules"]; | ||
| Notes.skipHidden = true; | ||
| Notes.concurrentFiles = 30; | ||
| function Notes(rootDir) { | ||
| this.rootDir = rootDir; | ||
| if (!this.rootDir) { | ||
| throw "Root directory is required."; | ||
| } | ||
| if (!this.rootDir) throw "Root directory is required."; | ||
| } | ||
| Notes.prototype.annotate = function() { | ||
@@ -49,3 +57,3 @@ var concurrency, files, output, run; | ||
| onLine = function(line, lineNum, filePath) { | ||
| var key, lineNumStr, n, pattern, spaces, _ref, _results2; | ||
| var key, lineNumStr, n, pattern, spaces, _i, _len, _ref, _ref2, _results2; | ||
| _ref = Notes.patterns; | ||
@@ -55,19 +63,18 @@ _results2 = []; | ||
| pattern = _ref[key]; | ||
| _results2.push((function() { | ||
| var _i, _len, _ref2; | ||
| if (line.match(pattern.regexp) != null) { | ||
| if (output[filePath] == null) { | ||
| output[filePath] = ("* " + filePath + "\n").green; | ||
| } | ||
| line = line.replace(pattern.regexp, ''); | ||
| spaces = ' '; | ||
| _ref2 = (lineNum + 1).toString(); | ||
| for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | ||
| n = _ref2[_i]; | ||
| spaces = spaces.substring(0, spaces.length - 1); | ||
| } | ||
| lineNumStr = ("Line " + lineNum + ":").grey; | ||
| return output[filePath] += " " + lineNumStr + spaces + pattern.label + " " + line + "\n"; | ||
| if (line.match(pattern.regexp) != null) { | ||
| if (output[filePath] == null) { | ||
| output[filePath] = ("* " + (filePath.replace('//', '/')) + "\n").green; | ||
| } | ||
| })()); | ||
| line = line.replace(pattern.regexp, ''); | ||
| spaces = ' '; | ||
| _ref2 = (lineNum + 1).toString(); | ||
| for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | ||
| n = _ref2[_i]; | ||
| spaces = spaces.substring(0, spaces.length - 1); | ||
| } | ||
| lineNumStr = ("Line " + lineNum + ":").grey; | ||
| _results2.push(output[filePath] += " " + lineNumStr + spaces + pattern.label + " " + line + "\n"); | ||
| } else { | ||
| _results2.push(void 0); | ||
| } | ||
| } | ||
@@ -77,5 +84,3 @@ return _results2; | ||
| onCompletion = function(filePath) { | ||
| if (output[filePath] != null) { | ||
| console.log(output[filePath]); | ||
| } | ||
| if (output[filePath] != null) console.log(output[filePath]); | ||
| concurrency--; | ||
@@ -92,2 +97,3 @@ return run(); | ||
| }; | ||
| filesUnderDirectory = function(dir, fileCallback) { | ||
@@ -104,5 +110,3 @@ var f, files, filter, _i, _len, _results; | ||
| f = files[_i]; | ||
| if (!f.match(/^\./)) { | ||
| _results.push(f); | ||
| } | ||
| if (!f.match(/^\./)) _results.push(f); | ||
| } | ||
@@ -117,5 +121,3 @@ return _results; | ||
| f = files[_i]; | ||
| if (Notes.filterDirectories.indexOf(f) < 0) { | ||
| _results.push(f); | ||
| } | ||
| if (Notes.filterDirectories.indexOf(f) < 0) _results.push(f); | ||
| } | ||
@@ -134,5 +136,3 @@ return _results; | ||
| filter = RegExp("(" + (Notes.filterExtensions.join('|')) + ")$"); | ||
| if (!dir.match(filter)) { | ||
| return fileCallback(dir); | ||
| } | ||
| if (!dir.match(filter)) return fileCallback(dir); | ||
| } else if (error.code === "ELOOP") { | ||
@@ -145,8 +145,7 @@ return console.log("" + error + "... continuing."); | ||
| }; | ||
| eachLineIn = function(filePath, onLine, onCompletion) { | ||
| return fs.readFile(filePath, function(err, data) { | ||
| var i, line, lines, _len; | ||
| if (err != null) { | ||
| throw err; | ||
| } | ||
| if (err != null) throw err; | ||
| lines = data.toString('utf-8').split("\n"); | ||
@@ -160,5 +159,9 @@ for (i = 0, _len = lines.length; i < _len; i++) { | ||
| }; | ||
| return Notes; | ||
| })(); | ||
| module.exports = Notes; | ||
| }).call(this); |
+1
-1
@@ -5,3 +5,3 @@ { | ||
| "description": "a node.js version of Rails' \"rake notes\" functionality", | ||
| "version": "0.0.2", | ||
| "version": "0.0.3", | ||
| "repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
+10
-17
| node-notes is a node.js version of Rails' "rake notes" functionality. It allows you | ||
| to put comments in your code and then have them annotated across your whole project. | ||
| To install: | ||
| ### Installation: | ||
| npm install notes | ||
| npm install notes -g | ||
| ### Usage: | ||
| $ notes # will search for notes in cwd | ||
| $ notes lib/ test/ # will search only in lib and test | ||
| ### What It Does: | ||
| For example, if a file contained these lines somewhere in it: | ||
@@ -27,16 +35,1 @@ | ||
| Line 11: ☂ FIXME Keep up with things to fix. | ||
| And this would collect all of the notes across your project. | ||
| Here's how you could use this in a Cakefile task (this is CoffeeScript). | ||
| Notes = require 'notes' | ||
| task 'notes', 'Print out notes from project', -> | ||
| notes = new Notes(__dirname) | ||
| notes.annotate() | ||
| As you can see, the usage is very simple. You just pass in a root directory path when | ||
| creating a notes object, then call annotate(). Notes has a handful of other options | ||
| you can customize and fine-tune for your needs that you can see in the code. | ||
+1
-1
@@ -67,3 +67,3 @@ fs = require 'fs' | ||
| if line.match(pattern.regexp)? | ||
| output[filePath] = "* #{filePath}\n".green unless output[filePath]? | ||
| output[filePath] = "* #{filePath.replace('//','/')}\n".green unless output[filePath]? | ||
| line = line.replace(pattern.regexp, '') | ||
@@ -70,0 +70,0 @@ # Make the output kinda pretty... |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
0
-100%11534
-4.23%141
-8.44%35
-16.67%