uniweb 1.32.1 → 1.33.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 +7 -7
- package/partials/agents.md +2 -2
- package/partials/guides/foundation.md +1 -1
- package/partials/guides/i18n.md +1 -1
- package/partials/guides/start.md +1 -0
- package/src/commands/add-library-section.js +302 -0
- package/src/commands/add-library.js +3 -3
- package/src/commands/add.js +63 -97
- package/src/commands/i18n.js +2 -1
- package/src/framework-index.json +10 -10
- package/src/index.js +6 -0
- package/src/utils/section-files.js +97 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The CLI for [Uniweb](https://uniweb.io), an open-source framework for building websites with an AI agent. Your agent builds the site, Uniweb hosting runs it, and you and the people you work with can edit it in a visual app.
|
|
4
4
|
|
|
5
|
-
**Agents build it. Uniweb runs it.
|
|
5
|
+
**Agents build it. Uniweb runs it. You can edit it too.**
|
|
6
6
|
|
|
7
7
|
## Quick Start
|
|
8
8
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uniweb",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.33.0",
|
|
4
4
|
"description": "Create structured Vite + React sites with content/code separation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -41,15 +41,15 @@
|
|
|
41
41
|
"js-yaml": "^4.3.2",
|
|
42
42
|
"prompts": "^2.4.2",
|
|
43
43
|
"tar": "^7.5.21",
|
|
44
|
-
"@uniweb/
|
|
44
|
+
"@uniweb/content-writer": "~1.3.2",
|
|
45
45
|
"@uniweb/core": "~1.6.12",
|
|
46
|
-
"@uniweb/
|
|
47
|
-
"@uniweb/
|
|
46
|
+
"@uniweb/schemas": "~1.7.1",
|
|
47
|
+
"@uniweb/semantic-parser": "~1.13.4"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@uniweb/build": "~1.
|
|
51
|
-
"@uniweb/semantic-parser": "~1.13.
|
|
52
|
-
"@uniweb/content-reader": "~1.5.
|
|
50
|
+
"@uniweb/build": "~1.22.0",
|
|
51
|
+
"@uniweb/semantic-parser": "~1.13.4",
|
|
52
|
+
"@uniweb/content-reader": "~1.5.10"
|
|
53
53
|
},
|
|
54
54
|
"peerDependenciesMeta": {
|
|
55
55
|
"@uniweb/build": {
|
package/partials/agents.md
CHANGED
|
@@ -109,10 +109,10 @@ When a rule in §2 feels like friction, that is the moment you are about to take
|
|
|
109
109
|
| A `Button` or `Card` in `sections/` | `components/`. Everything at the root of `sections/` becomes author vocabulary. | appears in the section picker |
|
|
110
110
|
| Helpers that take `{ content, params }` | Ordinary props. That signature is for section types only. | — |
|
|
111
111
|
| One section type per visual variant; or one with a conditional tree inside | A front desk (§1): one `type:`, a `variant` param, workers in `components/` with ordinary props. | author vocabulary bloats; variants invisible to the editor |
|
|
112
|
-
| Copy a worker, hook or data type into a second foundation | A library both depend on: `uniweb add library libraries/ui --foundation a,b`; types named in full (`@acme/plan`). `uniweb guide foundation` § Libraries. | silent: the copies drift; `doctor` names a type defined twice |
|
|
112
|
+
| Copy a worker, hook, section type or data type into a second foundation | A library both depend on: `uniweb add library libraries/ui --foundation a,b`; types named in full (`@acme/plan`). `uniweb guide foundation` § Libraries. | silent: the copies drift; `doctor` names a type defined twice |
|
|
113
113
|
| Copy another site's records into this one, by hand or with a script | Mount that site's folder for the type in `site.yml`: `paths: { records/acme/plan: ../../hub/site/records/acme/plan }`. `uniweb guide data`. | silent: the copies drift |
|
|
114
114
|
| Validate, enumerate or warn on content the component doesn't use; treat `content:` as an exact schema | Take what you expect and don't touch the rest (§1). `content:` declares what the type reads. | — |
|
|
115
|
-
| `params: { theme, background, grid, sticky, query }` | Section settings — read from `block`, never declared. | build
|
|
115
|
+
| `params: { theme, background, grid, sticky, query }` | Section settings — read from `block`, never declared. | foundation build stops, naming it |
|
|
116
116
|
| Write `meta.js` as internal metadata | It is the visual editor's UI and other agents' catalog. Labels for people, defaults for everything, author words for params (`columns`, not `gridCols`). | — |
|
|
117
117
|
| `window.uniweb`, `globalThis.uniweb` | `@uniweb/kit` and `block.*` only. | — |
|
|
118
118
|
| `<P text={member.bio} />` | Member and API text is **text**: `{value}` or `<PlainText>`. Only parser strings are safe HTML. | XSS |
|
|
@@ -170,7 +170,7 @@ A section type is a front desk; a **library** is the back office several foundat
|
|
|
170
170
|
- Export workers from its `index.js` and import them as from any package: `import { PlanCard } from 'ui'`.
|
|
171
171
|
- A worker takes ordinary props and reads every design decision from foundation vars and theme tokens (`var(--card-radius)`, `bg-card`), never a fixed radius or color. That is what lets one worker look classic in one foundation and modern in another.
|
|
172
172
|
- Import `@uniweb/core` by its bare name only, as kit does: a subpath bundles a second core.
|
|
173
|
-
- A section type the library holds stays each foundation's to offer: a directory in the foundation's `sections/` whose `index.jsx` is `export { default } from 'ui/sections/Banner/index.jsx'`, with a `meta.js` that re-exports the library's the same way, when both offer it alike. When only the component is the same, the foundation keeps its own `meta.js` and re-exports `index.jsx` alone. When the components differ, the type stays the foundation's whole, even with the same `meta.js`: a shared `meta.js` over two components shows each foundation's params in the other's editor.
|
|
173
|
+
- A section type the library holds stays each foundation's to offer: a directory in the foundation's `sections/` whose `index.jsx` is `export { default } from 'ui/sections/Banner/index.jsx'`, with a `meta.js` that re-exports the library's the same way, when both offer it alike. `uniweb add section Banner --library ui` writes the type into the library and those two files into each foundation that depends on it (`--foundation a,b` names them instead, wiring any that doesn't). When only the component is the same, the foundation keeps its own `meta.js` and re-exports `index.jsx` alone. When the components differ, the type stays the foundation's whole, even with the same `meta.js`: a shared `meta.js` over two components shows each foundation's params in the other's editor.
|
|
174
174
|
- Moving copies in: a file moves only with every file it imports by path (`./`, `#components/`), the same in each foundation holding it; a component that imports its foundation's own `Button` stays until `Button` moves. In the library it keeps its path, and foundations import it by name and path (`ui/components/Button.jsx`); give the library the foundations' `imports` map when the moved files use `#components/`. Build the workspace before and after and `diff -r -x '*.map'` each `dist/` (a sourcemap names source paths, which the move changes): the same files mean nothing a visitor sees or a publish sends changed. Steps: [Libraries](https://uniweb.io/docs/development/libraries.md) § *Moving copies into a library*.
|
|
175
175
|
- Split shared code by the foundations that use it, a library per group (one all of them use, one for each pair that shares more): a foundation's `@import "ui/styles.css"` has Tailwind read every file of the library, so one library for everything puts other foundations' classes in each one's CSS. A library that uses another lists it in its own dependencies (`"ui": "file:../ui"`).
|
|
176
176
|
- Data types: `uniweb add library libraries/data --schemas --scope @acme` gives it a `schemas/` folder and its scope (`"uniweb": { "scope": "@acme" }` in its package.json). Foundations name its types in full (`data: { plans: '@acme/plan' }`), with nothing to configure (`uniweb guide data`). On a synced site, `register` in a foundation registers the types it names from the library first, since a foundation is taken only once they are; `push` and `publish` release the foundation through `register`, so they do too, and a change to a type releases each foundation that names it on its site's next push. `uniweb register` in the library registers them alone.
|
package/partials/guides/i18n.md
CHANGED
|
@@ -24,7 +24,7 @@ uniweb build # merges translations, emits dist/es/, dist/fr/
|
|
|
24
24
|
|
|
25
25
|
Records are the exception: `extract` reads them from what a build left in `public/data/`, so build first when the site has records. After content changes: `uniweb i18n sync` updates the manifest, `init` refreshes language files, `status` and `audit` report coverage and stale entries. `status` counts an entry that is still the source's own text, as `init` writes it, apart from the translated ones, and an empty one as missing.
|
|
26
26
|
|
|
27
|
-
**A branch the site doesn't translate** — a mounted repo's docs shown in their own language — goes in `i18n: { exclude: [/docs] }` in `site.yml`, routes as `agents.exclude` takes them. `extract` takes no strings from it, so `init` and `status` leave it alone, and its pages show the source in every language,
|
|
27
|
+
**A branch the site doesn't translate** — a mounted repo's docs shown in their own language — goes in `i18n: { exclude: [/docs] }` in `site.yml`, routes as `agents.exclude` takes them. `extract` takes no strings from it, so `init` and `status` leave it alone, and its pages show the source in every language, even where the site translates the same words elsewhere. Only an override naming one of its places (`/docs/setup:intro`) applies there, which is how a pull writes what an author translated on such a page in the app; `audit` lists those apart and `--clean` keeps them.
|
|
28
28
|
|
|
29
29
|
**A value is inline Markdown.** Links and bold go into the translation (`"Voir [Rôles](page:docs/roles)."`) or it renders without them; `audit` lists these under *Loses markup*; `status` counts them as translated. A **button** (a line that is only a link) is the exception: translate the label alone and it keeps its link and options. Buttons on consecutive lines are one string — one label per line (`"Créer un groupe\nEn savoir plus"`). The same words are one string wherever they appear; where their places differ the manifest marks `markupVaries`, and the plain words are what to write.
|
|
30
30
|
|
package/partials/guides/start.md
CHANGED
|
@@ -42,6 +42,7 @@ uniweb add foundation [name|path] [--path parent] # no name → ./src/, bare na
|
|
|
42
42
|
uniweb add site [name|path]
|
|
43
43
|
uniweb add extension <name> [--site <name>] # secondary foundation; wired to the site named, or the only one
|
|
44
44
|
uniweb add section Hero [--foundation ui] # sections/Hero/{index.jsx,meta.js}
|
|
45
|
+
uniweb add section Banner --library ui # in a library; each foundation using it offers it
|
|
45
46
|
uniweb rename <foundation|site|extension> <old> <new> # rename across the whole workspace
|
|
46
47
|
```
|
|
47
48
|
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `uniweb add section <Name> --library <library> [--foundation a,b]`
|
|
3
|
+
*
|
|
4
|
+
* ⭐ A SECTION TYPE STAYS EACH FOUNDATION'S TO OFFER, EVEN WHEN ITS CODE IS A LIBRARY'S. Authors pick
|
|
5
|
+
* a type from a foundation's `sections/`, and a library has no type of its own. So this writes the
|
|
6
|
+
* type into the library, `<library>/sections/<Name>/` with the two files `add section` makes, and in
|
|
7
|
+
* each foundation the two lines that pass it on: an `index.jsx` and a `meta.js`, each
|
|
8
|
+
* `export { default } from '<library>/sections/<Name>/<file>'`. A foundation's editor schema then
|
|
9
|
+
* carries the library's `meta.js`, so authors see the same title, params and presets in each, and a
|
|
10
|
+
* change to the library's files reaches every foundation that passes them on.
|
|
11
|
+
*
|
|
12
|
+
* Run for a type the library holds already, it only passes it on. A foundation named that doesn't
|
|
13
|
+
* depend on the library is wired to it first, as `add library` wires one. With no `--foundation`, the
|
|
14
|
+
* type goes to every foundation that depends on the library. When a foundation named has a type of
|
|
15
|
+
* that name of its own, nothing is written.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs'
|
|
19
|
+
import { mkdir, writeFile } from 'node:fs/promises'
|
|
20
|
+
import { basename, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
21
|
+
import prompts from 'prompts'
|
|
22
|
+
import { classifyPackage, librariesOf, resolveFoundationSrcPath } from '@uniweb/build'
|
|
23
|
+
import { discoverFoundations } from '../utils/discover.js'
|
|
24
|
+
import { registerWorkspacePackage } from '../utils/config.js'
|
|
25
|
+
import { workspacePackages } from '../utils/workspace-packages.js'
|
|
26
|
+
import { writeJsonPreservingStyleAsync } from '../utils/json-file.js'
|
|
27
|
+
import { installCmd, pmToInstall } from '../utils/pm.js'
|
|
28
|
+
import { getCliPrefix, isNonInteractive } from '../utils/interactive.js'
|
|
29
|
+
import { passOnFiles, passOnSpecifier, writeSection } from '../utils/section-files.js'
|
|
30
|
+
import { wireFoundation } from './add-library.js'
|
|
31
|
+
|
|
32
|
+
const colors = {
|
|
33
|
+
reset: '\x1b[0m',
|
|
34
|
+
bright: '\x1b[1m',
|
|
35
|
+
dim: '\x1b[2m',
|
|
36
|
+
cyan: '\x1b[36m',
|
|
37
|
+
green: '\x1b[32m',
|
|
38
|
+
yellow: '\x1b[33m',
|
|
39
|
+
red: '\x1b[31m'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const posix = (path) => path.split(sep).join('/')
|
|
43
|
+
|
|
44
|
+
const real = (path) => {
|
|
45
|
+
try {
|
|
46
|
+
return realpathSync(path)
|
|
47
|
+
} catch {
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function readPackage(dir) {
|
|
53
|
+
try {
|
|
54
|
+
return JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'))
|
|
55
|
+
} catch {
|
|
56
|
+
return null
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Whether a package's `exports` lets another package import `subpath` (`./sections/Banner/meta.js`):
|
|
62
|
+
* every file when there is no map, an exact key, or a `*` pattern that matches it. A string, an
|
|
63
|
+
* array or an object of conditions is the package's `.` alone.
|
|
64
|
+
*
|
|
65
|
+
* @param {unknown} exports - `package.json` `exports`
|
|
66
|
+
* @param {string} subpath
|
|
67
|
+
*/
|
|
68
|
+
export function exportsSubpath(exports, subpath) {
|
|
69
|
+
if (exports === undefined || exports === null) return true
|
|
70
|
+
if (typeof exports !== 'object' || Array.isArray(exports)) return subpath === '.'
|
|
71
|
+
const keys = Object.keys(exports)
|
|
72
|
+
if (!keys.some((k) => k.startsWith('.'))) return subpath === '.'
|
|
73
|
+
if (Object.hasOwn(exports, subpath)) return exports[subpath] !== null
|
|
74
|
+
return keys.some((key) => {
|
|
75
|
+
const star = key.indexOf('*')
|
|
76
|
+
if (star === -1 || exports[key] === null) return false
|
|
77
|
+
const [before, after] = [key.slice(0, star), key.slice(star + 1)]
|
|
78
|
+
return subpath.length >= before.length + after.length && subpath.startsWith(before) && subpath.endsWith(after)
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* `exports` with `./sections/*` added: a map gets the key; a string, an array or conditions become
|
|
84
|
+
* the map's `.`.
|
|
85
|
+
*/
|
|
86
|
+
export function withSectionsExport(exports) {
|
|
87
|
+
const map =
|
|
88
|
+
exports && typeof exports === 'object' && !Array.isArray(exports) && Object.keys(exports).some((k) => k.startsWith('.'))
|
|
89
|
+
? { ...exports }
|
|
90
|
+
: { '.': exports }
|
|
91
|
+
map['./sections/*'] = './sections/*'
|
|
92
|
+
return map
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The library `ref` names: a folder, from the workspace's root, or a package's name. */
|
|
96
|
+
function findLibrary(rootDir, ref, foundations) {
|
|
97
|
+
const folder = real(resolve(rootDir, ref))
|
|
98
|
+
if (folder && existsSync(join(folder, 'package.json'))) {
|
|
99
|
+
return { dir: folder, name: readPackage(folder)?.name || basename(folder) }
|
|
100
|
+
}
|
|
101
|
+
for (const rel of workspacePackages(rootDir)) {
|
|
102
|
+
const dir = resolve(rootDir, rel)
|
|
103
|
+
if (readPackage(dir)?.name === ref) return { dir: real(dir) ?? dir, name: ref }
|
|
104
|
+
}
|
|
105
|
+
for (const f of foundations) {
|
|
106
|
+
const lib = librariesOf(join(rootDir, f.path)).find((l) => l.name === ref)
|
|
107
|
+
if (lib) return { dir: lib.dir, name: lib.name }
|
|
108
|
+
}
|
|
109
|
+
return null
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Whether a foundation depends on the library itself, not through another library. */
|
|
113
|
+
function dependsOn(foundationDir, libraryDir) {
|
|
114
|
+
const from = real(foundationDir)
|
|
115
|
+
return librariesOf(foundationDir).some((l) => l.dir === libraryDir && l.from === from)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Add a section type to a library, and pass it on to foundations.
|
|
120
|
+
*
|
|
121
|
+
* @param {string} rootDir - the workspace's root
|
|
122
|
+
* @param {{ name: string, library: string, foundation?: string|null, starter?: boolean, json?: boolean }} opts
|
|
123
|
+
* @returns {Promise<{ sectionDir: string, starterResult: object|null }>} the library's folder for the
|
|
124
|
+
* type, and, when it was made with `--starter`, the result its declaration came from
|
|
125
|
+
*/
|
|
126
|
+
export async function addLibrarySection(rootDir, opts) {
|
|
127
|
+
const prefix = getCliPrefix()
|
|
128
|
+
const { name, library: ref } = opts
|
|
129
|
+
// `--json` hands stdout to the starter's JSON, so everything said goes to stderr.
|
|
130
|
+
const log = (message) => (opts.json ? console.error(message) : console.log(message))
|
|
131
|
+
const fail = (message, ...lines) => {
|
|
132
|
+
console.error(`${colors.red}✗${colors.reset} ${message}`)
|
|
133
|
+
for (const line of lines) if (line) log(line)
|
|
134
|
+
process.exit(1)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const foundations = await discoverFoundations(rootDir)
|
|
138
|
+
if (!foundations.length) {
|
|
139
|
+
fail(`No foundation in this workspace to offer ${name}: a library's section type is offered by foundations.`, `Make one first: ${prefix} add foundation`)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const lib = findLibrary(rootDir, ref, foundations)
|
|
143
|
+
if (!lib) {
|
|
144
|
+
fail(
|
|
145
|
+
`No library named ${colors.bright}${ref}${colors.reset} in this workspace, by folder or by name.`,
|
|
146
|
+
`Make one, and wire the foundations that offer it:`,
|
|
147
|
+
` ${prefix} add library libraries/${basename(ref)} --foundation ${foundations
|
|
148
|
+
.slice(0, 2)
|
|
149
|
+
.map((f) => f.name)
|
|
150
|
+
.join(',')}`
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
const libRel = posix(relative(rootDir, lib.dir)) || '.'
|
|
154
|
+
const fromLibrary = relative(lib.dir, rootDir)
|
|
155
|
+
if (fromLibrary === '' || (!fromLibrary.startsWith('..') && !isAbsolute(fromLibrary))) {
|
|
156
|
+
fail(`A library is a package of the workspace, never the workspace's own folder or one that holds it: ${libRel}/`)
|
|
157
|
+
}
|
|
158
|
+
const kind = classifyPackage(lib.dir)
|
|
159
|
+
if (kind) {
|
|
160
|
+
fail(
|
|
161
|
+
`${libRel}/ is a ${kind}, not a library.`,
|
|
162
|
+
kind === 'foundation' ? `To add ${name} to it: ${prefix} add section ${name} --foundation ${lib.name}` : ''
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// The foundations to offer it: those named, else those that depend on the library, else the
|
|
167
|
+
// workspace's one foundation, else the ones a person picks.
|
|
168
|
+
let targets
|
|
169
|
+
if (opts.foundation) {
|
|
170
|
+
const wanted = opts.foundation.split(',').map((s) => s.trim()).filter(Boolean)
|
|
171
|
+
const missing = wanted.filter((n) => !foundations.some((f) => f.name === n))
|
|
172
|
+
if (missing.length) {
|
|
173
|
+
fail(
|
|
174
|
+
`No foundation named ${missing.map((n) => `'${n}'`).join(', ')} in this workspace.`,
|
|
175
|
+
`Foundations: ${foundations.map((f) => f.name).join(', ')}`
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
targets = wanted.map((n) => foundations.find((f) => f.name === n))
|
|
179
|
+
} else {
|
|
180
|
+
targets = foundations.filter((f) => dependsOn(join(rootDir, f.path), lib.dir))
|
|
181
|
+
if (!targets.length && foundations.length === 1) targets = foundations
|
|
182
|
+
if (!targets.length) {
|
|
183
|
+
if (isNonInteractive(process.argv)) {
|
|
184
|
+
fail(
|
|
185
|
+
`No foundation depends on ${lib.name} yet, so none offers its section types.`,
|
|
186
|
+
`Name the foundations to offer ${name}, and each is wired to ${lib.name}:`,
|
|
187
|
+
` ${prefix} add section ${name} --library ${ref} --foundation ${foundations
|
|
188
|
+
.slice(0, 2)
|
|
189
|
+
.map((f) => f.name)
|
|
190
|
+
.join(',')}`
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
const { picked } = await prompts(
|
|
194
|
+
{
|
|
195
|
+
type: 'multiselect',
|
|
196
|
+
name: 'picked',
|
|
197
|
+
message: `Which foundations offer ${name}?`,
|
|
198
|
+
choices: foundations.map((f) => ({ title: f.name, description: f.path, value: f.name })),
|
|
199
|
+
min: 1
|
|
200
|
+
},
|
|
201
|
+
{ onCancel: () => process.exit(0) }
|
|
202
|
+
)
|
|
203
|
+
targets = (picked || []).map((n) => foundations.find((f) => f.name === n))
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Each foundation's folder for the type, and whether it passes the library's on already. One that
|
|
208
|
+
// has a type of that name of its own stops the command before anything is written.
|
|
209
|
+
const files = passOnFiles(lib.name, name)
|
|
210
|
+
const plans = targets.map((f) => {
|
|
211
|
+
const foundationDir = join(rootDir, f.path)
|
|
212
|
+
const sectionDir = join(resolveFoundationSrcPath(foundationDir), 'sections', name)
|
|
213
|
+
let state = 'new'
|
|
214
|
+
if (existsSync(sectionDir)) {
|
|
215
|
+
const index = join(sectionDir, 'index.jsx')
|
|
216
|
+
const spec = passOnSpecifier(lib.name, name, 'index.jsx')
|
|
217
|
+
const text = existsSync(index) ? readFileSync(index, 'utf8') : ''
|
|
218
|
+
state = text.includes(`'${spec}'`) || text.includes(`"${spec}"`) ? 'already' : 'own'
|
|
219
|
+
}
|
|
220
|
+
return { f, foundationDir, sectionDir, state }
|
|
221
|
+
})
|
|
222
|
+
const own = plans.filter((p) => p.state === 'own')
|
|
223
|
+
if (own.length) {
|
|
224
|
+
const others = plans.filter((p) => p.state !== 'own').map((p) => p.f.name)
|
|
225
|
+
fail(
|
|
226
|
+
`${own.map((p) => `${p.f.name} has a section type ${name} of its own, at ${posix(relative(rootDir, p.sectionDir))}/`).join('; ')}. Nothing was written.`,
|
|
227
|
+
others.length
|
|
228
|
+
? `Rename one of them, or offer ${lib.name}'s in the others alone: --foundation ${others.join(',')}`
|
|
229
|
+
: `Rename one of them, or move that one into ${lib.name} (uniweb guide foundation § Libraries).`
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// The type in the library: made, or taken as it is there.
|
|
234
|
+
const sectionDir = join(lib.dir, 'sections', name)
|
|
235
|
+
const where = `${libRel}/sections/${name}/`
|
|
236
|
+
let starterResult = null
|
|
237
|
+
let created = false
|
|
238
|
+
if (existsSync(sectionDir)) {
|
|
239
|
+
if (!existsSync(join(sectionDir, 'index.jsx'))) {
|
|
240
|
+
fail(`${where} holds no index.jsx, so there is nothing to pass on.`, `Give it its component, or pick another name.`)
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
starterResult = await writeSection({ name, sectionDir, starter: opts.starter })
|
|
244
|
+
created = true
|
|
245
|
+
}
|
|
246
|
+
const hasMeta = existsSync(join(sectionDir, 'meta.js'))
|
|
247
|
+
|
|
248
|
+
// A foundation imports the library's files by their path in the package, which its `exports`
|
|
249
|
+
// has to allow (a library `add library` made exports `./sections/*`).
|
|
250
|
+
const pkgPath = join(lib.dir, 'package.json')
|
|
251
|
+
const pkgSource = readFileSync(pkgPath, 'utf8')
|
|
252
|
+
const pkg = JSON.parse(pkgSource)
|
|
253
|
+
const needed = hasMeta ? ['index.jsx', 'meta.js'] : ['index.jsx']
|
|
254
|
+
let exportsAdded = false
|
|
255
|
+
if (!needed.every((file) => exportsSubpath(pkg.exports, `./sections/${name}/${file}`))) {
|
|
256
|
+
await writeJsonPreservingStyleAsync(pkgPath, { ...pkg, exports: withSectionsExport(pkg.exports) }, pkgSource)
|
|
257
|
+
exportsAdded = true
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Each foundation: wired to the library (nothing changes when it is already), then its two lines.
|
|
261
|
+
const wired = []
|
|
262
|
+
const notes = []
|
|
263
|
+
for (const p of plans) {
|
|
264
|
+
const { changed, notes: left } = await wireFoundation({ foundationDir: p.foundationDir, libraryDir: lib.dir, libraryName: lib.name })
|
|
265
|
+
if (changed) wired.push(p.f.name)
|
|
266
|
+
for (const n of left) notes.push(`${p.f.name}: ${n}`)
|
|
267
|
+
if (p.state === 'already') continue
|
|
268
|
+
await mkdir(p.sectionDir, { recursive: true })
|
|
269
|
+
for (const file of needed) await writeFile(join(p.sectionDir, file), files[file])
|
|
270
|
+
}
|
|
271
|
+
// Listed in the workspace, as `add library` lists one, so the package manager links it.
|
|
272
|
+
if (wired.length) await registerWorkspacePackage(rootDir, libRel)
|
|
273
|
+
|
|
274
|
+
const passed = plans.filter((p) => p.state === 'new').map((p) => p.f.name)
|
|
275
|
+
const already = plans.filter((p) => p.state === 'already').map((p) => p.f.name)
|
|
276
|
+
const { green, dim, bright, cyan, yellow, reset } = colors
|
|
277
|
+
if (created) {
|
|
278
|
+
log(`${green}✓${reset} Created section '${name}' in the library ${bright}${lib.name}${reset}, at ${where}`)
|
|
279
|
+
log(` ${dim}index.jsx${reset} — component (customize the JSX)`)
|
|
280
|
+
log(` ${dim}meta.js${reset} — metadata (add content expectations, params, presets)`)
|
|
281
|
+
} else {
|
|
282
|
+
log(`${lib.name} holds ${name} already, at ${where}`)
|
|
283
|
+
}
|
|
284
|
+
if (passed.length) {
|
|
285
|
+
log(
|
|
286
|
+
`${green}✓${reset} Offered by ${passed.join(', ')}: ` +
|
|
287
|
+
`${passed.length === 1 ? 'its' : "each one's"} sections/${name}/ passes on ${lib.name}'s ${needed.join(' and ')}`
|
|
288
|
+
)
|
|
289
|
+
}
|
|
290
|
+
if (already.length) log(` ${dim}${already.join(', ')}: ${already.length === 1 ? 'passes' : 'pass'} on ${lib.name}'s ${name} already${reset}`)
|
|
291
|
+
if (wired.length) log(` ${dim}Wired to ${lib.name}: ${wired.join(', ')} (a file: dependency, and the import of its stylesheet)${reset}`)
|
|
292
|
+
if (exportsAdded) log(` ${dim}${libRel}/package.json exports ./sections/* now, so a foundation can import the section's files${reset}`)
|
|
293
|
+
for (const n of notes) log(` ${yellow}⚠ ${n}${reset}`)
|
|
294
|
+
if (!hasMeta) log(` ${yellow}⚠ ${where} has no meta.js, so each foundation offers ${name} with none: add one there, then run this again${reset}`)
|
|
295
|
+
log('')
|
|
296
|
+
log(`${dim}Authors pick ${name} from each foundation that offers it. A change to ${where} reaches them all, at each one's next build.${reset}`)
|
|
297
|
+
log(`${dim}To offer it differently in one of them, give that one its own meta.js: its index.jsx stays ${lib.name}'s.${reset}`)
|
|
298
|
+
log('')
|
|
299
|
+
if (wired.length) log(`Next: ${cyan}${installCmd(pmToInstall(rootDir))}${reset}`)
|
|
300
|
+
log(`Before editing it: ${cyan}${prefix} guide foundation${reset}`)
|
|
301
|
+
return { sectionDir, starterResult }
|
|
302
|
+
}
|
|
@@ -38,7 +38,7 @@ import { discoverFoundations } from '../utils/discover.js'
|
|
|
38
38
|
import { validatePackageName } from '../utils/names.js'
|
|
39
39
|
import { workspacePackages } from '../utils/workspace-packages.js'
|
|
40
40
|
import { writeJsonPreservingStyleAsync } from '../utils/json-file.js'
|
|
41
|
-
import { installCmd } from '../utils/pm.js'
|
|
41
|
+
import { installCmd, pmToInstall } from '../utils/pm.js'
|
|
42
42
|
import { getCliPrefix, isNonInteractive } from '../utils/interactive.js'
|
|
43
43
|
import { getVersionsForTemplates } from '../versions.js'
|
|
44
44
|
|
|
@@ -281,7 +281,7 @@ export async function wireFoundation({ foundationDir, libraryDir, libraryName })
|
|
|
281
281
|
/**
|
|
282
282
|
* Add a library to the workspace, or wire one that is there.
|
|
283
283
|
*/
|
|
284
|
-
export async function addLibrary(rootDir, projectName, opts
|
|
284
|
+
export async function addLibrary(rootDir, projectName, opts) {
|
|
285
285
|
const prefix = getCliPrefix()
|
|
286
286
|
if (opts.project) {
|
|
287
287
|
fail(
|
|
@@ -436,5 +436,5 @@ export async function addLibrary(rootDir, projectName, opts, pm = 'pnpm') {
|
|
|
436
436
|
)
|
|
437
437
|
}
|
|
438
438
|
log('')
|
|
439
|
-
log(`Next: ${colors.cyan}${installCmd(
|
|
439
|
+
log(`Next: ${colors.cyan}${installCmd(pmToInstall(rootDir))}${colors.reset}`)
|
|
440
440
|
}
|
package/src/commands/add.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* uniweb add extension [name] [--from <template>] [--site <name>] [--path <dir>]
|
|
11
11
|
* uniweb add library <name> [--foundation <a>,<b>] [--schemas] [--scope <@org>] [--path <dir>]
|
|
12
12
|
* uniweb add section <name> [--foundation <name>]
|
|
13
|
+
* uniweb add section <name> --library <name> [--foundation <a>,<b>]
|
|
13
14
|
* uniweb add version <name> [--in <folder>] [--label <text>] [--keep-in-search] [--dry-run] [--site <name>]
|
|
14
15
|
*/
|
|
15
16
|
|
|
@@ -39,8 +40,10 @@ import {
|
|
|
39
40
|
} from '../utils/placement.js'
|
|
40
41
|
import { registerWorkspacePackage, addRootScripts } from '../utils/config.js'
|
|
41
42
|
import { discoverFoundations, discoverSites } from '../utils/discover.js'
|
|
42
|
-
import { generateStarter, reportStarter
|
|
43
|
+
import { generateStarter, reportStarter } from './starter.js'
|
|
43
44
|
import { addLibrary } from './add-library.js'
|
|
45
|
+
import { addLibrarySection } from './add-library-section.js'
|
|
46
|
+
import { writeSection } from '../utils/section-files.js'
|
|
44
47
|
import {
|
|
45
48
|
validatePackageName,
|
|
46
49
|
getExistingPackageNames,
|
|
@@ -147,7 +150,9 @@ function parseArgs(args) {
|
|
|
147
150
|
dryRun: false,
|
|
148
151
|
// `add library` only: a `schemas/` folder for data types, and the scope they are named under.
|
|
149
152
|
schemas: false,
|
|
150
|
-
scope: null
|
|
153
|
+
scope: null,
|
|
154
|
+
// `add section` only: the library the section type goes in, which the foundations pass on.
|
|
155
|
+
library: null
|
|
151
156
|
}
|
|
152
157
|
|
|
153
158
|
// Booleans (no value) consumed up-front so the value-flag loop below
|
|
@@ -177,7 +182,8 @@ function parseArgs(args) {
|
|
|
177
182
|
'--write': 'write',
|
|
178
183
|
'--in': 'in',
|
|
179
184
|
'--label': 'label',
|
|
180
|
-
'--scope': 'scope'
|
|
185
|
+
'--scope': 'scope',
|
|
186
|
+
'--library': 'library'
|
|
181
187
|
}
|
|
182
188
|
|
|
183
189
|
/** Split `--flag=value` into [flag, value]; `--flag` into [flag, null]. */
|
|
@@ -227,6 +233,9 @@ function parseArgs(args) {
|
|
|
227
233
|
result.schemas = true
|
|
228
234
|
}
|
|
229
235
|
}
|
|
236
|
+
// `--library` with no name after it would otherwise read as no flag, and put the section in a
|
|
237
|
+
// foundation instead.
|
|
238
|
+
if (result.library === null && args.some((a) => a === '--library' || a === '--library=')) result.library = ''
|
|
230
239
|
|
|
231
240
|
return result
|
|
232
241
|
}
|
|
@@ -384,7 +393,7 @@ export async function add(rawArgs) {
|
|
|
384
393
|
await addExtension(rootDir, projectName, parsed, pm)
|
|
385
394
|
break
|
|
386
395
|
case 'library':
|
|
387
|
-
await addLibrary(rootDir, projectName, parsed
|
|
396
|
+
await addLibrary(rootDir, projectName, parsed)
|
|
388
397
|
break
|
|
389
398
|
case 'section':
|
|
390
399
|
await addSection(rootDir, parsed)
|
|
@@ -1029,7 +1038,7 @@ async function addProject(rootDir, projectName, opts, pm = 'pnpm') {
|
|
|
1029
1038
|
reportRootScripts(scriptsAdded)
|
|
1030
1039
|
log('')
|
|
1031
1040
|
log(
|
|
1032
|
-
`Next: ${colors.cyan}${installCmd(
|
|
1041
|
+
`Next: ${colors.cyan}${installCmd(pmToInstall(rootDir))} && uniweb dev ${sitePkgName}${colors.reset}`
|
|
1033
1042
|
)
|
|
1034
1043
|
}
|
|
1035
1044
|
|
|
@@ -1290,10 +1299,14 @@ async function wireExtensionToSite(rootDir, siteName, extensionFolder) {
|
|
|
1290
1299
|
}
|
|
1291
1300
|
|
|
1292
1301
|
/**
|
|
1293
|
-
* Add a section type to a foundation
|
|
1302
|
+
* Add a section type to a foundation, or with `--library`, to a library its foundations pass it on from
|
|
1294
1303
|
*/
|
|
1295
1304
|
async function addSection(rootDir, opts) {
|
|
1296
1305
|
setAddJsonMode(opts.json)
|
|
1306
|
+
if (opts.library === '') {
|
|
1307
|
+
error(`--library takes the library's folder or name: ${getCliPrefix()} add section <Name> --library libraries/ui`)
|
|
1308
|
+
process.exit(1)
|
|
1309
|
+
}
|
|
1297
1310
|
let name = opts.name
|
|
1298
1311
|
|
|
1299
1312
|
// Interactive name prompt when not provided
|
|
@@ -1332,6 +1345,13 @@ async function addSection(rootDir, opts) {
|
|
|
1332
1345
|
process.exit(1)
|
|
1333
1346
|
}
|
|
1334
1347
|
|
|
1348
|
+
// In a library: the type is the library's, and each foundation passes it on.
|
|
1349
|
+
if (opts.library) {
|
|
1350
|
+
const { sectionDir, starterResult } = await addLibrarySection(rootDir, { ...opts, name })
|
|
1351
|
+
if (opts.starter) await printStarter({ name, sectionDir, opts, scaffolded: !!starterResult })
|
|
1352
|
+
return
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1335
1355
|
// Find the foundation
|
|
1336
1356
|
const foundations = await discoverFoundations(rootDir)
|
|
1337
1357
|
let foundation
|
|
@@ -1397,17 +1417,7 @@ async function addSection(rootDir, opts) {
|
|
|
1397
1417
|
// Nothing is scaffolded and nothing is overwritten on this path.
|
|
1398
1418
|
if (existsSync(sectionDir)) {
|
|
1399
1419
|
if (opts.starter) {
|
|
1400
|
-
|
|
1401
|
-
name,
|
|
1402
|
-
sectionDir,
|
|
1403
|
-
preset: opts.preset,
|
|
1404
|
-
json: opts.json,
|
|
1405
|
-
write: opts.write,
|
|
1406
|
-
})
|
|
1407
|
-
if (!opts.json) {
|
|
1408
|
-
if (!opts.write) log('\n' + markdown.trimEnd())
|
|
1409
|
-
reportStarter(result, { write: opts.write })
|
|
1410
|
-
}
|
|
1420
|
+
await printStarter({ name, sectionDir, opts, scaffolded: false })
|
|
1411
1421
|
return
|
|
1412
1422
|
}
|
|
1413
1423
|
error(
|
|
@@ -1418,57 +1428,7 @@ async function addSection(rootDir, opts) {
|
|
|
1418
1428
|
}
|
|
1419
1429
|
|
|
1420
1430
|
// Create section directory and files
|
|
1421
|
-
await
|
|
1422
|
-
|
|
1423
|
-
const componentContent = `import { H2, P, Link, cn } from '@uniweb/kit'
|
|
1424
|
-
|
|
1425
|
-
export default function ${name}({ content, params }) {
|
|
1426
|
-
const { title, paragraphs = [], links = [] } = content || {}
|
|
1427
|
-
|
|
1428
|
-
return (
|
|
1429
|
-
<div className="max-w-4xl mx-auto px-6">
|
|
1430
|
-
{title && <H2 text={title} className="text-heading text-3xl font-bold" />}
|
|
1431
|
-
<P text={paragraphs} className="text-body mt-4" />
|
|
1432
|
-
{links.length > 0 && (
|
|
1433
|
-
<div className="mt-6 flex gap-3 flex-wrap">
|
|
1434
|
-
{links.map((link, i) => (
|
|
1435
|
-
<Link key={i} to={link.href} className={cn(
|
|
1436
|
-
'px-5 py-2.5 rounded-lg font-medium transition-colors',
|
|
1437
|
-
i === 0
|
|
1438
|
-
? 'bg-primary text-primary-foreground hover:bg-primary-hover'
|
|
1439
|
-
: 'bg-secondary text-secondary-foreground hover:bg-secondary-hover'
|
|
1440
|
-
)}>
|
|
1441
|
-
{link.label}
|
|
1442
|
-
</Link>
|
|
1443
|
-
))}
|
|
1444
|
-
</div>
|
|
1445
|
-
)}
|
|
1446
|
-
</div>
|
|
1447
|
-
)
|
|
1448
|
-
}
|
|
1449
|
-
`
|
|
1450
|
-
|
|
1451
|
-
// With `--starter`, the scaffold gets a `content:` declaration derived from
|
|
1452
|
-
// the family the name resolves to — so the three pieces agree: a declaration,
|
|
1453
|
-
// a component that reads it, and content that fills it. Without the flag the
|
|
1454
|
-
// stub declares nothing, exactly as before.
|
|
1455
|
-
let starterDeclaration = ''
|
|
1456
|
-
let starterResult = null
|
|
1457
|
-
if (opts.starter) {
|
|
1458
|
-
const preview = await generateStarter({ name, sectionDir: sectionDir })
|
|
1459
|
-
starterResult = preview.result
|
|
1460
|
-
starterDeclaration = await declarationFor(preview.result)
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
|
-
const metaContent = `export default {
|
|
1464
|
-
title: '${name}',
|
|
1465
|
-
description: '',${starterDeclaration}
|
|
1466
|
-
params: {},
|
|
1467
|
-
}
|
|
1468
|
-
`
|
|
1469
|
-
|
|
1470
|
-
await writeFile(join(sectionDir, 'index.jsx'), componentContent)
|
|
1471
|
-
await writeFile(join(sectionDir, 'meta.js'), metaContent)
|
|
1431
|
+
const starterResult = await writeSection({ name, sectionDir, starter: opts.starter })
|
|
1472
1432
|
|
|
1473
1433
|
success(`Created section '${name}' at ${foundation.path}/${relSectionPath}/`)
|
|
1474
1434
|
log(
|
|
@@ -1486,35 +1446,41 @@ export default function ${name}({ content, params }) {
|
|
|
1486
1446
|
log('')
|
|
1487
1447
|
log(`Before editing it: ${colors.cyan}${getCliPrefix()} guide foundation${colors.reset}`)
|
|
1488
1448
|
|
|
1489
|
-
if (starterResult) {
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1449
|
+
if (starterResult) await printStarter({ name, sectionDir, opts, scaffolded: true })
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
/**
|
|
1453
|
+
* Print a section type's starter content, from the `meta.js` in `sectionDir`. For a type just
|
|
1454
|
+
* scaffolded (`scaffolded`), it is generated again against the declaration just written, so what is
|
|
1455
|
+
* printed is what the section's own `meta.js` now asks for rather than the family's guess: the two
|
|
1456
|
+
* agree here, and saying it from the file keeps them so.
|
|
1457
|
+
*/
|
|
1458
|
+
async function printStarter({ name, sectionDir, opts, scaffolded }) {
|
|
1459
|
+
const { markdown, result } = await generateStarter({
|
|
1460
|
+
name,
|
|
1461
|
+
sectionDir,
|
|
1462
|
+
preset: opts.preset,
|
|
1463
|
+
json: opts.json,
|
|
1464
|
+
write: opts.write,
|
|
1465
|
+
})
|
|
1466
|
+
if (opts.json) return
|
|
1467
|
+
if (scaffolded) {
|
|
1468
|
+
log('')
|
|
1469
|
+
log(`${colors.dim}Starter content for a page section:${colors.reset}`)
|
|
1470
|
+
}
|
|
1471
|
+
if (!opts.write) log('\n' + markdown.trimEnd())
|
|
1472
|
+
reportStarter(result, { write: opts.write })
|
|
1473
|
+
if (!scaffolded) return
|
|
1474
|
+
// The stub component reads three elements. The declaration may name more, because it comes from
|
|
1475
|
+
// the family rather than from the stub: say so, rather than leave a developer wondering why half
|
|
1476
|
+
// the content they were just handed renders as nothing.
|
|
1477
|
+
const stubReads = new Set(['title', 'paragraphs', 'links'])
|
|
1478
|
+
const unread = Object.keys(result.content).filter((slot) => !stubReads.has(slot))
|
|
1479
|
+
if (unread.length) {
|
|
1480
|
+
log(
|
|
1481
|
+
` ${colors.dim}index.jsx reads title, paragraphs and links — extend it for: ${unread.join(', ')}${colors.reset}`
|
|
1482
|
+
)
|
|
1483
|
+
log('')
|
|
1518
1484
|
}
|
|
1519
1485
|
}
|
|
1520
1486
|
|
package/src/commands/i18n.js
CHANGED
|
@@ -1047,7 +1047,8 @@ async function runAudit(siteRoot, config, args) {
|
|
|
1047
1047
|
const results = []
|
|
1048
1048
|
|
|
1049
1049
|
for (const loc of localesToAudit) {
|
|
1050
|
-
|
|
1050
|
+
// A page translation for a place in a branch the site doesn't translate is that place's (`auditLocale`).
|
|
1051
|
+
const result = await auditLocale(localesPath, loc, { exclude: scope.records ? null : config.exclude })
|
|
1051
1052
|
results.push(result)
|
|
1052
1053
|
}
|
|
1053
1054
|
|
package/src/framework-index.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"generatedAt": "2026-11-
|
|
3
|
+
"generatedAt": "2026-11-11T18:04:19.533Z",
|
|
4
4
|
"packages": {
|
|
5
5
|
"@uniweb/api": {
|
|
6
6
|
"version": "1.7.0"
|
|
7
7
|
},
|
|
8
8
|
"@uniweb/build": {
|
|
9
|
-
"version": "1.
|
|
9
|
+
"version": "1.22.0"
|
|
10
10
|
},
|
|
11
11
|
"@uniweb/content-reader": {
|
|
12
|
-
"version": "1.5.
|
|
12
|
+
"version": "1.5.10"
|
|
13
13
|
},
|
|
14
14
|
"@uniweb/content-writer": {
|
|
15
|
-
"version": "1.3.
|
|
15
|
+
"version": "1.3.2"
|
|
16
16
|
},
|
|
17
17
|
"@uniweb/core": {
|
|
18
18
|
"version": "1.6.12"
|
|
19
19
|
},
|
|
20
20
|
"@uniweb/frame-bridge": {
|
|
21
|
-
"version": "1.0.
|
|
21
|
+
"version": "1.0.4"
|
|
22
22
|
},
|
|
23
23
|
"@uniweb/icons": {
|
|
24
|
-
"version": "1.0.
|
|
24
|
+
"version": "1.0.9"
|
|
25
25
|
},
|
|
26
26
|
"@uniweb/kit": {
|
|
27
27
|
"version": "1.7.20"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"version": "1.2.17"
|
|
37
37
|
},
|
|
38
38
|
"@uniweb/runtime": {
|
|
39
|
-
"version": "1.6.
|
|
39
|
+
"version": "1.6.1"
|
|
40
40
|
},
|
|
41
41
|
"@uniweb/scene": {
|
|
42
42
|
"version": "1.0.1"
|
|
@@ -48,19 +48,19 @@
|
|
|
48
48
|
"version": "1.1.2"
|
|
49
49
|
},
|
|
50
50
|
"@uniweb/semantic-parser": {
|
|
51
|
-
"version": "1.13.
|
|
51
|
+
"version": "1.13.4"
|
|
52
52
|
},
|
|
53
53
|
"@uniweb/snapshot": {
|
|
54
54
|
"version": "1.1.2"
|
|
55
55
|
},
|
|
56
56
|
"@uniweb/templates": {
|
|
57
|
-
"version": "1.2.
|
|
57
|
+
"version": "1.2.15"
|
|
58
58
|
},
|
|
59
59
|
"@uniweb/theming": {
|
|
60
60
|
"version": "1.3.2"
|
|
61
61
|
},
|
|
62
62
|
"@uniweb/unipress": {
|
|
63
|
-
"version": "1.1.
|
|
63
|
+
"version": "1.1.39"
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"templates": {
|
package/src/index.js
CHANGED
|
@@ -1791,6 +1791,10 @@ ${colors.bright}Library Options:${colors.reset}
|
|
|
1791
1791
|
|
|
1792
1792
|
${colors.bright}Section Options:${colors.reset}
|
|
1793
1793
|
--foundation <n> Foundation to add section to (prompted if multiple exist)
|
|
1794
|
+
--library <name> Put the section type in this library (its folder or package
|
|
1795
|
+
name), and have each foundation offer it with two lines
|
|
1796
|
+
that pass it on. With it, --foundation <a,b> names those
|
|
1797
|
+
foundations (default: the ones that depend on the library)
|
|
1794
1798
|
--in <folder> add version: the folder under pages/ holding the docs (. for all of pages/)
|
|
1795
1799
|
--label <text> add version: what a version switcher calls it
|
|
1796
1800
|
--keep-in-search add version: leave it open to search engines
|
|
@@ -1836,6 +1840,8 @@ ${colors.bright}Examples:${colors.reset}
|
|
|
1836
1840
|
uniweb add library ../acme-shared --foundation a # A library beside the workspace, another repo's
|
|
1837
1841
|
uniweb add section Hero # Create Hero section type
|
|
1838
1842
|
uniweb add section Hero --foundation ui # Target specific foundation
|
|
1843
|
+
uniweb add section Banner --library ui # In the library ui, offered by its foundations
|
|
1844
|
+
uniweb add section Banner --library ui --foundation c # Offered by one more foundation
|
|
1839
1845
|
uniweb add section Hero --starter # Starter content for an existing Hero
|
|
1840
1846
|
uniweb add section Pricing --starter # Scaffold Pricing + content that fills it
|
|
1841
1847
|
uniweb add section Hero --starter --preset split # Frontmatter it with the 'split' preset
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The files `uniweb add section` writes: a new section type's component and `meta.js`, in a
|
|
3
|
+
* foundation's `sections/` or a library's, and the lines a foundation passes a library's type on with.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { mkdir, writeFile } from 'node:fs/promises'
|
|
7
|
+
import { join } from 'node:path'
|
|
8
|
+
import { declarationFor, generateStarter } from '../commands/starter.js'
|
|
9
|
+
|
|
10
|
+
/** A new section type's component, which reads a title, paragraphs and links. */
|
|
11
|
+
export function sectionComponent(name) {
|
|
12
|
+
return `import { H2, P, Link, cn } from '@uniweb/kit'
|
|
13
|
+
|
|
14
|
+
export default function ${name}({ content, params }) {
|
|
15
|
+
const { title, paragraphs = [], links = [] } = content || {}
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div className="max-w-4xl mx-auto px-6">
|
|
19
|
+
{title && <H2 text={title} className="text-heading text-3xl font-bold" />}
|
|
20
|
+
<P text={paragraphs} className="text-body mt-4" />
|
|
21
|
+
{links.length > 0 && (
|
|
22
|
+
<div className="mt-6 flex gap-3 flex-wrap">
|
|
23
|
+
{links.map((link, i) => (
|
|
24
|
+
<Link key={i} to={link.href} className={cn(
|
|
25
|
+
'px-5 py-2.5 rounded-lg font-medium transition-colors',
|
|
26
|
+
i === 0
|
|
27
|
+
? 'bg-primary text-primary-foreground hover:bg-primary-hover'
|
|
28
|
+
: 'bg-secondary text-secondary-foreground hover:bg-secondary-hover'
|
|
29
|
+
)}>
|
|
30
|
+
{link.label}
|
|
31
|
+
</Link>
|
|
32
|
+
))}
|
|
33
|
+
</div>
|
|
34
|
+
)}
|
|
35
|
+
</div>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
`
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A new section type's `meta.js`, with the `content:` declaration `--starter` derived, if any. */
|
|
42
|
+
export function sectionMeta(name, declaration = '') {
|
|
43
|
+
return `export default {
|
|
44
|
+
title: '${name}',
|
|
45
|
+
description: '',${declaration}
|
|
46
|
+
params: {},
|
|
47
|
+
}
|
|
48
|
+
`
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Write a new section type's two files into `sectionDir`. With `starter`, its `meta.js` gets a
|
|
53
|
+
* `content:` declaration from the family the name resolves to, so the declaration, the component
|
|
54
|
+
* and the starter content agree; without it, the stub declares nothing.
|
|
55
|
+
*
|
|
56
|
+
* @param {{ name: string, sectionDir: string, starter?: boolean }} o
|
|
57
|
+
* @returns {Promise<object|null>} the starter result the declaration came from, with `starter`
|
|
58
|
+
*/
|
|
59
|
+
export async function writeSection({ name, sectionDir, starter = false }) {
|
|
60
|
+
await mkdir(sectionDir, { recursive: true })
|
|
61
|
+
let declaration = ''
|
|
62
|
+
let result = null
|
|
63
|
+
if (starter) {
|
|
64
|
+
const preview = await generateStarter({ name, sectionDir })
|
|
65
|
+
result = preview.result
|
|
66
|
+
declaration = await declarationFor(preview.result)
|
|
67
|
+
}
|
|
68
|
+
await writeFile(join(sectionDir, 'index.jsx'), sectionComponent(name))
|
|
69
|
+
await writeFile(join(sectionDir, 'meta.js'), sectionMeta(name, declaration))
|
|
70
|
+
return result
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The import a foundation's file of a section type passes a library's on with:
|
|
75
|
+
* `<library>/sections/<Name>/<file>`.
|
|
76
|
+
*/
|
|
77
|
+
export function passOnSpecifier(libraryName, name, file) {
|
|
78
|
+
return `${libraryName}/sections/${name}/${file}`
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The two files a foundation offers a library's section type with, as it is: each passes on the
|
|
83
|
+
* library's file of that name. A foundation that offers the type differently keeps its own
|
|
84
|
+
* `meta.js` and passes on `index.jsx` alone.
|
|
85
|
+
*
|
|
86
|
+
* @returns {{ 'index.jsx': string, 'meta.js': string }}
|
|
87
|
+
*/
|
|
88
|
+
export function passOnFiles(libraryName, name) {
|
|
89
|
+
return {
|
|
90
|
+
'index.jsx':
|
|
91
|
+
`// The library ${libraryName}'s ${name}, offered by this foundation as it is: edit it there, in sections/${name}/.\n` +
|
|
92
|
+
`export { default } from '${passOnSpecifier(libraryName, name, 'index.jsx')}'\n`,
|
|
93
|
+
'meta.js':
|
|
94
|
+
`// Its title, params and presets are ${libraryName}'s too. To offer it differently here, write this foundation's own instead.\n` +
|
|
95
|
+
`export { default } from '${passOnSpecifier(libraryName, name, 'meta.js')}'\n`
|
|
96
|
+
}
|
|
97
|
+
}
|