@@ -6,6 +6,9 @@ import { mkdir, readlink, symlink, unlink } from 'fs/promises'
66/** The path for the installed command line tool. */
77export const InstalledCLIPath = '/usr/local/bin/github-desktop-plus-cli'
88
9+ /** Shorter alias for the CLI. */
10+ const InstalledCLIAliasPath = '/usr/local/bin/github-plus'
11+
912/** The path to the packaged CLI. */
1013const PackagedPath = Path . resolve (
1114 __dirname ,
@@ -15,38 +18,45 @@ const PackagedPath = Path.resolve(
1518
1619/** Install the command line tool on macOS. */
1720export async function installCLI ( ) : Promise < void > {
18- const installedPath = await getResolvedInstallPath ( )
19- if ( installedPath === PackagedPath ) {
21+ await installCLIAt ( InstalledCLIPath )
22+ await installCLIAt ( InstalledCLIAliasPath )
23+ }
24+
25+ async function installCLIAt ( installPath : string ) : Promise < void > {
26+ const resolvedPath = await getResolvedInstallPath ( installPath )
27+ if ( resolvedPath === PackagedPath ) {
2028 return
2129 }
2230
2331 try {
24- await symlinkCLI ( false )
32+ await symlinkCLI ( installPath , false )
2533 } catch ( e ) {
2634 // If we error without running as an admin, try again as an admin.
27- await symlinkCLI ( true )
35+ await symlinkCLI ( installPath , true )
2836 }
2937}
3038
31- async function getResolvedInstallPath ( ) : Promise < string | null > {
39+ async function getResolvedInstallPath (
40+ installPath : string
41+ ) : Promise < string | null > {
3242 try {
33- return await readlink ( InstalledCLIPath )
43+ return await readlink ( installPath )
3444 } catch {
3545 return null
3646 }
3747}
3848
39- function removeExistingSymlink ( asAdmin : boolean ) {
49+ function removeExistingSymlink ( installPath : string , asAdmin : boolean ) {
4050 if ( ! asAdmin ) {
41- return unlink ( InstalledCLIPath )
51+ return unlink ( installPath )
4252 }
4353
4454 return new Promise < void > ( ( resolve , reject ) => {
45- fsAdmin . unlink ( InstalledCLIPath , error => {
55+ fsAdmin . unlink ( installPath , error => {
4656 if ( error !== null ) {
4757 reject (
4858 new Error (
49- `Failed to remove file at ${ InstalledCLIPath } . Authorization of GitHub Desktop Helper is required.`
59+ `Failed to remove file at ${ installPath } . Authorization of GitHub Desktop Helper is required.`
5060 )
5161 )
5262 return
@@ -57,8 +67,8 @@ function removeExistingSymlink(asAdmin: boolean) {
5767 } )
5868}
5969
60- function createDirectories ( asAdmin : boolean ) {
61- const path = Path . dirname ( InstalledCLIPath )
70+ function createDirectories ( installPath : string , asAdmin : boolean ) {
71+ const path = Path . dirname ( installPath )
6272
6373 if ( ! asAdmin ) {
6474 return mkdir ( path , { recursive : true } )
@@ -69,7 +79,7 @@ function createDirectories(asAdmin: boolean) {
6979 if ( error !== null ) {
7080 reject (
7181 new Error (
72- `Failed to create intermediate directories to ${ InstalledCLIPath } `
82+ `Failed to create intermediate directories to ${ installPath } `
7383 )
7484 )
7585 return
@@ -80,16 +90,16 @@ function createDirectories(asAdmin: boolean) {
8090 } )
8191}
8292
83- function createNewSymlink ( asAdmin : boolean ) {
93+ function createNewSymlink ( installPath : string , asAdmin : boolean ) {
8494 if ( ! asAdmin ) {
85- return symlink ( PackagedPath , InstalledCLIPath )
95+ return symlink ( PackagedPath , installPath )
8696 }
8797
8898 return new Promise < void > ( ( resolve , reject ) => {
89- fsAdmin . symlink ( PackagedPath , InstalledCLIPath , error => {
99+ fsAdmin . symlink ( PackagedPath , installPath , error => {
90100 if ( error !== null ) {
91101 reject (
92- new Error ( `Failed to symlink ${ PackagedPath } to ${ InstalledCLIPath } ` )
102+ new Error ( `Failed to symlink ${ PackagedPath } to ${ installPath } ` )
93103 )
94104 return
95105 }
@@ -99,8 +109,8 @@ function createNewSymlink(asAdmin: boolean) {
99109 } )
100110}
101111
102- async function symlinkCLI ( asAdmin : boolean ) : Promise < void > {
103- await removeExistingSymlink ( asAdmin )
104- await createDirectories ( asAdmin )
105- await createNewSymlink ( asAdmin )
112+ async function symlinkCLI ( installPath : string , asAdmin : boolean ) : Promise < void > {
113+ await removeExistingSymlink ( installPath , asAdmin )
114+ await createDirectories ( installPath , asAdmin )
115+ await createNewSymlink ( installPath , asAdmin )
106116}
0 commit comments