Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Apr 17, 2024
1 parent af5e9c6 commit d374d7e
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ function normalBin(baseUrl, hugoVersion) {
}

/**
* @param {string} cwd
* @param {import('pkg-conf').Config} config
*/
async function main(cwd) {
const config = await packageConfig('hugo-bin', { cwd });
function getOptions(config) {
const hugoVersion = [
process.env.HUGO_BIN_HUGO_VERSION,
process.env.npm_config_hugo_bin_hugo_version,
Expand All @@ -94,18 +93,31 @@ async function main(cwd) {
config.buildTags
].includes('extended');

debug('[main] hugoVersion:', hugoVersion);
debug('[main] downloadRepo:', downloadRepo);
debug('[main] isExtended:', isExtended);

// Strip any leading `v` from hugoVersion because otherwise we'll end up with duplicate `v`s
const version = hugoVersion[0] === 'v' ? hugoVersion.slice(1) : hugoVersion;
const baseUrl = new URL(`gohugoio/hugo/releases/download/v${version}/`, downloadRepo).href;

debug('[main] version:', version);
debug('[getOptions] hugoVersion:', version);
debug('[getOptions] downloadRepo:', downloadRepo);
debug('[getOptions] isExtended:', isExtended);

return {
hugoVersion: version,
downloadRepo,
isExtended
};
}

/**
* @param {string} cwd
*/
async function main(cwd) {
const config = await packageConfig('hugo-bin', { cwd });
const { hugoVersion, downloadRepo, isExtended } = getOptions(config);
const baseUrl = new URL(`gohugoio/hugo/releases/download/v${hugoVersion}/`, downloadRepo).href;

debug('[main] baseUrl:', baseUrl);

return isExtended ? extendedBin(baseUrl, version) : normalBin(baseUrl, version);
return isExtended ? extendedBin(baseUrl, hugoVersion) : normalBin(baseUrl, hugoVersion);
}

export default main;

0 comments on commit d374d7e

Please sign in to comment.