From fb235282162f869184dc7babacdb7bba3d58672c Mon Sep 17 00:00:00 2001 From: mattdesl Date: Tue, 10 Feb 2015 16:29:33 -0500 Subject: [PATCH 1/6] base path for from --- bin.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/bin.js b/bin.js index 31fe337..811421d 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,18 @@ if (subIdx > -1) { var argv = minimist(args) var port = argv.port || argv.p || (argv.https ? 4443 : 9966) +argv.path = argv.dir || argv.d || 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]} +}).map(function(e) { + return { + from: path.join(argv.path, e.from), + to: e.to + } }) argv.browserifyArgs = browserifyArgs From 55144e74ff3613d78896405083341e6a55d78556 Mon Sep 17 00:00:00 2001 From: mattdesl Date: Tue, 10 Feb 2015 17:49:25 -0500 Subject: [PATCH 2/6] get rid of empty index as it is breaking wzrd test/app.js command --- index.html | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 index.html diff --git a/index.html b/index.html deleted file mode 100644 index e69de29..0000000 From ce5fd2afd3cf53cd16ad82f1753a58ac76b7ea90 Mon Sep 17 00:00:00 2001 From: mattdesl Date: Tue, 10 Feb 2015 17:58:58 -0500 Subject: [PATCH 3/6] resolving path in API now --- bin.js | 5 ----- index.js | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/bin.js b/bin.js index 811421d..f8c7dee 100755 --- a/bin.js +++ b/bin.js @@ -21,11 +21,6 @@ argv.entries = argv._.map(function(arg) { return {from: arg, to: arg} var parts = arg.split(':') return {from: parts[0], to: parts[1]} -}).map(function(e) { - return { - from: path.join(argv.path, e.from), - to: e.to - } }) argv.browserifyArgs = browserifyArgs diff --git a/index.js b/index.js index 1c5bed6..2df1c3d 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,8 @@ module.exports.static = function(opts) { opts.entries.forEach(function(entry) { router.addRoute('/' + entry.to, function(req, res, params) { - module.exports.browserify(entry.from, opts, req, res) + var from = path.join(basedir, entry.from) + module.exports.browserify(from, opts, req, res) }) }) From d61fa462f22abb25b8cb2272641bf80966b2023d Mon Sep 17 00:00:00 2001 From: mattdesl Date: Wed, 11 Feb 2015 22:33:51 -0500 Subject: [PATCH 4/6] testing dir --- package.json | 1 + test/index.js | 41 ++++++++++++++++++++++++++++++++++------- test/other/test.js | 3 +++ 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 test/other/test.js 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/test/index.js b/test/index.js index a596aea..a74d84f 100644 --- a/test/index.js +++ b/test/index.js @@ -8,24 +8,51 @@ 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.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', function(t) { + run(t, { + port: 9966, + args: ['test.js', '--dir=other'], + e: '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 From f58f739b17ef363c8573217c2612f47d55559d62 Mon Sep 17 00:00:00 2001 From: mattdesl Date: Wed, 11 Feb 2015 22:39:06 -0500 Subject: [PATCH 5/6] fixing typo --- test/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.js b/test/index.js index a74d84f..e6fb4d9 100644 --- a/test/index.js +++ b/test/index.js @@ -48,7 +48,7 @@ test('from dir', function(t) { run(t, { port: 9966, args: ['test.js', '--dir=other'], - e: 'browserify ./other/test.js' + compare: 'browserify ./other/test.js' }, function() { t.end() From 6046fa29a3036348b95e76cf6bcc5e513b6fb07f Mon Sep 17 00:00:00 2001 From: mattdesl Date: Tue, 24 Feb 2015 10:54:58 -0500 Subject: [PATCH 6/6] reverting to old style and sticking with --path --- bin.js | 2 +- index.js | 3 +-- readme.md | 5 +++++ test/index.js | 7 ++++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/bin.js b/bin.js index f8c7dee..f68f815 100755 --- a/bin.js +++ b/bin.js @@ -14,7 +14,7 @@ if (subIdx > -1) { var argv = minimist(args) var port = argv.port || argv.p || (argv.https ? 4443 : 9966) -argv.path = argv.dir || argv.d || process.cwd() +argv.path = argv.path || process.cwd() argv.entries = argv._.map(function(arg) { if (arg.indexOf(':') === -1) diff --git a/index.js b/index.js index 2df1c3d..1c5bed6 100644 --- a/index.js +++ b/index.js @@ -29,8 +29,7 @@ module.exports.static = function(opts) { opts.entries.forEach(function(entry) { router.addRoute('/' + entry.to, function(req, res, params) { - var from = path.join(basedir, entry.from) - module.exports.browserify(from, opts, req, res) + module.exports.browserify(entry.from, opts, req, res) }) }) 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 e6fb4d9..5cf7285 100644 --- a/test/index.js +++ b/test/index.js @@ -16,7 +16,7 @@ function run(t, opt, cb) { var server = 'http://localhost:'+opt.port var startMsg = 'server started at '+server - var entry = opt.args[0] + 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) @@ -44,10 +44,11 @@ test('single entry', function(t) { }) }) -test('from dir', function(t) { +test('from dir with entry mapping', function(t) { run(t, { port: 9966, - args: ['test.js', '--dir=other'], + entry: 'bundle.js', + args: ['other/test.js:bundle.js', '--dir=other'], compare: 'browserify ./other/test.js' }, function() {