hugo-extended 0.86.0 → 0.88.1-patch1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -16
- package/index.d.ts +8 -0
- package/index.js +12 -4
- package/lib/cli.js +12 -0
- package/lib/install.js +66 -0
- package/lib/utils.js +94 -0
- package/package.json +27 -20
- package/cli.js +0 -9
- package/install.js +0 -154
package/README.md
CHANGED
|
@@ -14,17 +14,25 @@ yarn add hugo-extended --dev
|
|
|
14
14
|
|
|
15
15
|
This package's version numbers align with Hugo's — `hugo-extended@0.64.1` installs Hugo v0.64.1, for example.
|
|
16
16
|
|
|
17
|
+
_Note:_ If you'll be using the SCSS features of Hugo Extended, it's probably smart to install [`postcss`](https://www.npmjs.com/package/postcss), [`postcss-cli`](https://www.npmjs.com/package/postcss-cli), and [`autoprefixer`](https://www.npmjs.com/package/autoprefixer) as devDependencies too, since they can be conveniently called via [built-in Hugo pipes](https://gohugo.io/hugo-pipes/postcss/):
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install postcss postcss-cli autoprefixer --save-dev
|
|
21
|
+
# or...
|
|
22
|
+
yarn add postcss postcss-cli autoprefixer --dev
|
|
23
|
+
```
|
|
24
|
+
|
|
17
25
|
## Usage
|
|
18
26
|
|
|
19
27
|
The following examples simply refer to downloading and executing Hugo as a Node dependency. See the [official Hugo docs](https://gohugo.io/documentation/) for guidance on actual Hugo usage.
|
|
20
28
|
|
|
21
29
|
### via CLI / `package.json`:
|
|
22
30
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
The `build:preview` script below is designed for [Netlify deploy previews](https://www.netlify.com/blog/2016/07/20/introducing-deploy-previews-in-netlify/), where [`$DEPLOY_PRIME_URL`](https://docs.netlify.com/configure-builds/environment-variables/#deploy-urls-and-metadata) is substituted for the base URL (usually ending in netlify.app) of each commit or pull request.
|
|
31
|
+
The `build:preview` script below is designed for [Netlify deploy previews](https://www.netlify.com/blog/2016/07/20/introducing-deploy-previews-in-netlify/), where [`$DEPLOY_PRIME_URL`](https://docs.netlify.com/configure-builds/environment-variables/#deploy-urls-and-metadata) is substituted for the base URL (usually ending in .netlify.app) of each pull request, branch, or commit preview.
|
|
26
32
|
|
|
27
33
|
```jsonc
|
|
34
|
+
// package.json:
|
|
35
|
+
|
|
28
36
|
{
|
|
29
37
|
// ...
|
|
30
38
|
"scripts": {
|
|
@@ -33,9 +41,9 @@ The `build:preview` script below is designed for [Netlify deploy previews](https
|
|
|
33
41
|
"start": "hugo server"
|
|
34
42
|
},
|
|
35
43
|
"devDependencies": {
|
|
36
|
-
"autoprefixer": "^10.
|
|
37
|
-
"hugo-extended": "^0.
|
|
38
|
-
"postcss": "^8.
|
|
44
|
+
"autoprefixer": "^10.3.4",
|
|
45
|
+
"hugo-extended": "^0.88.1",
|
|
46
|
+
"postcss": "^8.3.6",
|
|
39
47
|
"postcss-cli": "^8.3.1"
|
|
40
48
|
}
|
|
41
49
|
// ...
|
|
@@ -45,7 +53,8 @@ The `build:preview` script below is designed for [Netlify deploy previews](https
|
|
|
45
53
|
```bash
|
|
46
54
|
$ npm run start
|
|
47
55
|
|
|
48
|
-
|
|
56
|
+
Start building sites …
|
|
57
|
+
hugo v0.88.1-5BC54738+extended darwin/amd64 BuildDate=2021-09-04T09:39:19Z VendorInfo=gohugoio
|
|
49
58
|
|
|
50
59
|
| EN
|
|
51
60
|
-------------------+------
|
|
@@ -59,6 +68,9 @@ Building sites …
|
|
|
59
68
|
Cleaned | 0
|
|
60
69
|
|
|
61
70
|
Built in 2361 ms
|
|
71
|
+
Watching for changes in {archetypes,assets,content,data,layouts,package.json,static}
|
|
72
|
+
Watching for config changes in config.toml
|
|
73
|
+
Environment: "development"
|
|
62
74
|
Serving pages from memory
|
|
63
75
|
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
|
|
64
76
|
```
|
|
@@ -66,24 +78,25 @@ Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
|
|
|
66
78
|
### via API:
|
|
67
79
|
|
|
68
80
|
```js
|
|
69
|
-
|
|
70
|
-
const hugo = require('hugo-extended');
|
|
81
|
+
// version.js:
|
|
71
82
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
83
|
+
import hugo from "hugo-extended";
|
|
84
|
+
import { execFile } from "child_process";
|
|
76
85
|
|
|
86
|
+
execFile(hugo, ["version"], (error, stdout) => {
|
|
77
87
|
console.log(stdout);
|
|
78
88
|
});
|
|
79
89
|
```
|
|
80
90
|
|
|
91
|
+
```bash
|
|
92
|
+
$ node version.js
|
|
93
|
+
hugo v0.88.1-5BC54738+extended darwin/amd64 BuildDate=2021-09-04T09:39:19Z VendorInfo=gohugoio
|
|
94
|
+
```
|
|
95
|
+
|
|
81
96
|
## Examples
|
|
82
97
|
|
|
83
98
|
- [jakejarvis/jarv.is](https://github.com/jakejarvis/jarv.is)
|
|
84
99
|
|
|
85
100
|
## License
|
|
86
101
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
Hugo is distributed under the [Apache License 2.0](https://github.com/gohugoio/hugo/blob/master/LICENSE).
|
|
102
|
+
This project is distributed under the [MIT License](LICENSE.md). Hugo is distributed under the [Apache License 2.0](https://github.com/gohugoio/hugo/blob/master/LICENSE).
|
package/index.d.ts
ADDED
package/index.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import { getBinFilename } from "./lib/utils.js";
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
// https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#what-do-i-use-instead-of-__dirname-and-__filename
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
|
|
8
|
+
const hugo = path.join(
|
|
4
9
|
__dirname,
|
|
5
|
-
|
|
6
|
-
|
|
10
|
+
"vendor",
|
|
11
|
+
getBinFilename(),
|
|
7
12
|
);
|
|
13
|
+
|
|
14
|
+
// The only thing this module really exports is the absolute path to Hugo:
|
|
15
|
+
export default hugo;
|
package/lib/cli.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawn } from "child_process";
|
|
4
|
+
import hugo from "../index.js";
|
|
5
|
+
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
|
|
8
|
+
spawn(hugo, args, { stdio: "inherit" })
|
|
9
|
+
.on("exit", (code) => {
|
|
10
|
+
// forward Hugo's exit code so this module itself reports success/failure
|
|
11
|
+
process.exit(code);
|
|
12
|
+
});
|
package/lib/install.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import downloader from "careful-downloader";
|
|
4
|
+
import logSymbols from "log-symbols";
|
|
5
|
+
import {
|
|
6
|
+
getPkgVersion,
|
|
7
|
+
getReleaseUrl,
|
|
8
|
+
getReleaseFilename,
|
|
9
|
+
getBinFilename,
|
|
10
|
+
getBinVersion,
|
|
11
|
+
getChecksumFilename,
|
|
12
|
+
isExtended,
|
|
13
|
+
} from "./utils.js";
|
|
14
|
+
|
|
15
|
+
installHugo()
|
|
16
|
+
.then((bin) =>
|
|
17
|
+
// try querying hugo's version via CLI
|
|
18
|
+
getBinVersion(bin),
|
|
19
|
+
)
|
|
20
|
+
.then((version) => {
|
|
21
|
+
// print output of `hugo version` to console
|
|
22
|
+
console.log(`${logSymbols.success} Hugo installed successfully!`);
|
|
23
|
+
console.log(version);
|
|
24
|
+
})
|
|
25
|
+
.catch((error) => {
|
|
26
|
+
// pass whatever error occured along the way to console
|
|
27
|
+
console.error(`${logSymbols.error} Hugo installation failed. :(`);
|
|
28
|
+
throw error;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
async function installHugo() {
|
|
32
|
+
const version = getPkgVersion();
|
|
33
|
+
const releaseFile = getReleaseFilename(version);
|
|
34
|
+
const checksumFile = getChecksumFilename(version);
|
|
35
|
+
const binFile = getBinFilename();
|
|
36
|
+
|
|
37
|
+
// stop here if there's nothing we can download
|
|
38
|
+
if (!releaseFile) {
|
|
39
|
+
throw new Error(`Are you sure this platform is supported? See: https://github.com/gohugoio/hugo/releases/tag/v${version}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// warn if platform doesn't support Hugo Extended, proceed with vanilla Hugo
|
|
43
|
+
if (!isExtended(releaseFile)) {
|
|
44
|
+
console.warn(`${logSymbols.info} Hugo Extended isn't supported on this platform, downloading vanilla Hugo instead.`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// download release from GitHub and verify its checksum
|
|
48
|
+
const download = await downloader(
|
|
49
|
+
getReleaseUrl(version, releaseFile),
|
|
50
|
+
getReleaseUrl(version, checksumFile),
|
|
51
|
+
{
|
|
52
|
+
filename: releaseFile,
|
|
53
|
+
destDir: "vendor",
|
|
54
|
+
cleanDestDir: false,
|
|
55
|
+
algorithm: "sha256",
|
|
56
|
+
encoding: "binary",
|
|
57
|
+
extract: true,
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// ensure hugo[.exe] is executable
|
|
62
|
+
fs.chmodSync(path.join(download, binFile), 0o755);
|
|
63
|
+
|
|
64
|
+
// return the full path to our Hugo binary
|
|
65
|
+
return path.join(download, binFile);
|
|
66
|
+
}
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { execFileSync } from "child_process";
|
|
2
|
+
import { readPackageUpSync } from "read-pkg-up";
|
|
3
|
+
|
|
4
|
+
// This package's version number (should) always match the Hugo release we want.
|
|
5
|
+
// We check for a `hugoVersion` field in package.json just in case it doesn't
|
|
6
|
+
// match in the future (from pushing an emergency package update, etc.).
|
|
7
|
+
export function getPkgVersion() {
|
|
8
|
+
const { packageJson } = readPackageUpSync();
|
|
9
|
+
return packageJson.hugoVersion || packageJson.version;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Generate the full GitHub URL to a given release file.
|
|
13
|
+
export function getReleaseUrl(version, filename) {
|
|
14
|
+
return `https://github.com/gohugoio/hugo/releases/download/v${version}/${filename}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Binary is named `hugo.exe` on Windows, and simply `hugo` otherwise.
|
|
18
|
+
export function getBinFilename() {
|
|
19
|
+
return process.platform === "win32" ? "hugo.exe" : "hugo";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Returns the output of the `hugo version` command, i.e.:
|
|
23
|
+
// "hugo v0.88.1-5BC54738+extended darwin/arm64 BuildDate=..."
|
|
24
|
+
export function getBinVersion(bin) {
|
|
25
|
+
const stdout = execFileSync(bin, ["version"]);
|
|
26
|
+
return stdout.toString();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Hugo Extended supports: macOS x64, macOS ARM64, Linux x64, Windows x64.
|
|
30
|
+
// all other combos fall back to vanilla Hugo. There are surely much better ways
|
|
31
|
+
// to do this but this is easy to read/update. :)
|
|
32
|
+
export function getReleaseFilename(version) {
|
|
33
|
+
const { platform, arch } = process;
|
|
34
|
+
|
|
35
|
+
const filename =
|
|
36
|
+
// macOS
|
|
37
|
+
platform === "darwin" && arch === "x64" ?
|
|
38
|
+
`hugo_extended_${version}_macOS-64bit.tar.gz` :
|
|
39
|
+
platform === "darwin" && arch === "arm64" ?
|
|
40
|
+
`hugo_extended_${version}_macOS-ARM64.tar.gz` :
|
|
41
|
+
|
|
42
|
+
// Windows
|
|
43
|
+
platform === "win32" && arch === "x64" ?
|
|
44
|
+
`hugo_extended_${version}_Windows-64bit.zip` :
|
|
45
|
+
platform === "win32" && arch.endsWith("32") ?
|
|
46
|
+
`hugo_${version}_Windows-32bit.zip` :
|
|
47
|
+
platform === "win32" && "arm" ?
|
|
48
|
+
`hugo_${version}_Windows-ARM.zip` :
|
|
49
|
+
|
|
50
|
+
// Linux
|
|
51
|
+
platform === "linux" && arch === "x64" ?
|
|
52
|
+
`hugo_extended_${version}_Linux-64bit.tar.gz` :
|
|
53
|
+
platform === "linux" && arch.endsWith("32") ?
|
|
54
|
+
`hugo_${version}_Linux-32bit.tar.gz` :
|
|
55
|
+
platform === "linux" && arch === "arm" ?
|
|
56
|
+
`hugo_${version}_Linux-ARM.tar.gz` :
|
|
57
|
+
platform === "linux" && arch === "arm64" ?
|
|
58
|
+
`hugo_${version}_Linux-ARM64.tar.gz` :
|
|
59
|
+
|
|
60
|
+
// FreeBSD
|
|
61
|
+
platform === "freebsd" && arch === "x64" ?
|
|
62
|
+
`hugo_${version}_FreeBSD-64bit.tar.gz` :
|
|
63
|
+
platform === "freebsd" && arch.endsWith("32") ?
|
|
64
|
+
`hugo_${version}_FreeBSD-32bit.tar.gz` :
|
|
65
|
+
platform === "freebsd" && arch === "arm" ?
|
|
66
|
+
`hugo_${version}_FreeBSD-ARM.tar.gz` :
|
|
67
|
+
platform === "freebsd" && arch === "arm64" ?
|
|
68
|
+
`hugo_${version}_FreeBSD-ARM64.tar.gz` :
|
|
69
|
+
|
|
70
|
+
// OpenBSD
|
|
71
|
+
platform === "openbsd" && arch === "x64" ?
|
|
72
|
+
`hugo_${version}_OpenBSD-64bit.tar.gz` :
|
|
73
|
+
platform === "openbsd" && arch.endsWith("32") ?
|
|
74
|
+
`hugo_${version}_OpenBSD-32bit.tar.gz` :
|
|
75
|
+
platform === "openbsd" && arch === "arm" ?
|
|
76
|
+
`hugo_${version}_OpenBSD-ARM.tar.gz` :
|
|
77
|
+
platform === "openbsd" && arch === "arm64" ?
|
|
78
|
+
`hugo_${version}_OpenBSD-ARM64.tar.gz` :
|
|
79
|
+
|
|
80
|
+
// not gonna work :(
|
|
81
|
+
null;
|
|
82
|
+
|
|
83
|
+
return filename;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Simple formula for the checksums.txt file.
|
|
87
|
+
export function getChecksumFilename(version) {
|
|
88
|
+
return `hugo_${version}_checksums.txt`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Check if Hugo extended is being downloaded (as opposed to plain Hugo) based on the release filename.
|
|
92
|
+
export function isExtended(releaseFile) {
|
|
93
|
+
return releaseFile.startsWith("hugo_extended_");
|
|
94
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hugo-extended",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.88.1-patch1",
|
|
4
|
+
"hugoVersion": "0.88.1",
|
|
5
|
+
"description": "✏️ Plug-and-play binary wrapper for Hugo Extended, the awesomest static-site generator.",
|
|
5
6
|
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/jakejarvis/hugo-extended",
|
|
6
8
|
"author": {
|
|
7
9
|
"name": "Jake Jarvis",
|
|
8
10
|
"email": "jake@jarv.is",
|
|
@@ -14,31 +16,32 @@
|
|
|
14
16
|
},
|
|
15
17
|
"files": [
|
|
16
18
|
"index.js",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
+
"index.d.ts",
|
|
20
|
+
"lib"
|
|
19
21
|
],
|
|
20
22
|
"bin": {
|
|
21
|
-
"hugo": "cli.js",
|
|
22
|
-
"hugo-extended": "cli.js"
|
|
23
|
+
"hugo": "lib/cli.js",
|
|
24
|
+
"hugo-extended": "lib/cli.js"
|
|
23
25
|
},
|
|
24
|
-
"
|
|
26
|
+
"type": "module",
|
|
27
|
+
"exports": "./index.js",
|
|
28
|
+
"types": "./index.d.ts",
|
|
25
29
|
"dependencies": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"got": "^11.8.2",
|
|
30
|
-
"sumchecker": "^3.0.1"
|
|
30
|
+
"careful-downloader": "^1.4.0",
|
|
31
|
+
"log-symbols": "^5.0.0",
|
|
32
|
+
"read-pkg-up": "^9.0.0"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
|
-
"eslint": "
|
|
34
|
-
"
|
|
35
|
+
"@jakejarvis/eslint-config": "*",
|
|
36
|
+
"eslint": "^8.0.0",
|
|
37
|
+
"mocha": "^9.1.2"
|
|
35
38
|
},
|
|
36
39
|
"scripts": {
|
|
37
|
-
"postinstall": "node install.js",
|
|
38
|
-
"test": "eslint
|
|
40
|
+
"postinstall": "node lib/install.js",
|
|
41
|
+
"test": "eslint . && mocha"
|
|
39
42
|
},
|
|
40
43
|
"engines": {
|
|
41
|
-
"node": ">=
|
|
44
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
42
45
|
},
|
|
43
46
|
"keywords": [
|
|
44
47
|
"hugo",
|
|
@@ -60,14 +63,18 @@
|
|
|
60
63
|
"golang"
|
|
61
64
|
],
|
|
62
65
|
"eslintConfig": {
|
|
63
|
-
"extends": "eslint
|
|
66
|
+
"extends": "@jakejarvis/eslint-config",
|
|
64
67
|
"parserOptions": {
|
|
65
|
-
"ecmaVersion":
|
|
68
|
+
"ecmaVersion": 2020,
|
|
66
69
|
"sourceType": "module"
|
|
67
70
|
},
|
|
68
71
|
"env": {
|
|
69
72
|
"node": true,
|
|
70
73
|
"es6": true
|
|
71
|
-
}
|
|
74
|
+
},
|
|
75
|
+
"ignorePatterns": [
|
|
76
|
+
"vendor/**",
|
|
77
|
+
"*.d.ts"
|
|
78
|
+
]
|
|
72
79
|
}
|
|
73
80
|
}
|
package/cli.js
DELETED
package/install.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const stream = require('stream');
|
|
5
|
-
const { promisify } = require('util');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const execa = require('execa');
|
|
8
|
-
const chalk = require('chalk');
|
|
9
|
-
const got = require('got');
|
|
10
|
-
const decompress = require('decompress');
|
|
11
|
-
const sumchecker = require('sumchecker');
|
|
12
|
-
|
|
13
|
-
installHugo()
|
|
14
|
-
.then((bin) => {
|
|
15
|
-
// print output of `hugo version` to console
|
|
16
|
-
const { stdout } = execa.sync(bin, ['version']);
|
|
17
|
-
return stdout;
|
|
18
|
-
})
|
|
19
|
-
.then((version) => {
|
|
20
|
-
console.log(chalk.green('✔ Hugo installed successfully!'));
|
|
21
|
-
console.log(version);
|
|
22
|
-
})
|
|
23
|
-
.catch((error) => {
|
|
24
|
-
// pass whatever error occured along the way along to console
|
|
25
|
-
console.error(chalk.red('✖ Hugo installation failed. :('));
|
|
26
|
-
throw error;
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
async function installHugo() {
|
|
30
|
-
// this package's version number (should) always match the Hugo release we want
|
|
31
|
-
const { version } = require('./package.json');
|
|
32
|
-
const downloadBaseUrl = `https://github.com/gohugoio/hugo/releases/download/v${version}/`;
|
|
33
|
-
const releaseFile = getArchiveFilename(version, process.platform, process.arch);
|
|
34
|
-
const checksumFile = `hugo_${version}_checksums.txt`;
|
|
35
|
-
|
|
36
|
-
// stop here if there's nothing we can download
|
|
37
|
-
if (!releaseFile) throw 'Are you sure this platform is supported?';
|
|
38
|
-
|
|
39
|
-
const releaseUrl = downloadBaseUrl + releaseFile;
|
|
40
|
-
const checksumUrl = downloadBaseUrl + checksumFile;
|
|
41
|
-
const vendorDir = path.join(__dirname, 'vendor');
|
|
42
|
-
const archivePath = path.join(vendorDir, releaseFile);
|
|
43
|
-
const checksumPath = path.join(vendorDir, checksumFile);
|
|
44
|
-
const binName = process.platform === 'win32' ? 'hugo.exe' : 'hugo';
|
|
45
|
-
const binPath = path.join(vendorDir, binName);
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
// ensure the target directory exists
|
|
49
|
-
await fs.promises.mkdir(vendorDir, { recursive: true });
|
|
50
|
-
|
|
51
|
-
await Promise.all([
|
|
52
|
-
// fetch the archive file from GitHub
|
|
53
|
-
downloadFile(releaseUrl, archivePath),
|
|
54
|
-
// fetch the checksum file from GitHub
|
|
55
|
-
downloadFile(checksumUrl, checksumPath),
|
|
56
|
-
]);
|
|
57
|
-
|
|
58
|
-
// validate the checksum of the download
|
|
59
|
-
await checkChecksum(vendorDir, checksumPath, releaseFile);
|
|
60
|
-
|
|
61
|
-
// extract the downloaded file
|
|
62
|
-
await decompress(archivePath, vendorDir);
|
|
63
|
-
} finally {
|
|
64
|
-
await Promise.all([
|
|
65
|
-
// delete the downloaded archive when finished
|
|
66
|
-
deleteFile(archivePath),
|
|
67
|
-
// ...and the checksum file
|
|
68
|
-
deleteFile(checksumPath),
|
|
69
|
-
]);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// return the full path to our Hugo binary
|
|
73
|
-
return binPath;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async function downloadFile(url, dest) {
|
|
77
|
-
const pipeline = promisify(stream.pipeline);
|
|
78
|
-
return await pipeline(
|
|
79
|
-
got.stream(url, { followRedirect: true }), // GitHub releases redirect to unpredictable URLs
|
|
80
|
-
fs.createWriteStream(dest)
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async function deleteFile(path) {
|
|
85
|
-
if (fs.existsSync(path)) {
|
|
86
|
-
return await fs.promises.unlink(path);
|
|
87
|
-
} else {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async function checkChecksum(baseDir, checksumFile, binFile) {
|
|
93
|
-
const checker = new sumchecker.ChecksumValidator('sha256', checksumFile, {
|
|
94
|
-
// returns a completely different hash without this for some reason
|
|
95
|
-
defaultTextEncoding: 'binary'
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
return await checker.validate(baseDir, binFile);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Hugo Extended supports: macOS x64, macOS ARM64, Linux x64, Windows x64.
|
|
102
|
-
// all other combos fall back to vanilla Hugo. there are surely much better ways
|
|
103
|
-
// to do this but this is easy to read/update. :)
|
|
104
|
-
function getArchiveFilename(version, os, arch) {
|
|
105
|
-
const filename =
|
|
106
|
-
// macOS
|
|
107
|
-
os === 'darwin' && arch === 'x64'
|
|
108
|
-
? `hugo_extended_${version}_macOS-64bit.tar.gz` :
|
|
109
|
-
os === 'darwin' && arch === 'arm64'
|
|
110
|
-
? `hugo_extended_${version}_macOS-ARM64.tar.gz` :
|
|
111
|
-
|
|
112
|
-
// Windows
|
|
113
|
-
os === 'win32' && arch === 'x64'
|
|
114
|
-
? `hugo_extended_${version}_Windows-64bit.zip` :
|
|
115
|
-
os === 'win32' && arch.endsWith('32')
|
|
116
|
-
? `hugo_${version}_Windows-32bit.zip` :
|
|
117
|
-
|
|
118
|
-
// Linux
|
|
119
|
-
os === 'linux' && arch === 'x64'
|
|
120
|
-
? `hugo_extended_${version}_Linux-64bit.tar.gz` :
|
|
121
|
-
os === 'linux' && arch.endsWith('32')
|
|
122
|
-
? `hugo_${version}_Linux-32bit.tar.gz` :
|
|
123
|
-
os === 'linux' && arch === 'arm'
|
|
124
|
-
? `hugo_${version}_Linux-ARM.tar.gz` :
|
|
125
|
-
os === 'linux' && arch === 'arm64'
|
|
126
|
-
? `hugo_${version}_Linux-ARM64.tar.gz` :
|
|
127
|
-
|
|
128
|
-
// FreeBSD
|
|
129
|
-
os === 'freebsd' && arch === 'x64'
|
|
130
|
-
? `hugo_${version}_FreeBSD-64bit.tar.gz` :
|
|
131
|
-
os === 'freebsd' && arch.endsWith('32')
|
|
132
|
-
? `hugo_${version}_FreeBSD-32bit.tar.gz` :
|
|
133
|
-
os === 'freebsd' && arch === 'arm'
|
|
134
|
-
? `hugo_${version}_FreeBSD-ARM.tar.gz` :
|
|
135
|
-
os === 'freebsd' && arch === 'arm64'
|
|
136
|
-
? `hugo_${version}_FreeBSD-ARM64.tar.gz` :
|
|
137
|
-
|
|
138
|
-
// OpenBSD
|
|
139
|
-
os === 'openbsd' && arch === 'x64'
|
|
140
|
-
? `hugo_${version}_OpenBSD-64bit.tar.gz` :
|
|
141
|
-
os === 'openbsd' && arch.endsWith('32')
|
|
142
|
-
? `hugo_${version}_OpenBSD-32bit.tar.gz` :
|
|
143
|
-
os === 'openbsd' && arch === 'arm'
|
|
144
|
-
? `hugo_${version}_OpenBSD-ARM.tar.gz` :
|
|
145
|
-
os === 'openbsd' && arch === 'arm64'
|
|
146
|
-
? `hugo_${version}_OpenBSD-ARM64.tar.gz` :
|
|
147
|
-
|
|
148
|
-
// not gonna work :(
|
|
149
|
-
null;
|
|
150
|
-
|
|
151
|
-
return filename;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
module.exports.installHugo = installHugo;
|