-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
index.js
66 lines (59 loc) · 3.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import fs from 'node:fs/promises';
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import BinWrapper from '@xhmikosr/bin-wrapper';
import { packageConfig } from 'pkg-conf';
const pkg = new URL('../package.json', import.meta.url);
const { hugoVersion } = JSON.parse(await fs.readFile(pkg, 'utf8'));
const destDir = path.join(fileURLToPath(new URL('../vendor/', import.meta.url)));
const binName = process.platform === 'win32' ? 'hugo.exe' : 'hugo';
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);
}
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 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 isExtended ? extendedBin(baseUrl) : normalBin(baseUrl);
}
export default main;