|
| 1 | +# npmtohugomod |
1 | 2 |
|
2 | | -## Module wrapper versioning |
| 3 | +A small tool that wraps npm packages as Hugo Modules, so a Hugo site can |
| 4 | +consume them without an npm dependency. |
| 5 | + |
| 6 | +Given a `package.json` with a `dependencies` block, it downloads each package |
| 7 | +from the npm registry, drops it into a per-package directory with a `go.mod` |
| 8 | +and `hugo.toml`, and writes a root `hugo.toml` that re-exports all of them |
| 9 | +as a single Hugo Module. |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +Run it from the root of a git repo that will host the wrappers. The Go |
| 14 | +module base path is derived from the repo's `origin` remote. |
| 15 | + |
| 16 | +```sh |
| 17 | +# Sync wrappers from ./package.json |
| 18 | +npmtohugomod |
| 19 | + |
| 20 | +# Override the module base path (skip git-remote auto-detection) |
| 21 | +npmtohugomod --module-base github.com/owner/repo |
| 22 | +``` |
| 23 | + |
| 24 | +Re-runs with an unchanged `package.json` are no-ops; on a version bump only |
| 25 | +the affected package is refetched. Requires `hugo` and `git` on `PATH`. |
3 | 26 |
|
4 | | -We use a simple versioning scheme where the the upstream controls the major and minor version and `W` gets incremented whenever something in the wrapper changes (e.g. `hugo.toml` config update): |
| 27 | +## What gets generated |
5 | 28 |
|
6 | | ->vX.Y.(Z*1000+W) |
| 29 | +For each entry in `dependencies` (e.g. `@alpinejs/focus`): |
| 30 | + |
| 31 | +- `alpinejs/focus/package/…` — the npm tarball contents. |
| 32 | +- `alpinejs/focus/npmpackage.json` — npm metadata (informational). |
| 33 | +- `alpinejs/focus/hugo.toml` — mounts the ESM build under `assets/@alpinejs/focus`. |
| 34 | +- `alpinejs/focus/go.mod` — created by `hugo mod init`. For majors ≥ 2 the module path includes a `/vN` suffix (Go semantic import versioning). |
| 35 | +- `alpinejs/focus/README.md` — has a marker-delimited block showing the import path; updates regenerate just that block, anything outside is preserved. |
| 36 | + |
| 37 | +At the repo root, `hugo.toml` lists every wrapper as a `[[module.imports]]` |
| 38 | +entry, so a downstream Hugo site can import the whole bundle in one line. |
| 39 | + |
| 40 | +## Releasing |
| 41 | + |
| 42 | +```sh |
| 43 | +npmtohugomod release |
| 44 | +``` |
| 45 | + |
| 46 | +Walks all wrapper directories and creates a local annotated git tag for each |
| 47 | +(then stops — tags are **not** pushed). Existing tags are skipped, so re-runs |
| 48 | +are safe. Fails if the working tree is dirty; pass `--allow-dirty` to |
| 49 | +override. |
| 50 | + |
| 51 | +## Module wrapper versioning |
7 | 52 |
|
8 | | -`W` starts at 0 and resets on any upstream-change. |
| 53 | +Tags follow `vX.Y.(Z*1000+W)`, where `X.Y.Z` is the upstream npm version and |
| 54 | +`W` is bumped on wrapper-only changes (e.g. a `hugo.toml` tweak). `W` starts |
| 55 | +at 0 and resets on any upstream-version change. The release command |
| 56 | +currently always emits `W=0`; re-tagging after a wrapper-only change is |
| 57 | +manual for now. |
0 commit comments