1- import os from 'node:os' ;
2- import path from 'node:path' ;
1+ import { arch , platform } from 'node:os' ;
2+ import { join } from 'node:path' ;
33
4- const ARCHITECTURE = {
5- arm : 'arm' ,
6- arm64 : 'arm64' ,
7- x32 : '386' ,
8- x64 : 'amd64' ,
9- } as const ;
4+ enum Architecture {
5+ arm = 'arm' ,
6+ arm64 = 'arm64' ,
7+ x32 = '386' ,
8+ x64 = 'amd64' ,
9+ }
1010
1111/**
1212 * Gets the operating system CPU architecture.
@@ -17,14 +17,14 @@ const ARCHITECTURE = {
1717 * @returns - Return value in [arm, arm64, 386, amd64]
1818 */
1919function getArch ( arch : NodeJS . Architecture ) {
20- return ARCHITECTURE [ arch as keyof typeof ARCHITECTURE ] || arch ;
20+ return Architecture [ arch as keyof typeof Architecture ] || arch ;
2121}
2222
23- const PLATFORM = {
24- darwin : 'macOS' ,
25- linux : 'linux' ,
26- win32 : 'windows' ,
27- } as const ;
23+ enum Platform {
24+ darwin = 'macOS' ,
25+ linux = 'linux' ,
26+ win32 = 'windows' ,
27+ }
2828
2929/**
3030 * Gets a string identifying the operating system platform.
@@ -35,7 +35,7 @@ const PLATFORM = {
3535 * @returns - Return value in [macOS, linux, windows]
3636 */
3737function getOS ( os : NodeJS . Platform ) {
38- return PLATFORM [ os as keyof typeof PLATFORM ] || os ;
38+ return Platform [ os as keyof typeof Platform ] || os ;
3939}
4040
4141/**
@@ -47,14 +47,14 @@ function getOS(os: NodeJS.Platform) {
4747 * @returns - URL and binary path
4848 */
4949export function getDownloadObject ( version : string ) {
50- const platform = os . platform ( ) ;
51- const arch = os . arch ( ) as NodeJS . Architecture ;
50+ const os = platform ( ) ;
51+ const architecture = arch ( ) as NodeJS . Architecture ;
5252
53- const filename = `gh_${ version } _${ getOS ( platform ) } _${ getArch ( arch ) } ` ;
54- const extension = platform === 'win32' ? 'zip' : 'tar.gz' ;
53+ const filename = `gh_${ version } _${ getOS ( os ) } _${ getArch ( architecture ) } ` ;
54+ const extension = os === 'win32' ? 'zip' : 'tar.gz' ;
5555
5656 return {
57- binaryDirectory : platform === 'win32' ? 'bin' : path . join ( filename , 'bin' ) ,
57+ binaryDirectory : os === 'win32' ? 'bin' : join ( filename , 'bin' ) ,
5858 url : `https://github.com/cli/cli/releases/download/v${ version } /${ filename } .${ extension } ` ,
5959 } ;
6060}
@@ -67,5 +67,5 @@ export function getDownloadObject(version: string) {
6767 * @returns - Binary path
6868 */
6969export function getBinaryPath ( directory : string , name : string ) {
70- return path . join ( directory , name + ( os . platform ( ) === 'win32' ? '.exe' : '' ) ) ;
70+ return join ( directory , name + ( platform ( ) === 'win32' ? '.exe' : '' ) ) ;
7171}
0 commit comments