uniweb 1.32.0 → 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 +33 -36
- package/package.json +7 -7
- package/partials/agents.md +5 -4
- package/partials/guides/foundation.md +1 -1
- package/partials/guides/i18n.md +1 -1
- package/partials/guides/ship.md +16 -2
- package/partials/guides/start.md +1 -0
- package/partials/start.md +9 -2
- package/src/backend/blueprint-reach.js +5 -2
- 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/commands/update.js +5 -4
- package/src/framework-index.json +11 -11
- package/src/index.js +6 -0
- package/src/utils/lockfile-uniweb.js +18 -6
- package/src/utils/section-files.js +97 -0
- package/templates/workspace/README.md.hbs +59 -48
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/commands/update.js
CHANGED
|
@@ -171,10 +171,10 @@ export function printStaleCliNotice({
|
|
|
171
171
|
return true
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
/** `pnpm update <14 @uniweb packages
|
|
174
|
+
/** `pnpm dedupe` or `npm update <14 @uniweb packages>`: the lift's command, short enough to read in a log. */
|
|
175
175
|
function liftCommandShort(pm, count) {
|
|
176
176
|
const names = `<${count} @uniweb package${count === 1 ? '' : 's'}>`
|
|
177
|
-
return pm === 'pnpm' ?
|
|
177
|
+
return pm === 'pnpm' ? 'pnpm dedupe' : `npm update ${names}`
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
/** The workspace's package.json files as they are now: the root's and each workspace package's. */
|
|
@@ -225,8 +225,9 @@ async function liftUniwebPackages(workspaceDir, pm) {
|
|
|
225
225
|
return
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
//
|
|
229
|
-
// command aligned them, and install again, which keeps the newer version: it meets the
|
|
228
|
+
// A package manager may write a newer version into a range a package.json declares. Put the ranges
|
|
229
|
+
// back as this command aligned them, and install again, which keeps the newer version: it meets the
|
|
230
|
+
// range. (`pnpm dedupe` writes none.)
|
|
230
231
|
const rewritten = manifests.filter(({ path, text }) => readFileSync(path, 'utf8') !== text)
|
|
231
232
|
if (rewritten.length) {
|
|
232
233
|
for (const { path, text } of rewritten) writeFileSync(path, text)
|
package/src/framework-index.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
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
|
-
"version": "1.7.
|
|
27
|
+
"version": "1.7.20"
|
|
28
28
|
},
|
|
29
29
|
"@uniweb/loom": {
|
|
30
30
|
"version": "1.1.3"
|
|
@@ -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
|
|
@@ -8,11 +8,22 @@
|
|
|
8
8
|
* got it at once. Measured 2026-11-10, twice: semantic-parser 1.13.3 stayed 1.13.2, because core
|
|
9
9
|
* 1.6.12's `~1.13.2` is met by the locked 1.13.2, and runtime 1.5.7 stayed 1.5.6 behind the peer pnpm
|
|
10
10
|
* had installed for a root by itself. Lifted, an existing project's @uniweb packages resolve as a
|
|
11
|
-
* new project's would
|
|
11
|
+
* new project's would.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* ⭐ WITH PNPM IT IS `pnpm dedupe`: it drops each older version the lockfile holds where a newer one
|
|
14
|
+
* its range allows is installed, which is the case `update` leaves (its install brings the new version
|
|
15
|
+
* through the packages it aligned, and keeps the old one beside it), and it leaves every other
|
|
16
|
+
* resolution as it was. ⛔ Until 2026-11-11 (uniweb 1.32.0) it was `pnpm update <names> -r`, which
|
|
17
|
+
* resolves every dependency of every workspace package again: a local foundation or library a
|
|
18
|
+
* project takes as `file:`, whose package.json declares a peer its dependent doesn't have, came back
|
|
19
|
+
* as an installed copy instead of a link, so `uniweb dev` imported the copy and never saw an edit
|
|
20
|
+
* (the build says the foundation "resolves to two different directories"). Measured that day on six
|
|
21
|
+
* studio projects and on a library four packages of one workspace take. In those projects `dedupe`
|
|
22
|
+
* moved @uniweb versions only, but it may drop an older copy of any package the same way.
|
|
23
|
+
*
|
|
24
|
+
* ⛔ A package manager may also write a newer version into a range a package.json declares (pnpm's
|
|
25
|
+
* `update` did: `~1.20.9` became `~1.20.10`). The caller puts those files back as `update` aligned
|
|
26
|
+
* them and installs again, which keeps the newer version, since it meets the range.
|
|
16
27
|
*
|
|
17
28
|
* yarn is left as it is: classic yarn and berry spell this differently (`yarn upgrade`, `yarn up -R`).
|
|
18
29
|
*/
|
|
@@ -82,7 +93,8 @@ function sorted(found) {
|
|
|
82
93
|
|
|
83
94
|
/**
|
|
84
95
|
* The command that moves each named package, wherever the workspace holds it, to the newest version
|
|
85
|
-
* its range allows. Never `--latest`: a range is the project's promise.
|
|
96
|
+
* its range allows. Never `--latest`: a range is the project's promise. With pnpm it names none:
|
|
97
|
+
* `dedupe` reads the lockfile whole (the header says why it is not `update -r`).
|
|
86
98
|
*
|
|
87
99
|
* @param {'pnpm'|'npm'} pm
|
|
88
100
|
* @param {string[]} names
|
|
@@ -90,7 +102,7 @@ function sorted(found) {
|
|
|
90
102
|
*/
|
|
91
103
|
export function liftCommand(pm, names) {
|
|
92
104
|
if (!names.length) return null
|
|
93
|
-
if (pm === 'pnpm') return
|
|
105
|
+
if (pm === 'pnpm') return 'pnpm dedupe'
|
|
94
106
|
if (pm === 'npm') return `npm update ${names.join(' ')}`
|
|
95
107
|
return null
|
|
96
108
|
}
|
|
@@ -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
|
+
}
|