stefanpenner/ember-app-kit — pull request #426 by pangratz (2014-01-18 19:19:03+00:00)
Title: Merge `custom-options` to allow additional tasks

Changes in 2ae12fb9d2b9169a53dc5748fe9ce66e52bcbdbf and fe0f687d0958a508bf2e8118c17a8f419af5277d made it possible to specifycustom grunt configurations. The idea is to specify custom tasks inside the `tasks/custom-options` folder. For example there are already tasks for the `copy` plugin defined in `tasks/options/copy.js`, but we can specify a new task in `tasks/custom-options/copy.js`:

```javascript
module.exports = {
custom_copy_task: { ... }
}
```

The problem with the current implementation is that the custom `copy` configuration would completely overwrite the already defined one. That's because Lo-Dash's `_.extend` is used, which [*... will overwrite property assignments of previous sources*](http://lodash.com/docs#assign).

By using `_.merge` instead, the properties are merged since it [*... recursively merges own enumerable properties of the source object(s), that don't resolve to undefined into the destination object*](http://lodash.com/docs#merge) so it is possible to specify a custom configuration and preserve the existing one, as illustrated with the following simple example:

```javascript
var a = { first: { a: "a" } };
var b = { first: { b: "b" } };

grunt.file.write("tmp/extend.js", JSON.stringify(_.extend({}, a, b), null, 2));
grunt.file.write("tmp/merge.js", JSON.stringify(_.merge({}, a, b), null, 2));
```

`diff tmp/extend.js tmp/merge.js --side-by-side` results in the following diff:

```
{ {
"first": { "first": {
> "a": "a",
"b": "b" "b": "b"
} }
} }
```

A task `_log:config` has been added which writes the used grunt configuration to `tmp/grunt_config.js` so the resulting configuration can be inspected to check if the custom tasks are configured correctly.

---

If this PR is merged, I'll give the `gh-pages` branch some :heart: and add documentation on how to specify custom tasks.

cc @MajorBreakfast @Pradeek