UNPKG

hugo-extended

Version:

✏️ Plug-and-play binary wrapper for Hugo Extended, the awesomest static-site generator.

215 lines (214 loc) 10.4 kB
import { HugoCommand, HugoOptionsFor } from "./generated/types.mjs"; import { ENV_VAR_DOCS, HugoEnvConfig, getEnvConfig } from "./lib/env.mjs"; //#region src/hugo.d.ts /** * Gets the path to the Hugo binary, automatically installing it if it's missing. * * This is the main entry point for the hugo-extended package. It checks if Hugo * is already installed and available, and if not, triggers an automatic installation * before returning the binary path. * * This handles the case where Hugo may mysteriously disappear (see issue #81), * ensuring the binary is always available when this function is called. * * Environment variables that affect behavior: * - HUGO_BIN_PATH: Use a custom binary path (skips auto-install if missing) * * @returns A promise that resolves with the absolute path to the Hugo binary * @throws {Error} If installation fails, the platform is unsupported, or custom binary is missing * * @example * ```typescript * import hugo from 'hugo-extended'; * * const hugoPath = await hugo(); * console.log(hugoPath); // "/usr/local/bin/hugo" or "./bin/hugo" * ``` */ declare const getHugoBinary: () => Promise<string>; /** * Execute a Hugo command with type-safe options. * * This function runs Hugo with the specified command and options, inheriting stdio * so output goes directly to the console. It's perfect for interactive commands * like `hugo server` or build commands where you want to see live output. * * @param command - Hugo command to execute (e.g., "server", "build", "mod clean") * @param positionalArgsOrOptions - Either positional arguments array or options object * @param options - Type-safe options object (if first param is positional args) * @returns A promise that resolves when the command completes successfully * @throws {Error} If the command fails or Hugo is not available * * @example * ```typescript * import { exec } from 'hugo-extended'; * * // Start development server * await exec("server", { * port: 1313, * buildDrafts: true, * baseURL: "http://localhost:1313" * }); * * // Create a new project * await exec("new project", ["my-site"], { format: "yaml" }); * * // Build site for production * await exec("build", { * minify: true, * cleanDestinationDir: true * }); * ``` */ declare function exec<C extends HugoCommand>(command: C, positionalArgsOrOptions?: string[] | HugoOptionsFor<C>, options?: HugoOptionsFor<C>): Promise<void>; /** * Execute a Hugo command and capture its output. * * This function runs Hugo with the specified command and options, capturing * stdout and stderr. It's useful for commands where you need to process the * output programmatically, like `hugo version` or `hugo list all`. * * @param command - Hugo command to execute (e.g., "version", "list all") * @param positionalArgsOrOptions - Either positional arguments array or options object * @param options - Type-safe options object (if first param is positional args) * @returns A promise that resolves with stdout and stderr strings * @throws {Error} If the command fails or Hugo is not available * * @example * ```typescript * import { execWithOutput } from 'hugo-extended'; * * // Get Hugo version * const { stdout } = await execWithOutput("version"); * console.log(stdout); // "hugo v0.154.3+extended ..." * * // List all content * const { stdout: content } = await execWithOutput("list all"); * const pages = content.split('\n'); * ``` */ declare function execWithOutput<C extends HugoCommand>(command: C, positionalArgsOrOptions?: string[] | HugoOptionsFor<C>, options?: HugoOptionsFor<C>): Promise<{ stdout: string; stderr: string; }>; /** * Builder-style API for executing Hugo commands. * * Provides a fluent interface where each Hugo command is a method on the * builder object. All methods are type-safe with autocomplete for options. * * @example * ```typescript * import { hugo } from 'hugo-extended'; * * // Start server * await hugo.server({ port: 1313, buildDrafts: true }); * * // Build site * await hugo.build({ minify: true }); * * // Module operations * await hugo.mod.clean({ all: true }); * await hugo.mod.get(); * ``` */ declare const hugo: { /** Build your site */build: (options?: HugoOptionsFor<"build">) => Promise<void>; /** Generate shell completion scripts */ completion: { bash: (options?: HugoOptionsFor<"completion bash">) => Promise<void>; fish: (options?: HugoOptionsFor<"completion fish">) => Promise<void>; powershell: (options?: HugoOptionsFor<"completion powershell">) => Promise<void>; zsh: (options?: HugoOptionsFor<"completion zsh">) => Promise<void>; }; /** Print Hugo configuration */ config: (options?: HugoOptionsFor<"config">) => Promise<void>; /** Convert content to different formats */ convert: { toJSON: (options?: HugoOptionsFor<"convert toJSON">) => Promise<void>; toTOML: (options?: HugoOptionsFor<"convert toTOML">) => Promise<void>; toYAML: (options?: HugoOptionsFor<"convert toYAML">) => Promise<void>; }; /** Print Hugo environment info */ env: (options?: HugoOptionsFor<"env">) => Promise<void>; /** Generate documentation */ gen: { doc: (options?: HugoOptionsFor<"gen doc">) => Promise<void>; man: (options?: HugoOptionsFor<"gen man">) => Promise<void>; }; /** Import your site from others */ import: { jekyll: (options?: HugoOptionsFor<"import jekyll">) => Promise<void>; }; /** List various types of content */ list: { all: (options?: HugoOptionsFor<"list all">) => Promise<void>; drafts: (options?: HugoOptionsFor<"list drafts">) => Promise<void>; expired: (options?: HugoOptionsFor<"list expired">) => Promise<void>; future: (options?: HugoOptionsFor<"list future">) => Promise<void>; published: (options?: HugoOptionsFor<"list published">) => Promise<void>; }; /** Module operations */ mod: { clean: (options?: HugoOptionsFor<"mod clean">) => Promise<void>; get: (options?: HugoOptionsFor<"mod get">) => Promise<void>; graph: (options?: HugoOptionsFor<"mod graph">) => Promise<void>; init: (options?: HugoOptionsFor<"mod init">) => Promise<void>; npm: { pack: (options?: HugoOptionsFor<"mod npm pack">) => Promise<void>; }; tidy: (options?: HugoOptionsFor<"mod tidy">) => Promise<void>; vendor: (options?: HugoOptionsFor<"mod vendor">) => Promise<void>; verify: (options?: HugoOptionsFor<"mod verify">) => Promise<void>; }; /** Create new content */ new: ((pathOrOptions?: string | HugoOptionsFor<"new">, options?: HugoOptionsFor<"new">) => Promise<void>) & { content: (pathOrOptions?: string | HugoOptionsFor<"new content">, options?: HugoOptionsFor<"new content">) => Promise<void>; project: (pathOrOptions?: string | HugoOptionsFor<"new project">, options?: HugoOptionsFor<"new project">) => Promise<void>; theme: (nameOrOptions?: string | HugoOptionsFor<"new theme">, options?: HugoOptionsFor<"new theme">) => Promise<void>; }; /** Start the Hugo development server */ server: (options?: HugoOptionsFor<"server">) => Promise<void>; /** Print the Hugo version */ version: (options?: HugoOptionsFor<"version">) => Promise<void>; }; declare const _default: (() => Promise<string>) & { /** Build your site */build: (options?: HugoOptionsFor<"build">) => Promise<void>; /** Generate shell completion scripts */ completion: { bash: (options?: HugoOptionsFor<"completion bash">) => Promise<void>; fish: (options?: HugoOptionsFor<"completion fish">) => Promise<void>; powershell: (options?: HugoOptionsFor<"completion powershell">) => Promise<void>; zsh: (options?: HugoOptionsFor<"completion zsh">) => Promise<void>; }; /** Print Hugo configuration */ config: (options?: HugoOptionsFor<"config">) => Promise<void>; /** Convert content to different formats */ convert: { toJSON: (options?: HugoOptionsFor<"convert toJSON">) => Promise<void>; toTOML: (options?: HugoOptionsFor<"convert toTOML">) => Promise<void>; toYAML: (options?: HugoOptionsFor<"convert toYAML">) => Promise<void>; }; /** Print Hugo environment info */ env: (options?: HugoOptionsFor<"env">) => Promise<void>; /** Generate documentation */ gen: { doc: (options?: HugoOptionsFor<"gen doc">) => Promise<void>; man: (options?: HugoOptionsFor<"gen man">) => Promise<void>; }; /** Import your site from others */ import: { jekyll: (options?: HugoOptionsFor<"import jekyll">) => Promise<void>; }; /** List various types of content */ list: { all: (options?: HugoOptionsFor<"list all">) => Promise<void>; drafts: (options?: HugoOptionsFor<"list drafts">) => Promise<void>; expired: (options?: HugoOptionsFor<"list expired">) => Promise<void>; future: (options?: HugoOptionsFor<"list future">) => Promise<void>; published: (options?: HugoOptionsFor<"list published">) => Promise<void>; }; /** Module operations */ mod: { clean: (options?: HugoOptionsFor<"mod clean">) => Promise<void>; get: (options?: HugoOptionsFor<"mod get">) => Promise<void>; graph: (options?: HugoOptionsFor<"mod graph">) => Promise<void>; init: (options?: HugoOptionsFor<"mod init">) => Promise<void>; npm: { pack: (options?: HugoOptionsFor<"mod npm pack">) => Promise<void>; }; tidy: (options?: HugoOptionsFor<"mod tidy">) => Promise<void>; vendor: (options?: HugoOptionsFor<"mod vendor">) => Promise<void>; verify: (options?: HugoOptionsFor<"mod verify">) => Promise<void>; }; /** Create new content */ new: ((pathOrOptions?: string | HugoOptionsFor<"new">, options?: HugoOptionsFor<"new">) => Promise<void>) & { content: (pathOrOptions?: string | HugoOptionsFor<"new content">, options?: HugoOptionsFor<"new content">) => Promise<void>; project: (pathOrOptions?: string | HugoOptionsFor<"new project">, options?: HugoOptionsFor<"new project">) => Promise<void>; theme: (nameOrOptions?: string | HugoOptionsFor<"new theme">, options?: HugoOptionsFor<"new theme">) => Promise<void>; }; /** Start the Hugo development server */ server: (options?: HugoOptionsFor<"server">) => Promise<void>; /** Print the Hugo version */ version: (options?: HugoOptionsFor<"version">) => Promise<void>; }; //#endregion export { ENV_VAR_DOCS, type HugoCommand, type HugoEnvConfig, type HugoOptionsFor, _default as default, exec, execWithOutput, getEnvConfig, getHugoBinary, hugo };