Skip to content

Commit

Permalink
Merge 6d2ee64 into ea663a4
Browse files Browse the repository at this point in the history
  • Loading branch information
Nataniel López committed Oct 1, 2019
2 parents ea663a4 + 6d2ee64 commit 87841c7
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 44 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Removed
- log

## [1.0.0] - 2019-09-27
### Added
- `run.js` for autorun only with npx
- usage as module support
- api usage docs

## [1.1.0] - 2019-09-27
### Added
- lllog package

### Removed
- log

## [1.0.0] - 2019-09-27
### Added
- `yml-builder` package
Expand Down
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A package for build a single yml file from multiple source files.
npm install @janiscommerce/yml-builder
```

## Usage
## Usage (command line)
```sh
npx @janiscommerce/yml-builder -i sourceDir -o outputFile.yml
```
Expand All @@ -35,4 +35,34 @@ npx @janiscommerce/yml-builder -i permissions/src -o permissions/permissions.yml

# Will get the source files from /path/to/root/permissions/src
# Will generate the output file into /path/to/root/permissions/permissions.yml
```

## Usage (as module)
```js
const YmlBuilder = require('@janiscommerce/yml-builder');
```

## API

### **`new YmlBuilder(input, output)`**

Constructs the YmlBuilder instance, configuring the `input [String]` and `output [String]` path.

### **`async execute(input, output)`**

Builds the ymls from the input path into the output file path.
Optionally you can specify the `input [String]` and `output [String]` path, by default it will be obtained from the constructor config.

## Examples

```js
const YmlBuilder = require('@janiscommerce/yml-builder');

const ymlBuilder = new YmlBuilder('input-dir', 'output-file.yml');

(async () => {

await ymlBuilder.execute(); // It will run the build process...

})();
```
40 changes: 1 addition & 39 deletions index.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,43 +1,5 @@
#!/usr/bin/env node

'use strict';

const { argv } = require('yargs')
.option('input', {
alias: 'i',
describe: 'path to your sources directory',
type: 'string',
demandOption: true
})
.option('output', {
alias: 'o',
describe: 'path to the file that will be generated',
type: 'string',
demandOption: true
});

const log = require('./lib/utils/lllog-wrapper');
const { YmlBuilder } = require('./lib');

(async () => {

const { input, output } = argv;

const ymlBuilder = new YmlBuilder(input, output);

try {

await ymlBuilder.execute();

log.confirm('Operation completed successfully', '✓ YML-BUILDER');

process.exit(0);

} catch(error) {

log.error(error.message, 'Operation failed', '⨯ YML-BUILDER');

process.exit(1);
}

})();
module.exports = YmlBuilder;
8 changes: 8 additions & 0 deletions lib/yml-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ class YmlBuilder {
}


/**
* Merge the ymls from the input directory into a single yml
* @param {String} input the input directory for getting ymls to build
* @param {String} output the output file path where build the yml
* @throws if any of the steps fails
* @example
* await ymlBuilder.execute('./input-dir', './output-file.yml');
*/
async execute(input = this._inputPath, output = this._outputPath) {

log.message('Checking input directory...', '⚙ YML-BUILDER');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A package for build a single yml file from multiple source files.",
"main": "index.js",
"bin": {
"yml-builder": "index.js"
"yml-builder": "run.js"
},
"scripts": {
"test": "export TEST_ENV=true; mocha --exit -R nyan --recursive tests/",
Expand Down
43 changes: 43 additions & 0 deletions run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env node

'use strict';

const { argv } = require('yargs')
.option('input', {
alias: 'i',
describe: 'path to your sources directory',
type: 'string',
demandOption: true
})
.option('output', {
alias: 'o',
describe: 'path to the file that will be generated',
type: 'string',
demandOption: true
});

const log = require('./lib/utils/lllog-wrapper');
const YmlBuilder = require('./index');

(async () => {

const { input, output } = argv;

const ymlBuilder = new YmlBuilder(input, output);

try {

await ymlBuilder.execute();

log.confirm('Operation completed successfully', '✓ YML-BUILDER');

process.exit(0);

} catch(error) {

log.error(error.message, 'Operation failed', '⨯ YML-BUILDER');

process.exit(1);
}

})();
6 changes: 3 additions & 3 deletions tests/index-test.js → tests/run-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('index', () => {
beforeEach(() => {
sandbox.stub(process, 'exit').returns();
sandbox.stub(console, 'log').returns();
YmlBuilder = require('./../lib/yml-builder'); // eslint-disable-line
YmlBuilder = require('./../index'); // eslint-disable-line
});

afterEach(() => {
Expand All @@ -35,7 +35,7 @@ describe('index', () => {
.expects('execute')
.returns();

const index = require('./../index'); // eslint-disable-line
const index = require('./../run'); // eslint-disable-line

ymlBuilderMock.verify();
});
Expand All @@ -46,7 +46,7 @@ describe('index', () => {
.expects('execute')
.rejects();

const index = require('./../index'); // eslint-disable-line
const index = require('./../run'); // eslint-disable-line

ymlBuilderMock.verify();
});
Expand Down

0 comments on commit 87841c7

Please sign in to comment.