Skip to content

Commit

Permalink
feat(api): support programmatic API (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous authored Sep 27, 2017
1 parent a3fef0c commit 9c22a80
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ npm install ybiq --save-dev

## Usage

### CLI

For details, please show help.

```sh
Expand All @@ -31,6 +33,12 @@ Setup Node.js project.
ybiq init
```

### Programmatic API

```js
const ybiq = require('ybiq')
```

## License

[MIT](LICENSE) © ybiquitous
9 changes: 2 additions & 7 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#!/usr/bin/env node
const dir = require('../src/select-dir')

const semver = require('semver')

if (semver.satisfies(process.version, '>=8')) {
require('../src/cli')() // eslint-disable-line global-require
} else {
require('../lib/cli')() // eslint-disable-line global-require
}
require(`../${dir}/cli`)() // eslint-disable-line import/no-dynamic-require
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
'coverage',
'release',
'init',
'api',
]],
},
}
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const dir = require('./src/select-dir')

// eslint-disable-next-line import/no-dynamic-require
const init = require(`./${dir}/init`)

module.exports = { init }
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"src",
".editorconfig",
".eslintrc.js",
"commitlint.config.js"
"commitlint.config.js",
"index.js"
],
"main": "index.js",
"bin": {
Expand Down
3 changes: 3 additions & 0 deletions src/select-dir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const semver = require('semver')

module.exports = semver.satisfies(process.version, '>=8') ? 'src' : 'lib'
10 changes: 10 additions & 0 deletions test/main.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import assert from 'assert'
import main from '..'

suite('main', () => {
test('init', async () => {
const init = main.init
assert(typeof init === 'function')
assert(init.name === 'init')
})
})

0 comments on commit 9c22a80

Please sign in to comment.