Skip to content

Commit

Permalink
feat(open): add open which uses opn-cli
Browse files Browse the repository at this point in the history
Closes #4
  • Loading branch information
Kent C. Dodds committed Mar 2, 2017
1 parent 5a5f606 commit e341807
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 10 deletions.
6 changes: 5 additions & 1 deletion package-scripts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require('babel-register') // eslint-disable-line import/no-unassigned-import
const path = require('path')
const {oneLine} = require('common-tags')
const {concurrent, series} = require('./src')
const {concurrent, series, open} = require('./src')

module.exports = {
scripts: {
Expand All @@ -15,6 +16,9 @@ module.exports = {
default: `jest --coverage`,
watch: 'jest --watch',
},
openCoverage: open(
`file://${path.resolve('coverage/lcov-report/index.html')}`
),
build: {
description: 'delete the dist directory and run babel to build the files',
script: oneLine`
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"cpy-cli": "^1.0.1",
"is-windows": "^1.0.0",
"mkdirp": "^0.5.1",
"opn-cli": "^3.1.0",
"rimraf": "^2.6.1"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions src/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ exports[`mkdirp as darwin 1`] = `"node node_modules/mkdirp/bin/cmd.js /tmp/foo/b

exports[`mkdirp as win32 1`] = `"node node_modules/mkdirp/bin/cmd.js /tmp/foo/bar/baz"`;

exports[`open as darwin 1`] = `"node node_modules/opn-cli/cli.js http://kentcdodds.com -- \\"google chrome\\" --incognito"`;

exports[`open as win32 1`] = `"node node_modules/opn-cli/cli.js http://kentcdodds.com -- \\"google chrome\\" --incognito"`;

exports[`rimraf as darwin 1`] = `"node node_modules/rimraf/bin.js build"`;

exports[`rimraf as win32 1`] = `"node node_modules/rimraf/bin.js build"`;
Expand Down
13 changes: 13 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export {
ifNotWindows,
copy,
mkdirp,
open,
}

/**
Expand Down Expand Up @@ -276,6 +277,18 @@ function mkdirp(args) {
return `${getBin('mkdirp')} ${args}`
}

/**
* Gets a script that uses the opn-cli binary. opn-cli
* is a dependency of nps-utils, so you don't need to
* install it yourself.
* @param {string} args - args to pass to opn-cli
* learn more from http://npm.im/opn-cli
* @return {string} - the command with the opn-cli binary
*/
function open(args) {
return `${getBin('opn-cli', 'opn')} ${args}`
}

// utils

function quoteScript(script, escaped) {
Expand Down
2 changes: 2 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const snapshotTests = {
ifNotWindows: ({ifNotWindows}) => ifNotWindows('echo main', 'echo alternate'),
copy: ({copy}) => copy('"**/*.html" "../dist/" --cwd=src --parents'),
mkdirp: ({mkdirp}) => mkdirp('/tmp/foo/bar/baz'),
open: ({open}) =>
open('http://kentcdodds.com -- "google chrome" --incognito'),
}

Object.keys(snapshotTests).forEach(testName => {
Expand Down
48 changes: 39 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2149,6 +2149,10 @@ file-entry-cache@^2.0.0:
flat-cache "^1.2.1"
object-assign "^4.0.1"

file-type@^3.6.0:
version "3.9.0"
resolved "https://registry.yarnpkg.com/file-type/-/file-type-3.9.0.tgz#257a078384d1db8087bc449d107d52a52672b9e9"

filename-regex@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.0.tgz#996e3e80479b98b9897f15a8a58b3d084e926775"
Expand Down Expand Up @@ -3677,7 +3681,7 @@ memory-fs@^0.4.0, memory-fs@~0.4.1:
errno "^0.1.3"
readable-stream "^2.0.1"

meow@^3.3.0, meow@^3.6.0:
meow@^3.3.0, meow@^3.6.0, meow@^3.7.0:
version "3.7.0"
resolved "https://registry.yarnpkg.com/meow/-/meow-3.7.0.tgz#72cb668b425228290abbfa856892587308a801fb"
dependencies:
Expand Down Expand Up @@ -4092,6 +4096,23 @@ onetime@^2.0.0:
dependencies:
mimic-fn "^1.0.0"

opn-cli@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/opn-cli/-/opn-cli-3.1.0.tgz#f819ae6cae0b411bd0149b8560fe6c88adad20f8"
dependencies:
file-type "^3.6.0"
get-stdin "^5.0.1"
meow "^3.7.0"
opn "^4.0.0"
temp-write "^2.1.0"

opn@^4.0.0:
version "4.0.2"
resolved "https://registry.yarnpkg.com/opn/-/opn-4.0.2.tgz#7abc22e644dff63b0a96d5ab7f2790c0f01abc95"
dependencies:
object-assign "^4.0.1"
pinkie-promise "^2.0.0"

opt-cli@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/opt-cli/-/opt-cli-1.5.1.tgz#04db447b13c96b992eb31685266f4ed0d9736dc2"
Expand Down Expand Up @@ -4283,7 +4304,7 @@ pbkdf2@^3.0.3:
dependencies:
create-hmac "^1.1.2"

pify@^2.0.0, pify@^2.3.0:
pify@^2.0.0, pify@^2.2.0, pify@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c"

Expand Down Expand Up @@ -4804,13 +4825,7 @@ rx@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/rx/-/rx-4.1.0.tgz#a5f13ff79ef3b740fe30aa803fb09f98805d4782"

rxjs@^5.0.0-beta.11:
version "5.1.1"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.1.1.tgz#fc48922965bc6c5efbcc0fe46e90a3af64137a7b"
dependencies:
symbol-observable "^1.0.1"

rxjs@^5.2.0:
rxjs@^5.0.0-beta.11, rxjs@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.2.0.tgz#db537de8767c05fa73721587a29e0085307d318b"
dependencies:
Expand Down Expand Up @@ -5186,6 +5201,17 @@ tar@~2.2.1:
fstream "^1.0.2"
inherits "2"

temp-write@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/temp-write/-/temp-write-2.1.0.tgz#59890918e0ef09d548aaa342f4bd3409d8404e96"
dependencies:
graceful-fs "^4.1.2"
mkdirp "^0.5.0"
os-tmpdir "^1.0.0"
pify "^2.2.0"
pinkie-promise "^2.0.0"
uuid "^2.0.1"

temp@~0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/temp/-/temp-0.5.1.tgz#77ab19c79aa7b593cbe4fac2441768cad987b8df"
Expand Down Expand Up @@ -5381,6 +5407,10 @@ util@0.10.3, util@^0.10.3:
dependencies:
inherits "2.0.1"

uuid@^2.0.1:
version "2.0.3"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a"

uuid@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1"
Expand Down

0 comments on commit e341807

Please # to comment.