From 18324f0a7b4d3c49bd16800a7ba77cf13ea2449a Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Thu, 5 Feb 2015 14:08:51 +0000 Subject: [PATCH] fix(cli): explode files args when given on command line. fixes #425, fixes #426 --- lib/cli/cli-options.js | 19 ++++++++++--- test/specs/e2e/cli/e2e.cli.files.js | 42 +++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/lib/cli/cli-options.js b/lib/cli/cli-options.js index 5a6fd57a9..6b875d92f 100644 --- a/lib/cli/cli-options.js +++ b/lib/cli/cli-options.js @@ -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} @@ -229,14 +240,12 @@ 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); } @@ -244,7 +253,9 @@ opts.callbacks = { if (argv.exclude) { merged = merged.concat(opts.utils.addExcluded(argv.exclude)); } + return Immutable.List(merged); + } else { if (value === false) { return false; diff --git a/test/specs/e2e/cli/e2e.cli.files.js b/test/specs/e2e/cli/e2e.cli.files.js index 8b7e20468..98bcde791 100644 --- a/test/specs/e2e/cli/e2e.cli.files.js +++ b/test/specs/e2e/cli/e2e.cli.files.js @@ -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; @@ -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)); }); });