CoffeeScript Lately+ Add-on for Todo.txt
Unsatistied by the ramp-up time and extra libraries needed to run my todo.txt lately+ add-on posted in the last blog post, I decided to write a CoffeeScript version for Node.js. I thought it would avoid the ramp-up needed for groovyclient and be faster to boot.
One of the good things about building on top of Node is that you have alot of libraries to draw upon. A quick Google search surfaced a libraries to parse and manipulate dates in a way similar to Groovy and another to produce colored console text, moment and colors reqpectively. Both of the aforementioned are available as npm packages. To run our script, we need to install the dependencies along with our todotxt-coffee package.
npm install moment npm install colors npm install todotxt-coffee
We can see that much of the heavy lifting is done by the CoffeeScript library and most of the logic below is determining what and how to print it. colors decorates strings with a properties for a base set of colors and styling(underline, bold, italic, etc) but you can create your own as well.
printTask = (d,r) -> console.log d.format('YYYY-MM-DD').green + r.yellow printTasks = () -> if project is undefined for task in todos.list date = moment(task.date().toString().trim()) restOfLine = task.raw().substr(12) printTask(date, restOfLine) if startDate <= date else tasks = todos.byProject(project) for t in tasks date = moment(t.date().toString().trim()) restOfLine = t.raw().substr(12) printTask(date, restOfLine) if startDate <= date
This and my other add-ons live here
Living on a Chromebook
Creating Mobile Apps for Firefox OS article posted