Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions bin.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Empty file removed index.html
Empty file.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"test": "test"
},
"devDependencies": {
"browserify": "^8.1.3",
"request": "^2.51.0",
"tape": "^3.0.3",
"through2": "^0.6.3",
Expand Down
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
42 changes: 35 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions test/other/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
process.nextTick(function() {
console.log("from browserify")
})