-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/sc-126222/update-the-particle-cli-executable-in…
…-workbench' of github.com:particle-iot/particle-cli into feature/sc-126222/update-the-particle-cli-executable-in-workbench
- Loading branch information
Showing
4 changed files
with
58 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,53 @@ | ||
// Copy of https://github.com/rauschma/openurl with additional error handling | ||
const spawn = require('child_process').spawn; | ||
|
||
let command; | ||
|
||
switch(process.platform) { | ||
case 'darwin': | ||
command = 'open'; | ||
break; | ||
case 'win32': | ||
command = 'explorer.exe'; | ||
break; | ||
case 'linux': | ||
command = 'xdg-open'; | ||
break; | ||
default: | ||
throw new Error('Unsupported platform: ' + process.platform); | ||
} | ||
|
||
/** | ||
* Error handling is deliberately minimal, as this function is to be easy to use for shell scripting | ||
* | ||
* @param url The URL to open | ||
* @param callback A function with a single error argument. Optional. | ||
*/ | ||
|
||
function open(url, callback) { | ||
const child = spawn(command, [url]); | ||
child.on('error', function (error) { | ||
callback(error); | ||
}); | ||
let errorText = ""; | ||
child.stderr.setEncoding('utf8'); | ||
child.stderr.on('data', function (data) { | ||
errorText += data; | ||
}); | ||
child.stderr.on('end', function () { | ||
if (errorText.length > 0) { | ||
const error = new Error(errorText); | ||
if (callback) { | ||
callback(error); | ||
} else { | ||
throw error; | ||
} | ||
} else if (callback) { | ||
callback(); | ||
} | ||
}); | ||
} | ||
|
||
module.exports = { | ||
open | ||
}; |
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