Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,94 @@
'use strict';
const path = require('path');
const childProcess = require('child_process');
const isWsl = require('is-wsl');
module.exports = (target, opts) => {
if (typeof target !== 'string') {
return Promise.reject(new Error('Expected a `target`'));
}
opts = Object.assign({wait: true}, opts);
let cmd;
let appArgs = [];
let args = [];
const cpOpts = {};
if (Array.isArray(opts.app)) {
appArgs = opts.app.slice(1);
opts.app = opts.app[0];
}
if (process.platform === 'darwin') {
cmd = 'open';
if (opts.wait) {
args.push('-W');
}
if (opts.app) {
args.push('-a', opts.app);
}
} else if (process.platform === 'win32' || isWsl) {
cmd = 'cmd' + (isWsl ? '.exe' : '');
args.push('/c', 'start', '""');
target = target.replace(/&/g, '^&');
if (opts.wait) {
args.push('/wait');
}
if (opts.app) {
args.push(opts.app);
}
if (appArgs.length > 0) {
args = args.concat(appArgs);
}
} else {
if (opts.app) {
cmd = opts.app;
} else {
cmd = path.join(__dirname, 'xdg-open');
}
if (appArgs.length > 0) {
args = args.concat(appArgs);
}
if (!opts.wait) {
// `xdg-open` will block the process unless
// stdio is ignored even if it's unref'd
cpOpts.stdio = 'ignore';
}
}
args.push(target);
if (process.platform === 'darwin' && appArgs.length > 0) {
args.push('--args');
args = args.concat(appArgs);
}
const cp = childProcess.spawn(cmd, args, cpOpts);
if (opts.wait) {
return new Promise((resolve, reject) => {
cp.once('error', reject);
cp.once('close', code => {
if (code > 0) {
reject(new Error('Exited with code ' + code));
return;
}
resolve(cp);
});
});
}
cp.unref();
return Promise.resolve(cp);
};

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,92 @@
{
"_args": [
[
"opn@5.1.0",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "opn@5.1.0",
"_id": "opn@5.1.0",
"_inBundle": false,
"_integrity": "sha512-iPNl7SyM8L30Rm1sjGdLLheyHVw5YXVfi3SKWJzBI7efxRwHojfRFjwE/OLM6qp9xJYMgab8WicTU1cPoY+Hpg==",
"_location": "/react-scripts/opn",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "opn@5.1.0",
"name": "opn",
"escapedName": "opn",
"rawSpec": "5.1.0",
"saveSpec": null,
"fetchSpec": "5.1.0"
},
"_requiredBy": [
"/react-scripts/react-dev-utils",
"/react-scripts/webpack-dev-server"
],
"_resolved": "https://registry.npmjs.org/opn/-/opn-5.1.0.tgz",
"_spec": "5.1.0",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"bugs": {
"url": "https://github.com/sindresorhus/opn/issues"
},
"dependencies": {
"is-wsl": "^1.1.0"
},
"description": "A better node-open. Opens stuff like websites, files, executables. Cross-platform.",
"devDependencies": {
"ava": "*",
"xo": "*"
},
"engines": {
"node": ">=4"
},
"files": [
"index.js",
"xdg-open"
],
"homepage": "https://github.com/sindresorhus/opn#readme",
"keywords": [
"app",
"open",
"opn",
"opener",
"opens",
"launch",
"start",
"xdg-open",
"xdg",
"default",
"cmd",
"browser",
"editor",
"executable",
"exe",
"url",
"urls",
"arguments",
"args",
"spawn",
"exec",
"child",
"process",
"website",
"file"
],
"license": "MIT",
"name": "opn",
"repository": {
"type": "git",
"url": "git+https://github.com/sindresorhus/opn.git"
},
"scripts": {
"test": "xo && ava"
},
"version": "5.1.0"
}

View File

@@ -0,0 +1,88 @@
# opn
> A better [node-open](https://github.com/pwnall/node-open). Opens stuff like websites, files, executables. Cross-platform.
#### Why?
- Actively maintained
- Supports app arguments
- Safer as it uses `spawn` instead of `exec`
- Fixes most of the open `node-open` issues
- Includes the latest [`xdg-open` script](http://cgit.freedesktop.org/xdg/xdg-utils/commit/?id=c55122295c2a480fa721a9614f0e2d42b2949c18) for Linux
## Install
```
$ npm install --save opn
```
## Usage
```js
const opn = require('opn');
// Opens the image in the default image viewer
opn('unicorn.png').then(() => {
// image viewer closed
});
// Opens the url in the default browser
opn('http://sindresorhus.com');
// Specify the app to open in
opn('http://sindresorhus.com', {app: 'firefox'});
// Specify app arguments
opn('http://sindresorhus.com', {app: ['google chrome', '--incognito']});
```
## API
Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
### opn(target, [options])
Returns a promise for the [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You would normally not need to use this for anything, but it can be useful if you'd like to attach custom event listeners or perform other operations directly on the spawned process.
#### target
Type: `string`
The thing you want to open. Can be a URL, file, or executable.
Opens in the default app for the file type. For example, URLs opens in your default browser.
#### options
Type: `Object`
##### wait
Type: `boolean`<br>
Default: `true`
Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.
On Windows you have to explicitly specify an app for it to be able to wait.
##### app
Type: `string` `Array`
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. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows.
## Related
- [opn-cli](https://github.com/sindresorhus/opn-cli) - CLI for this module
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

File diff suppressed because it is too large Load Diff