forked from laptou/astro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* So This works π * need to add to the cli next * Renamed Files and Export Applied creditation to where I found the 'inspiration' for this application. * applied `astro docs` to cli * Trying to add to CLI, Not working π€·ββοΈ * Converted into async method, * ππ It works!!! π₯³ππ₯³ Embarrasing as it is I totally missed the part where logic was to be in. * Moved `docs` cmd to `supportedCommands` * refactor: cleanup docs command * chore: add changeset * chore: rename browser to open Co-authored-by: Nate Moore <[email protected]>
- Loading branch information
1 parent
ef610f0
commit 0aafba4
Showing
2 changed files
with
44 additions
and
3 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,32 @@ | ||
import type { ExecaChildProcess } from 'execa'; | ||
import { execa } from 'execa'; | ||
|
||
/** | ||
* Credit: Azhar22 | ||
* @see https://github.com/azhar22k/ourl/blob/master/index.js | ||
*/ | ||
const getPlatformSpecificCommand = (): [string]|[string, string[]] => { | ||
const isGitPod = Boolean(process.env.GITPOD_REPO_ROOT); | ||
const platform = isGitPod ? 'gitpod' : process.platform; | ||
|
||
switch (platform) { | ||
case 'android': | ||
case 'linux': | ||
return ['xdg-open']; | ||
case 'darwin': | ||
return ['open']; | ||
case 'win32': | ||
return ['cmd', ['/c', 'start']]; | ||
case 'gitpod': | ||
return ['/ide/bin/remote-cli/gitpod-code', ['--openExternal']]; | ||
default: | ||
throw new Error( | ||
`It looks like your platform ("${platform}") isn't supported!\nTo view Astro's docs, please visit https://docs.astro.build` | ||
); | ||
} | ||
}; | ||
|
||
export async function openInBrowser(url: string): Promise<ExecaChildProcess> { | ||
const [command, args = []] = getPlatformSpecificCommand(); | ||
return execa(command, [...args, encodeURI(url)]); | ||
}; |