@nera-static/plugin-utils 1.2.0 โ†’ 1.3.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.
Files changed (2) hide show
  1. package/README.md +62 -6
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # @nera-static/plugin-utils
2
2
 
3
+ [![Test](https://github.com/seebaermichi/nera-plugin-utils/actions/workflows/test.yml/badge.svg)](https://github.com/seebaermichi/nera-plugin-utils/actions/workflows/test.yml)
4
+ [![npm version](https://img.shields.io/npm/v/@nera-static/plugin-utils)](https://www.npmjs.com/package/@nera-static/plugin-utils)
5
+
3
6
  ๐Ÿ›  Utility helpers for developing plugins for the [Nera](https://github.com/seebaermichi/nera) static site generator.
4
7
 
5
8
  ---
@@ -20,11 +23,16 @@ npm install @nera-static/plugin-utils
20
23
 
21
24
  Reads and parses a YAML config file, returning its contents as a JavaScript object.
22
25
 
26
+ Returns `{}` if the file does not exist or is empty โ€” it never throws. **Supply a JS fallback for every key you read.**
27
+
28
+ Plugins read config from the *user's* site, not from the package. The `config/<name>.yaml` shipped inside a plugin is documentation only; it is never merged with the user's copy. Resolve against `process.cwd()`:
29
+
23
30
  ```js
31
+ import path from 'path'
24
32
  import { getConfig } from '@nera-static/plugin-utils'
25
33
 
26
- const config = getConfig('./path/to/config.yaml')
27
- console.log(config.title)
34
+ const config = getConfig(path.resolve(process.cwd(), 'config/my-plugin.yaml'))
35
+ const title = config.title || 'Default title'
28
36
  ```
29
37
 
30
38
  ### Template Publishing
@@ -33,7 +41,7 @@ console.log(config.title)
33
41
 
34
42
  Validates if the current working directory is a valid Nera project.
35
43
 
36
- A directory qualifies if it *looks* like a Nera project โ€” it contains both `config/app.yaml` and `pages/` โ€” or if its `package.json` name matches `expectedPackageName` or starts with `nera`. The shape check means a project can be named anything.
44
+ A `package.json` must be present. Given that, the directory qualifies if it *looks* like a Nera project โ€” it contains both `config/app.yaml` and `pages/` โ€” or if its `package.json` name matches `expectedPackageName` or starts with `nera`. The shape check means a project can be named anything, but it does not remove the `package.json` requirement.
37
45
 
38
46
  ```js
39
47
  import { validateNeraProject } from '@nera-static/plugin-utils'
@@ -78,6 +86,10 @@ const result = publishAllTemplates({
78
86
  })
79
87
  ```
80
88
 
89
+ Returns `true` and logs a warning if `sourceDir` contains no `.pug` files; an unreadable `sourceDir` returns `false`. A publish script following the `process.exit(result ? 0 : 1)` pattern below therefore exits `0` having copied nothing โ€” check your `sourceDir` if a plugin's templates never appear.
90
+
91
+ > The `__dirname` used in these option examples is not defined in ESM. See the CLI Integration example below for the two lines that define it.
92
+
81
93
  ### Template Publishing CLI Integration
82
94
 
83
95
  These functions are designed to be used in `bin/publish-template.js` scripts that can be executed via npm scripts:
@@ -116,12 +128,18 @@ This package is intended for use inside Nera plugins to:
116
128
 
117
129
  ```js
118
130
  // index.js - Main plugin file
131
+ import path from 'path'
119
132
  import { getConfig } from '@nera-static/plugin-utils'
120
133
 
121
- export function getAppData(app) {
122
- const config = getConfig(`${__dirname}/config/my-plugin.yaml`)
134
+ export function getAppData(data) {
135
+ const config = getConfig(
136
+ path.resolve(process.cwd(), 'config/my-plugin.yaml')
137
+ )
123
138
 
139
+ // Spread the incoming app. The return value REPLACES `app` wholesale --
140
+ // returning a bare object discards every other plugin's data, silently.
124
141
  return {
142
+ ...data.app,
125
143
  myPlugin: {
126
144
  // ... plugin logic using config
127
145
  },
@@ -129,6 +147,10 @@ export function getAppData(app) {
129
147
  }
130
148
  ```
131
149
 
150
+ A plugin exports `getAppData` and/or `getMetaData`. Both receive a single object โ€” `{ app, pagesData }` โ€” and both must be **synchronous**. `getAppData` must return a plain object, `getMetaData` an array; a wrong return type is skipped with a console warning while the build still succeeds, so a plugin that appears to "do nothing" is usually a return-type problem.
151
+
152
+ See the [Nera contributing guide](https://github.com/seebaermichi/nera/blob/main/CONTRIBUTING.md) for the full plugin contract.
153
+
132
154
  ```js
133
155
  // bin/publish-template.js - Template publishing script
134
156
  #!/usr/bin/env node
@@ -149,12 +171,46 @@ process.exit(result ? 0 : 1)
149
171
 
150
172
  ---
151
173
 
174
+ ## ๐Ÿงช Development
175
+
176
+ ```bash
177
+ npx vitest run # single pass -- `npm test` is watch mode
178
+ npm run lint
179
+ ```
180
+
181
+ ---
182
+
183
+ ## ๐Ÿค Contributing
184
+
185
+ Issues and pull requests are welcome. See the
186
+ [Nera contributing guide](https://github.com/seebaermichi/nera/blob/main/CONTRIBUTING.md)
187
+ for plugin development, the hook contract, and local setup.
188
+
189
+ For this repo specifically:
190
+
191
+ - `npx vitest run` and `npm run lint` must pass (`npm test` is watch mode).
192
+ - Bump the version and update `CHANGELOG.md` **in the same commit** as the change.
193
+ - Every plugin in the fleet depends on this package, so treat the exported
194
+ function signatures as a public contract โ€” changing one is a **major** bump.
195
+ - Releases publish from CI on a pushed `v*` tag. Never run `npm publish`.
196
+
197
+ ---
198
+
152
199
  ## ๐Ÿง‘โ€๐Ÿ’ป Maintainers
153
200
 
154
201
  Created and maintained by [@seebaermichi](https://github.com/seebaermichi)
155
202
 
156
203
  ---
157
204
 
158
- ## ๐Ÿ“„ License
205
+ ## ๐Ÿงฉ Compatibility
206
+
207
+ - **Node.js**: >= 20.0.0
208
+ - **Runtime dependency**: `js-yaml ^4.1.0` only
209
+ - **Nera**: no direct dependency on the generator โ€” this package is used by
210
+ plugins, not by the generator itself
211
+
212
+ ---
213
+
214
+ ## ๐Ÿ“ฆ License
159
215
 
160
216
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nera-static/plugin-utils",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "Shared utility functions for Nera plugins (config loading, template publishing)",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -37,7 +37,7 @@
37
37
  "test": "vitest",
38
38
  "lint": "eslint .",
39
39
  "lint:fix": "eslint . --fix",
40
- "prepare": "git config core.hooksPath .husky || true"
40
+ "prepare": "husky"
41
41
  },
42
42
  "exports": {
43
43
  ".": "./index.js"
@@ -46,6 +46,6 @@
46
46
  "index.js"
47
47
  ],
48
48
  "engines": {
49
- "node": ">=18"
49
+ "node": ">=20.0.0"
50
50
  }
51
51
  }