@unterberg/nivel 0.1.4 → 0.1.6

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 CHANGED
@@ -1,28 +1,83 @@
1
- # nivel engine
1
+ # @unterberg/nivel
2
2
 
3
- `@unterberg/nivel` is the docs runtime for this repo's Vike-based documentation sites.
3
+ Opinionated docs engine for Vike + Vite + React.
4
4
 
5
- It currently owns:
5
+ `@unterberg/nivel` owns the docs runtime: Vike integration, MDX setup, docs-graph validation, route code generation, page shell rendering, and reusable docs UI primitives. The consumer stays thin and keeps its content, docs graph, visible Vike shell files, and theme files local.
6
6
 
7
- - docs graph validation and resolution
8
- - generated Vike routes from MDX content
9
- - docs layout primitives such as navbar, sidebar, table of contents, pagination, and meta head wiring
10
- - MDX setup with built-in docs components and code-block transforms
11
- - optional Algolia search wiring
12
- - engine-owned fonts and shared assets
7
+ ## What It Provides
13
8
 
14
- The supported stack is currently Vike + Vite + React. Expect breaking changes while the package is still alpha.
9
+ - typed docs config and docs graph helpers
10
+ - generated Vike docs pages from a single docs graph
11
+ - docs shell primitives such as navbar, sidebar, table of contents, pagination, search, and meta head wiring
12
+ - MDX support with built-in docs components and code-block tooling
13
+ - Tailwind v4 and daisyUI integration helpers
14
+ - a small CLI for consumer scaffolding and docs page generation
15
15
 
16
- ## Public Helpers
16
+ ## Install
17
17
 
18
- ```ts
19
- import { defineDocsConfig, defineDocsGraph } from '@unterberg/nivel/config'
18
+ ```bash
19
+ pnpm add @unterberg/nivel react react-dom vike vike-react
20
+ pnpm add -D vite typescript @types/react @types/react-dom
21
+ ```
22
+
23
+ `vike` and `vite` are peer dependencies. The package exposes a local `nivel` binary after install.
24
+
25
+ ## Quick Start
26
+
27
+ Scaffold a consumer:
28
+
29
+ ```bash
30
+ pnpm exec nivel init
20
31
  ```
21
32
 
22
- Both helpers are identity functions. They are also re-exported from `@unterberg/nivel`, but the dedicated config entry keeps `pages/+docs.ts` and `docs/docs.graph.ts` on a lean config-time import path.
33
+ Generate docs pages:
34
+
35
+ ```bash
36
+ pnpm exec nivel prepare
37
+ ```
38
+
39
+ Typical consumer scripts:
40
+
41
+ ```json
42
+ {
43
+ "scripts": {
44
+ "generate:docs": "nivel prepare",
45
+ "predev": "pnpm generate:docs",
46
+ "dev": "vike dev",
47
+ "prebuild": "pnpm generate:docs",
48
+ "build": "vike build",
49
+ "pretypecheck": "pnpm generate:docs",
50
+ "typecheck": "tsc --noEmit -p tsconfig.json"
51
+ }
52
+ }
53
+ ```
54
+
55
+ ## Consumer Shape
56
+
57
+ Keep these files local and visible in the consumer:
58
+
59
+ - `docs/docs.graph.ts`
60
+ - `pages/+docs.ts`
61
+ - `pages/+config.ts`
62
+ - `pages/+Head.tsx`
63
+ - `pages/+Layout.tsx`
64
+ - `pages/+onCreateGlobalContext.ts`
65
+ - `pages/+Wrapper.tsx`
66
+ - `global.d.ts`
67
+ - docs content, brand assets, and consumer CSS/theme files
68
+
69
+ Only `pages/(nivel-generated)` is engine-generated and should not be edited by hand.
70
+
71
+ `docs/docs.graph.ts` is the single source of truth for docs structure. Navbar and sidebar behavior come from that graph.
72
+
73
+ ## Minimal Setup
74
+
75
+ `docs/docs.graph.ts`
23
76
 
24
77
  ```ts
25
- const docsGraph = defineDocsGraph({
78
+ import { defineDocsGraph } from '@unterberg/nivel/config'
79
+
80
+ export const docsGraph = defineDocsGraph({
26
81
  items: [
27
82
  {
28
83
  kind: 'section',
@@ -31,56 +86,37 @@ const docsGraph = defineDocsGraph({
31
86
  items: [
32
87
  {
33
88
  kind: 'page',
34
- id: 'quickStart',
35
- title: 'Quick Start',
36
- slug: 'quick-start',
37
- source: 'content/quick-start/content.mdx',
89
+ id: 'gettingStarted',
90
+ title: 'Getting Started',
91
+ slug: 'getting-started',
92
+ source: 'content/getting-started/content.mdx',
93
+ description: 'Getting started with @unterberg/nivel.',
38
94
  },
39
95
  ],
40
96
  },
41
97
  ],
42
98
  })
43
-
44
- export default defineDocsConfig({
45
- siteTitle: 'My Docs',
46
- siteDescription: 'Documentation site powered by @unterberg/nivel.',
47
- basePath: '/docs',
48
- // Optional project-relative root for page.source resolution.
49
- // contentDir: 'docs',
50
- graph: docsGraph,
51
- })
52
99
  ```
53
100
 
54
- ## Recommended Consumer Files
55
-
56
- A consumer should keep these files explicit and local:
57
-
58
- - hand-authored: `pages/+docs.ts`, `docs/docs.graph.ts`, docs content, brand assets, and consumer CSS/Tailwind/theme files
59
- - scaffolded once but still editable: `pages/+config.ts`, `pages/+Head.tsx`, `pages/+Layout.tsx`, `pages/+onCreateGlobalContext.ts`, `pages/+Wrapper.tsx`, and `global.d.ts`
60
-
61
- Only `(nivel-generated)` stays engine-generated.
62
-
63
- ## Standard Vike Config
64
-
65
- Keep `pages/+config.ts` looking like normal Vike config and spread in the engine-owned config from `@unterberg/nivel/vike`:
101
+ `pages/+docs.ts`
66
102
 
67
103
  ```ts
68
- // pages/+docs.ts
69
104
  import { defineDocsConfig } from '@unterberg/nivel/config'
70
105
  import { docsGraph } from '../docs/docs.graph'
71
106
 
72
- export default defineDocsConfig({
107
+ const docsConfig = defineDocsConfig({
108
+ graph: docsGraph,
73
109
  siteTitle: 'My Docs',
74
110
  siteDescription: 'Documentation site powered by @unterberg/nivel.',
75
111
  basePath: '/docs',
76
- graph: docsGraph,
77
112
  })
113
+
114
+ export default docsConfig
78
115
  ```
79
116
 
80
- `basePath` controls the public docs route prefix. `contentDir` is an optional project-relative filesystem root for resolving `page.source` entries and defaults to `docs`.
117
+ `pages/+config.ts`
81
118
 
82
119
  ```ts
83
- // pages/+config.ts
84
120
  import nivel from '@unterberg/nivel/vike'
85
121
  import type { Config } from 'vike/types'
86
122
  import vikeReact from 'vike-react/config'
@@ -100,43 +136,101 @@ const config: Config = {
100
136
  title: docsConfig.siteTitle,
101
137
  description: docsConfig.siteDescription ?? `${docsConfig.siteTitle} documentation`,
102
138
  htmlAttributes: { 'data-theme': dataTheme },
103
- passToClient: ['docs'],
104
-
105
- // User-facing Vike levers stay visible here.
106
139
  prerender: true,
107
- // ssr: true,
108
- // prefetchStaticAssets: 'viewport',
109
140
  }
110
141
  ```
111
142
 
112
- The engine still owns the MDX, Vite, route-generation, and runtime wiring. The consumer keeps the normal Vike entry file and can adjust visible levers such as `prerender`, `ssr`, and prefetch-related settings directly in `+config.ts`.
143
+ `vite.config.ts`
113
144
 
114
- ## CLI
145
+ ```ts
146
+ import { nivelTailwindVite } from '@unterberg/nivel/tailwind'
147
+ import vike from 'vike/plugin'
115
148
 
116
- `nivel prepare` generates docs pages from `pages/+docs.ts`.
149
+ process.env.VIKE_CRAWL ??= JSON.stringify({ git: false })
117
150
 
118
- `nivel init` scaffolds the visible consumer shell files and updates the standard docs scripts in `package.json`.
151
+ export default {
152
+ plugins: [nivelTailwindVite(), vike()],
153
+ }
154
+ ```
119
155
 
120
- ```bash
121
- nivel init
122
- nivel prepare
156
+ `pages/+Head.tsx`
157
+
158
+ ```tsx
159
+ import { MetaHead } from '@unterberg/nivel/client'
160
+
161
+ export const Head = () => {
162
+ return <MetaHead />
163
+ }
123
164
  ```
124
165
 
125
- `nivel init` does not create or overwrite consumer CSS/Tailwind/theme files. Keep those hand-authored. Add the engine Tailwind helper manually in your stylesheet:
166
+ `pages/+Layout.tsx`
126
167
 
127
- ```css
128
- @import '@unterberg/nivel/tailwind-sources.css';
168
+ ```tsx
169
+ import { AppLayout } from '@unterberg/nivel/client'
170
+ import type { ReactNode } from 'react'
171
+
172
+ const Layout = ({ children }: { children: ReactNode }) => {
173
+ return <AppLayout>{children}</AppLayout>
174
+ }
175
+
176
+ export default Layout
129
177
  ```
130
178
 
131
- If you use Algolia, `apiKey` must be a search-only public key because requests are made from the browser.
179
+ `pages/+Wrapper.tsx`
180
+
181
+ ```tsx
182
+ import type { ReactNode } from 'react'
183
+ import '../styles/global.css'
184
+
185
+ const Wrapper = ({ children }: { children: ReactNode }) => {
186
+ return <>{children}</>
187
+ }
188
+
189
+ export default Wrapper
190
+ ```
132
191
 
133
- ## Commands
192
+ `styles/global.css`
193
+
194
+ ```css
195
+ @import '@unterberg/nivel/tailwind.css';
196
+ @import './theme.css';
197
+
198
+ @source '../pages';
199
+ @source '../docs';
200
+ ```
201
+
202
+ ## CLI
134
203
 
135
204
  ```bash
136
- pnpm install
137
- pnpm dev
138
- pnpm build
139
- pnpm typecheck
140
- pnpm format
141
- pnpm knip
205
+ nivel init [--root <path>] [--force]
206
+ nivel prepare [--root <path>]
207
+ nivel --help
142
208
  ```
209
+
210
+ - `nivel init` scaffolds the visible consumer files and patches the standard docs scripts in `package.json`
211
+ - `nivel init --force` overwrites scaffold-managed files if they already exist
212
+ - `nivel prepare` reads `pages/+docs.ts` and generates `pages/(nivel-generated)`
213
+
214
+ `nivel init` does not create or overwrite your brand assets or consumer-specific styling decisions beyond the initial scaffold. Theme and palette files stay consumer-owned.
215
+
216
+ ## Public Entry Points
217
+
218
+ | Entry | Purpose |
219
+ | --- | --- |
220
+ | `@unterberg/nivel` | main types, docs helpers, MDX components, shared utilities |
221
+ | `@unterberg/nivel/config` | lean config-time entry for `defineDocsConfig()` and `defineDocsGraph()` |
222
+ | `@unterberg/nivel/vike` | engine-owned Vike config for the consumer's `pages/+config.ts` |
223
+ | `@unterberg/nivel/client` | `AppLayout`, `MetaHead`, `UserSettingsSync`, `DocsPage`, and client stores |
224
+ | `@unterberg/nivel/mdx` | MDX provider entry |
225
+ | `@unterberg/nivel/mdx/code-blocks` | code-block components and transforms |
226
+ | `@unterberg/nivel/tailwind` | `nivelTailwindVite()` helper |
227
+ | `@unterberg/nivel/daisyui-theme` | daisyUI theme plugin surface |
228
+ | `@unterberg/nivel/runtime/node` | lower-level runtime helpers for loading config, resolving docs, scaffolding, and codegen |
229
+ | `@unterberg/nivel/runtime/client` | lower-level client runtime entry |
230
+
231
+ ## Notes
232
+
233
+ - `basePath` controls the public docs route prefix.
234
+ - `contentDir` is optional and defaults to `docs`.
235
+ - If you configure Algolia, `apiKey` must be a browser-safe search key.
236
+ - The repo validates this package through both the in-repo consumer at `packages/consumer-dev` and the standalone fixture at `tests/npm-consumer`.