Skip to content
This repository has been archived by the owner on Nov 3, 2019. It is now read-only.

Commit

Permalink
feat(CLI): move cli to the bin folder
Browse files Browse the repository at this point in the history
Move CLI to the bin folder, use loud-rejection.
  • Loading branch information
zkochan committed May 8, 2016
1 parent a42d72c commit 692fe68
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 31 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ Do you want to write a new one? Read the [plugins readme](./docs/PLUGINS.md).
- [file-exists](https://github.com/scottcorgan/file-exists): Check if filepath exists and is a file
- [github-url-to-object](https://github.com/zeke/github-url-to-object): Extract user, repo, and other interesting properties from GitHub URLs
- [glob](https://github.com/isaacs/node-glob): a little globber
- [loud-rejection](https://github.com/sindresorhus/loud-rejection): Make unhandled promise rejections fail loudly instead of the default silent fail
- [meow](https://github.com/sindresorhus/meow): CLI app helper
- [mos-init](https://github.com/zkochan/mos-init): Add mos to your project
- [mos-plugin-dependencies](https://github.com/zkochan/mos-plugin-dependencies): A mos plugin that creates dependencies sections
Expand Down
22 changes: 22 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node
'use strict'
const loudRejection = require('loud-rejection')
loudRejection()

const resolve = require('resolve')
const cwd = process.cwd()

let localCLI
try {
localCLI = resolve.sync('mos/bin', { basedir: cwd })
} catch (err) {
localCLI = __filename
}

if (localCLI && localCLI !== __filename) {
console.log('Using local install of mos')
require(localCLI)
return // eslint-disable-line
}

require('../lib/cli')
5 changes: 0 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
'use strict'
process.on('unhandledRejection', function (reason, p) {
console.log('Possibly Unhandled Rejection at: Promise ', p, ' reason: ',
reason)
})

module.exports = require('./lib')
26 changes: 3 additions & 23 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
#!/usr/bin/env node
'use strict'

process.on('unhandledRejection', function (reason, p) {
console.log('Possibly Unhandled Rejection at: Promise ', p, ' reason: ',
reason)
})

const resolve = require('resolve')
const cwd = process.cwd()

let localCLI
try {
localCLI = resolve.sync('mos/lib/cli', { basedir: cwd })
} catch (err) {
localCLI = __filename
}

if (localCLI && localCLI !== __filename) {
console.log('Using local install of mos')
require(localCLI)
return // eslint-disable-line
}

const updateNotifier = require('update-notifier')
const meow = require('meow')
const processFiles = require('./process-files')
Expand All @@ -36,6 +13,9 @@ const tapDiff = require('@zkochan/tap-diff')
const readPkgUp = require('@zkochan/read-pkg-up')
const mos = require('.')
const initCustomPlugins = require('./init-custom-plugins')
const resolve = require('resolve')

const cwd = process.cwd()

const cli = meow([
'Usage',
Expand Down
2 changes: 1 addition & 1 deletion lib/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const expect = require('chai').expect
const execa = require('execa')
const pkg = require('../package.json')
const path = require('path')
const cli = path.resolve(__dirname, './cli.js')
const cli = path.resolve(__dirname, '../bin/index.js')
const testcwd = path.resolve(__dirname, 'test-cli')

describe('cli', () => {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"files": [
"index.js",
"lib",
"plugins"
"bin"
],
"bin": "./lib/cli.js",
"bin": "./bin/index.js",
"preferDev": true,
"engines": {
"node": ">=4"
Expand Down Expand Up @@ -66,6 +66,7 @@
"file-exists": "~1.0.0",
"github-url-to-object": "~2.2.1",
"glob": "~7.0.3",
"loud-rejection": "^1.3.0",
"meow": "~3.7.0",
"mos-init": "^1.0.0",
"mos-plugin-dependencies": "^1.0.2",
Expand Down

0 comments on commit 692fe68

Please sign in to comment.