Skip to content

Commit

Permalink
Merge pull request #980 from simlu/master
Browse files Browse the repository at this point in the history
feat: added "resolve" method
  • Loading branch information
simlu authored Oct 8, 2020
2 parents 7c6da0f + 65bf7a6 commit d5a2afa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions .idea/jsLinters/eslint.xml

This file was deleted.

16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ Useful for loading improved [serverless](https://serverless.com/) configuration.

$ npm install --save yaml-boost

## Api

### resolve(refPath, content, vars)

Resolve content with variables at given refPath.

### load(filePath, vars = {})

Load filePath with given variables.

### dump

As provided by `js-yaml` through `safeDump`

## Usage

<!-- eslint-disable import/no-unresolved, import/no-extraneous-dependencies -->
Expand Down Expand Up @@ -84,7 +98,7 @@ Once can reference files relative to the current file by using `^` as a prefix l

```yaml
${file(^/subfolder/of/current/file.yml)}
```
```

##### Deep Merge

Expand Down
11 changes: 8 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ const loadRecursive = (dir, relDir, data, vars) => {
return result;
};

module.exports.load = (filePath, vars = {}) => loadRecursive(
path.dirname(filePath),
path.dirname(filePath),
const resolve = (refPath, content, vars) => {
const dirname = path.dirname(refPath);
return loadRecursive(dirname, dirname, content, vars);
};
module.exports.resolve = resolve;

module.exports.load = (filePath, vars = {}) => resolve(
filePath,
yaml.safeLoad(fs.readFileSync(filePath, 'utf8')),
vars
);
Expand Down

0 comments on commit d5a2afa

Please sign in to comment.