Skip to content

Commit

Permalink
Merge pull request #425 from blackflux/dev
Browse files Browse the repository at this point in the history
[Gally]: master <- dev
  • Loading branch information
simlu authored Aug 10, 2019
2 parents 89a9b5e + a8475e9 commit 1d25a18
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 188 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ ${fileFn(./path/to/file.js)}
The reference file needs to export simple function returning an object. Available variables are passed in.

```js
module.exports = args => ({ args });
module.exports = (args) => ({ args });
```

##### Relative File References
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"chai": "4.2.0",
"coveralls": "3.0.6",
"eslint": "6.1.0",
"js-gardener": "2.0.58",
"js-gardener": "2.0.59",
"nyc": "14.1.1",
"semantic-release": "15.13.19"
},
Expand Down
11 changes: 7 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ const loadRecursive = (dir, relDir, data, vars) => {
/^\${(require|file|fileFn)\(([~^]?[a-zA-Z\d._\-@/]+?)\)(?::([a-zA-Z\d.]+?))?(?:, ([a-zA-Z\d=\-&/.:[\],]+?))?}$/g
).exec(result);
if (match) {
const varsNew = Object.assign({}, vars, match[4] ? JSON
.parse(`{"${match[4].replace(/&/g, '","').replace(/=/g, '":"')}"}`) : {});
const varsNew = {
...vars,
...(match[4] ? JSON
.parse(`{"${match[4].replace(/&/g, '","').replace(/=/g, '":"')}"}`) : {})
};

let loaded;
let newRelDir = relDir;
Expand All @@ -47,9 +50,9 @@ const loadRecursive = (dir, relDir, data, vars) => {
}
}
if (result instanceof Object) {
const toMerge = get(result, '<<<', []).map(e => loadRecursive(dir, relDir, e, vars));
const toMerge = get(result, '<<<', []).map((e) => loadRecursive(dir, relDir, e, vars));
delete result['<<<'];
Object.keys(result).forEach(key => set(result, key, loadRecursive(dir, relDir, get(result, key), vars)));
Object.keys(result).forEach((key) => set(result, key, loadRecursive(dir, relDir, get(result, key), vars)));
result = toMerge.reduce((prev, cur) => mergeWith(prev, cur, concatArrays), result);
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion test/resources/child-fn.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = args => ({ key: args });
module.exports = (args) => ({ key: args });
Loading

0 comments on commit 1d25a18

Please sign in to comment.