mirror of
https://github.com/jakejarvis/hugo-extended.git
synced 2026-10-04 14:25:39 -04:00
refactor directory structure and modularize a few common functions
This commit is contained in:
9 files changed
+185
-141
No files matched your search
@@ -0,0 +1,57 @@
|
||||
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);
|
||||
}
|
||||
Reference in new issue
Block a user