mirror of
https://github.com/jakejarvis/hugo-extended.git
synced 2025-04-26 09:05:20 -04:00
58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
import path from "path";
|
|
import fs from "fs";
|
|
import downloader from "careful-downloader";
|
|
import logSymbols from "log-symbols";
|
|
import { getPkgVersion, getReleaseUrl, getReleaseFilename, getBinFilename, getBinVersion, getChecksumFilename, isExtended } from "./utils.js";
|
|
|
|
installHugo()
|
|
.then((bin) =>
|
|
// try querying hugo's version via CLI
|
|
getBinVersion(bin),
|
|
)
|
|
.then((version) => {
|
|
// print output of `hugo version` to console
|
|
console.log(`${logSymbols.success} Hugo installed successfully!`);
|
|
console.log(version);
|
|
})
|
|
.catch((error) => {
|
|
// pass whatever error occured along the way to console
|
|
console.error(`${logSymbols.error} Hugo installation failed. :(`);
|
|
throw error;
|
|
});
|
|
|
|
async function installHugo() {
|
|
const version = getPkgVersion();
|
|
const releaseFile = getReleaseFilename(version);
|
|
const checksumFile = getChecksumFilename(version);
|
|
const binFile = getBinFilename();
|
|
|
|
// stop here if there's nothing we can download
|
|
if (!releaseFile) {
|
|
throw new Error(`Are you sure this platform is supported? See: https://github.com/gohugoio/hugo/releases/tag/v${version}`);
|
|
}
|
|
|
|
// warn if platform doesn't support Hugo Extended, proceed with vanilla Hugo
|
|
if (!isExtended(releaseFile)) {
|
|
console.warn(`${logSymbols.info} Hugo Extended isn't supported on this platform, downloading vanilla Hugo instead.`);
|
|
}
|
|
|
|
const download = await downloader(
|
|
getReleaseUrl(version, releaseFile),
|
|
getReleaseUrl(version, checksumFile),
|
|
{
|
|
filename: releaseFile,
|
|
destDir: "vendor",
|
|
cleanDestDir: false,
|
|
algorithm: "sha256",
|
|
encoding: "binary",
|
|
extract: true,
|
|
},
|
|
);
|
|
|
|
// ensure hugo[.exe] is executable
|
|
fs.chmodSync(path.join(download, binFile), 0o755);
|
|
|
|
// return the full path to our Hugo binary
|
|
return path.join(download, binFile);
|
|
}
|