Skip to content

Commit

Permalink
fix(cli): explode files args when given on command line. fixes #425, f…
Browse files Browse the repository at this point in the history
…ixes #426
  • Loading branch information
shakyShane committed Feb 5, 2015
1 parent ae34a2c commit 18324f0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
19 changes: 15 additions & 4 deletions lib/cli/cli-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ var opts = exports;
* @type {{wrapPattern: Function}}
*/
opts.utils = {

/**
* Transform a string arg such as "*.html, css/*.css" into array
* @param string
* @returns {Array}
*/
explodeFilesArg: function (string) {
return string.split(",").map(function (item) {
return item.trim();
});
},
/**
* @param pattern
* @returns {*|string}
Expand Down Expand Up @@ -229,22 +240,22 @@ opts.callbacks = {
var merged = [];

if (_.isString(value)) {
merged.push(value);
merged = merged.concat(opts.utils.explodeFilesArg(value));
}

if (argv && argv.files) {
if (~argv.files.indexOf(",")) {
merged = merged.concat(argv.files.split(",").map(function (item) {
return item.trim();
}));
merged = merged.concat(opts.utils.explodeFilesArg(argv.files));
} else {
merged.push(argv.files);
}

if (argv.exclude) {
merged = merged.concat(opts.utils.addExcluded(argv.exclude));
}

return Immutable.List(merged);

} else {
if (value === false) {
return false;
Expand Down
42 changes: 40 additions & 2 deletions test/specs/e2e/cli/e2e.cli.files.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"use strict";

var path = require("path");
var utils = require("../../../../lib/utils");
var assert = require("chai").assert;
var browserSync = require(path.resolve("./"));

var pkg = require(path.resolve("package.json"));
var cli = require(path.resolve(pkg.bin));

describe("E2E CLI `files` arg", function () {
describe("E2E CLI `files` arg - multi globs", function () {

var instance;

Expand All @@ -33,7 +34,44 @@ describe("E2E CLI `files` arg", function () {
after(function () {
instance.cleanup();
});
it.only("Converts cli files arg to correct namespaced watchers", function () {
it("Converts cli files arg to correct namespaced watchers", function () {
assert.equal(instance.options.getIn(["files", "core"]).size, 2);
assert.equal(instance.watchers.core.glob.size, 2);

assert.isTrue(utils.isList(instance.watchers.core.glob));
});
});

describe("E2E CLI `files` arg, single glob", function () {

var instance;

before(function (done) {

browserSync.reset();

cli({
cli: {
input: ["start"],
flags: {
logLevel: "silent",
open: false,
files: "*.html"
}
},
cb: function (err, bs) {
instance = bs;
done();
}
});
});
after(function () {
instance.cleanup();
});
it("Converts cli files arg to correct namespaced watchers", function () {
assert.equal(instance.options.getIn(["files", "core"]).size, 1);
assert.equal(instance.watchers.core.glob.size, 1);

assert.isTrue(utils.isList(instance.watchers.core.glob));
});
});

0 comments on commit 18324f0

Please sign in to comment.