Skip to content

Commit ae8e03d

Browse files
refactor: tidy index and utils imports
1 parent 45afb57 commit ae8e03d

3 files changed

Lines changed: 25 additions & 28 deletions

File tree

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'node:path';
1+
import { dirname, join } from 'node:path';
22

33
import { addPath, getInput, setFailed } from '@actions/core';
44
import { exec } from '@actions/exec';
@@ -36,10 +36,7 @@ export async function run() {
3636
const extractDirectory = await extract(pathToTarball);
3737

3838
// Get the binary
39-
const binaryDirectory = path.join(
40-
extractDirectory,
41-
download.binaryDirectory,
42-
);
39+
const binaryDirectory = join(extractDirectory, download.binaryDirectory);
4340
binaryPath = getBinaryPath(binaryDirectory, cliName);
4441

4542
// Rename the binary
@@ -53,7 +50,7 @@ export async function run() {
5350
}
5451

5552
// Expose the tool by adding it to the PATH
56-
addPath(path.dirname(binaryPath));
53+
addPath(dirname(binaryPath));
5754

5855
// Cache the tool
5956
/* istanbul ignore else */

src/utils.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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
*/
1919
function 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
*/
3737
function 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
*/
4949
export 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
*/
6969
export 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

Comments
 (0)