Permalink
Browse files

added search and colors... that's it... super simple

  • Loading branch information...
1 parent 654759b commit f76238029eddea1af1cd58ff5d2b0153468de34f @csanz csanz committed Jun 3, 2011
Showing with 212 additions and 0 deletions.
  1. +6 −0 History.md
  2. +22 −0 LICENSE
  3. +29 −0 Readme.md
  4. +47 −0 lib/cli.js
  5. +82 −0 lib/ntodo.js
  6. +26 −0 package.json
View
@@ -0,0 +1,6 @@
+0.0.1 / 2011-06-2
+==================
+
+ * Added TODO Search and cool colors
+ * Started the project @Csanz
+
View
@@ -0,0 +1,22 @@
+Copyright (c) 2011 Geeklist, Inc
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,29 @@
+ntodo
+=====
+
+A simple CLI TODO parser for the lazy coder
+
+Installation
+------------
+
+With [npm](http://github.com/isaacs/npm):
+
+ npm install ntodo
+
+CLI
+---
+
+ Usage: ntodo [Options]
+
+ [Options]
+
+ -h, --help Display help
+ -p, --path It sets the path
+ ex: ntodo -p .
+ ex: ntodo -p ../
+
+ you can also skip the -p ;-)
+
+ ntodo .
+ ntod ../
+
View
@@ -0,0 +1,47 @@
+#!/usr/bin/env node
+
+var os = require('os')
+ , ntodo = require('./ntodo')
+ , opt = require('optimist').argv
+ , colors = require('colors')
+ , sys = require('sys');
+
+/**
+ * Run
+ *
+ * @api private
+ */
+run = function() {
+ path = opt._;
+ if (opt._.length === 0) {
+ opt._ = null;
+ }
+ opt.help = opt.help || opt.h;
+ opt.path = opt.path || opt.p;
+ if (opt.help) {
+ help();
+ }else{
+ if (path!="" || opt.path) {
+ dir = path[0] || opt.path;
+ if (dir[0]==null && opt.path==true)
+ return console.log("\t\nmissing text! try again\n".red.bold);
+ ntodo.search(dir)
+ }else{
+ help();
+ }
+ }
+}
+/**
+ * Get yam user
+ *
+ * @api private
+ */
+function help(){
+ console.log("\nntodo <PATH>\n".green)
+ console.log("\tExamples:".white.bold)
+ console.log("\t\tntodo .".green)
+ console.log("\t\tntodo ../".green)
+ console.log("\t\tntodo -p ../".green)
+ console.log("\n")
+}
+run();
View
@@ -0,0 +1,82 @@
+var fs = require('fs')
+ , colors = require('colors')
+ , path = require('path');
+
+/**
+ * Search for Todos
+ *
+ * @param {Pointer} callback
+ * @api public
+ */
+exports.search = function(path){
+ console.log("\n::::::::::::::::::::::::::::::::::::::::".green)
+ console.log("::: Searching TODOs here: ".green + path)
+ console.log("::::::::::::::::::::::::::::::::::::::::\n".green)
+ traverseDirectory(path)
+}
+
+/**
+ * Traverse Directory
+ *
+ * @param {Object} file
+ * @api private
+ */
+
+function traverseDirectory(file){
+ fs.readdir(file, function(err, files){
+ if (err) throw err;
+ files.map(function(path){
+ return file + '/' + path;
+ }).forEach(parseFile);
+ });
+}
+
+/**
+ * Parse File
+ *
+ * @param {Object} file
+ * @api private
+ */
+
+function parseFile(file) {
+ // ensure file exists
+ fs.lstat(file, function(err, stat){
+ if (err) throw err;
+ // file
+ if (stat.isFile()) {
+ if(file.match(/\.js$/) ||
+ file.match(/\.jade$/) ||
+ file.match(/\.styl$/) )
+ lookForTodos(file);
+ // directory
+ } else if (stat.isDirectory()) {
+ //console.log(file);
+ traverseDirectory(file)
+ }
+ });
+}
+
+/**
+ * Look for Todos! Whooohoo
+ *
+ * @param {Object} file
+ * @api private
+ */
+
+function lookForTodos(file){
+ fs.readFile(file, 'utf8', function(err, data){
+ if (err) throw err;
+ var regex = new RegExp(/\/\/.*TODO\:\s.*?\n/g);
+ var test = data.match(regex);
+ if(test){
+ console.log('FILE: '.green.bold + file.green);
+ console.log('\n' +test +'');
+ }
+ });
+}
+
+// TODO: Cache all files with the datestamp, do not parse if they haven't been updated
+// TODO: Integrate with Git? Perhaps
+// TODO: OH going crazy here, integrate with Gihub?? Imjustaying
+// TODO: Add folder exclusion for /public/javascript/pluggins for instance
+// TODO: Ok, of course add file water ;)
View
@@ -0,0 +1,26 @@
+{
+ "name": "ntodo",
+ "description": "A simple CLI TODO parser for the lazy coder",
+ "keywords": ["todo", "cli", "github", "utils"],
+ "author": "Christian Sanz <chris@geekli.st>",
+ "version": "0.0.1",
+ "licenses": [{
+ "type": "MIT",
+ "url": "http://github.com/csanz/nyam/raw/master/LICENSE"
+ }],
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/geeklist/ntodo.git"
+ },
+ "engines": {
+ "node": ">=0.4.0"
+ },
+ "dependencies": {
+ "optimist": ">= 0.1.5"
+ , "colors": "*"
+ },
+ "main" : "./lib/ntodo",
+ "bin": {
+ "nyam": "./lib/cli.js"
+ }
+}

0 comments on commit f762380

Please sign in to comment.