Comparing version 1.0.2 to 2.0.0
27
cli.js
#!/usr/bin/env node | ||
'use strict'; | ||
var pkg = require('./package.json'); | ||
var meow = require('meow'); | ||
var opn = require('./'); | ||
function help() { | ||
console.log([ | ||
pkg.description, | ||
'', | ||
var cli = meow({ | ||
help: [ | ||
'Usage', | ||
' $ opn <file|url> [app]', | ||
' $ opn <file|url> [app] [app arguments]', | ||
'', | ||
@@ -16,16 +14,7 @@ 'Example', | ||
' $ opn http://sindresorhus.com firefox', | ||
' $ opn http://sindresorhus.com \'google chrome\' --incognito', | ||
' $ opn unicorn.png' | ||
].join('\n')); | ||
} | ||
].join('\n') | ||
}); | ||
if (process.argv.indexOf('--help') !== -1) { | ||
help(); | ||
return; | ||
} | ||
if (process.argv.indexOf('--version') !== -1) { | ||
console.log(pkg.version); | ||
return; | ||
} | ||
opn(process.argv[2], process.argv[3]); | ||
opn(cli.input[0], process.argv.slice(3)); |
30
index.js
@@ -16,4 +16,10 @@ 'use strict'; | ||
var cmd; | ||
var appArgs; | ||
var args = []; | ||
if (Array.isArray(app)) { | ||
appArgs = app.slice(1); | ||
app = app[0]; | ||
} | ||
if (process.platform === 'darwin') { | ||
@@ -29,2 +35,7 @@ cmd = 'open'; | ||
} | ||
if (appArgs) { | ||
args.push('--args') | ||
args = args.concat(appArgs); | ||
} | ||
} else if (process.platform === 'win32') { | ||
@@ -42,2 +53,6 @@ cmd = 'cmd'; | ||
} | ||
if (appArgs) { | ||
args = args.concat(appArgs); | ||
} | ||
} else { | ||
@@ -47,5 +62,8 @@ if (app) { | ||
} else { | ||
// http://portland.freedesktop.org/download/xdg-utils-1.1.0-rc1.tar.gz | ||
cmd = path.join(__dirname, 'xdg-open'); | ||
} | ||
if (appArgs) { | ||
args = args.concat(appArgs); | ||
} | ||
} | ||
@@ -66,3 +84,11 @@ | ||
cp.once('error', cb); | ||
cp.once('close', cb); | ||
cp.once('close', function (code) { | ||
if (code > 0) { | ||
cb(new Error('Exited with code ' + code)); | ||
return; | ||
} | ||
cb(); | ||
}); | ||
} else { | ||
@@ -69,0 +95,0 @@ cp.unref(); |
{ | ||
"name": "opn", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "A better node-open. Opens stuff like websites, files, executables. Cross-platform.", | ||
"license": "MIT", | ||
"repository": "sindresorhus/opn", | ||
"bin": { | ||
"opn": "cli.js" | ||
}, | ||
"bin": "cli.js", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "http://sindresorhus.com" | ||
"url": "sindresorhus.com" | ||
}, | ||
@@ -27,10 +25,13 @@ "engines": { | ||
"keywords": [ | ||
"cli-app", | ||
"cli", | ||
"bin", | ||
"app", | ||
"open", | ||
"opn", | ||
"opener", | ||
"opens", | ||
"launch", | ||
"start", | ||
"xdg-open", | ||
"xdg", | ||
"default", | ||
@@ -40,4 +41,18 @@ "cmd", | ||
"editor", | ||
"executable" | ||
"executable", | ||
"exe", | ||
"url", | ||
"urls", | ||
"arguments", | ||
"args", | ||
"spawn", | ||
"exec", | ||
"child", | ||
"process", | ||
"website", | ||
"file" | ||
], | ||
"dependencies": { | ||
"meow": "^3.1.0" | ||
}, | ||
"devDependencies": { | ||
@@ -44,0 +59,0 @@ "mocha": "*" |
@@ -9,4 +9,7 @@ # opn | ||
- Actively maintained | ||
- Includes the latest [xdg-open script](http://portland.freedesktop.org/download/) | ||
- Fixes most of the `node-open` issues | ||
- Supports app arguments | ||
- Safer as it uses `spawn` instead of `exec` | ||
- Fixes most of the open `node-open` issues | ||
- Comes with a CLI for use in your scripts | ||
- Includes the latest [`xdg-open` script](http://cgit.freedesktop.org/xdg/xdg-utils/commit/?id=c55122295c2a480fa721a9614f0e2d42b2949c18) for Linux | ||
@@ -16,3 +19,3 @@ | ||
```sh | ||
``` | ||
$ npm install --save opn | ||
@@ -27,10 +30,13 @@ ``` | ||
opn('unicorn.png'); | ||
// opens the image in the default image viewer | ||
opn('http://sindresorhus.com'); | ||
// opens that url in the default browser | ||
// opens the url in the default browser | ||
opn('http://sindresorhus.com', 'firefox'); | ||
// you can also specify the app to open in | ||
// specify the app to open in | ||
opn('unicorn.png'); | ||
// opens the image in the default image viewer | ||
opn('http://sindresorhus.com', ['google chrome', '--incognito']); | ||
// specify app arguments | ||
``` | ||
@@ -43,3 +49,3 @@ | ||
### opn(target, [app, callback]) | ||
### opn(target, [app], [callback]) | ||
@@ -51,19 +57,19 @@ #### target | ||
The thing you want to open. Can be a url, file, or executable. | ||
The thing you want to open. Can be a URL, file, or executable. | ||
Opens in the default app for the file type. Eg. urls opens in your default browser. | ||
Opens in the default app for the file type. Eg. URLs opens in your default browser. | ||
#### app | ||
Type: `string` | ||
Type: `string`, `array` | ||
Specify the app to open the `target` with. | ||
Specify the app to open the `target` with, or an array with the app and app arguments. | ||
The app name is platform dependent. Don't hard code it in reusable modules. | ||
The app name is platform dependent. Don't hard code it in reusable modules. Eg. Chrome is `google chrome` on OS X, `google-chrome` on Linux and `chrome` on Windows. | ||
#### callback(err) | ||
#### callback(error) | ||
Type: `function` | ||
Executes when the opened app exits. | ||
Called when the opened app exits. | ||
@@ -75,18 +81,17 @@ On Windows you have to explicitly specify an app for it to be able to wait. | ||
You can also use it as a CLI app by installing it globally: | ||
```sh | ||
``` | ||
$ npm install --global opn | ||
``` | ||
```sh | ||
``` | ||
$ opn --help | ||
Usage | ||
$ opn <file|url> [app] | ||
Usage | ||
$ opn <file|url> [app] [app arguments] | ||
Example | ||
$ opn http://sindresorhus.com | ||
$ opn http://sindresorhus.com firefox | ||
$ opn unicorn.png | ||
Example | ||
$ opn http://sindresorhus.com | ||
$ opn http://sindresorhus.com firefox | ||
$ opn http://sindresorhus.com 'google chrome' --incognito | ||
$ opn unicorn.png | ||
``` | ||
@@ -93,0 +98,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27328
90
97
1
+ Addedmeow@^3.1.0
+ Addedarray-find-index@1.0.2(transitive)
+ Addedcamelcase@2.1.1(transitive)
+ Addedcamelcase-keys@2.1.0(transitive)
+ Addedcurrently-unhandled@0.4.1(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedfind-up@1.1.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-stdin@4.0.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedindent-string@2.1.0(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-finite@1.1.0(transitive)
+ Addedis-utf8@0.2.1(transitive)
+ Addedload-json-file@1.1.0(transitive)
+ Addedloud-rejection@1.6.0(transitive)
+ Addedmap-obj@1.0.1(transitive)
+ Addedmeow@3.7.0(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedparse-json@2.2.0(transitive)
+ Addedpath-exists@2.1.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@1.1.0(transitive)
+ Addedpify@2.3.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedread-pkg@1.1.0(transitive)
+ Addedread-pkg-up@1.0.1(transitive)
+ Addedredent@1.0.0(transitive)
+ Addedrepeating@2.0.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedstrip-bom@2.0.0(transitive)
+ Addedstrip-indent@1.0.1(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtrim-newlines@1.0.0(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)