diff --git a/bin.js b/bin.js index 31fe337..f68f815 100755 --- a/bin.js +++ b/bin.js @@ -1,6 +1,7 @@ #!/usr/bin/env node var minimist = require('minimist') var wzrd = require('./') +var path = require('path') var args = process.argv.slice(2) var browserifyArgs @@ -13,16 +14,13 @@ if (subIdx > -1) { var argv = minimist(args) var port = argv.port || argv.p || (argv.https ? 4443 : 9966) +argv.path = argv.path || process.cwd() -argv.entries = [] - -argv._.map(function(arg) { - if (arg.indexOf(':') === -1) { - argv.entries.push({from: arg, to: arg}) - return - } +argv.entries = argv._.map(function(arg) { + if (arg.indexOf(':') === -1) + return {from: arg, to: arg} var parts = arg.split(':') - argv.entries.push({from: parts[0], to: parts[1]}) + return {from: parts[0], to: parts[1]} }) argv.browserifyArgs = browserifyArgs diff --git a/index.html b/index.html deleted file mode 100644 index e69de29..0000000 diff --git a/package.json b/package.json index ef39cf4..a3e99ac 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "test": "test" }, "devDependencies": { + "browserify": "^8.1.3", "request": "^2.51.0", "tape": "^3.0.3", "through2": "^0.6.3", diff --git a/readme.md b/readme.md index 715c13c..274f2d3 100644 --- a/readme.md +++ b/readme.md @@ -57,3 +57,8 @@ wzrd app.js -- -t brfs ``` anything after `--` will get passed directly to `browserify` as arguments. so the example above would spawn the command `browserify app.js -t brfs` + +### other options + +- `--port` the port to run on (default 9966) +- `--path` the base path for the server and optional `index.html` diff --git a/test/index.js b/test/index.js index a596aea..5cf7285 100644 --- a/test/index.js +++ b/test/index.js @@ -8,24 +8,52 @@ var npmSpawn = require('npm-execspawn') var request = require('request') var concat = require('concat-stream') var wzrd = require('../') +var noop = function(){} var cliPath = path.resolve(__dirname, '..', 'bin.js') -var server = 'http://localhost:9966' -test('single entry', function(t) { - var startMsg = 'server started at http://localhost:9966' - var proc = spawn(cliPath, ['app.js'], { cwd: __dirname, env: process.env }) +function run(t, opt, cb) { + var server = 'http://localhost:'+opt.port + var startMsg = 'server started at '+server + + var entry = opt.entry || opt.args[0] + var proc = spawn(cliPath, opt.args, { cwd: __dirname, env: process.env }) waitFor(startMsg, proc.stderr, function(output) { t.ok(output.indexOf(startMsg) > -1, startMsg) - request({url: server + '/app.js'}, function(err, resp, bundle) { - var bfy = npmSpawn('browserify ' + 'app.js', { cwd: __dirname, env: process.env }) + + var url = [server, entry].join('/') + request({url: url }, function(err, resp, bundle) { + var bfy = npmSpawn(opt.compare, { cwd: __dirname, env: process.env }) bfy.stdout.pipe(concat(function gotbundle(bundle2) { t.equal(bundle.toString(), bundle2.toString(), 'bundles match') + proc.on('exit', cb||noop) kill(proc.pid) - t.end() })) }) }) +} + +test('single entry', function(t) { + run(t, { + port: 9966, + args: ['app.js'], + compare: 'browserify app.js' + }, + function() { + t.end() + }) +}) + +test('from dir with entry mapping', function(t) { + run(t, { + port: 9966, + entry: 'bundle.js', + args: ['other/test.js:bundle.js', '--dir=other'], + compare: 'browserify ./other/test.js' + }, + function() { + t.end() + }) }) function waitFor(string, stream, cb) { diff --git a/test/other/test.js b/test/other/test.js new file mode 100644 index 0000000..cd247b3 --- /dev/null +++ b/test/other/test.js @@ -0,0 +1,3 @@ +process.nextTick(function() { + console.log("from browserify") +}) \ No newline at end of file