diff --git a/src/get-url.ts b/src/get-url.ts index 2a106c4..f6a07cc 100644 --- a/src/get-url.ts +++ b/src/get-url.ts @@ -1,41 +1,30 @@ export default function getURL( - os: string, - arch: string, - extended: string, - withdeploy: string, - version: string + system: { + os: string, + arch: string, + }, + options: { + extended: string, + withdeploy: string, + version: string + } ): string { - const extendedStr = (extended: string): string => { - if (extended === 'true') { - return 'extended_'; - } else { - return ''; - // } else { - // throw new Error(`Invalid input (extended): ${extended}`); - } - }; + let extendedStr = ''; + if (options.extended === 'true') { + extendedStr = 'extended_'; + } + let withdeployStr = ''; + if (options..withdeploy === 'true') { + withdeployStr = 'withdeploy_'; + } + let ext = 'tar.gz'; + if (system.os === 'Windows') { + ext = 'zip'; + } - const withdeployStr = (withdeploy: string): string => { - if (withdeploy === 'true') { - return 'withdeploy_'; - } else { - return ''; - // } else { - // throw new Error(`Invalid input (withdeploy): ${withdeploy}`); - } - }; - - const ext = (os: string): string => { - if (os === 'Windows') { - return 'zip'; - } else { - return 'tar.gz'; - } - }; - - const hugoName = `hugo_${extendedStr(extended)}${withdeployStr(withdeploy)}${version}_${os}-${arch}`; + const hugoName = `hugo_${extendedStr}${withdeployStr}${options.version}_${system.os}-${system.arch}`; const baseURL = 'https://github.com/gohugoio/hugo/releases/download'; - const url = `${baseURL}/v${version}/${hugoName}.${ext(os)}`; + const url = `${baseURL}/v${options.version}/${hugoName}.${ext}`; return url; } diff --git a/src/installer.ts b/src/installer.ts index 9a22f1e..fe761ad 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -56,7 +56,10 @@ export async function installer(version: string): Promise { const archName: string = getArch(process.arch); core.debug(`Processor Architecture: ${archName}`); - const toolURL: string = getURL(osName, archName, extended, withdeploy, version); + const system = { os: osName, arch: archName }; + const options = { extended: extended, withdeploy: withdeploy, version: version } + + const toolURL: string = getURL(system, options); core.debug(`toolURL: ${toolURL}`); const workDir = await createWorkDir();