Created
January 8, 2014 08:18
-
-
Save Raynos/8313477 to your computer and use it in GitHub Desktop.
Revisions
-
James Halliday created this gist
Jan 8, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ # why `./task.js`? One word: task automation. It's basically zero effort and you can use the [./task.js package manager](https://npmjs.org) 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](https://gist.github.com/substack/7819530), 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](http://nodejs.org). Now you'll need to generate some scaffolding for your project. You can use the following scaffold generator: ``` js #!/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](http://browserify.org), [watchify](https://npmjs.org/package/watchify), and [catw](https://npmjs.org/package/catw) plugins published to the [./task.js plugin repository](https://npmjs.org/): ``` js #!/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](http://nodejs.org).