Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
introducing ./task.js, THE new javascript task runner automation framework

why ./task.js?

One word: task automation. It's basically zero effort and you can use the ./task.js package manager to handle any repetitive tasks. You can use ./task.js to automate everything with minimum effort.

./task.js provides the structure, order, and authority that you as a developer so desperately crave. ./task.js will also take responsibility for your actions if you need it to. It's what everybody is using now. ./task.js is the new hotness. It's all about ./task.js now, just like that.

This is compared to npm run/bash scripts, which are:

  • scary
  • not cross-platformant for deploying to windows server 2003
  • old news. Nobody uses bash these days.

getting started

To install ./task.js, first install node.js.

Now you'll need to generate some scaffolding for your project.

You can use the following scaffold generator:

#!/usr/bin/env node
var fs = require('fs');
['browser','static','style'].forEach(fs.mkdir);
fs.writeFile('task.js', '#!/usr/bin/env node\n', { mode: 0775 });

browser code goes in browser/, stylesheets go in style/, static assets go in static/. You are free to change these directory names to be whatever you want. Just modify the scaffold generator.

Now you can get started writing your ./task.js script. Here is an example script that uses the browserify, watchify, and catw plugins published to the ./task.js plugin repository:

#!/usr/bin/env node

var fs = require('fs');
var browserify = require('browserify');
var watchify = require('watchify');
var catw = require('catw');

var cmd = process.argv[2];
if (cmd === 'build') build({ watch: false })
else if (cmd === 'watch') build({ watch: true })
else usage(1)

function build (opts) {
  var js = opts.watch ? watchify : browserify;
  js('./browser/main.js').bundle()
    .pipe(fs.createWriteStream('static/bundle.js'))
  ;
  
  var css = catw('style/*.css', { watch: opts.watch });
  css.on('stream', function (stream) {
    stream.pipe(fs.createWriteStream('static/bundle.css'));
  });
}

function usage (code) {
  console.error('usage: ./task.js { build | watch }');
  if (code) process.exit(code);
}

install

To install ./task.js, first install node.js.

@NamelessCoder
Copy link

NamelessCoder commented Jan 8, 2014

Please make a bash plugin.

@pvorb
Copy link

pvorb commented Jan 8, 2014

@jamwaffles: Grunt is for all lovers of huge monolithic frameworks like jQuery. ./task.js is better cause you decide what it does and how it behaves. It is immediately understood by every programmer who knows Node.js. You can achieve the same without having to learn anything new. It's pointless to tie oneself to a framework that has only the benefit of needing a plugin for each and every feature one needs. Use modular code, not frameworks. That's the Unix way.

@substack: You can't simply call ./task.js from a CMD prompt on any Windows version, btw. So it's not cross-platform either. :(

@donaldpipowitch
Copy link

donaldpipowitch commented Jan 8, 2014

I think every new JS developer would benefit from your knowledge if you would write this in a non-ironic way. I don't want to rant - that is my honest opinion. How about writing examples of tasks with frameworks like grunt or gulp and without any frameworks side-by-side in a serious and well explained fashion? And maybe even with bash as an additional example? Truth is: Grunt plugins have a clear interface and good docs so that everybody can use them. New JS developers maybe don't know what ['browser','static','style'].forEach(fs.mkdir) does and so they use more bloated frameworks like Grunt even if they don't need them.

@millermedeiros
Copy link

millermedeiros commented Jan 8, 2014

@substack nailed it. Been saying the same thing ever since grunt got popular. Plugins suck, no need for propriety task runners: http://blog.millermedeiros.com/node-js-ant-grunt-and-other-build-tools/

@sindresorhus
Copy link

sindresorhus commented Jan 8, 2014

lol

@alanhoff
Copy link

alanhoff commented Jan 8, 2014

It doesn't run on IE7 :(

@idx3d
Copy link

idx3d commented Jan 8, 2014

Haha, its nice tool

@jasonpincin
Copy link

jasonpincin commented Jan 8, 2014

@pvorb +1 1st post. I laughed.

@rafaelrinaldi
Copy link

rafaelrinaldi commented Jan 8, 2014

LOL

@jmeiss
Copy link

jmeiss commented Jan 9, 2014

Ah ah love it!

@pvorb
Copy link

pvorb commented Jan 9, 2014

@jasonpincin nice to hear

@h2non
Copy link

h2non commented Jan 9, 2014

Nobody uses bash these days? I feel myself like an old guy xD

@radum
Copy link

radum commented Jan 9, 2014

What, I was doing all this manually and now you are telling me you'll had this figured out and now got bored about it?!?!?!

Damn I need to stream the news more often so I can keep up.

@timkock
Copy link

timkock commented Jan 9, 2014

lolz, for a moment I thought not another %&^%#$%@$# task runner :P

@poeticninja
Copy link

poeticninja commented Jan 9, 2014

:)

@shama
Copy link

shama commented Jan 10, 2014

Needs more holy war. You forgot to include a style guide.

@yocontra
Copy link

yocontra commented Jan 10, 2014

Missing an example that isn't just concating files

@spencercarnage
Copy link

spencercarnage commented Jan 10, 2014

Needs more auto-magic.

@cowboy
Copy link

cowboy commented Jan 10, 2014

but how does it jquery

@adambiggs
Copy link

adambiggs commented Jan 10, 2014

Eww, don't make me write code! I got into coding so I could learn to write config!

@raffi-minassian
Copy link

raffi-minassian commented Jan 13, 2014

LOL!

@nicovalencia
Copy link

nicovalencia commented Jan 16, 2014

👍 I lol'd

@shanestillwell
Copy link

shanestillwell commented Jan 20, 2014

Sorry, this task automator will NEVER take off until it has a cool logo. I'll need to get some stickers too before I even give this a look.

@mciparelli
Copy link

mciparelli commented Jan 25, 2014

Please, let the community choose their own THE.

@mciparelli
Copy link

mciparelli commented Jan 25, 2014

I'd agree with you if you just stick to write the (GREAT) packages you frequently write for the community instead of just this kind of gists which demonstrates that you are a person who thinks that the solutions you write are better than everyone else's. Even if the community agrees with that, Im not sure they will agree with your manners.

@BadOPCode
Copy link

BadOPCode commented Aug 3, 2014

WHAT IS THIS MADNESS?!?! Don't you know we should reinvent the wheel over and over because it makes our lives easier?
How about a library for reading JavaScript files in Node JS. I get so confused by 'require.' If they could just add about a dozen more steps to 'require' it would make it so much easier and more readable.
LOL I actually ended up here because I was trying to figure out what grandiose thing that these task runners are supposed to do that's better than just doing it yourself. Their mush mouth explanations and this gist tells me there is nothing great about them. In a weird way I got my answer.

@aluanhaddad
Copy link

aluanhaddad commented Mar 6, 2015

I came across this and it made me smile. Thank you :)

@sthames42
Copy link

sthames42 commented Feb 18, 2016

Really?? I must have read the post four times thinking "where is the damn package to install?" and "how is this any different than writing it up yourself in Node scripts?" Seriously, I think the only thing missing from Node is GNU Make.

@balupton
Copy link

balupton commented Mar 2, 2016

Not enough jQuery

@balupton
Copy link

balupton commented Mar 2, 2016

For what it's worth, while I'm sure this isn't new... we do the same but call them Nakefiles: https://github.com/bevry/base/blob/master/README.md#nakefile

We're probably going to simplify this further still and just go with npm scripts only: bevry/base#24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment