@nera-static/nera 1.1.0 → 1.2.0
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 +1 -1
- package/package.json +2 -2
- package/src/commands/dev.js +47 -14
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ npm run dev # or: nera dev
|
|
|
20
20
|
|---|---|
|
|
21
21
|
| `nera new <name>` | Scaffold a new thin Nera site (one dependency: `@nera-static/nera`). Add `--theme <name>` to start from a theme. |
|
|
22
22
|
| `nera build` | Render `pages/` → `public/`. |
|
|
23
|
-
| `nera dev` | Build, serve `public/`, and rebuild on change with live reload. |
|
|
23
|
+
| `nera dev` | Build, serve `public/`, and rebuild on change with live reload. Watches `pages/`, `config/`, `theme/` and a local theme (`theme: ./themes/<name>`). |
|
|
24
24
|
| `nera serve` | Serve the already-built `public/` folder. |
|
|
25
25
|
| `nera update` | Update the site's Nera packages. On a legacy cloned site, `nera update --migrate` converts it to the thin model. |
|
|
26
26
|
| `nera validate` | Check the site (layouts, includes, YAML) before publishing; exits non-zero on any error. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nera-static/nera",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "The Nera CLI — scaffold, build, preview and update a Nera static site with one command over the @nera-static/core engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@nera-static/core": "^4.
|
|
45
|
+
"@nera-static/core": "^4.12.0",
|
|
46
46
|
"@nera-static/validate": "^1.0.0",
|
|
47
47
|
"chokidar": "^5.0.0",
|
|
48
48
|
"semver": "^7.8.5",
|
package/src/commands/dev.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fssync from 'fs'
|
|
2
|
-
import
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import run, { resolveSiteModel } from '@nera-static/core'
|
|
3
4
|
import { startServer } from './serve.js'
|
|
4
5
|
|
|
5
6
|
// Build once, serve `public/`, then rebuild on any change to the site's
|
|
@@ -19,13 +20,8 @@ export async function runDev(args = []) {
|
|
|
19
20
|
|
|
20
21
|
const { default: chokidar } = await import('chokidar')
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const watchDirs = [
|
|
25
|
-
'pages',
|
|
26
|
-
'config',
|
|
27
|
-
fssync.existsSync('theme') ? 'theme' : 'views',
|
|
28
|
-
].filter((d) => fssync.existsSync(d))
|
|
23
|
+
const watched = new Set(watchTargets())
|
|
24
|
+
const watcher = chokidar.watch([...watched], { ignoreInitial: true })
|
|
29
25
|
|
|
30
26
|
// Serialise rebuilds: coalesce changes that land mid-build into one re-run.
|
|
31
27
|
let building = false
|
|
@@ -42,22 +38,59 @@ export async function runDev(args = []) {
|
|
|
42
38
|
console.error('❌ Build error:', err.message)
|
|
43
39
|
}
|
|
44
40
|
building = false
|
|
41
|
+
// config/app.yaml may now name a different local theme — start
|
|
42
|
+
// watching it too. A dropped one stays watched; that only costs an
|
|
43
|
+
// extra rebuild if it is edited.
|
|
44
|
+
for (const dir of watchTargets()) {
|
|
45
|
+
if (!watched.has(dir)) {
|
|
46
|
+
watched.add(dir)
|
|
47
|
+
watcher.add(dir)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
45
50
|
if (queued) {
|
|
46
51
|
queued = false
|
|
47
52
|
await rebuild()
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
watcher.on('all', async (event, filePath) => {
|
|
57
|
+
console.log(
|
|
58
|
+
`↻ ${event} ${path.relative(process.cwd(), filePath)} — rebuilding`
|
|
59
|
+
)
|
|
60
|
+
await rebuild()
|
|
61
|
+
})
|
|
57
62
|
|
|
58
63
|
return server
|
|
59
64
|
}
|
|
60
65
|
|
|
66
|
+
// What a rebuild depends on: pages/, config/, the site's presentation folder
|
|
67
|
+
// — theme/ in the current layout, or the deprecated root views/ on an
|
|
68
|
+
// unmigrated site — and a LOCAL theme (`theme: ./themes/classic`, or the same
|
|
69
|
+
// via NERA_THEME), which lives outside all of those. The theme is resolved
|
|
70
|
+
// through core, so the watcher follows exactly the spec the build uses. Only
|
|
71
|
+
// the theme's payload folders are watched, never its root: `theme: .` makes
|
|
72
|
+
// the root the site itself, and watching public/ would rebuild forever. An
|
|
73
|
+
// installed theme package under node_modules is left alone: it changes only on
|
|
74
|
+
// npm install, and watching node_modules is expensive.
|
|
75
|
+
export function watchTargets(cwd = process.cwd()) {
|
|
76
|
+
const dirs = [
|
|
77
|
+
'pages',
|
|
78
|
+
'config',
|
|
79
|
+
fssync.existsSync(path.join(cwd, 'theme')) ? 'theme' : 'views',
|
|
80
|
+
].map((d) => path.join(cwd, d))
|
|
81
|
+
|
|
82
|
+
const { theme } = resolveSiteModel({ cwd })
|
|
83
|
+
if (theme && !theme.root.split(path.sep).includes('node_modules')) {
|
|
84
|
+
dirs.push(
|
|
85
|
+
theme.viewsRoot,
|
|
86
|
+
theme.assetsRoot,
|
|
87
|
+
path.join(theme.root, 'config')
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return [...new Set(dirs)].filter((d) => fssync.existsSync(d))
|
|
92
|
+
}
|
|
93
|
+
|
|
61
94
|
const parsePort = (args) => {
|
|
62
95
|
const i = args.indexOf('--port')
|
|
63
96
|
const val = i >= 0 ? Number(args[i + 1]) : NaN
|