-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 <nate@skypack.dev>
- Loading branch information
1 parent
b5ed099
commit d0777ad
Showing
3 changed files
with
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Add `astro docs` command which opens the Astro docs in your preferred browser. |
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)]); | ||
}; |