Skip to content

Commit

Permalink
Tweak lib/index.js (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR authored May 23, 2023
1 parent 2d54c7c commit 8ebe254
Showing 1 changed file with 45 additions and 33 deletions.
78 changes: 45 additions & 33 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,56 @@ const { hugoVersion } = JSON.parse(await fs.readFile(pkg));
const destDir = path.join(fileURLToPath(new URL('../vendor/', import.meta.url)));
const binName = process.platform === 'win32' ? 'hugo.exe' : 'hugo';

const extendedBin = baseDownloadUrl => new BinWrapper()
.src(`${baseDownloadUrl}hugo_extended_${hugoVersion}_darwin-universal.tar.gz`, 'darwin', 'arm64')
.src(`${baseDownloadUrl}hugo_extended_${hugoVersion}_darwin-universal.tar.gz`, 'darwin', 'x64')
.src(`${baseDownloadUrl}hugo_extended_${hugoVersion}_linux-amd64.tar.gz`, 'linux', 'x64')
.src(`${baseDownloadUrl}hugo_extended_${hugoVersion}_linux-arm64.tar.gz`, 'linux', 'arm64')
.src(`${baseDownloadUrl}hugo_extended_${hugoVersion}_windows-amd64.zip`, 'win32', 'x64')
// Fall back to the normal version on unsupported platforms
.src(`${baseDownloadUrl}hugo_${hugoVersion}_dragonfly-amd64.tar.gz`, 'dragonflybsd', 'x64')
.src(`${baseDownloadUrl}hugo_${hugoVersion}_freebsd-amd64.tar.gz`, 'freebsd', 'x64')
.src(`${baseDownloadUrl}hugo_${hugoVersion}_linux-arm.tar.gz`, 'linux', 'arm')
.src(`${baseDownloadUrl}hugo_${hugoVersion}_netbsd-amd64.tar.gz`, 'netbsd', 'x64')
.src(`${baseDownloadUrl}hugo_${hugoVersion}_openbsd-amd64.tar.gz`, 'openbsd', 'x64')
.src(`${baseDownloadUrl}hugo_${hugoVersion}_windows-arm64.zip`, 'win32', 'arm64')
.dest(destDir)
.use(binName);
function extendedBin(baseUrl) {
return new BinWrapper()
.src(`${baseUrl}hugo_extended_${hugoVersion}_darwin-universal.tar.gz`, 'darwin', 'arm64')
.src(`${baseUrl}hugo_extended_${hugoVersion}_darwin-universal.tar.gz`, 'darwin', 'x64')
.src(`${baseUrl}hugo_extended_${hugoVersion}_linux-amd64.tar.gz`, 'linux', 'x64')
.src(`${baseUrl}hugo_extended_${hugoVersion}_linux-arm64.tar.gz`, 'linux', 'arm64')
.src(`${baseUrl}hugo_extended_${hugoVersion}_windows-amd64.zip`, 'win32', 'x64')
// Fall back to the normal version on unsupported platforms
.src(`${baseUrl}hugo_${hugoVersion}_dragonfly-amd64.tar.gz`, 'dragonflybsd', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_freebsd-amd64.tar.gz`, 'freebsd', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_linux-arm.tar.gz`, 'linux', 'arm')
.src(`${baseUrl}hugo_${hugoVersion}_netbsd-amd64.tar.gz`, 'netbsd', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_openbsd-amd64.tar.gz`, 'openbsd', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_windows-arm64.zip`, 'win32', 'arm64')
.dest(destDir)
.use(binName);
}

const normalBin = baseDownloadUrl => new BinWrapper()
.src(`${baseDownloadUrl}hugo_${hugoVersion}_darwin-universal.tar.gz`, 'darwin', 'arm64')
.src(`${baseDownloadUrl}hugo_${hugoVersion}_darwin-universal.tar.gz`, 'darwin', 'x64')
.src(`${baseDownloadUrl}hugo_${hugoVersion}_dragonfly-amd64.tar.gz`, 'dragonflybsd', 'x64')
.src(`${baseDownloadUrl}hugo_${hugoVersion}_freebsd-amd64.tar.gz`, 'freebsd', 'x64')
.src(`${baseDownloadUrl}hugo_${hugoVersion}_linux-amd64.tar.gz`, 'linux', 'x64')
.src(`${baseDownloadUrl}hugo_${hugoVersion}_linux-arm.tar.gz`, 'linux', 'arm')
.src(`${baseDownloadUrl}hugo_${hugoVersion}_linux-arm64.tar.gz`, 'linux', 'arm64')
.src(`${baseDownloadUrl}hugo_${hugoVersion}_netbsd-amd64.tar.gz`, 'netbsd', 'x64')
.src(`${baseDownloadUrl}hugo_${hugoVersion}_openbsd-amd64.tar.gz`, 'openbsd', 'x64')
.src(`${baseDownloadUrl}hugo_${hugoVersion}_windows-amd64.zip`, 'win32', 'x64')
.src(`${baseDownloadUrl}hugo_${hugoVersion}_windows-arm64.zip`, 'win32', 'arm64')
.dest(destDir)
.use(binName);
function normalBin(baseUrl) {
return new BinWrapper()
.src(`${baseUrl}hugo_${hugoVersion}_darwin-universal.tar.gz`, 'darwin', 'arm64')
.src(`${baseUrl}hugo_${hugoVersion}_darwin-universal.tar.gz`, 'darwin', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_dragonfly-amd64.tar.gz`, 'dragonflybsd', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_freebsd-amd64.tar.gz`, 'freebsd', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_linux-amd64.tar.gz`, 'linux', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_linux-arm.tar.gz`, 'linux', 'arm')
.src(`${baseUrl}hugo_${hugoVersion}_linux-arm64.tar.gz`, 'linux', 'arm64')
.src(`${baseUrl}hugo_${hugoVersion}_netbsd-amd64.tar.gz`, 'netbsd', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_openbsd-amd64.tar.gz`, 'openbsd', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_windows-amd64.zip`, 'win32', 'x64')
.src(`${baseUrl}hugo_${hugoVersion}_windows-arm64.zip`, 'win32', 'arm64')
.dest(destDir)
.use(binName);
}

async function main(cwd) {
const config = await packageConfig('hugo-bin', { cwd });
const extended = (process.env.HUGO_BIN_BUILD_TAGS || process.env.npm_config_hugo_bin_build_tags || config.buildTags) === 'extended';
const downloadRepo = process.env.HUGO_BIN_DOWNLOAD_REPO || process.env.npm_config_hugo_bin_download_repo || config.downloadRepo || 'https://github.com';
const baseDownloadUrl = `${downloadRepo}/gohugoio/hugo/releases/download/v${hugoVersion}/`;
const downloadRepo = [
process.env.HUGO_BIN_DOWNLOAD_REPO,
process.env.npm_config_hugo_bin_download_repo,
config.downloadRepo
].find(Boolean) || 'https://github.com';
const isExtended = [
process.env.HUGO_BIN_BUILD_TAGS,
process.env.npm_config_hugo_bin_build_tags,
config.buildTags
].includes('extended');
const baseUrl = `${downloadRepo}/gohugoio/hugo/releases/download/v${hugoVersion}/`;

return extended ? extendedBin(baseDownloadUrl) : normalBin(baseDownloadUrl);
return isExtended ? extendedBin(baseUrl) : normalBin(baseUrl);
}

export default main;

0 comments on commit 8ebe254

Please sign in to comment.