This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ux from '../src' | ||
|
||
ux.open('https://oclif.io') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// this code is largely taken from opn | ||
import * as childProcess from 'child_process' | ||
import * as path from 'path' | ||
const isWsl = require('is-wsl') | ||
|
||
export namespace open { | ||
export interface Options { | ||
// wait: boolean | ||
app?: string | string[] | ||
} | ||
} | ||
|
||
export default function open(target: string, opts: open.Options = {}) { | ||
// opts = {wait: true, ...opts} | ||
|
||
let cmd | ||
let appArgs: string[] = [] | ||
let args: string[] = [] | ||
const cpOpts: childProcess.SpawnOptions = {} | ||
|
||
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', '""', '/b') | ||
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 = process.platform === 'android' ? 'xdg-open' : 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 and it's detached from the parent | ||
// even if it's unref'd | ||
cpOpts.stdio = 'ignore' | ||
cpOpts.detached = true | ||
// } | ||
} | ||
|
||
args.push(target) | ||
|
||
if (process.platform === 'darwin' && appArgs.length > 0) { | ||
args.push('--args') | ||
args = args.concat(appArgs) | ||
} | ||
|
||
const cp = childProcess.spawn(cmd, args, cpOpts) | ||
|
||
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) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -813,6 +813,10 @@ is-resolvable@^1.0.0: | |
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/is-resolvable/-/is-resolvable-1.1.0.tgz#fb18f87ce1feb925169c9a407c19318a3206ed88" | ||
|
||
is-wsl@^1.1.0: | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d" | ||
|
||
[email protected]: | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" | ||
|