@nera-static/plugin-utils 1.3.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.
- package/README.md +59 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,11 +23,16 @@ npm install @nera-static/plugin-utils
|
|
|
23
23
|
|
|
24
24
|
Reads and parses a YAML config file, returning its contents as a JavaScript object.
|
|
25
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
|
+
|
|
26
30
|
```js
|
|
31
|
+
import path from 'path'
|
|
27
32
|
import { getConfig } from '@nera-static/plugin-utils'
|
|
28
33
|
|
|
29
|
-
const config = getConfig('
|
|
30
|
-
|
|
34
|
+
const config = getConfig(path.resolve(process.cwd(), 'config/my-plugin.yaml'))
|
|
35
|
+
const title = config.title || 'Default title'
|
|
31
36
|
```
|
|
32
37
|
|
|
33
38
|
### Template Publishing
|
|
@@ -36,7 +41,7 @@ console.log(config.title)
|
|
|
36
41
|
|
|
37
42
|
Validates if the current working directory is a valid Nera project.
|
|
38
43
|
|
|
39
|
-
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.
|
|
40
45
|
|
|
41
46
|
```js
|
|
42
47
|
import { validateNeraProject } from '@nera-static/plugin-utils'
|
|
@@ -81,6 +86,10 @@ const result = publishAllTemplates({
|
|
|
81
86
|
})
|
|
82
87
|
```
|
|
83
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
|
+
|
|
84
93
|
### Template Publishing CLI Integration
|
|
85
94
|
|
|
86
95
|
These functions are designed to be used in `bin/publish-template.js` scripts that can be executed via npm scripts:
|
|
@@ -119,12 +128,18 @@ This package is intended for use inside Nera plugins to:
|
|
|
119
128
|
|
|
120
129
|
```js
|
|
121
130
|
// index.js - Main plugin file
|
|
131
|
+
import path from 'path'
|
|
122
132
|
import { getConfig } from '@nera-static/plugin-utils'
|
|
123
133
|
|
|
124
|
-
export function getAppData(
|
|
125
|
-
const config = getConfig(
|
|
134
|
+
export function getAppData(data) {
|
|
135
|
+
const config = getConfig(
|
|
136
|
+
path.resolve(process.cwd(), 'config/my-plugin.yaml')
|
|
137
|
+
)
|
|
126
138
|
|
|
139
|
+
// Spread the incoming app. The return value REPLACES `app` wholesale --
|
|
140
|
+
// returning a bare object discards every other plugin's data, silently.
|
|
127
141
|
return {
|
|
142
|
+
...data.app,
|
|
128
143
|
myPlugin: {
|
|
129
144
|
// ... plugin logic using config
|
|
130
145
|
},
|
|
@@ -132,6 +147,10 @@ export function getAppData(app) {
|
|
|
132
147
|
}
|
|
133
148
|
```
|
|
134
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
|
+
|
|
135
154
|
```js
|
|
136
155
|
// bin/publish-template.js - Template publishing script
|
|
137
156
|
#!/usr/bin/env node
|
|
@@ -152,12 +171,46 @@ process.exit(result ? 0 : 1)
|
|
|
152
171
|
|
|
153
172
|
---
|
|
154
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
|
+
|
|
155
199
|
## 🧑💻 Maintainers
|
|
156
200
|
|
|
157
201
|
Created and maintained by [@seebaermichi](https://github.com/seebaermichi)
|
|
158
202
|
|
|
159
203
|
---
|
|
160
204
|
|
|
161
|
-
##
|
|
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
|
|
162
215
|
|
|
163
216
|
MIT
|