Create a gist now

Instantly share code, notes, and snippets.

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.

@pvorb

This comment has been minimized.

Show comment Hide comment
@pvorb

pvorb Jan 8, 2014

Wow.

Screw Gulp, which I learned yesterday! Screw Grunt, which I learned two weeks ago. Screw Make, which I learned 2 years ago. Screw Bash, which I could never learn.

This is the new hot shit!

Please create a cool HTML5 website with some scrolling effects and shit, so real developers can use it. It also has to list all modules that are supported and companies who are using it.

pvorb commented Jan 8, 2014

Wow.

Screw Gulp, which I learned yesterday! Screw Grunt, which I learned two weeks ago. Screw Make, which I learned 2 years ago. Screw Bash, which I could never learn.

This is the new hot shit!

Please create a cool HTML5 website with some scrolling effects and shit, so real developers can use it. It also has to list all modules that are supported and companies who are using it.

@jamwaffles

This comment has been minimized.

Show comment Hide comment
@jamwaffles

jamwaffles Jan 8, 2014

Everybody I know uses Windows Server 2003. It has the largest market share and is the most up to date server OS out there! Linux is just a blip on the horizon, and Grunt can fuck off because it totally doesn't have hundreds of packages for doing everything you'd want to do.

On a more serious note: why is ./task.js (stupid name) better than every other solution out there, particularly Grunt?

Everybody I know uses Windows Server 2003. It has the largest market share and is the most up to date server OS out there! Linux is just a blip on the horizon, and Grunt can fuck off because it totally doesn't have hundreds of packages for doing everything you'd want to do.

On a more serious note: why is ./task.js (stupid name) better than every other solution out there, particularly Grunt?

@contra

This comment has been minimized.

Show comment Hide comment
@contra

contra Jan 8, 2014

Pretty funny

contra commented Jan 8, 2014

Pretty funny

@vmakhaev

This comment has been minimized.

Show comment Hide comment
@vmakhaev

vmakhaev Jan 8, 2014

TaskJS and VanillaJS are my favorite frameworks

vmakhaev commented Jan 8, 2014

TaskJS and VanillaJS are my favorite frameworks

@kahlil

This comment has been minimized.

Show comment Hide comment
@kahlil

kahlil Jan 8, 2014

😆 this is great!

kahlil commented Jan 8, 2014

😆 this is great!

@NamelessCoder

This comment has been minimized.

Show comment Hide comment
@NamelessCoder

NamelessCoder Jan 8, 2014

Please make a bash plugin.

Please make a bash plugin.

@pvorb

This comment has been minimized.

Show comment Hide comment
@pvorb

pvorb 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. :(

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

This comment has been minimized.

Show comment Hide comment
@donaldpipowitch

donaldpipowitch 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.

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

This comment has been minimized.

Show comment Hide comment
@millermedeiros

millermedeiros 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/

@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

This comment has been minimized.

Show comment Hide comment
@sindresorhus

sindresorhus Jan 8, 2014

lol

lol

@alanhoff

This comment has been minimized.

Show comment Hide comment
@alanhoff

alanhoff Jan 8, 2014

It doesn't run on IE7 :(

alanhoff commented Jan 8, 2014

It doesn't run on IE7 :(

@id0x3d

This comment has been minimized.

Show comment Hide comment
@id0x3d

id0x3d Jan 8, 2014

Haha, its nice tool

id0x3d commented Jan 8, 2014

Haha, its nice tool

@jasonpincin

This comment has been minimized.

Show comment Hide comment
@jasonpincin

jasonpincin Jan 8, 2014

@pvorb +1 1st post. I laughed.

@pvorb +1 1st post. I laughed.

@rafaelrinaldi

This comment has been minimized.

Show comment Hide comment
@rafaelrinaldi

rafaelrinaldi Jan 8, 2014

LOL

LOL

@jmeiss

This comment has been minimized.

Show comment Hide comment
@jmeiss

jmeiss Jan 9, 2014

Ah ah love it!

jmeiss commented Jan 9, 2014

Ah ah love it!

@pvorb

This comment has been minimized.

Show comment Hide comment
@pvorb

pvorb Jan 9, 2014

@jasonpincin nice to hear

pvorb commented Jan 9, 2014

@jasonpincin nice to hear

@h2non

This comment has been minimized.

Show comment Hide comment
@h2non

h2non Jan 9, 2014

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

h2non commented Jan 9, 2014

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

@radum

This comment has been minimized.

Show comment Hide comment
@radum

radum 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.

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

This comment has been minimized.

Show comment Hide comment
@timkock

timkock Jan 9, 2014

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

timkock commented Jan 9, 2014

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

@poeticninja

This comment has been minimized.

Show comment Hide comment
@poeticninja

poeticninja Jan 9, 2014

:)

:)

@shama

This comment has been minimized.

Show comment Hide comment
@shama

shama Jan 10, 2014

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

shama commented Jan 10, 2014

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

@contra

This comment has been minimized.

Show comment Hide comment
@contra

contra Jan 10, 2014

Missing an example that isn't just concating files

contra commented Jan 10, 2014

Missing an example that isn't just concating files

@spencercarnage

This comment has been minimized.

Show comment Hide comment
@spencercarnage

spencercarnage Jan 10, 2014

Needs more auto-magic.

Needs more auto-magic.

@cowboy

This comment has been minimized.

Show comment Hide comment
@cowboy

cowboy Jan 10, 2014

but how does it jquery

cowboy commented Jan 10, 2014

but how does it jquery

@adambiggs

This comment has been minimized.

Show comment Hide comment
@adambiggs

adambiggs Jan 10, 2014

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

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

@raffi-minassian

This comment has been minimized.

Show comment Hide comment
@raffi-minassian

raffi-minassian Jan 13, 2014

LOL!

LOL!

@nicovalencia

This comment has been minimized.

Show comment Hide comment
@nicovalencia

nicovalencia Jan 16, 2014

👍 I lol'd

👍 I lol'd

@shanestillwell

This comment has been minimized.

Show comment Hide comment
@shanestillwell

shanestillwell 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.

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

This comment has been minimized.

Show comment Hide comment
@mciparelli

mciparelli Jan 25, 2014

Please, let the community choose their own THE.

Please, let the community choose their own THE.

@mciparelli

This comment has been minimized.

Show comment Hide comment
@mciparelli

mciparelli 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.

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

This comment has been minimized.

Show comment Hide comment
@BadOPCode

BadOPCode 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.

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

This comment has been minimized.

Show comment Hide comment
@aluanhaddad

aluanhaddad Mar 6, 2015

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

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

@sthames42

This comment has been minimized.

Show comment Hide comment
@sthames42

sthames42 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.

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

This comment has been minimized.

Show comment Hide comment
@balupton

balupton Mar 2, 2016

Not enough jQuery

balupton commented Mar 2, 2016

Not enough jQuery

@balupton

This comment has been minimized.

Show comment Hide comment
@balupton

balupton 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

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