Skip to content

Commit

Permalink
Merge pull request #67 from SparshithNR/dest-dir
Browse files Browse the repository at this point in the history
[Feature] : Provide destDir as an option.
  • Loading branch information
stefanpenner authored Dec 19, 2019
2 parents 896a467 + b880d52 commit 04de5e7
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 222 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ let mergedNode = new MergeTrees(inputNodes, options);

* `annotation`: A note to help tell multiple plugin instances apart.

* `destDir`: A string representing the destination path that merged files will be copied to.

### Example

If this is your `Brocfile.js`:
Expand Down Expand Up @@ -74,6 +76,26 @@ Then running `broccoli build the-output` will generate this folder:

The parent folders, `public` and `scripts` in this case, are not included in the output. The output tree contains only the files *within* each folder, all mixed together.

------

If this is your `Brocfile.js`:

```js
var BroccoliMergeTrees = require('broccoli-merge-trees');

module.exports = new BroccoliMergeTrees(['public', 'scripts'], {
destDir: 'assets'
});
```
Then running `broccoli build the-output` will generate this folder:

the-output
└─ assets
├─ app.js
├─ index.html
└─ images
└─ logo.png

## Contributing

Clone this repo and run the tests like so:
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class BroccoliMergeTrees extends Plugin {
if (this.mergeTrees == null) {
// Defer instantiation until the first build because we only
// have this.inputPaths and this.outputPath once we build.
this.mergeTrees = new MergeTrees(this.inputPaths, this.outputPath, {
let outputPath = `${this.outputPath}${this.options.destDir ? '/' + this.options.destDir : ''}`;
this.mergeTrees = new MergeTrees(this.inputPaths, outputPath, {
overwrite: this.options.overwrite,
annotation: this.options.annotation
});
Expand Down
20 changes: 20 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ describe('MergeTrees', function() {
'a.log': 'B',
});
});

it('smoke test with destDir', async function() {
input.write({
foo: '1'
});
input2.write({
baz: {}
});
subject = new MergeTrees([input.path(), input2.path()], {
destDir: 'test'
});
output = createBuilder(subject);
await output.build();
expect(output.read()).to.deep.equal({
test : {
foo: '1',
baz: {}
}
});
});
});


Expand Down
Loading

0 comments on commit 04de5e7

Please sign in to comment.