Skip to content

Commit

Permalink
cli: cleaning up --watch and --no-watch option
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod committed Dec 4, 2017
1 parent d9e18e9 commit d19417c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
8 changes: 6 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function broccoliCLI(args) {
.option('--output-path <path>', 'the path to target output folder')
.option('--no-watch', 'turn off the watcher')
.action(options => {
const Watcher = options.watch ? broccoli.Watcher : broccoli.DummyWatcher;
const Watcher = getWatcher(options.watch);
const outputDir = options.outputPath;
const builder = getBuilder({ brocfilePath: options.brocfilePath });
const watcher = new Watcher(builder);
Expand All @@ -52,7 +52,7 @@ module.exports = function broccoliCLI(args) {
.option('--output-path <path>', 'the path to target output folder')
.option('--watch', 'turn on the watcher')
.action((outputDir, options) => {
const Watcher = options.watch ? broccoli.Watcher : broccoli.DummyWatcher;
const Watcher = getWatcher(options.watch);

if (outputDir && options.outputPath) {
console.error('option --output-path and [target] cannot be passed at same time');
Expand Down Expand Up @@ -117,6 +117,10 @@ function getBuilder(options) {
return new broccoli.Builder(broccoli.loadBrocfile(options.brocfilePath));
}

function getWatcher(isWatching) {
return isWatching ? broccoli.Watcher : require('./dummy-watcher');
}

function guardOutputDir(outputDir) {
if (fs.existsSync(outputDir)) {
console.error(outputDir + '/ already exists; we cannot build into an existing directory');
Expand Down
3 changes: 0 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ module.exports = {
get getMiddleware() {
return require('./middleware');
},
get DummyWatcher() {
return require('./dummy-watcher');
},
get Watcher() {
return require('./watcher');
},
Expand Down
7 changes: 2 additions & 5 deletions test/cli_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const sinon = require('sinon').createSandbox();
const sinonChai = require('sinon-chai');

const Builder = require('../lib/builder');
const DummyWatcher = require('../lib/dummy-watcher');
const broccoli = require('../lib/index');
const cli = require('../lib/cli');
const loadBrocfile = require('../lib/load_brocfile');
Expand Down Expand Up @@ -239,11 +240,7 @@ describe('cli', function() {
server
.expects('serve')
.once()
.withArgs(
sinon.match.instanceOf(broccoli.DummyWatcher),
sinon.match.string,
sinon.match.number
);
.withArgs(sinon.match.instanceOf(DummyWatcher), sinon.match.string, sinon.match.number);
cli(['node', 'broccoli', 'serve', '--no-watch']);
server.verify();
});
Expand Down

0 comments on commit d19417c

Please sign in to comment.