@unbase-app/cli 0.5.0 → 0.6.1

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 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 rename /funding /financiering [--name "Financiering"] [--not-live]
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
@@ -57,7 +57,7 @@ versions:
57
57
 
58
58
  | Package | Version | |
59
59
  |---|---|---|
60
- | `@unbase-app/astro` | 0.4.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), the draft-pages kit (`@unbase-app/pages` 0.4.1: 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) |
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:
@@ -216,13 +216,16 @@ The route files, the settings file and the layout's reads stay: they are the sit
216
216
 
217
217
  ## `unbase page`
218
218
 
219
- Renames, duplicates and deletes a page by the kit's own rule (`planPage` in `@unbase-app/pages`'s
220
- core, bundled here), so the files change exactly as they do when Unbase's editor does it: the
221
- same files always give the same changes. It writes them in the working tree and commits nothing;
222
- 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.
223
224
 
224
225
  ```bash
225
- npx @unbase-app/cli page rename /funding /financiering --name Financiering
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
226
229
  npx @unbase-app/cli page duplicate /pricing /pricing-2027
227
230
  npx @unbase-app/cli page delete /old-offer --redirect /pricing
228
231
  npx @unbase-app/cli page list
@@ -230,7 +233,10 @@ npx @unbase-app/cli page list
230
233
 
231
234
  | Command | |
232
235
  |---|---|
233
- | `page rename <from> <to> [--name <name>] [--not-live]` | A new address: the page's files move (on Next.js its folder, on React Router the route's `path`), every quoted link to it or below it in code and content follows, its route file's `pad` too, and the pages under it come along. `--name` sets its name in Unbase (`<to>` the same as `<from>`: only the name) |
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 |
234
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 |
235
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 |
236
242
  | `page list [--not-live]` | Per page: whether it can be renamed, duplicated and deleted here, and if not, why |
@@ -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 }])`) are not read: their pages have no draft and no place in
80
- comment mode's page tree. Do not rewrite a router for Unbase.
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 rename <from> <to> [--name <name>] [--not-live]
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 Rename, duplicate or delete a page by the kit's rule, the changes Unbase's
50
- editor makes; written in the working tree, never committed
51
- rename <from> <to> a new address (the links and its route file follow)
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/page.mjs CHANGED
@@ -1,10 +1,15 @@
1
1
  // ============================================================================
2
- // unbase page — rename, duplicate or delete a page, or list what can be done
3
- // to each, by the kit's own rule (core.planPage, docs/plan-page-actions.md):
4
- // the same files give the same changes as Unbase's editor makes. It writes
5
- // them in the working tree and commits nothing.
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 rename <from> <to> [--name <name>] [--not-live]
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
- rename: { args: [2, 2], usage: "rename <from> <to>", flags: ["name", "not-live"] },
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 and Vite + React Router",
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 === "rename") request = { action, path: at, to: addresses[1], live, ...(flags.name !== undefined ? { name: String(flags.name) } : {}) };
163
- else if (action === "duplicate") {
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
- const args = {
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