@unbase-app/cli 0.2.0 → 0.4.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/lib/uninstall.mjs CHANGED
@@ -1,9 +1,11 @@
1
1
  // ============================================================================
2
2
  // unbase uninstall — init backwards. Refuses while unbase.pages.json holds a
3
- // draft (without the kit a draft is built and goes live). Then removes the
3
+ // draft (without the kit a draft is built and goes live), or a redirect
4
+ // (without the package an old address stops working). Then removes the
4
5
  // packages, what the framework's module names (on Astro: their lines in
5
6
  // astro.config, comment-modus.json, unbase.pages.json,
6
- // src/content/.schemas/) and the pointer line init may have written, and
7
+ // src/content/.schemas/), the analytics collector init allowed in the CSP of
8
+ // vercel.json and public/_headers, and the pointer line init may have written, and
7
9
  // compares every built page's HTML before and after: the packages may change
8
10
  // how a site is edited and built, never how it renders.
9
11
  // ============================================================================
@@ -13,6 +15,7 @@ import { join } from "node:path";
13
15
  import { buildSite, tailOf } from "./build.mjs";
14
16
  import { comparePages } from "./compare.mjs";
15
17
  import { CouldNotRun, FAILED, PASSED } from "./errors.mjs";
18
+ import { planCsp } from "./analytics.mjs";
16
19
  import { POINTER_BEFORE, POINTER_FILES, POINTER_LINE } from "./init.mjs";
17
20
  import { dropDependencies, lockfileOf, packageManagerOf, removePackages } from "./pm.mjs";
18
21
  import { core } from "./readers.mjs";
@@ -36,6 +39,19 @@ export async function uninstall(flags, io) {
36
39
  message: `${core.PAGE_FILE} holds ${drafts.length} draft page(s). Without the kit they would be built and go live: publish or delete each in Unbase first.`,
37
40
  };
38
41
  }
42
+ // Redirects next: the package applies them, so without it a renamed or deleted page's old address breaks.
43
+ const redirects = pageFile.redirects ?? {};
44
+ if (Object.keys(redirects).length) {
45
+ return {
46
+ command: "uninstall",
47
+ ok: false,
48
+ exitCode: FAILED,
49
+ site: site.root,
50
+ refused: "redirects",
51
+ redirects,
52
+ message: `${core.PAGE_FILE} sends ${Object.keys(redirects).length} old address(es) on, which only the package applies. Put them in the site's own redirects (its framework's config, or the host's), take them out of ${core.PAGE_FILE}, and run uninstall again:`,
53
+ };
54
+ }
39
55
 
40
56
  if (!flags.yes) {
41
57
  if (!io.interactive) throw new CouldNotRun("choice_missing", "Pass --yes to remove Unbase from this site: there is no terminal to ask in.");
@@ -43,7 +59,9 @@ export async function uninstall(flags, io) {
43
59
  }
44
60
 
45
61
  // Plan everything before changing anything: a config that cannot be edited stops here.
46
- const plan = site.framework.uninstall(site);
62
+ const own = site.framework.uninstall(site);
63
+ // The collector init allowed in the site's CSP goes with the package.
64
+ const plan = { ...own, files: [...own.files, ...planCsp(site, { add: false }).files] };
47
65
  const deps = depsOf(site.pkg);
48
66
  const packages = plan.packages.filter((n) => deps[n]);
49
67
  const pm = packages.length && !flags["no-install"] ? packageManagerOf(site) : null;
package/lib/versions.mjs CHANGED
@@ -11,16 +11,19 @@ const own = JSON.parse(readFileSync(new URL("../package.json", import.meta.url),
11
11
  export const SELF = { name: own.name, version: own.version, dev: true };
12
12
 
13
13
  /**
14
- * Unbase in an Astro site, one package (K5): comment mode and the draft-pages kit below, at the
15
- * versions its own package.json pins (kit/astro; a test holds the two equal).
14
+ * Unbase in an Astro site, one package (K5): comment mode, the draft-pages kit and the analytics
15
+ * beacon below, at the versions its own package.json pins (kit/astro; a test holds the two equal).
16
16
  */
17
- export const ASTRO = { name: "@unbase-app/astro", version: "0.1.0", dev: false };
17
+ export const ASTRO = { name: "@unbase-app/astro", version: "0.3.0", dev: false };
18
18
 
19
19
  /** Comments on the live site (`?comment`), and the content schemas, page list and markers it writes. Inside ASTRO. */
20
20
  export const COMMENT_MODUS = { name: "@jens4m/comment-modus", version: "1.9.0", dev: false };
21
21
 
22
- /** Keeps draft pages out of production builds. Inside ASTRO. */
23
- export const PAGES = { name: "@unbase-app/pages", version: "0.3.0", dev: false };
22
+ /** Keeps draft pages out of production builds, and applies the redirects a moved page leaves. Inside ASTRO. */
23
+ export const PAGES = { name: "@unbase-app/pages", version: "0.4.0", dev: false };
24
+
25
+ /** Unbase's analytics beacon (kit/analytics). Inside ASTRO, VITE and NEXT; never installed on its own. */
26
+ export const ANALYTICS = { name: "@unbase-app/analytics", version: "0.1.0", dev: false };
24
27
 
25
28
  /**
26
29
  * The names before K5 (03-11): a site installed then has the pair (comment-modus and the kit) and
@@ -29,10 +32,17 @@ export const PAGES = { name: "@unbase-app/pages", version: "0.3.0", dev: false }
29
32
  export const BEFORE = { pages: "@jens4m/unbase-pages", cli: "@jens4m/unbase" };
30
33
 
31
34
  /** Vite + React Router: the draft-pages kit and comment mode's loader, in one Vite plugin (kit/vite). A build tool, so a devDependency, beside vite. */
32
- export const VITE = { name: "@unbase-app/vite", version: "0.1.0", dev: true };
35
+ export const VITE = { name: "@unbase-app/vite", version: "0.3.0", dev: true };
36
+
37
+ /** Next.js: draft pages kept out of production builds, comments on the live site and analytics (`withUnbase`). */
38
+ export const NEXT = { name: "@unbase-app/next", version: "0.3.0", dev: false };
33
39
 
34
- /** Next.js: draft pages kept out of production builds, and comments on the live site (`withUnbase`). */
35
- export const NEXT = { name: "@unbase-app/next", version: "0.1.0", dev: false };
40
+ /**
41
+ * The first version of each framework's package that brings the analytics beacon: doctor's
42
+ * "new enough" (Unbase's read_install reads the same, _shared/framework-packages.ts ANALYTICS_CALLS;
43
+ * a test holds the two equal).
44
+ */
45
+ export const ANALYTICS_FROM = { [ASTRO.name]: "0.2.0", [VITE.name]: "0.2.0", [NEXT.name]: "0.2.0" };
36
46
 
37
47
  /** Where comment mode's layer is served from: only fetched by a visitor who opens `?comment` (ADR-0012's one exception). */
38
48
  export const LAYER_URL = "https://layer.unbase.app/v1/loader.js";
@@ -115,16 +115,18 @@ function pluginsArray(prop) {
115
115
  return null;
116
116
  }
117
117
 
118
- /** unbase()'s literal options: `comments: false`, a literal `project`; null when they cannot be read. */
118
+ /** unbase()'s literal options: `comments: false`, `analytics: false`, a literal `project`; null when they cannot be read. */
119
119
  function optionsOf(call) {
120
- if (!call.arguments.length) return { comments: true, project: null, only: null };
120
+ if (!call.arguments.length) return { comments: true, analytics: true, project: null, only: null };
121
121
  const o = unwrap(call.arguments[0]);
122
122
  if (o?.type !== "ObjectExpression" || o.properties.some((p) => p.type !== "ObjectProperty" || p.computed)) return null;
123
123
  const prop = (name) => o.properties.find((p) => keyName(p) === name);
124
124
  const c = prop("comments") ? unwrap(prop("comments").value) : null;
125
+ const a = prop("analytics") ? unwrap(prop("analytics").value) : null;
125
126
  const p = prop("project") ? unwrap(prop("project").value) : null;
126
127
  return {
127
128
  comments: !(c?.type === "BooleanLiteral" && c.value === false),
129
+ analytics: !(a?.type === "BooleanLiteral" && a.value === false),
128
130
  project: p?.type === "StringLiteral" ? p.value : null,
129
131
  /** The one property there is, when there is one: init turns `{ comments: false }` into nothing. */
130
132
  only: o.properties.length === 1 ? keyName(o.properties[0]) : null,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unbase-app/cli",
3
- "version": "0.2.0",
4
- "description": "Adds Unbase to an Astro, Vite + React or Next.js site, checks it, and takes it out again: unbase init, unbase doctor, unbase uninstall.",
3
+ "version": "0.4.0",
4
+ "description": "Adds Unbase to an Astro, Vite + React or Next.js site, checks it, takes it out again, and renames, duplicates and deletes its pages: unbase init, doctor, uninstall and page.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "bin": {
@@ -23,7 +23,8 @@
23
23
  "cli",
24
24
  "cms",
25
25
  "comments",
26
- "drafts"
26
+ "drafts",
27
+ "analytics"
27
28
  ],
28
29
  "publishConfig": {
29
30
  "access": "public"