npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hugo-install

v2.0.2

Published

Automagically install Hugo (<https://gohugo.io>) as part of `npm install` without using got.

Downloads

17

Readme

hugo-install

npm version Build Status

Automagically install Hugo (https://gohugo.io) as part of npm install without using got.

Hugo is one of the most popular and best static site generators. If you read this, you chose npm as your package manager. However, Hugo is written in Go and not installable with npm.

Don't worry, Hugo Install, is a JS script which downloads the correct Hugo binary, e.g. via the postinstall script automagically as part of npm install. Nice!

The JS script installs the extended Hugo version if possible (because it was much easier to code). For usage within corporate networks or behind corporate proxies, the download url can of course be overwritten.

How to install

Run the following command to add hugo-install to your devDependencies in package.json.

npm install hugo-install --save-dev

All other Javascript package manager also work (this package is developed with Bun).

Requirements

This project uses native fetch, so you need nodejs version >= 18.0.0.

How to use

I recommend to run the script as part of your postinstall script. The Hugo version must be set using the --version/-v CLI argument. For example:

{
  "scripts": {
    "postinstall": "hugo-install -v 0.123.2"
  }
}

Important: Make sure to use the exact version number as used in the official Hugo GitHub releases (e.g. trailing zeros that exist or do not exist).

Download URL

hugo-install supports overwriting the download url. There are multiple ways to do this:

As CLI argument

Pass the --url/-u CLI argument.

{
  "scripts": {
    "postinstall": "hugo-install -v 0.123.2 -u https://example.com/hugo/v0.123.2/hugo_0.123.2_freebsd-amd64.tar.gz"
  }
}

As local or global .npmrc configuration file

hugo_install_url = "https://example.com/hugo/v0.123.2/hugo_0.123.2_freebsd-amd64.tar.gz"

As environment variables

export HUGO_INSTALL_URL="https://example.com/hugo/v0.123.2/hugo_0.123.2_freebsd-amd64.tar.gz"

Note that you have to run the postinstall script again with npm install.

Using the Hugo Binary

When the binary is fetched, it is usable as command, as part of an npm script or from within another JS script.

As command (only works on *nix)

Set alias hugo="npm run hugo in your shell. Then nothing changes in your workflow.

npm run scripts

The first script is required. The others are to make your life easier.

{
  "scripts": {
    "hugo": "hugo",
    "build": "hugo",
    "new": "hugo new",
    "serve": "hugo server"
  }
}

To create a new post run:

npm run create content post/my-new-post.md

JS

To execute the Hugo Binary using the Node.JS spawn function do for example this:

import { spawn } from "node:child_process";
import hugoPath from "hugo-install";

spawn(hugoPath, ["--config=path/to/config.toml"], {
  stdio: "inherit",
}).on("exit", () => {
  // Callback
});

Super Inspired By

Thank you!

License

MIT © Frederik Zorn

Made with :heart: