hugo-extended 0.154.2 → 0.154.3-sudoless.1

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
@@ -1,106 +1,261 @@
1
- # <img src="https://raw.githubusercontent.com/gohugoio/gohugoioTheme/master/static/images/hugo-logo-wide.svg?sanitize=true" alt="Hugo" width="115"> via NPM [![npm](https://img.shields.io/npm/v/hugo-extended?color=blue&logo=npm)](https://www.npmjs.com/package/hugo-extended) [![CI status](https://github.com/jakejarvis/hugo-extended/workflows/Run%20tests/badge.svg)](https://github.com/jakejarvis/hugo-extended/actions)
1
+ # <img src="https://raw.githubusercontent.com/gohugoio/gohugoioTheme/master/static/images/hugo-logo-wide.svg?sanitize=true" alt="Hugo" width="115"> via NPM
2
2
 
3
- > Plug-and-play binary wrapper for [Hugo Extended](https://gohugo.io/), the awesomest static-site generator.
3
+ [![NPM Version](https://img.shields.io/npm/v/hugo-extended?color=blue)](https://www.npmjs.com/package/hugo-extended)
4
+ [![NPM Downloads](https://img.shields.io/npm/dw/hugo-extended?color=rebeccapurple)](https://www.npmjs.com/package/hugo-extended)
5
+ [![CI status](https://github.com/jakejarvis/hugo-extended/workflows/Run%20tests/badge.svg)](https://github.com/jakejarvis/hugo-extended/actions)
6
+
7
+ > Plug-and-play binary wrapper for [Hugo Extended](https://gohugo.io/), the awesomest static-site generator. Now with full TypeScript support and type-safe APIs!
8
+
9
+ ## Features
10
+
11
+ - 🚀 **Zero configuration** — Hugo binary is automatically downloaded on install
12
+ - 📦 **Version-locked** — Package version matches Hugo version (e.g., `hugo-extended@0.140.0` = Hugo v0.140.0)
13
+ - 🔒 **Type-safe API** — Full TypeScript support with autocomplete for all Hugo commands and flags
14
+ - ⚡ **Multiple APIs** — Use CLI, function-based, or builder-style APIs
15
+ - 🎯 **Extended by default** — Automatically uses Hugo Extended on supported platforms
4
16
 
5
17
  ## Installation
6
18
 
7
19
  ```sh
8
20
  npm install hugo-extended --save-dev
9
- # or...
21
+ # or
10
22
  yarn add hugo-extended --dev
23
+ # or
24
+ pnpm add hugo-extended --save-dev
11
25
  ```
12
26
 
13
- `hugo-extended` defaults to the [extended version](https://gohugo.io/troubleshooting/faq/#i-get--this-feature-is-not-available-in-your-current-hugo-version) of Hugo on [supported platforms](https://github.com/gohugoio/hugo/releases), and automatically falls back to vanilla Hugo if unsupported (mainly on 32-bit systems).
27
+ ### SCSS/PostCSS Support
14
28
 
15
- This package's version numbers align with Hugo's — `hugo-extended@0.64.1` installs Hugo v0.64.1, for example.
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/):
29
+ If you're using Hugo's SCSS features, you'll also want:
18
30
 
19
31
  ```sh
20
32
  npm install postcss postcss-cli autoprefixer --save-dev
21
- # or...
22
- yarn add postcss postcss-cli autoprefixer --dev
23
33
  ```
24
34
 
25
- ## Usage
35
+ These integrate seamlessly with Hugo's [built-in PostCSS pipes](https://gohugo.io/functions/css/postcss/).
26
36
 
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.
37
+ ## Usage
28
38
 
29
- ### via CLI / `package.json`:
39
+ ### CLI Usage
30
40
 
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.
41
+ The simplest way just run `hugo` commands directly:
32
42
 
33
43
  ```jsonc
34
- // package.json:
35
-
44
+ // package.json
36
45
  {
37
- // ...
38
46
  "scripts": {
39
- "build": "hugo",
40
- "build:preview": "hugo --baseURL \"${DEPLOY_PRIME_URL:-/}\" --buildDrafts --buildFuture",
41
- "start": "hugo server"
42
- },
43
- "devDependencies": {
44
- "autoprefixer": "^10.3.4",
45
- "hugo-extended": "^0.88.1",
46
- "postcss": "^8.3.6",
47
- "postcss-cli": "^8.3.1"
47
+ "dev": "hugo server --buildDrafts",
48
+ "build": "hugo --minify",
49
+ "build:preview": "hugo --baseURL \"${DEPLOY_PRIME_URL:-/}\" --buildDrafts --buildFuture"
48
50
  }
49
- // ...
50
51
  }
51
52
  ```
52
53
 
53
- ```bash
54
- $ npm run start
55
-
56
- Start building sites …
57
- hugo v0.88.1-5BC54738+extended darwin/amd64 BuildDate=2021-09-04T09:39:19Z VendorInfo=gohugoio
58
-
59
- | EN
60
- -------------------+------
61
- Pages | 50
62
- Paginator pages | 0
63
- Non-page files | 138
64
- Static files | 39
65
- Processed images | 63
66
- Aliases | 0
67
- Sitemaps | 1
68
- Cleaned | 0
69
-
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"
74
- Serving pages from memory
75
- Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
54
+ ```sh
55
+ npm run dev
56
+ ```
57
+
58
+ ### Programmatic API
59
+
60
+ #### Builder-style API
61
+
62
+ A fluent interface where each Hugo command is a method:
63
+
64
+ ```typescript
65
+ import hugo from "hugo-extended";
66
+
67
+ // Start server
68
+ await hugo.server({
69
+ port: 1313,
70
+ buildDrafts: true,
71
+ });
72
+
73
+ // Build site
74
+ await hugo.build({
75
+ minify: true,
76
+ environment: "production",
77
+ });
78
+
79
+ // Module commands
80
+ await hugo.mod.get();
81
+ await hugo.mod.tidy();
82
+ await hugo.mod.clean({ all: true });
83
+
84
+ // Generate shell completions
85
+ await hugo.completion.zsh();
86
+ ```
87
+
88
+ #### Function-based API
89
+
90
+ Use `exec()` for commands that output to the console, or `execWithOutput()` to capture the output:
91
+
92
+ ```typescript
93
+ import { exec, execWithOutput } from "hugo-extended";
94
+
95
+ // Start development server with full type safety
96
+ await exec("server", {
97
+ port: 1313,
98
+ buildDrafts: true,
99
+ navigateToChanged: true,
100
+ });
101
+
102
+ // Build for production
103
+ await exec("build", {
104
+ minify: true,
105
+ cleanDestinationDir: true,
106
+ baseURL: "https://example.com",
107
+ });
108
+
109
+ // Capture command output
110
+ const { stdout } = await execWithOutput("version");
111
+ console.log(stdout); // "hugo v0.140.0+extended darwin/arm64 ..."
112
+
113
+ // List all content pages
114
+ const { stdout: pages } = await execWithOutput("list all");
76
115
  ```
77
116
 
78
- ### via API:
117
+ #### Direct Binary Access
79
118
 
80
- ```js
81
- // version.js:
119
+ For advanced use cases, get the Hugo binary path directly:
82
120
 
121
+ ```typescript
83
122
  import hugo from "hugo-extended";
84
- import { execFile } from "child_process";
123
+ import { spawn } from "child_process";
124
+
125
+ const binPath = await hugo();
126
+ console.log(binPath); // "/usr/local/bin/hugo" or similar
127
+
128
+ // Use with spawn, exec, or any process library
129
+ spawn(binPath, ["version"], { stdio: "inherit" });
130
+ ```
131
+
132
+ ### Type Imports
133
+
134
+ Import Hugo types for use in your own code:
135
+
136
+ ```typescript
137
+ import type { HugoCommand, HugoOptionsFor, HugoServerOptions } from "hugo-extended";
85
138
 
86
- (async () => {
87
- const binPath = await hugo();
139
+ // Type-safe option objects
140
+ const serverOpts: HugoServerOptions = {
141
+ port: 1313,
142
+ buildDrafts: true,
143
+ disableLiveReload: false,
144
+ };
88
145
 
89
- execFile(binPath, ["version"], (error, stdout) => {
90
- console.log(stdout);
91
- });
92
- })();
146
+ // Generic helper
147
+ function runHugo<C extends HugoCommand>(cmd: C, opts: HugoOptionsFor<C>) {
148
+ // ...
149
+ }
150
+ ```
151
+
152
+ ## API Reference
153
+
154
+ ### `exec(command, options?)`
155
+
156
+ Execute a Hugo command with inherited stdio (output goes to console).
157
+
158
+ - **command** — Hugo command string (e.g., `"server"`, `"build"`, `"mod clean"`)
159
+ - **options** — Type-safe options object (optional)
160
+ - **Returns** — `Promise<void>`
161
+
162
+ ### `execWithOutput(command, options?)`
163
+
164
+ Execute a Hugo command and capture output.
165
+
166
+ - **command** — Hugo command string
167
+ - **options** — Type-safe options object (optional)
168
+ - **Returns** — `Promise<{ stdout: string; stderr: string }>`
169
+
170
+ ### `hugo` (default export)
171
+
172
+ The default export is both callable (returns binary path) and has builder methods:
173
+
174
+ ```typescript
175
+ // Get binary path (backward compatible)
176
+ const binPath = await hugo();
177
+
178
+ // Builder methods
179
+ await hugo.build({ minify: true });
180
+ await hugo.server({ port: 3000 });
181
+ ```
182
+
183
+ ### Available Commands
184
+
185
+ All Hugo commands are fully typed with autocomplete:
186
+
187
+ | Command | Builder Method | Description |
188
+ |---------|---------------|-------------|
189
+ | `build` | `hugo.build()` | Build your site |
190
+ | `server` | `hugo.server()` | Start dev server |
191
+ | `new` | `hugo.new()` | Create new content |
192
+ | `mod get` | `hugo.mod.get()` | Download modules |
193
+ | `mod tidy` | `hugo.mod.tidy()` | Clean go.mod/go.sum |
194
+ | `mod clean` | `hugo.mod.clean()` | Clean module cache |
195
+ | `mod vendor` | `hugo.mod.vendor()` | Vendor dependencies |
196
+ | `list all` | `hugo.list.all()` | List all content |
197
+ | `list drafts` | `hugo.list.drafts()` | List draft content |
198
+ | `config` | `hugo.config()` | Print configuration |
199
+ | `version` | `hugo.version()` | Print version |
200
+ | `env` | `hugo.env()` | Print environment |
201
+ | ... | ... | [All Hugo commands supported](https://gohugo.io/commands/) |
202
+
203
+ ## Platform Support
204
+
205
+ Hugo Extended is automatically used on supported platforms:
206
+
207
+ | Platform | Architecture | Hugo Extended |
208
+ |----------|-------------|---------------|
209
+ | macOS | x64, ARM64 | ✅ |
210
+ | Linux | x64, ARM64 | ✅ |
211
+ | Windows | x64 | ✅ |
212
+ | Windows | ARM64 | ❌ (vanilla Hugo) |
213
+ | FreeBSD | x64 | ❌ (vanilla Hugo) |
214
+
215
+ ## Environment Variables
216
+
217
+ Customize installation and runtime behavior with these environment variables:
218
+
219
+ | Variable | Description |
220
+ |----------|-------------|
221
+ | `HUGO_OVERRIDE_VERSION` | Install a specific Hugo version instead of the package version. Example: `HUGO_OVERRIDE_VERSION=0.139.0 npm install` |
222
+ | `HUGO_NO_EXTENDED` | Force vanilla Hugo instead of Extended edition. Example: `HUGO_NO_EXTENDED=1 npm install` |
223
+ | `HUGO_SKIP_DOWNLOAD` | Skip the postinstall binary download entirely. Useful for CI caching or Docker layer optimization. |
224
+ | `HUGO_BIN_PATH` | Use a pre-existing Hugo binary instead of the bundled one. Example: `HUGO_BIN_PATH=/usr/local/bin/hugo` |
225
+ | `HUGO_MIRROR_BASE_URL` | Download from a custom mirror instead of GitHub releases. Example: `HUGO_MIRROR_BASE_URL=https://mirror.example.com/hugo` |
226
+ | `HUGO_SKIP_CHECKSUM` | Skip SHA-256 checksum verification. **Use with caution.** |
227
+ | `HUGO_QUIET` | Suppress installation progress output. |
228
+
229
+ ### Examples
230
+
231
+ ```sh
232
+ # Install a specific older version
233
+ HUGO_OVERRIDE_VERSION=0.139.0 npm install hugo-extended
234
+
235
+ # Skip download for CI caching (when binary is already cached)
236
+ HUGO_SKIP_DOWNLOAD=1 npm ci
237
+
238
+ # Use smaller vanilla Hugo (no SCSS support)
239
+ HUGO_NO_EXTENDED=1 npm install hugo-extended
240
+
241
+ # Use a corporate mirror
242
+ HUGO_MIRROR_BASE_URL=https://internal.example.com/hugo npm install hugo-extended
93
243
  ```
94
244
 
95
- ```bash
96
- $ node version.js
97
- hugo v0.88.1-5BC54738+extended darwin/amd64 BuildDate=2021-09-04T09:39:19Z VendorInfo=gohugoio
245
+ ## Troubleshooting
246
+
247
+ ### Hugo binary not found
248
+
249
+ If Hugo seems to disappear (rare edge case), it will be automatically reinstalled on next use. You can also manually trigger reinstallation:
250
+
251
+ ```sh
252
+ npm rebuild hugo-extended
98
253
  ```
99
254
 
100
- ## Examples
255
+ ### macOS installation
101
256
 
102
- - [jakejarvis/jarv.is](https://github.com/jakejarvis/jarv.is)
257
+ As of [v0.153.0](https://github.com/gohugoio/hugo/releases/tag/v0.153.0), Hugo is distributed as a `.pkg` installer for macOS. This package extracts the binary locally using `pkgutil --expand-full`, so **no sudo or global installation is required**. The Hugo binary stays in `node_modules` just like on other platforms.
103
258
 
104
259
  ## License
105
260
 
106
- 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).
261
+ This project is distributed under the [MIT License](LICENSE). Hugo is distributed under the [Apache License 2.0](https://github.com/gohugoio/hugo/blob/master/LICENSE).
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/cli.mjs ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env node
2
+ import hugo_default from "./hugo.mjs";
3
+ import { spawn } from "node:child_process";
4
+
5
+ //#region src/cli.ts
6
+ process.on("unhandledRejection", (reason) => {
7
+ console.error("Unhandled promise rejection:", reason);
8
+ process.exitCode = 1;
9
+ });
10
+ (async () => {
11
+ try {
12
+ const args = process.argv.slice(2);
13
+ const child = spawn(await hugo_default(), args, { stdio: "inherit" });
14
+ child.on("error", (err) => {
15
+ console.error("Failed to spawn Hugo binary:", err.message);
16
+ process.exitCode = 1;
17
+ });
18
+ child.on("exit", (code) => {
19
+ process.exitCode = code ?? void 0;
20
+ });
21
+ } catch (err) {
22
+ console.error("Failed to initialize Hugo:", err instanceof Error ? err.message : err);
23
+ process.exitCode = 1;
24
+ }
25
+ })();
26
+
27
+ //#endregion
28
+ export { };