-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James Halliday
committed
May 30, 2013
1 parent
838bebd
commit cf69a7d
Showing
3 changed files
with
38 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,41 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env node | ||
|
||
var watchify = require('../'); | ||
var through = require('through'); | ||
var fs = require('fs'); | ||
var argv = require('optimist').argv; | ||
var outfile = argv.o || argv.outfile; | ||
var path = require('path'); | ||
var fromArgs = require('browserify/bin/args'); | ||
|
||
var w = watchify(argv._); | ||
w.on('update', function () { | ||
console.log('UPDATE'); | ||
var s = w.bundle(); | ||
s.pipe(fs.createWriteStream('.' + outfile)); | ||
s.on('data', function () {}); | ||
s.on('end', function () { | ||
fs.rename('.' + outfile, outfile, function (err) { | ||
if (err) console.error(err) | ||
else console.log(outfile + ' written') | ||
}); | ||
var w = watchify(fromArgs(process.argv.slice(2))); | ||
var outfile = w.argv.o || w.argv.outfile; | ||
var verbose = w.argv.v || w.argv.verbose; | ||
|
||
if (!outfile) { | ||
console.error('You MUST specify an outfile with -o.'); | ||
process.exit(1); | ||
} | ||
var dotfile = path.join(path.dirname(outfile), '.' + path.basename(outfile)); | ||
|
||
w.on('update', bundle); | ||
bundle(); | ||
|
||
function bundle () { | ||
var wb = w.bundle(); | ||
wb.on('error', function (err) { | ||
console.error(String(err)); | ||
}); | ||
}); | ||
w.bundle().pipe(fs.createWriteStream(outfile)); | ||
wb.pipe(fs.createWriteStream(dotfile)); | ||
var bytes = 0; | ||
wb.pipe(through(write, end)); | ||
|
||
function write (buf) { bytes += buf.length } | ||
|
||
function end () { | ||
fs.rename(dotfile, outfile, function (err) { | ||
if (err) return console.error(err); | ||
if (verbose) { | ||
console.error(bytes + ' bytes written to ' + outfile); | ||
} | ||
}); | ||
} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
var two = require('./two'); | ||
|
||
module.exports = function (x) { return x * two(x + 6) }; | ||
module.exports = function (x) { return x * two(x + 5) }; |
This file contains 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 characters