hugo-extended 0.88.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 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
- 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 called via [built-in Hugo pipes](https://gohugo.io/hugo-pipes/postcss/).
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.2.5",
37
- "hugo-extended": "^0.83.1",
38
- "postcss": "^8.2.9",
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
- Building sites …
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,6 +78,8 @@ Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
66
78
  ### via API:
67
79
 
68
80
  ```js
81
+ // version.js:
82
+
69
83
  import hugo from "hugo-extended";
70
84
  import { execFile } from "child_process";
71
85
 
@@ -74,12 +88,15 @@ execFile(hugo, ["version"], (error, stdout) => {
74
88
  });
75
89
  ```
76
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
+
77
96
  ## Examples
78
97
 
79
98
  - [jakejarvis/jarv.is](https://github.com/jakejarvis/jarv.is)
80
99
 
81
100
  ## License
82
101
 
83
- Forked from [fenneclab/hugo-bin](https://github.com/fenneclab/hugo-bin) under the [MIT License](https://github.com/fenneclab/hugo-bin/blob/master/LICENSE), (c) [Shun Sato](http://blog.fenneclab.com/).
84
-
85
- 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
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+
3
+ /**
4
+ * @returns {string} Absolute path to the Hugo executable (`hugo.exe` on
5
+ * Windows, simply `hugo` otherwise).
6
+ */
7
+ declare const hugo: string;
8
+ export = hugo;
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import path from "path";
2
2
  import { fileURLToPath } from "url";
3
+ import { getBinFilename } from "./lib/utils.js";
3
4
 
4
5
  // https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#what-do-i-use-instead-of-__dirname-and-__filename
5
6
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -7,7 +8,8 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
8
  const hugo = path.join(
8
9
  __dirname,
9
10
  "vendor",
10
- process.platform === "win32" ? "hugo.exe" : "hugo",
11
+ getBinFilename(),
11
12
  );
12
13
 
14
+ // The only thing this module really exports is the absolute path to Hugo:
13
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.88.0",
3
+ "version": "0.88.1-patch1",
4
+ "hugoVersion": "0.88.1",
4
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,28 @@
14
16
  },
15
17
  "files": [
16
18
  "index.js",
17
- "cli.js",
18
- "install.js"
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",
25
27
  "exports": "./index.js",
28
+ "types": "./index.d.ts",
26
29
  "dependencies": {
27
- "chalk": "^4.1.2",
28
- "decompress": "^4.2.1",
29
- "execa": "^5.1.1",
30
- "fs-extra": "^10.0.0",
31
- "got": "^11.8.2",
32
- "sumchecker": "^3.0.1",
33
- "tempy": "^2.0.0"
30
+ "careful-downloader": "^1.4.0",
31
+ "log-symbols": "^5.0.0",
32
+ "read-pkg-up": "^9.0.0"
34
33
  },
35
34
  "devDependencies": {
36
35
  "@jakejarvis/eslint-config": "*",
37
- "eslint": "^7.32.0",
38
- "mocha": "^9.1.1"
36
+ "eslint": "^8.0.0",
37
+ "mocha": "^9.1.2"
39
38
  },
40
39
  "scripts": {
41
- "postinstall": "node install.js",
40
+ "postinstall": "node lib/install.js",
42
41
  "test": "eslint . && mocha"
43
42
  },
44
43
  "engines": {
@@ -70,13 +69,12 @@
70
69
  "sourceType": "module"
71
70
  },
72
71
  "env": {
73
- "node": true
74
- },
75
- "rules": {
76
- "compat/compat": "off"
72
+ "node": true,
73
+ "es6": true
77
74
  },
78
75
  "ignorePatterns": [
79
- "vendor/**"
76
+ "vendor/**",
77
+ "*.d.ts"
80
78
  ]
81
79
  }
82
80
  }
package/cli.js DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import execa from "execa";
4
- import hugo from "./index.js";
5
-
6
- const args = process.argv.slice(2);
7
-
8
- execa(hugo, args, { stdio: "inherit" });
package/install.js DELETED
@@ -1,150 +0,0 @@
1
- import fs from "fs-extra";
2
- import stream from "stream";
3
- import { fileURLToPath } from "url";
4
- import { promisify } from "util";
5
- import path from "path";
6
- import tempy from "tempy";
7
- import execa from "execa";
8
- import chalk from "chalk";
9
- import got from "got";
10
- import decompress from "decompress";
11
- import sumchecker from "sumchecker";
12
-
13
- // https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#what-do-i-use-instead-of-__dirname-and-__filename
14
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
15
-
16
- installHugo()
17
- .then((bin) => {
18
- // print output of `hugo version` to console
19
- const { stdout } = execa.sync(bin, ["version"]);
20
- return stdout;
21
- })
22
- .then((version) => {
23
- console.log(chalk.green("✔ Hugo installed successfully!"));
24
- console.log(version);
25
- })
26
- .catch((error) => {
27
- // pass whatever error occured along the way along to console
28
- console.error(chalk.red("✖ Hugo installation failed. :("));
29
- throw error;
30
- });
31
-
32
- async function installHugo() {
33
- // this package's version number (should) always match the Hugo release we want
34
- const { version } = await fs.readJson("./package.json");
35
- const downloadBaseUrl = `https://github.com/gohugoio/hugo/releases/download/v${version}/`;
36
- const releaseFile = getArchiveFilename(version, process.platform, process.arch);
37
- const checksumFile = `hugo_${version}_checksums.txt`;
38
-
39
- // stop here if there's nothing we can download
40
- if (!releaseFile) {
41
- throw "Are you sure this platform is supported?";
42
- }
43
-
44
- const releaseUrl = downloadBaseUrl + releaseFile;
45
- const checksumUrl = downloadBaseUrl + checksumFile;
46
- const vendorDir = path.join(__dirname, "vendor");
47
- const tempDir = tempy.directory({ prefix: "hugo-node" });
48
- const archivePath = path.join(tempDir, releaseFile);
49
- const checksumPath = path.join(tempDir, checksumFile);
50
- const binName = process.platform === "win32" ? "hugo.exe" : "hugo";
51
- const binPath = path.join(vendorDir, binName);
52
-
53
- try {
54
- // ensure the target directory exists
55
- await fs.mkdirp(vendorDir, {
56
- mode: 0o2775, // ensure binary is executable
57
- });
58
-
59
- await Promise.all([
60
- // fetch the archive file from GitHub
61
- downloadFile(releaseUrl, archivePath),
62
- // fetch the checksum file from GitHub
63
- downloadFile(checksumUrl, checksumPath),
64
- ]);
65
-
66
- // validate the checksum of the download
67
- await checkChecksum(tempDir, checksumPath, releaseFile);
68
-
69
- // extract the downloaded file
70
- await decompress(archivePath, vendorDir);
71
- } finally {
72
- // delete temporary directory
73
- await fs.remove(tempDir);
74
- }
75
-
76
- // return the full path to our Hugo binary
77
- return binPath;
78
- }
79
-
80
- async function downloadFile(url, dest) {
81
- const pipeline = promisify(stream.pipeline);
82
-
83
- return await pipeline(
84
- got.stream(url, { followRedirect: true }), // GitHub releases redirect to unpredictable URLs
85
- fs.createWriteStream(dest),
86
- );
87
- }
88
-
89
- async function checkChecksum(baseDir, checksumFile, binFile) {
90
- const checker = new sumchecker.ChecksumValidator("sha256", checksumFile, {
91
- defaultTextEncoding: "binary",
92
- });
93
-
94
- return await checker.validate(baseDir, binFile);
95
- }
96
-
97
- // Hugo Extended supports: macOS x64, macOS ARM64, Linux x64, Windows x64.
98
- // all other combos fall back to vanilla Hugo. there are surely much better ways
99
- // to do this but this is easy to read/update. :)
100
- function getArchiveFilename(version, os, arch) {
101
- const filename =
102
- // macOS
103
- os === "darwin" && arch === "x64" ?
104
- `hugo_extended_${version}_macOS-64bit.tar.gz` :
105
- os === "darwin" && arch === "arm64" ?
106
- `hugo_extended_${version}_macOS-ARM64.tar.gz` :
107
-
108
- // Windows
109
- os === "win32" && arch === "x64" ?
110
- `hugo_extended_${version}_Windows-64bit.zip` :
111
- os === "win32" && arch.endsWith("32") ?
112
- `hugo_${version}_Windows-32bit.zip` :
113
-
114
- // Linux
115
- os === "linux" && arch === "x64" ?
116
- `hugo_extended_${version}_Linux-64bit.tar.gz` :
117
- os === "linux" && arch.endsWith("32") ?
118
- `hugo_${version}_Linux-32bit.tar.gz` :
119
- os === "linux" && arch === "arm" ?
120
- `hugo_${version}_Linux-ARM.tar.gz` :
121
- os === "linux" && arch === "arm64" ?
122
- `hugo_${version}_Linux-ARM64.tar.gz` :
123
-
124
- // FreeBSD
125
- os === "freebsd" && arch === "x64" ?
126
- `hugo_${version}_FreeBSD-64bit.tar.gz` :
127
- os === "freebsd" && arch.endsWith("32") ?
128
- `hugo_${version}_FreeBSD-32bit.tar.gz` :
129
- os === "freebsd" && arch === "arm" ?
130
- `hugo_${version}_FreeBSD-ARM.tar.gz` :
131
- os === "freebsd" && arch === "arm64" ?
132
- `hugo_${version}_FreeBSD-ARM64.tar.gz` :
133
-
134
- // OpenBSD
135
- os === "openbsd" && arch === "x64" ?
136
- `hugo_${version}_OpenBSD-64bit.tar.gz` :
137
- os === "openbsd" && arch.endsWith("32") ?
138
- `hugo_${version}_OpenBSD-32bit.tar.gz` :
139
- os === "openbsd" && arch === "arm" ?
140
- `hugo_${version}_OpenBSD-ARM.tar.gz` :
141
- os === "openbsd" && arch === "arm64" ?
142
- `hugo_${version}_OpenBSD-ARM64.tar.gz` :
143
-
144
- // not gonna work :(
145
- null;
146
-
147
- return filename;
148
- }
149
-
150
- export { installHugo };