Skip to content

Commit

Permalink
Add bin and style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Oct 20, 2017
1 parent 72153ff commit 675bac9
Show file tree
Hide file tree
Showing 8 changed files with 1,058 additions and 52 deletions.
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.json]
indent_size = 2
11 changes: 10 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ module.exports = {
}],
// Template strings inner spacing
"template-curly-spacing": 0,
"operator-linebreak": [2, "before"]
"operator-linebreak": [2, "before"],
// Line length
"max-len": [2, {
"code": 90,
"ignoreUrls": true,
"ignoreComments": false,
"ignoreStrings": true,
"ignoreTemplateLiterals": true,
"ignoreRegExpLiterals": true
}]
}
};
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ language: node_js
node_js:
- "8"
script:
- npm run prepublish
- npm run prepublishOnly
after_success:
- coveralls < coverage/lcov.info
38 changes: 32 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Version](https://img.shields.io/github/package-json/v/rafamel/yaml-import.svg)](https://github.com/rafamel/yaml-import)
[![Build Status](https://travis-ci.org/rafamel/yaml-import.svg)](https://travis-ci.org/rafamel/yaml-import)
[![Coverage](https://img.shields.io/coveralls/rafamel/yaml-import.svg)](https://coveralls.io/github/rafamel/yaml-import?branch=master)
[![Coverage](https://img.shields.io/coveralls/rafamel/yaml-import.svg)](https://coveralls.io/github/rafamel/yaml-import)
[![Dependencies](https://david-dm.org/rafamel/yaml-import/status.svg)](https://david-dm.org/rafamel/yaml-import)
[![Vulnerabilities](https://snyk.io/test/npm/yaml-import/badge.svg)](https://snyk.io/test/npm/yaml-import)
[![Issues](https://img.shields.io/github/issues/rafamel/yaml-import.svg)](https://github.com/rafamel/yaml-import/issues)
Expand All @@ -23,7 +23,7 @@ With `yaml-import`, the imports are relative to the current *YAML* file.
Import the contents of a single file

```yaml
some:
some:
- yaml
- where I
import: a file like
Expand All @@ -35,7 +35,7 @@ or:

### `!!import/merge` *array*

Merge the contents of numerous files into one object or array.
Merge the contents of numerous files into one object or array.

- If all the files are objects, it will merge all the keys into one single object.
- If one or more of the files contain any other type, it will concatenate an array (so if any of the files is an array itself, all its elements will go into the top level).
Expand Down Expand Up @@ -74,7 +74,30 @@ It will create an `mapping` (object) with keys equivalent to the directory tree

## Usage

### `yimp.write(input, output, options)`
### Command Line

#### `yimp -i input -o output`

If there is not `output` file, the contents will be written to the `stdout`. The list of `ext` (file extensions for directory imports, read more on [`yimp.write()`](#yimpwriteinput-output-options)) must be comma separated, without spaces or dots.

```bash
Options:
-i, --input Path to input file
-o, --output Path to output file
-e, --ext Extension array (comma separated, optional)
--version Show version number
--help Show help
```

#### Example

```bash
yimp -i my-input-file.yml -o my-output-file.yml -e yml,yaml,raml
```

### Simple Programatic Usage

#### `yimp.write(input, output, options)`

Reads a *YAML* file and writes the output on a file.

Expand All @@ -89,10 +112,13 @@ Reads a *YAML* file and writes the output on a file.
const yimp = require('yaml-import');
const path = require('path');

yimp.write(path.join(__dirname, 'myfiles/base.yml'), path.join(__dirname, 'out/yaml.yml'));
yimp.write(
path.join(__dirname, 'myfiles/base.yml'),
path.join(__dirname, 'out/yaml.yml')
);
```

### `yimp.read(input, options)`
#### `yimp.read(input, options)`

Reads a *YAML* file and returns the parsed object.

Expand Down
43 changes: 43 additions & 0 deletions bin/yimp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env node
'use strict';
const yimp = require('../lib');
const yaml = require('js-yaml');
const path = require('path');
const yargs = require('yargs');

const argv = yargs
.alias('i', 'input')
.describe('i', 'Path to input file')
.alias('o', 'output')
.describe('o', 'Path to output file (optional)')
.alias('e', 'ext')
.describe('e', 'Extension array (comma separated, optional)')
.version('version')
.help('help')
.showHelpOnFail(true)
.argv;

const cleanPath = (x) => (x[0] === path.sep) ? x : path.join(process.cwd(), x);

(() => {
if (typeof argv.i !== 'string' || argv.i.length < 1
|| (argv.o !== undefined && (typeof argv.o !== 'string' || argv.o.length < 1))
|| (argv.e !== undefined && typeof argv.e !== 'string')
) {
return yargs.showHelp();
}

let ext;
if (argv.e) {
ext = argv.e.split(',').map(x => `.${x}`);
}

const input = cleanPath(argv.i);
if (!argv.o) {
process.stdout.write(yaml.dump(yimp.read(input)));
return;
}

const output = cleanPath(argv.o);
yimp.write(input, output, { ext });
})();
4 changes: 4 additions & 0 deletions markdown.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"ul-indent": { "indent": 4 },
"line-length": false
}

0 comments on commit 675bac9

Please sign in to comment.