Skip to content

Commit

Permalink
cli: build option --output-path
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod committed Nov 28, 2017
1 parent a8f9fb2 commit 0ae0447
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,22 @@ module.exports = function broccoliCLI(args) {
});

program
.command('build <target>')
.command('build [target]')
.description('output files to target directory')
.option('--brocfile-path <path>', 'the path to brocfile')
.option('--output-path <path>', 'the path to target output folder')
.action((outputDir, options) => {
actionPerformed = true;

if (outputDir && options.outputPath) {
console.error('option --output-path and [target] cannot be passed at same time');
process.exit(1);
}

if (options.outputPath) {
outputDir = options.outputPath;
}

if (fs.existsSync(outputDir)) {
console.error(outputDir + '/ already exists; we cannot build into an existing directory');
process.exit(1);
Expand Down
55 changes: 54 additions & 1 deletion test/cli_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Builder = require('../lib/builder');
const broccoli = require('../lib/index');
const chai = require('chai');
const cli = require('../lib/cli');
const fs = require('fs');
const loadBrocfile = require('../lib/load_brocfile');
const rimraf = require('rimraf');
const sinon = require('sinon').createSandbox();
Expand Down Expand Up @@ -55,9 +56,17 @@ describe('cli', function() {
done();
});
});

it('creates output folder', function(done) {
cli(['node', 'broccoli', 'build', 'dist']);
process.nextTick(() => {
chai.expect(fs.existsSync('dist')).to.be.true;
done();
});
});
});

context('param --brocfile-path', function() {
context('with param --brocfile-path', function() {
it('closes process on completion', function(done) {
cli(['node', 'broccoli', 'build', 'dist', '--brocfile-path', '../Brocfile.js']);

Expand All @@ -74,6 +83,50 @@ describe('cli', function() {
chai.expect(spy).to.be.calledWith('../Brocfile.js');
});
});

context('with param --output-path', function() {
it('closes process on completion', function(done) {
cli(['node', 'broccoli', 'build', '--output-path', 'dist']);

process.nextTick(() => {
chai.expect(exitStub).to.be.calledWith(0);
done();
});
});

it('creates output folder', function(done) {
cli(['node', 'broccoli', 'build', '--output-path', 'dist']);
process.nextTick(() => {
chai.expect(fs.existsSync('dist')).to.be.true;
done();
});
});

context('and with [target]', function() {
it('exits with error', function(done) {
cli(['node', 'broccoli', 'build', 'dist', '--output-path', 'dist']);
process.nextTick(() => {
chai.expect(exitStub).to.be.calledWith(1);
done();
});
});

it('outputs error reason to console', function(done) {
const consoleMock = sinon.mock(console);
consoleMock
.expects('error')
.once()
.withArgs('option --output-path and [target] cannot be passed at same time');

cli(['node', 'broccoli', 'build', 'dist', '--output-path', 'dist']);

process.nextTick(() => {
consoleMock.verify();
done();
});
});
});
});
});

describe('serve', function() {
Expand Down

0 comments on commit 0ae0447

Please sign in to comment.