@unbase-app/cli 0.4.1 → 0.6.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/AGENTS.md +3 -1
- package/README.md +20 -11
- package/agents/astro.md +3 -2
- package/agents/vite-react.md +4 -2
- package/bin/unbase.mjs +11 -5
- package/lib/config-edit.mjs +6 -4
- package/lib/frameworks/astro.mjs +47 -25
- package/lib/page.mjs +30 -10
- package/lib/pm.mjs +17 -6
- package/lib/readers.mjs +1304 -435
- package/lib/versions.mjs +17 -10
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -40,7 +40,9 @@ file, `unbase.pages.json`).
|
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
42
|
npx @unbase-app/cli page list # what each page can do here, and why not
|
|
43
|
-
npx @unbase-app/cli page
|
|
43
|
+
npx @unbase-app/cli page create /prijzen --name "Prijzen" # a new page in the site's layout
|
|
44
|
+
npx @unbase-app/cli page rename /funding --name "Financiering" # its name only; the address stays
|
|
45
|
+
npx @unbase-app/cli page move /funding /financiering [--not-live]
|
|
44
46
|
npx @unbase-app/cli page duplicate /pricing [/pricing-2027] [--name "Pricing 2027"]
|
|
45
47
|
npx @unbase-app/cli page delete /old-offer [--redirect /pricing | --not-found] [--not-live]
|
|
46
48
|
```
|
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ the framework's own file, [`agents/astro.md`](./agents/astro.md) or
|
|
|
44
44
|
|
|
45
45
|
| Flag | |
|
|
46
46
|
|---|---|
|
|
47
|
-
| `--comments` / `--no-comments` | Comments on the live site, with `?comment` (`@
|
|
47
|
+
| `--comments` / `--no-comments` | Comments on the live site, with `?comment` (`@unbase-app/layer`, inside `@unbase-app/astro`). Default: in, or as the site has it when Unbase is in it already |
|
|
48
48
|
| `--project <id or slug>` | Link comment mode and analytics to an Unbase project now (see *Linking*) |
|
|
49
49
|
| `--pointer[=AGENTS.md\|CLAUDE.md]` / `--no-pointer` | One line in the site's `AGENTS.md` (or `CLAUDE.md`) pointing its agent at this package's `AGENTS.md`. Default: no |
|
|
50
50
|
| `--no-install` | Write `package.json` only; install yourself |
|
|
@@ -57,7 +57,7 @@ versions:
|
|
|
57
57
|
|
|
58
58
|
| Package | Version | |
|
|
59
59
|
|---|---|---|
|
|
60
|
-
| `@unbase-app/astro` | 0.
|
|
60
|
+
| `@unbase-app/astro` | 0.5.0 | Unbase in an Astro site, one integration: comment mode (`@unbase-app/layer` 2.0.0: comments on the live site; it writes the content schemas Unbase reads, and its page list and content map reach a host adapter's copy of the output too), the draft-pages kit (`@unbase-app/pages` 0.5.0: draft pages kept out of production builds, and the redirects a moved page leaves applied) and the analytics beacon (`@unbase-app/analytics` 0.1.0) |
|
|
61
61
|
| `@unbase-app/cli` | this one | devDependency: `AGENTS.md` and `doctor`, pinned |
|
|
62
62
|
|
|
63
63
|
In `astro.config`, found and changed through its syntax tree, never by text substitution:
|
|
@@ -158,9 +158,12 @@ moves it across, and it is how Unbase's Update does it:
|
|
|
158
158
|
- `unbase()` takes `commentModus()`'s place with its options as they are (a site's own `project`,
|
|
159
159
|
`titles`, `language`…); the `commentModusConfig.project ? … : null` init wrote around it goes,
|
|
160
160
|
since `unbase()` waits for the project itself. `unbasePages()` and its import go.
|
|
161
|
-
-
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
- Comment mode's own package goes too, under either name (`@unbase-app/layer`, or
|
|
162
|
+
`@jens4m/comment-modus` before 2.0), unless the site uses it for itself: a name its config still
|
|
163
|
+
imports from it, the package named in its code or a workflow, or the layer's CLI in a script.
|
|
164
|
+
The layer then stays, moved to the version `@unbase-app/astro` brings, so there is one;
|
|
165
|
+
`@jens4m/comment-modus` stays as it is, as the layer has no release under that name. Its CLI alone
|
|
166
|
+
keeps neither: the layer answers to `comment-modus` too.
|
|
164
167
|
- The pointer line moves to `node_modules/@unbase-app/cli/AGENTS.md`.
|
|
165
168
|
- With `--yes`, a site keeps its choice of comments. A second run changes nothing.
|
|
166
169
|
|
|
@@ -213,13 +216,16 @@ The route files, the settings file and the layout's reads stay: they are the sit
|
|
|
213
216
|
|
|
214
217
|
## `unbase page`
|
|
215
218
|
|
|
216
|
-
|
|
217
|
-
core, bundled here), so the files change exactly as they do when Unbase's
|
|
218
|
-
same files always give the same changes. It writes them in the working tree
|
|
219
|
-
review them with `git diff` and commit them yourself.
|
|
219
|
+
Makes, renames, moves, duplicates and deletes a page by the kit's own rule (`planPage` in
|
|
220
|
+
`@unbase-app/pages`'s core, bundled here), so the files change exactly as they do when Unbase's
|
|
221
|
+
editor does it: the same files always give the same changes. It writes them in the working tree
|
|
222
|
+
and commits nothing; review them with `git diff` and commit them yourself. A page's name and its
|
|
223
|
+
address are apart: `rename` changes the name, `move` the address.
|
|
220
224
|
|
|
221
225
|
```bash
|
|
222
|
-
npx @unbase-app/cli page
|
|
226
|
+
npx @unbase-app/cli page create /prijzen --name Prijzen
|
|
227
|
+
npx @unbase-app/cli page rename /funding --name Financiering
|
|
228
|
+
npx @unbase-app/cli page move /funding /financiering
|
|
223
229
|
npx @unbase-app/cli page duplicate /pricing /pricing-2027
|
|
224
230
|
npx @unbase-app/cli page delete /old-offer --redirect /pricing
|
|
225
231
|
npx @unbase-app/cli page list
|
|
@@ -227,7 +233,10 @@ npx @unbase-app/cli page list
|
|
|
227
233
|
|
|
228
234
|
| Command | |
|
|
229
235
|
|---|---|
|
|
230
|
-
| `page
|
|
236
|
+
| `page create <address> [--name <name>]` | A new page in the site's layout, with a heading of its name, made the way the site makes its pages (a file on Astro and Next.js, a route and its file on React Router, a file from the home page's shell on plain HTML); a draft where the kit is installed. The name defaults to the address's last part in words |
|
|
237
|
+
| `page rename <path> --name <name>` | Its name in Unbase only (`unbase.pages.json`); the address stays |
|
|
238
|
+
| `page move <from> <to> [--not-live]` | A new address: the page's files move (on Next.js its folder, on React Router the route's `path`, on plain HTML the file), every link to it or below it in code and content follows (code samples in text are left alone), its route file's `pad` too, and the pages under it come along |
|
|
239
|
+
| `page rename <from> <to> [--name <name>] [--not-live]` | Both at once, as before `move` existed |
|
|
231
240
|
| `page duplicate <path> [<to>] [--name <name>]` | A copy, by default at the first free `<path>-copy`, with its own copy of what only the page owns (its modules and content); a draft where the kit is installed. Named "… (copy)" when the original has a name |
|
|
232
241
|
| `page delete <path> [--redirect <to> \| --not-found] [--not-live]` | Its file and what only it owns; shared parts stay. The links to it are listed, not changed. Visitors to the old address go to the page above it, `--redirect`'s page, or with `--not-found` nowhere |
|
|
233
242
|
| `page list [--not-live]` | Per page: whether it can be renamed, duplicated and deleted here, and if not, why |
|
package/agents/astro.md
CHANGED
|
@@ -20,7 +20,7 @@ first written.
|
|
|
20
20
|
changes nothing, and a package that is older than the version init pins is moved up to it. It adds:
|
|
21
21
|
|
|
22
22
|
- `@unbase-app/astro`, and one entry in `integrations`, `unbase({ … })`. It brings comment mode
|
|
23
|
-
(`@
|
|
23
|
+
(`@unbase-app/layer`: comments on the live site with `?comment`; it also writes the content
|
|
24
24
|
schemas, step 4) and the draft-pages kit (`@unbase-app/pages`), and adds both after every other
|
|
25
25
|
integration itself. Its options are comment mode's own. `--no-comments` writes
|
|
26
26
|
`unbase({ comments: false })`, which leaves comment mode out, and with it page and site settings.
|
|
@@ -32,7 +32,8 @@ changes nothing, and a package that is older than the version init pins is moved
|
|
|
32
32
|
A site installed before 03-11 has the pair instead (`@jens4m/comment-modus` and
|
|
33
33
|
`@jens4m/unbase-pages`, `commentModus()` and `unbasePages()`) and the CLI as `@jens4m/unbase`. init
|
|
34
34
|
moves it across: `unbase()` takes `commentModus()`'s place with its options as they are, and the old
|
|
35
|
-
packages go. A site that imports something of comment
|
|
35
|
+
packages go. A site that imports something of comment mode for itself, or names its package in its
|
|
36
|
+
code or a workflow, keeps it.
|
|
36
37
|
|
|
37
38
|
If init says it cannot edit `astro.config` safely, make the same change by hand: import `unbase`
|
|
38
39
|
from `@unbase-app/astro` and `commentModusConfig` from `./comment-modus.json`, and add
|
package/agents/vite-react.md
CHANGED
|
@@ -76,8 +76,10 @@ in a file that imports `react-router-dom` (or `react-router`): a literal `path`,
|
|
|
76
76
|
`element`, that component imported (or `lazy(() => import(…))`) from its own file. A page that
|
|
77
77
|
cannot be a draft is fine (a dynamic route such as `/blog/:slug`, a page another file imports, a
|
|
78
78
|
route with child routes); doctor lists them. Routes written as objects
|
|
79
|
-
(`createBrowserRouter([{ path, element }])`)
|
|
80
|
-
|
|
79
|
+
(`createBrowserRouter([{ path, element }])`, `useRoutes([...])`, in the router's file or a module it
|
|
80
|
+
imports) are read the same way: a literal `path`, `element: <X />` or `Component: X` from its own file,
|
|
81
|
+
or `lazy: () => import(…)`. A draft on one needs `@unbase-app/vite` 0.4.0 or later; a live one cannot
|
|
82
|
+
move with a redirect yet. Do not rewrite a router for Unbase.
|
|
81
83
|
|
|
82
84
|
## 4. Comments on the site
|
|
83
85
|
|
package/bin/unbase.mjs
CHANGED
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
// [--no-install] [--tarballs <dir>] [--yes] [--json] [--dir <path>]
|
|
7
7
|
// unbase doctor [--no-build] [--json] [--dir <path>]
|
|
8
8
|
// unbase uninstall [--yes] [--no-build] [--no-install] [--json] [--dir <path>]
|
|
9
|
-
// unbase page
|
|
9
|
+
// unbase page create <address> [--name <name>]
|
|
10
|
+
// rename <path> --name <name>
|
|
11
|
+
// move <from> <to> [--not-live]
|
|
12
|
+
// rename <from> <to> [--name <name>] [--not-live]
|
|
10
13
|
// duplicate <path> [<to>] [--name <name>]
|
|
11
14
|
// delete <path> [--redirect <to> | --not-found] [--not-live]
|
|
12
15
|
// list [--not-live]
|
|
@@ -46,13 +49,16 @@ const USAGE = `unbase ${SELF.version}: Unbase in a site (${FRAMEWORKS.map((f) =>
|
|
|
46
49
|
--yes do it without asking
|
|
47
50
|
--no-build skip the comparison
|
|
48
51
|
--no-install change package.json only
|
|
49
|
-
unbase page
|
|
50
|
-
editor makes; written in the working tree, never committed
|
|
51
|
-
|
|
52
|
+
unbase page Make, rename, move, duplicate or delete a page by the kit's rule, the changes
|
|
53
|
+
Unbase's editor makes; written in the working tree, never committed
|
|
54
|
+
create <address> a new page in the site's layout; a draft where the site has drafts
|
|
55
|
+
rename <path> --name <name> its name in Unbase only; the address stays
|
|
56
|
+
move <from> <to> a new address (the links and its route file follow)
|
|
57
|
+
rename <from> <to> both at once, as before move existed
|
|
52
58
|
duplicate <path> [<to>] a copy, by default at <path>-copy; a draft where the site has drafts
|
|
53
59
|
delete <path> its file and what only it owns; links to it are listed
|
|
54
60
|
list what each page can do here, and why not
|
|
55
|
-
--name <name> the page's name in Unbase (rename, duplicate)
|
|
61
|
+
--name <name> the page's name in Unbase (create, rename, duplicate)
|
|
56
62
|
--redirect <to> | --not-found
|
|
57
63
|
delete: where visitors to the old address go (default: the page
|
|
58
64
|
above it)
|
package/lib/config-edit.mjs
CHANGED
|
@@ -20,18 +20,20 @@
|
|
|
20
20
|
|
|
21
21
|
import { parse } from "@babel/parser";
|
|
22
22
|
import { CouldNotRun } from "./errors.mjs";
|
|
23
|
-
import { ASTRO, BEFORE,
|
|
23
|
+
import { ASTRO, BEFORE, COMMENT_NAMES, LAYER, LAYER_URL, PAGES, SELF } from "./versions.mjs";
|
|
24
24
|
|
|
25
25
|
/** The modules init imports, and the entries it adds or moves. */
|
|
26
26
|
export const SOURCES = {
|
|
27
27
|
unbase: ASTRO.name,
|
|
28
|
-
comments:
|
|
28
|
+
comments: LAYER.name,
|
|
29
29
|
pages: `${PAGES.name}/astro`,
|
|
30
30
|
link: "./comment-modus.json",
|
|
31
31
|
sitemap: "@astrojs/sitemap",
|
|
32
32
|
};
|
|
33
33
|
/** The kit's integration, under its name now and before K5, as a site may import it. */
|
|
34
34
|
const PAGES_ALSO = new Set([`${PAGES.name}/astro`, PAGES.name, `${BEFORE.pages}/astro`, BEFORE.pages]);
|
|
35
|
+
/** Comment mode, under its name now and before 2.0. */
|
|
36
|
+
const COMMENTS_ALSO = new Set(COMMENT_NAMES);
|
|
35
37
|
const NAMES = { unbase: "unbase", comments: "commentModus", pages: "unbasePages", link: "commentModusConfig" };
|
|
36
38
|
/** The line init writes above unbase({ … }), with comments and without. */
|
|
37
39
|
export const UNBASE_LINE = "// Unbase: comments with ?comment once comment-modus.json names the project, and drafts kept off Live.";
|
|
@@ -98,7 +100,7 @@ function importsOf(ast) {
|
|
|
98
100
|
for (const n of ast.program.body) {
|
|
99
101
|
if (n.type !== "ImportDeclaration") continue;
|
|
100
102
|
const src = n.source.value;
|
|
101
|
-
const kind = src === SOURCES.unbase ? "unbase" : src
|
|
103
|
+
const kind = src === SOURCES.unbase ? "unbase" : COMMENTS_ALSO.has(src) ? "comments" : PAGES_ALSO.has(src) ? "pages" : src === SOURCES.link ? "link" : src === SOURCES.sitemap ? "sitemap" : null;
|
|
102
104
|
if (!kind) continue;
|
|
103
105
|
found.nodes.push({ kind, node: n });
|
|
104
106
|
for (const s of n.specifiers) {
|
|
@@ -307,7 +309,7 @@ function reindent(text, indent) {
|
|
|
307
309
|
|
|
308
310
|
/**
|
|
309
311
|
* Splices that take a package's imports out: a declaration whose names all go is removed with its
|
|
310
|
-
* line; one that keeps a name the site uses for itself (`import commentModus, {
|
|
312
|
+
* line; one that keeps a name the site uses for itself (`import commentModus, { keyFromPath }`)
|
|
311
313
|
* loses only the entry's name. Returns the splices and the first declaration removed whole, where
|
|
312
314
|
* the new import can stand.
|
|
313
315
|
*/
|
package/lib/frameworks/astro.mjs
CHANGED
|
@@ -20,7 +20,7 @@ import { CouldNotRun } from "../errors.mjs";
|
|
|
20
20
|
import { check, featureState } from "../feature.mjs";
|
|
21
21
|
import { core, readSettings, registryFiles, registryOf } from "../readers.mjs";
|
|
22
22
|
import { depsOf, installedVersion, uncommitted } from "../site.mjs";
|
|
23
|
-
import { ASTRO, BEFORE,
|
|
23
|
+
import { ASTRO, BEFORE, COMMENT_NAMES, compareVersions, LAYER, MARKERS_PREVIEW, PAGES, SELF, UNLISTED_BUILD_FAILURE, versionIn } from "../versions.mjs";
|
|
24
24
|
|
|
25
25
|
/** The file with the steps init leaves, in this package. */
|
|
26
26
|
const AGENTS = "agents/astro.md";
|
|
@@ -141,30 +141,44 @@ function analyticsOption(site) {
|
|
|
141
141
|
|
|
142
142
|
// ── The move (K5) ──────────────────────────────────────────────────────────
|
|
143
143
|
|
|
144
|
-
/** Files that may name comment
|
|
144
|
+
/** Files that may name comment mode's package for the site's own use: code, scripts and CI, not docs or lockfiles. */
|
|
145
145
|
const OWN_USE = /\.(astro|ts|tsx|js|jsx|mjs|cjs|mts|cts|yml|yaml)$/;
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
* What init takes out of a site from before K5, once the one package is in: the kit and the CLI
|
|
149
|
-
* under their old names, the kit under its own name (unbase() brings it), and comment
|
|
150
|
-
* the site still uses it for itself (a name its config imports,
|
|
151
|
-
*
|
|
149
|
+
* under their old names, the kit under its own name (unbase() brings it), and comment mode under
|
|
150
|
+
* either name unless the site still uses it for itself (a name its config imports, the package
|
|
151
|
+
* named in its code or CI, the layer's CLI in a script). The layer a site keeps is moved to the
|
|
152
|
+
* version the one package brings, so there is one. comment-modus under its name before 2.0 is left
|
|
153
|
+
* as the site has it when the site uses it for itself (the layer has no release under that name),
|
|
154
|
+
* and goes when only its CLI is used: the layer answers to `comment-modus` too.
|
|
152
155
|
* `planned`: init's plan for the config, which tells what the config still imports.
|
|
153
156
|
*/
|
|
154
157
|
function planReplaced(site, planned) {
|
|
155
158
|
const deps = depsOf(site.pkg);
|
|
156
159
|
const remove = [BEFORE.pages, BEFORE.cli, PAGES.name].filter((n) => deps[n] !== undefined);
|
|
157
160
|
const keep = [];
|
|
158
|
-
|
|
161
|
+
const listed = COMMENT_NAMES.filter((n) => deps[n] !== undefined);
|
|
162
|
+
if (listed.length) {
|
|
159
163
|
const config = planned.find((f) => f.file === site.configFile)?.text ?? site.text(site.configFile) ?? "";
|
|
160
|
-
|
|
164
|
+
/** The comment mode packages the planned config still imports from. */
|
|
165
|
+
const imports = new Set();
|
|
161
166
|
try {
|
|
162
|
-
|
|
167
|
+
for (const { kind, node } of inspectConfig(config, site.configFile).imports.nodes) if (kind === "comments") imports.add(node.source.value);
|
|
163
168
|
} catch {}
|
|
164
|
-
const scripts = Object.values(site.pkg.scripts ?? {}).some((c) => /\
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
169
|
+
const scripts = Object.values(site.pkg.scripts ?? {}).some((c) => /\b(comment-modus|unbase-layer)\b/.test(String(c)));
|
|
170
|
+
for (const name of listed) {
|
|
171
|
+
const ownUse = imports.has(name) || site.appPaths.some((p) => p !== site.configFile && OWN_USE.test(p) && !p.startsWith("node_modules/") && (site.text(p) ?? "").includes(name));
|
|
172
|
+
if (name === LAYER.name) {
|
|
173
|
+
if (ownUse || scripts) keep.push(LAYER);
|
|
174
|
+
else remove.push(name);
|
|
175
|
+
} else if (!ownUse) remove.push(name);
|
|
176
|
+
else {
|
|
177
|
+
// Kept at the version it has, so init's report names it.
|
|
178
|
+
const have = installedVersion(site, name) ?? versionIn(deps[name]);
|
|
179
|
+
if (have) keep.push({ name, version: have, dev: false });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
168
182
|
}
|
|
169
183
|
return { remove, keep, by: ASTRO.name };
|
|
170
184
|
}
|
|
@@ -172,7 +186,7 @@ function planReplaced(site, planned) {
|
|
|
172
186
|
/** What of Unbase the site has now, for init's defaults: null without any of it; else whether comment mode is set up. */
|
|
173
187
|
function currentOf(site) {
|
|
174
188
|
const deps = depsOf(site.pkg);
|
|
175
|
-
if (![ASTRO.name,
|
|
189
|
+
if (![ASTRO.name, ...COMMENT_NAMES, PAGES.name, BEFORE.pages].some((n) => deps[n] !== undefined) || !site.configFile) return null;
|
|
176
190
|
try {
|
|
177
191
|
return { comments: inspectConfig(site.text(site.configFile), site.configFile).has.commentMode };
|
|
178
192
|
} catch {
|
|
@@ -184,7 +198,7 @@ function currentOf(site) {
|
|
|
184
198
|
function planUninstall(site) {
|
|
185
199
|
const config = site.configFile ? removeFromConfig(site.text(site.configFile), site.configFile) : { code: null, changes: [] };
|
|
186
200
|
return {
|
|
187
|
-
packages: [ASTRO.name,
|
|
201
|
+
packages: [ASTRO.name, ...COMMENT_NAMES, PAGES.name, BEFORE.pages, SELF.name, BEFORE.cli],
|
|
188
202
|
files: config.changes.length ? [{ file: site.configFile, action: "changed", changes: config.changes, text: config.code }] : [],
|
|
189
203
|
remove: [LINK_FILE, core.PAGE_FILE, SCHEMAS],
|
|
190
204
|
};
|
|
@@ -251,6 +265,14 @@ async function doctorFeatures(site, { build }) {
|
|
|
251
265
|
const known = build && !build.ok ? knownFailure(site, deps, build.output) : null;
|
|
252
266
|
/** The one package (K5): comment mode and the kit come inside it, in node_modules without being listed. */
|
|
253
267
|
const one = deps[ASTRO.name] !== undefined;
|
|
268
|
+
/**
|
|
269
|
+
* Comment mode's package as the site has it: inside the one package, the layer when it is there
|
|
270
|
+
* (@unbase-app/astro 0.4.0 on) and else comment-modus; otherwise the name package.json lists, or
|
|
271
|
+
* the one in node_modules.
|
|
272
|
+
*/
|
|
273
|
+
const commentName = one
|
|
274
|
+
? (COMMENT_NAMES.find((n) => installedVersion(site, n)) ?? LAYER.name)
|
|
275
|
+
: (COMMENT_NAMES.find((n) => deps[n] !== undefined) ?? COMMENT_NAMES.find((n) => installedVersion(site, n)) ?? LAYER.name);
|
|
254
276
|
/** A package in node_modules (or in the config) that package.json does not list: Unbase reads package.json, and the build may not find it. */
|
|
255
277
|
const unlisted = (p, usedInConfig) =>
|
|
256
278
|
!one && !deps[p.name] && (installedVersion(site, p.name) || usedInConfig)
|
|
@@ -266,7 +288,7 @@ async function doctorFeatures(site, { build }) {
|
|
|
266
288
|
const checks = [check("astro", "ok", `Astro ${installedVersion(site, "astro") ?? detection.framework.version ?? ""}, which Unbase reads with its Astro adapter: texts are edited where they are written, nothing installed.`)];
|
|
267
289
|
if (!build) checks.push(check("build", "skipped", "Not built (--no-build)."));
|
|
268
290
|
else if (built) checks.push(check("build", "ok", `A production build works (${build.html.size} pages).`));
|
|
269
|
-
else if (known) checks.push(check("build", "missing", `The production build fails: ${known}`, { missing: `${
|
|
291
|
+
else if (known) checks.push(check("build", "missing", `The production build fails: ${known}`, { missing: `${UNLISTED_BUILD_FAILURE.package} listed in package.json`, file: "package.json", step: STEPS.install, detail: tailOf(build.output, 6) }));
|
|
270
292
|
else checks.push(check("build", "missing", "The production build fails, so Unbase cannot start or check the site.", { missing: "a site that builds", file: site.configFile, detail: tailOf(build.output) }));
|
|
271
293
|
const names = detection.settings.map((s) => s.name);
|
|
272
294
|
if (names.length) checks.push(check("settings", "info", `The code reads ${names.length} setting(s) (${names.slice(0, 6).join(", ")}${names.length > 6 ? ", …" : ""}). If the site needs them to start, give them development values in Unbase.`));
|
|
@@ -294,13 +316,13 @@ async function doctorFeatures(site, { build }) {
|
|
|
294
316
|
? `No data-c markers in the production build (${setting}): they are in the dev server and previews only, so a pin on the live site is named after its section.`
|
|
295
317
|
: `No data-c markers in the production build (${setting}).`,
|
|
296
318
|
);
|
|
297
|
-
const have = commentsInstalled ? installedVersion(site,
|
|
298
|
-
const tooOld = when === "preview" && have && compareVersions(have, MARKERS_PREVIEW.since) < 0;
|
|
319
|
+
const have = commentsInstalled ? installedVersion(site, commentName) : null;
|
|
320
|
+
const tooOld = when === "preview" && commentName === MARKERS_PREVIEW.package && have && compareVersions(have, MARKERS_PREVIEW.since) < 0;
|
|
299
321
|
const found = `${htmlWithMarkers.length} built page(s) carry data-c markers`;
|
|
300
322
|
const where = `(e.g. ${htmlWithMarkers[0]})`;
|
|
301
323
|
if (tooOld)
|
|
302
|
-
return check("markers", "missing", `${found} ${where}: ${site.configFile} says ${setting}, which ${
|
|
303
|
-
missing: `${
|
|
324
|
+
return check("markers", "missing", `${found} ${where}: ${site.configFile} says ${setting}, which ${commentName} ${have} does not know; ${MARKERS_PREVIEW.since} keeps them out of production builds, and so does ${LAYER.name}.`, {
|
|
325
|
+
missing: `${LAYER.name}, or ${MARKERS_PREVIEW.package} ${MARKERS_PREVIEW.since} or later`,
|
|
304
326
|
file: "package.json",
|
|
305
327
|
step: STEPS.install,
|
|
306
328
|
});
|
|
@@ -314,7 +336,7 @@ async function doctorFeatures(site, { build }) {
|
|
|
314
336
|
? check("markers", "ok", `${htmlWithMarkers.length} of ${build.html.size} built pages carry comment mode's data-c markers: a pin's title and source file come from them.`)
|
|
315
337
|
: check("markers", "info", "No data-c markers in the build: comment mode marks the components in src/components, and found none on these pages.");
|
|
316
338
|
};
|
|
317
|
-
const notListed = unlisted(
|
|
339
|
+
const notListed = unlisted({ name: commentName }, !!config?.has.comments);
|
|
318
340
|
/** Where comment mode is set up: unbase() (K5), or commentModus() of its own. */
|
|
319
341
|
const call = config?.has.unbase && config.unbaseComments !== false ? "unbase()" : "commentModus()";
|
|
320
342
|
if (!commentsInstalled && notListed) {
|
|
@@ -327,7 +349,7 @@ async function doctorFeatures(site, { build }) {
|
|
|
327
349
|
"info",
|
|
328
350
|
one && config?.unbaseComments === false
|
|
329
351
|
? `Left out: unbase({ comments: false }); \`unbase init --comments\` turns it on. Comments on the canvas in Unbase work without it.`
|
|
330
|
-
: `Not in the code: \`unbase init --comments\` adds it (${ASTRO.name}, with ${
|
|
352
|
+
: `Not in the code: \`unbase init --comments\` adds it (${ASTRO.name}, with ${LAYER.name}). Comments on the canvas in Unbase work without it.`,
|
|
331
353
|
),
|
|
332
354
|
);
|
|
333
355
|
checks.push(markersCheck(false));
|
|
@@ -338,8 +360,8 @@ async function doctorFeatures(site, { build }) {
|
|
|
338
360
|
"package",
|
|
339
361
|
"ok",
|
|
340
362
|
one
|
|
341
|
-
? `${ASTRO.name} ${installedVersion(site, ASTRO.name) ?? deps[ASTRO.name]} is a dependency, with ${[
|
|
342
|
-
: `${
|
|
363
|
+
? `${ASTRO.name} ${installedVersion(site, ASTRO.name) ?? deps[ASTRO.name]} is a dependency, with ${[commentName, installedVersion(site, commentName)].filter(Boolean).join(" ")} in it.`
|
|
364
|
+
: `${commentName} ${installedVersion(site, commentName) ?? deps[commentName]} is a dependency.`,
|
|
343
365
|
),
|
|
344
366
|
);
|
|
345
367
|
if (configError) checks.push(check("config", "missing", configError, { file: site.configFile, step: STEPS.install }));
|
|
@@ -397,7 +419,7 @@ async function doctorFeatures(site, { build }) {
|
|
|
397
419
|
}),
|
|
398
420
|
);
|
|
399
421
|
// A site from before K5 works as it is; the one package is where Update goes.
|
|
400
|
-
const before = [
|
|
422
|
+
const before = [...COMMENT_NAMES, BEFORE.pages].filter((n) => deps[n] !== undefined);
|
|
401
423
|
if (!one && before.includes(BEFORE.pages))
|
|
402
424
|
checks.push(check("moved", "info", `${before.join(" and ")} ${before.length > 1 ? "are" : "is"} one package since 03-11, ${ASTRO.name}: \`npx ${SELF.name} init\` moves the site across (one dependency, one line in ${site.configFile ?? "astro.config"}).`));
|
|
403
425
|
if (config && config.has.pages && !config.orderOk)
|
|
@@ -501,7 +523,7 @@ async function doctorFeatures(site, { build }) {
|
|
|
501
523
|
configured: !!config?.has.unbase,
|
|
502
524
|
option: config ? config.unbaseAnalytics : null,
|
|
503
525
|
project: readLink(site) ?? config?.unbaseProject ?? null,
|
|
504
|
-
before: !one && [
|
|
526
|
+
before: !one && [...COMMENT_NAMES, BEFORE.pages].some((n) => deps[n] !== undefined),
|
|
505
527
|
step: STEPS.analytics,
|
|
506
528
|
install: STEPS.install,
|
|
507
529
|
config: site.configFile ?? "astro.config.mjs",
|
package/lib/page.mjs
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
// ============================================================================
|
|
2
|
-
// unbase page — rename, duplicate or delete a page, or list what
|
|
3
|
-
// to each, by the kit's own rule (core.planPage,
|
|
4
|
-
// the same files give
|
|
5
|
-
// them in the working
|
|
2
|
+
// unbase page — make, rename, move, duplicate or delete a page, or list what
|
|
3
|
+
// can be done to each, by the kit's own rule (core.planPage,
|
|
4
|
+
// docs/plan-page-actions.md, docs/plan-page-engine.md): the same files give
|
|
5
|
+
// the same changes as Unbase's editor makes. It writes them in the working
|
|
6
|
+
// tree and commits nothing. A page's name and its address are apart: rename
|
|
7
|
+
// changes the name, move the address (Jens, 17-11).
|
|
6
8
|
//
|
|
7
|
-
// unbase page
|
|
9
|
+
// unbase page create <address> [--name <name>]
|
|
10
|
+
// unbase page rename <path> --name <name>
|
|
11
|
+
// unbase page move <from> <to> [--not-live]
|
|
12
|
+
// unbase page rename <from> <to> [--name <name>] [--not-live] (both at once, as before)
|
|
8
13
|
// unbase page duplicate <path> [<to>] [--name <name>]
|
|
9
14
|
// unbase page delete <path> [--redirect <to> | --not-found] [--not-live]
|
|
10
15
|
// unbase page list [--not-live]
|
|
@@ -22,11 +27,13 @@ import { CouldNotRun, FAILED, PASSED } from "./errors.mjs";
|
|
|
22
27
|
import { core } from "./readers.mjs";
|
|
23
28
|
import { openSite } from "./site.mjs";
|
|
24
29
|
|
|
25
|
-
export const ACTIONS = ["rename", "duplicate", "delete", "list"];
|
|
30
|
+
export const ACTIONS = ["create", "rename", "move", "duplicate", "delete", "list"];
|
|
26
31
|
|
|
27
32
|
/** Per action: how many addresses it takes (at least, at most), and which of the page flags. */
|
|
28
33
|
const SHAPE = {
|
|
29
|
-
|
|
34
|
+
create: { args: [1, 1], usage: "create <address> [--name <name>]", flags: ["name"] },
|
|
35
|
+
rename: { args: [1, 2], usage: "rename <path> --name <name> (or rename <from> <to>)", flags: ["name", "not-live"] },
|
|
36
|
+
move: { args: [2, 2], usage: "move <from> <to>", flags: ["not-live"] },
|
|
30
37
|
duplicate: { args: [1, 2], usage: "duplicate <path> [<to>]", flags: ["name"] },
|
|
31
38
|
delete: { args: [1, 1], usage: "delete <path>", flags: ["redirect", "not-found", "not-live"] },
|
|
32
39
|
list: { args: [0, 0], usage: "list", flags: ["not-live"] },
|
|
@@ -46,7 +53,9 @@ const TEXT = /\.(astro|tsx|jsx|ts|js|mjs|cjs|mts|cts|vue|svelte|md|mdx|markdown|
|
|
|
46
53
|
*/
|
|
47
54
|
export const REASONS = {
|
|
48
55
|
invalid: (d) => `${core.PAGE_FILE} is not valid${d ? ` (${d})` : ""}: fix it first`,
|
|
49
|
-
framework: () => "the kit has no page actions for this framework; it has them for Astro, Next.js
|
|
56
|
+
framework: () => "the kit has no page actions for this framework; it has them for Astro, Next.js, Vite + React Router and plain HTML",
|
|
57
|
+
routes_unread: (d) => `the kit cannot read how this site makes its pages${d ? ` (${d})` : ""}: change it by hand, or with Unbase's Operator`,
|
|
58
|
+
kit_old: (d, framework) => `this site's ${PACKAGE[String(framework)] ?? "Unbase package"} is too old for this${d ? ` (${d})` : ""}: update it (unbase init)`,
|
|
50
59
|
missing: () => "the code makes no page at this address",
|
|
51
60
|
template: (d) => `the page is made by a dynamic route${d ? ` (${d})` : ""}: change it where its data is`,
|
|
52
61
|
unparsed: (d) => `the kit cannot trace this page's route to its file${d ? ` (${d})` : ""}: change it by hand, or with Unbase's Operator`,
|
|
@@ -159,8 +168,19 @@ export async function page(flags, io, args = []) {
|
|
|
159
168
|
const at = core.normalisePath(addresses[0]);
|
|
160
169
|
/** @type {Record<string, unknown>} */
|
|
161
170
|
let request;
|
|
162
|
-
if (action === "
|
|
163
|
-
|
|
171
|
+
if (action === "create") {
|
|
172
|
+
// The name is the one given, else the address's last part as words ("/over-ons" → "Over ons").
|
|
173
|
+
const last = at.split("/").filter(Boolean).at(-1) ?? "";
|
|
174
|
+
const words = decodeURIComponent(last).replace(/\.html?$/i, "").replace(/[-_]+/g, " ").trim();
|
|
175
|
+
const name = flags.name !== undefined ? String(flags.name) : words.charAt(0).toUpperCase() + words.slice(1);
|
|
176
|
+
if (!name) throw new CouldNotRun("usage", "unbase page create: give the page a --name.");
|
|
177
|
+
request = { action, path: at, name, drafts: core.kitInstalled({ framework, text: files.text }) };
|
|
178
|
+
} else if (action === "move") request = { action: "rename", path: at, to: addresses[1], live };
|
|
179
|
+
else if (action === "rename") {
|
|
180
|
+
if (!addresses[1] && flags.name === undefined) throw new CouldNotRun("usage", "unbase page rename: give the new --name (a new address is unbase page move).");
|
|
181
|
+
// A name only changes the name; a second address moves the page too, as before.
|
|
182
|
+
request = { action, path: at, ...(addresses[1] ? { to: addresses[1] } : {}), live, ...(flags.name !== undefined ? { name: String(flags.name) } : {}) };
|
|
183
|
+
} else if (action === "duplicate") {
|
|
164
184
|
// Named after the original, as Unbase's menu names a copy, when the original has a name.
|
|
165
185
|
const name = flags.name !== undefined ? String(flags.name) : pageFile.ok && pageFile.pages[at]?.name ? `${pageFile.pages[at].name} (copy)` : undefined;
|
|
166
186
|
request = { action, path: at, ...(addresses[1] ? { to: addresses[1] } : {}), ...(name ? { name } : {}), drafts: core.kitInstalled({ framework, text: files.text }) };
|
package/lib/pm.mjs
CHANGED
|
@@ -39,17 +39,28 @@ function run(cmd, args, cwd, quiet) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* The site is the root of a pnpm workspace (a pnpm-workspace.yaml beside its package.json, as on
|
|
44
|
+
* gs-meppel and rsc): pnpm 9 refuses `add` there without -w (ERR_PNPM_ADDING_TO_ROOT); pnpm 10 and
|
|
45
|
+
* later take it either way.
|
|
46
|
+
*/
|
|
47
|
+
export const pnpmWorkspaceRoot = (site) => site.root === site.repoRoot && existsSync(join(site.root, "pnpm-workspace.yaml"));
|
|
48
|
+
|
|
49
|
+
/** The package manager's arguments that add `list` to the site, exact, as dependencies or dev dependencies. */
|
|
50
|
+
export function addArgs(site, pm, dev, list) {
|
|
51
|
+
return {
|
|
52
|
+
npm: ["install", "--save-exact", ...(dev ? ["--save-dev"] : []), "--no-audit", "--no-fund", ...list],
|
|
53
|
+
pnpm: ["add", ...(pnpmWorkspaceRoot(site) ? ["-w"] : []), "--save-exact", ...(dev ? ["--save-dev"] : []), ...list],
|
|
54
|
+
yarn: ["add", "--exact", ...(dev ? ["--dev"] : []), ...list],
|
|
55
|
+
}[pm];
|
|
56
|
+
}
|
|
57
|
+
|
|
42
58
|
/** Adds (or moves) packages to exact versions: `specs` are { name, version, dev, tarball? }. */
|
|
43
59
|
export function addPackages(site, pm, specs, { quiet }) {
|
|
44
60
|
for (const dev of [false, true]) {
|
|
45
61
|
const list = specs.filter((s) => s.dev === dev).map((s) => s.tarball ?? `${s.name}@${s.version}`);
|
|
46
62
|
if (!list.length) continue;
|
|
47
|
-
|
|
48
|
-
npm: ["install", "--save-exact", ...(dev ? ["--save-dev"] : []), "--no-audit", "--no-fund", ...list],
|
|
49
|
-
pnpm: ["add", "--save-exact", ...(dev ? ["--save-dev"] : []), ...list],
|
|
50
|
-
yarn: ["add", "--exact", ...(dev ? ["--dev"] : []), ...list],
|
|
51
|
-
}[pm];
|
|
52
|
-
run(pm, args, site.root, quiet);
|
|
63
|
+
run(pm, addArgs(site, pm, dev, list), site.root, quiet);
|
|
53
64
|
}
|
|
54
65
|
}
|
|
55
66
|
|