Comparing version 3.0.0-rc3 to 3.0.0
@@ -6,43 +6,3 @@ #!/usr/bin/env node | ||
//Uses auto port-finding | ||
var args = process.argv.slice(2) | ||
var opts = require('minimist')(args) | ||
var getport = require('getport') | ||
var entries = opts._ | ||
opts.stream = process.stdout | ||
delete opts._ | ||
var showHelp = opts.h || opts.help | ||
if (!showHelp && (!entries || entries.filter(Boolean).length === 0)) { | ||
console.error('ERROR:\n no entry scripts specified\n use --help for examples') | ||
process.exit(1) | ||
} | ||
if (showHelp) { | ||
var vers = require('../package.json').version | ||
console.log('budo ' + vers, '\n') | ||
var help = require('path').join(__dirname, 'help.txt') | ||
require('fs').createReadStream(help) | ||
.pipe(process.stdout) | ||
return | ||
} | ||
var basePort = opts.port || 9966 | ||
getport(basePort, function(err, port) { | ||
if (err) { | ||
console.error("Could not find available port", err) | ||
process.exit(1) | ||
} | ||
opts.port = port | ||
require('../')(entries, opts) | ||
.on('error', function(err) { | ||
//Some more helpful error messaging | ||
if (err.message === 'listen EADDRINUSE') | ||
console.error("Port", port, "is not available\n") | ||
else | ||
console.error('Error:\n ' + err.message) | ||
process.exit(1) | ||
}) | ||
}) | ||
require('../').cli(args) |
133
index.js
@@ -1,94 +0,63 @@ | ||
var bole = require('bole') | ||
var log = bole('budo') | ||
var xtend = require('xtend') | ||
var budo = require('./lib/budo') | ||
var url = require('url') | ||
var create = require('./lib') | ||
module.exports = function(entry, opts) { | ||
var argv = xtend(opts) | ||
if (argv.stream) { | ||
bole.output({ | ||
stream: argv.stream, | ||
level: 'debug' | ||
}) | ||
} | ||
var emitter = budo() | ||
//public programmatic API | ||
// expects args to be camelCase | ||
// supports objects in transforms | ||
module.exports = function budo(entry, opt) { | ||
return create(entry, opt, false) | ||
} | ||
if (argv.o || argv.outfile) { | ||
log.warn('--outfile has been removed in budo@3.0') | ||
//ensure we don't pass to watchify | ||
delete argv.o | ||
delete argv.outfile | ||
} | ||
//CLI entry point (undocumented, private for now) | ||
// uses watchify/bin/args to arg parse | ||
// does not support objects in transforms | ||
// uses portfinding on base port | ||
// prints to stdout | ||
module.exports.cli = function cli(args) { | ||
var getport = require('getport') | ||
var opts = require('minimist')(args, { | ||
boolean: ['stream'], | ||
default: { stream: true } | ||
}) | ||
var entries = Array.isArray(entry) ? entry : [entry] | ||
entries = entries.filter(Boolean) | ||
if (entries.length === 0) { | ||
return bail("No entry scripts specified!") | ||
//user can silent budo with --no-stream | ||
if (opts.stream !== false) { | ||
opts.stream = process.stdout | ||
} | ||
//clean up entries and take the first one for bundle mapping | ||
var file | ||
entries = entries.map(function(entry, i) { | ||
var map = mapping(entry) | ||
if (i === 0) | ||
file = map.to | ||
return map.from | ||
}) | ||
//if user specified -o use that as our entry map | ||
var serveAs = argv.serve | ||
if (serveAs && typeof serveAs === 'string') | ||
file = serveAs | ||
argv.port = typeof argv.port === 'number' ? argv.port : 9966 | ||
argv.dir = argv.dir || process.cwd() | ||
argv.serve = url.parse(file).path | ||
var entries = opts._ | ||
delete opts._ | ||
if (typeof argv.dir !== 'string') | ||
return bail('--dir must be a path') | ||
var showHelp = opts.h || opts.help | ||
//run watchify server | ||
emitter.on('connect', setupLive) | ||
emitter._start(entries, argv) | ||
.on('exit', function() { | ||
log.info('closing') | ||
}) | ||
return emitter | ||
if (showHelp) { | ||
var vers = require('./package.json').version | ||
console.log('budo ' + vers, '\n') | ||
var help = require('path').join(__dirname, 'bin', 'help.txt') | ||
require('fs').createReadStream(help) | ||
.pipe(process.stdout) | ||
return | ||
} | ||
//if user requested live: true, set it up with some defaults | ||
function setupLive() { | ||
if (argv.live || argv['live-plugin']) { | ||
emitter | ||
.watch() | ||
.live() | ||
.on('watch', function(ev, file) { | ||
//HTML/CSS changes | ||
if (ev === 'change' || ev === 'add') | ||
emitter.reload(file) | ||
}) | ||
.on('update', function(file) { | ||
//bundle.js changes | ||
emitter.reload(file) | ||
}) | ||
} | ||
if (!entries || entries.filter(Boolean).length === 0) { | ||
console.error('ERROR:\n no entry scripts specified\n use --help for examples') | ||
process.exit(1) | ||
} | ||
function mapping(entry) { | ||
var parts = entry.split(':') | ||
if (parts.length > 1 && parts[1].length > 0) { | ||
return { from: parts[0], to: parts[1] } | ||
var basePort = opts.port || 9966 | ||
getport(basePort, function(err, port) { | ||
if (err) { | ||
console.error("Could not find available port", err) | ||
process.exit(1) | ||
} | ||
return { from: entry, to: entry } | ||
} | ||
function bail(msg) { | ||
process.nextTick(function() { | ||
emitter.emit('error', new Error(msg)) | ||
}) | ||
return emitter | ||
} | ||
opts.port = port | ||
create(entries, opts, true) | ||
.on('error', function(err) { | ||
//Some more helpful error messaging | ||
if (err.message === 'listen EADDRINUSE') | ||
console.error("Port", port, "is not available\n") | ||
else | ||
console.error('Error:\n ' + err.message) | ||
process.exit(1) | ||
}) | ||
}) | ||
} |
@@ -5,3 +5,2 @@ var Emitter = require('events/') | ||
var log = require('bole')('budo') | ||
var dargs = require('dargs') | ||
@@ -30,3 +29,3 @@ var createServer = require('./server') | ||
emitter._start = function(entries, opt) { | ||
emitter._start = function(entries, opt, cli) { | ||
opt = opt || {} | ||
@@ -46,2 +45,3 @@ var port = opt.port | ||
var uri = "http://" + hostname + ":" + opt.port + "/" | ||
log.info("Server running at", uri) | ||
@@ -58,13 +58,13 @@ | ||
poll: opt.poll, | ||
'ignore-watch': ignoreWatchArg | ||
'ignore-watch': opt.ignoreWatch || ignoreWatchArg | ||
} | ||
//and default live options | ||
defaultLiveOpts = { | ||
plugin: opt['live-plugin'], | ||
plugin: opt.livePlugin || opt['live-plugin'], | ||
host: opt.host, | ||
port: emitter['live-port'] | ||
port: opt.livePort || opt['live-port'] | ||
} | ||
//start watchify process | ||
runWatchify(entries, opt) | ||
runWatchify(entries, opt, cli) | ||
@@ -87,4 +87,3 @@ serveAs = opt.serve | ||
entries: entries, | ||
dir: opt.dir, | ||
'live-port': opt['live-port'] | ||
dir: opt.dir | ||
}) | ||
@@ -114,11 +113,14 @@ }) | ||
//enable live-reload capabilities | ||
emitter.live = function(liveOpt) { | ||
emitter.live = function(liveOpts) { | ||
if (!started) { | ||
deferreds.push(emitter.live.bind(null, liveOpt)) | ||
deferreds.push(emitter.live.bind(null, liveOpts)) | ||
} else { | ||
liveOpt = liveOpt||{} | ||
server._live = !liveOpt.plugin | ||
tinylr = createTinylr(xtend(defaultLiveOpts, liveOpt)) | ||
liveOpts = xtend(defaultLiveOpts, liveOpts) | ||
//if plugin, ignore live reload in HTML, | ||
//otherwise inject with new options (host/port) | ||
server._live = liveOpts.plugin ? null : liveOpts | ||
tinylr = createTinylr(liveOpts) | ||
emitter.reload = function(file) { | ||
file = file | ||
tinylr.reload(file) | ||
@@ -153,11 +155,9 @@ emitter.emit('reload', file) | ||
function runWatchify(entries, opt) { | ||
function runWatchify(entries, opt, cli) { | ||
if (closed) | ||
return | ||
//get watchify args (with --debug by default) | ||
var watchifyArgs = getWatchifyArgs(entries, opt) | ||
//create a new watchify instance | ||
watchify = createWatchify(watchifyArgs, { | ||
watchify = createWatchify(entries, opt, { | ||
cli: cli, //whether to use watchify/bin/args or not | ||
dir: opt.dir, | ||
@@ -177,2 +177,5 @@ serve: opt.serve, | ||
}) | ||
.on('pending', function() { | ||
emitter.emit('pending', serveAs) | ||
}) | ||
.on('error', emitter.emit.bind(emitter, 'error')) | ||
@@ -205,31 +208,1 @@ } | ||
} | ||
function getWatchifyArgs(entries, opt) { | ||
//do not mutate original opts | ||
opt = assign({}, opt) | ||
//disable delay since we will handle debouncing manually | ||
opt.delay = 0 | ||
//enable debug by default | ||
if (opt.d !== false && opt.debug !== false) { | ||
delete opt.d | ||
opt.debug = true | ||
} | ||
//if user explicitly disabled debug... | ||
else if (opt.d === false || opt.debug === false) { | ||
delete opt.d | ||
delete opt.debug | ||
} | ||
//clean up some possible collisions | ||
var collisions = [ | ||
'dir', 'o', 'outfile', 'port', | ||
'host', 'live', 'serve', 'live-port', | ||
'live-plugin', 'defaultIndex' | ||
] | ||
collisions.forEach(function(col) { | ||
delete opt[col] | ||
}) | ||
return entries.concat(dargs(opt)) | ||
} |
@@ -44,4 +44,9 @@ var ecstatic = require('ecstatic') | ||
var defaulLiveOpts = { | ||
host: opts.host, | ||
port: opts.livePort || opts['live-port'] | ||
} | ||
var emitter = new Emitter() | ||
emitter.live = opts.live | ||
emitter.live = opts.live ? defaulLiveOpts : null | ||
emitter.router = router | ||
@@ -51,7 +56,2 @@ emitter.pending = false | ||
var liveOpts = { | ||
host: opts.host, | ||
port: opts['live-port'] | ||
} | ||
router.addRoute('/' + url.parse(opts.serve).pathname, function(req, res) { | ||
@@ -85,3 +85,3 @@ log.info({ | ||
if (html && emitter.live) | ||
res = inject(res, liveOpts) | ||
res = inject(res, emitter.live) | ||
log.info({ | ||
@@ -104,3 +104,3 @@ url: req.url, | ||
if (emitter.live) | ||
res = inject(res, liveOpts) | ||
res = inject(res, emitter.live) | ||
@@ -107,0 +107,0 @@ var type = exists ? 'static' : 'generated' |
var log = require('bole')('budo') | ||
var getWatchify = require('./get-watchify') | ||
var createWatchify = require('./create-watchify') | ||
var Emitter = require('events/') | ||
var debounce = require('debounce') | ||
var concat = require('concat-stream') | ||
//Eventually this may split into a watchify-server module | ||
module.exports = function(watchifyArgs, opt) { | ||
module.exports = function(entries, userArgs, opt) { | ||
var emitter = new Emitter() | ||
@@ -32,3 +31,6 @@ var delay = opt.delay | ||
getWatchify({ basedir: opt.dir }, function(err, fromArgs) { | ||
createWatchify(entries, userArgs, { | ||
cli: opt.cli, | ||
basedir: opt.dir | ||
}, function(err, instance) { | ||
if (err) { | ||
@@ -46,4 +48,3 @@ var msg = [ | ||
watchify = fromArgs(watchifyArgs) | ||
watchify = instance | ||
var bundleDebounced = debounce(bundle, delay) | ||
@@ -70,34 +71,20 @@ watchify.on('update', function() { | ||
var didError = false | ||
var outStream = concat(function(body) { | ||
contents = body | ||
bundleEnd() | ||
}) | ||
var wb = watchify.bundle() | ||
wb.on('error', function(err) { | ||
err = String(err) | ||
console.error(err) | ||
didError = true | ||
outStream.end('console.error(' + JSON.stringify(err) + ');') | ||
}) | ||
wb.pipe(outStream) | ||
outStream.on('error', function(err) { | ||
console.error(err) | ||
watchify.bundle(function(err, src) { | ||
if (err) { | ||
err = String(err) | ||
console.error(err) | ||
contents = new Buffer('console.error(' + JSON.stringify(err) + ');') | ||
} else { | ||
contents = src | ||
if (opt.verbose) { | ||
var delay = Date.now() - time | ||
log.info({ | ||
elapsed: Math.round(delay) + 'ms', | ||
type: 'bundle', | ||
url: opt.serve | ||
}) | ||
} | ||
} | ||
update() | ||
}) | ||
function bundleEnd() { | ||
if (opt.verbose && !didError) { | ||
var delay = Date.now() - time | ||
log.info({ | ||
elapsed: Math.round(delay) + 'ms', | ||
type: 'bundle', | ||
url: opt.serve | ||
}) | ||
} | ||
update() | ||
} | ||
} | ||
@@ -104,0 +91,0 @@ return emitter |
{ | ||
"name": "budo", | ||
"version": "3.0.0-rc3", | ||
"version": "3.0.0", | ||
"description": "a browserify server for rapid prototyping", | ||
@@ -18,3 +18,2 @@ "main": "index.js", | ||
"chokidar": "^1.0.1", | ||
"concat-stream": "^1.4.8", | ||
"dargs": "^4.0.0", | ||
@@ -46,11 +45,14 @@ "debounce": "^1.0.0", | ||
"tape": "^4.0.0", | ||
"tree-kill": "0.0.6", | ||
"uglify-js": "^2.4.19", | ||
"vm": "0.0.1", | ||
"watchify": "^3.1.0" | ||
"watchify": "^3.1.0", | ||
"win-spawn": "^2.0.0" | ||
}, | ||
"scripts": { | ||
"test": "tape test/test*.js | tap-spec", | ||
"start": "./bin/cmd.js example/*.js --dir example --verbose | garnish", | ||
"live": "./bin/cmd.js example/*.js --dir example --live -v | garnish -v", | ||
"live-plugin": "./bin/cmd.js example/*.js --dir example --live-plugin -v | garnish", | ||
"silent": "./bin/cmd.js example/app.js:bundle.js --dir example --stream false", | ||
"start": "./bin/cmd.js example/app.js:bundle.js --dir example --verbose | garnish", | ||
"live": "./bin/cmd.js example/app.js:bundle.js --dir example --live -v | garnish -v", | ||
"live-plugin": "./bin/cmd.js example/app.js:bundle.js --dir example --live-plugin -v | garnish", | ||
"remap": "./bin/cmd.js example/*.js --serve bundle2.js --dir example --live -v | garnish" | ||
@@ -57,0 +59,0 @@ }, |
@@ -68,9 +68,11 @@ # budō | ||
--poll=N use polling for file watch, with optional interval N | ||
--no-stream do not print messages to stdout | ||
--no-debug do not use inline source maps | ||
``` | ||
By default, the `--debug` option will be sent to browserify (for source maps). If this is unwanted, you can use `--no-debug` or `--debug=false` to disable source maps. | ||
By default, messages will be printed to `stdout` and `debug` will be sent to browserify (for source maps). You can turn these off with `--no-stream` and `--no-debug`, respectively. | ||
### API | ||
The API mirrors the CLI except you must provide a `stream` for logging, and it does not attempt to auto-portfind. | ||
The API mirrors the CLI except it does not write to `process.stdout` by default, and does not attempt to find available ports from a base port. | ||
@@ -77,0 +79,0 @@ ```js |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
27384
15
14
691
0
103
16
6
- Removedconcat-stream@^1.4.8
- Removedbuffer-from@1.1.2(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedtypedarray@0.0.6(transitive)