#!/usr/bin/env node

/**
 * Module dependencies.
 */

var minimist = require('minimist');
var BrowserifySingleFile = require('../');

var argv = minimist(process.argv.slice(2));

var filenames = argv._;
if (filenames.length !== 1) {
  throw new Error('only one source filename may be given at a time');
}
var filename = filenames.shift();

var bsf = new BrowserifySingleFile(filename);

// apply any "transform"
var transform = argv.transform || argv.t;
if (transform) {
  var t = require(transform);
  bsf.transform(t);
}

// apply any "plugin"
var plugin = argv.plugin || argv.p;
if (plugin) {
  var pargv = minimist(plugin.split(/\s+/));
  var pname = pargv._[0];
  var p = require(pname);
  p(bsf, pargv);
}

// output the pipeline to `stdout`
bsf.bundle().pipe(process.stdout);

@@ -404,16 +404,27 @@
 ansform%22
+ parameters
 %0Avar tra
@@ -429,19 +429,28 @@
 ransform
+s
  = 
+%5B%5D;%0Aif (
 argv.tra
@@ -459,22 +459,325 @@
 form
- %7C%7C argv.t;%0Aif
+) %7B%0A  if (Array.isArray(argv.transform)) %7B%0A    transforms.push.apply(transforms, argv.transform);%0A  %7D else %7B%0A    transforms.push(argv.transform);%0A  %7D%0A%7D%0Aif (argv.t) %7B%0A  if (Array.isArray(argv.t)) %7B%0A    transforms.push.apply(transforms, argv.t);%0A  %7D else %7B%0A    transforms.push(argv.t);%0A  %7D%0A%7D%0Atransforms.forEach(function
  (tr
@@ -834,24 +834,27 @@
 nsform(t);%0A%7D
+);%0A
 %0A%0A// apply a
@@ -875,19 +875,28 @@
 r plugin
+s
  = 
+%5B%5D;%0Aif (
 argv.plu
@@ -902,22 +902,295 @@
 ugin
- %7C%7C argv.p;%0Aif
+) %7B%0A  if (Array.isArray(argv.plugin)) %7B%0A    plugins.push.apply(plugins, argv.plugin);%0A  %7D else %7B%0A    plugins.push(argv.plugin);%0A  %7D%0A%7D%0Aif (argv.p) %7B%0A  if (Array.isArray(argv.p)) %7B%0A    plugins.push.apply(plugins, argv.p);%0A  %7D else %7B%0A    plugins.push(argv.p);%0A  %7D%0A%7D%0Aplugins.forEach(function
  (pl
@@ -1311,17 +1311,20 @@
 pargv);%0A
-
 %7D
+);%0A
 %0A%0A// out

add support for multiple --transform/--plugin arguments