@kidecms/wordpress 0.1.0 → 0.2.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 CHANGED
@@ -1,9 +1,9 @@
1
1
  # @kidecms/wordpress
2
2
 
3
3
  WordPress → Kide CMS importer. Scout a MySQL dump, describe the target with `defineMapping`, then
4
- `kide import plan → apply → verify → check-live`. The playbook is `MIGRATING.md` in a Kide project.
4
+ `kide-wp plan → apply → verify → check-live`. The playbook is `MIGRATING.md` in a Kide project.
5
5
 
6
6
  ```bash
7
7
  pnpm add -D @kidecms/wordpress
8
- pnpm exec kide import scout wordpress.sql.gz
8
+ pnpm exec kide-wp scout wordpress.sql.gz
9
9
  ```
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ // The importer ships as TypeScript; tsx loads it.
3
+ import { register } from "tsx/esm/api";
4
+
5
+ register();
6
+ await import("../src/cli.ts");
package/package.json CHANGED
@@ -1,33 +1,37 @@
1
1
  {
2
2
  "name": "@kidecms/wordpress",
3
- "version": "0.1.0",
4
- "description": "WordPress → Kide CMS importer: scout a MySQL dump, map it with defineMapping, then plan → apply → verify → check-live.",
3
+ "version": "0.2.0",
4
+ "description": "WordPress → Kide CMS importer: scout a MySQL dump, map it with defineMapping, then kide-wp plan → apply → verify → check-live.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/mhernesniemi/kide-cms.git",
10
+ "directory": "packages/wordpress"
11
+ },
12
+ "bin": {
13
+ "kide-wp": "./bin/kide-wp.mjs"
14
+ },
7
15
  "exports": {
8
- ".": "./src/index.ts",
9
- "./cli": "./src/cli.ts"
16
+ ".": "./src/index.ts"
10
17
  },
11
18
  "files": [
19
+ "bin",
12
20
  "src",
13
21
  "!src/__tests__"
14
22
  ],
15
23
  "dependencies": {
16
24
  "@wordpress/autop": "5.1.0",
17
25
  "@wordpress/block-serialization-default-parser": "6.1.0",
18
- "@wordpress/shortcode": "5.1.0"
26
+ "@wordpress/shortcode": "5.1.0",
27
+ "tsx": "^4.23.15"
19
28
  },
20
29
  "peerDependencies": {
21
30
  "@kidecms/core": ">=0.41.0",
22
31
  "better-sqlite3": "^12.0.0 || ^13.0.0"
23
32
  },
24
33
  "devDependencies": {
25
- "@kidecms/core": "0.41.0"
26
- },
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/mhernesniemi/kide-cms.git",
30
- "directory": "packages/wordpress"
34
+ "@kidecms/core": "0.42.0"
31
35
  },
32
36
  "scripts": {
33
37
  "check": "tsc --noEmit -p .",
package/src/apply.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `kide import apply`: write the stored plan incrementally. Unchanged documents
2
+ * `kide-wp apply`: write the stored plan incrementally. Unchanged documents
3
3
  * (same hash, still present) are skipped, media is uploaded once in parallel and
4
4
  * remembered, writes are batched in transactions with a savepoint per document,
5
5
  * and documents the importer created earlier but the plan no longer contains are
@@ -107,7 +107,7 @@ export const applyImport = async (
107
107
  ): Promise<ApplyReport> => {
108
108
  const started = Date.now();
109
109
  const plan = loadPlan(staging);
110
- if (!plan) throw new Error("No plan yet — run `kide import plan` first.");
110
+ if (!plan) throw new Error("No plan yet — run `kide-wp plan` first.");
111
111
  if (plan.blocking.length && !options.force)
112
112
  throw new Error(
113
113
  `The plan is blocked (${plan.blocking.length} problem(s), see .kide/import/ledger.md). Fix them or pass --force.`,
package/src/cli.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * Mapping-driven content import (WordPress for now).
3
3
  *
4
- * kide import scout <dump.sql[.gz]> [--uploads <wp-content/uploads dir>] [--media-base <url>] [--site-url <url>] [--prefix wp_]
5
- * kide import sample <type> [--id <n>] [--n 2] [--full]
6
- * kide import plan [--only <type,type>] [--show <id|key>] [--min-recall 0.95]
7
- * kide import apply [--all] [--force] [--no-prune] [--concurrency 12]
8
- * kide import verify [--min-recall 0.95]
9
- * kide import check-live [--base <url>] [--min-score 0.9] [--concurrency 6] [--limit N] [--refresh]
4
+ * kide-wp scout <dump.sql[.gz]> [--uploads <wp-content/uploads dir>] [--media-base <url>] [--site-url <url>] [--prefix wp_]
5
+ * kide-wp sample <type> [--id <n>] [--n 2] [--full]
6
+ * kide-wp plan [--only <type,type>] [--show <id|key>] [--min-recall 0.95]
7
+ * kide-wp apply [--all] [--force] [--no-prune] [--concurrency 12]
8
+ * kide-wp verify [--min-recall 0.95]
9
+ * kide-wp check-live [--base <url>] [--min-score 0.9] [--concurrency 6] [--limit N] [--refresh]
10
10
  *
11
11
  * Mappings live in migration/*.map.ts. Outputs go to .kide/import/.
12
12
  */
@@ -27,7 +27,7 @@ import { loadProjectConfig, loadProjectRuntime } from "@kidecms/core/internals/p
27
27
  // Per-document audit lines would bury the report on a real site.
28
28
  process.env.CMS_LOG_LEVEL ??= "warn";
29
29
 
30
- const USAGE = `Usage: kide import <command> (playbook: MIGRATING.md)
30
+ const USAGE = `Usage: kide-wp <command> (playbook: MIGRATING.md)
31
31
 
32
32
  scout <dump.sql[.gz]> [--uploads <dir>] [--site-url <url>] [--media-base <url>] [--prefix wp_]
33
33
  sample <type> [--id <n>] [--n 2] [--full] staged records of a source type
@@ -52,7 +52,7 @@ const option = (name: string) => {
52
52
  const positional = args.filter((a, i) => !a.startsWith("--") && !args[i - 1]?.startsWith("--"));
53
53
  const out = (file: string) => path.relative(process.cwd(), path.join(importDir(), file));
54
54
  const fail = (message: string): never => {
55
- console.error(`[kide import] ${message}`);
55
+ console.error(`[kide-wp] ${message}`);
56
56
  process.exit(1);
57
57
  };
58
58
 
@@ -70,7 +70,7 @@ const shorten = (value: unknown, full: boolean): unknown => {
70
70
  try {
71
71
  switch (command) {
72
72
  case "scout": {
73
- const dump = positional[0] ?? fail("usage: kide import scout <dump.sql[.gz]> [--uploads <dir>]");
73
+ const dump = positional[0] ?? fail("usage: kide-wp scout <dump.sql[.gz]> [--uploads <dir>]");
74
74
  const started = Date.now();
75
75
  let uploads = option("uploads") ? path.resolve(option("uploads")!) : undefined;
76
76
  // A Bedrock checkout has an empty uploads folder (just .gitkeep): download from the site instead.
@@ -78,7 +78,7 @@ try {
78
78
  uploads &&
79
79
  !readdirSync(uploads, { recursive: true }).some((f) => !String(f).split("/").pop()!.startsWith("."))
80
80
  ) {
81
- console.log(`[kide import] ${uploads} holds no files — media will be downloaded from the site on apply.`);
81
+ console.log(`[kide-wp] ${uploads} holds no files — media will be downloaded from the site on apply.`);
82
82
  uploads = undefined;
83
83
  }
84
84
  const summary = await scoutWordPress(staging, path.resolve(dump), {
@@ -95,16 +95,16 @@ try {
95
95
  writeFileSync(path.join(importDir(), "profile.md"), renderProfile(meta, profile, loadMedia(staging)));
96
96
  writeFileSync(path.join(importDir(), "profile.json"), JSON.stringify({ meta, types: profile }, null, 2));
97
97
  console.log(
98
- `[kide import] Staged ${summary.records} records + ${summary.media} media from ${summary.siteUrl || dump} (prefix ${summary.prefix}) in ${Date.now() - started}ms.`,
98
+ `[kide-wp] Staged ${summary.records} records + ${summary.media} media from ${summary.siteUrl || dump} (prefix ${summary.prefix}) in ${Date.now() - started}ms.`,
99
99
  );
100
100
  for (const [type, n] of Object.entries(summary.types).sort((a, b) => b[1] - a[1]))
101
101
  console.log(` ${type.padEnd(28)} ${n}`);
102
- console.log(`Read ${out("profile.md")}, then write migration/<type>.map.ts and run \`kide import plan\`.`);
102
+ console.log(`Read ${out("profile.md")}, then write migration/<type>.map.ts and run \`kide-wp plan\`.`);
103
103
  break;
104
104
  }
105
105
 
106
106
  case "sample": {
107
- const type = positional[0] ?? fail("usage: kide import sample <type> [--id <n>] [--n 2] [--full]");
107
+ const type = positional[0] ?? fail("usage: kide-wp sample <type> [--id <n>] [--n 2] [--full]");
108
108
  const id = option("id");
109
109
  const n = Number(option("n") ?? 2);
110
110
  const list = loadRecords(staging).filter((r) => r.type === type && (!id || String(r.id) === id));
@@ -137,7 +137,7 @@ try {
137
137
  const issues = l.issues.filter((i) => i.kind !== "warning").length;
138
138
  return ` ${l.source.padEnd(24)} → ${String(l.collection).padEnd(16)} ${String(l.docs).padStart(5)} docs · ${open} unaccounted · ${issues} issues · recall min ${(l.recall.min * 100).toFixed(1)}%`;
139
139
  });
140
- console.log(`[kide import] Planned ${plan.docs.length} documents in ${plan.durationMs}ms.`);
140
+ console.log(`[kide-wp] Planned ${plan.docs.length} documents in ${plan.durationMs}ms.`);
141
141
  console.log(totals.join("\n"));
142
142
  if (plan.blocking.length) {
143
143
  console.log(`\nBLOCKED (${plan.blocking.length}) — details in ${out("ledger.md")}:`);
@@ -159,7 +159,7 @@ try {
159
159
  concurrency: option("concurrency") ? Number(option("concurrency")) : undefined,
160
160
  });
161
161
  console.log(
162
- `[kide import] ${r.created} created · ${r.updated} updated · ${r.unchanged} unchanged · ${r.deleted} deleted · media ${r.media.uploaded} uploaded, ${r.media.reused} reused · ${r.durationMs}ms`,
162
+ `[kide-wp] ${r.created} created · ${r.updated} updated · ${r.unchanged} unchanged · ${r.deleted} deleted · media ${r.media.uploaded} uploaded, ${r.media.reused} reused · ${r.durationMs}ms`,
163
163
  );
164
164
  if (r.media.missing.length)
165
165
  console.log(` ${r.media.missing.length} file(s) missing at the source (4xx), their references dropped:`);
@@ -167,7 +167,7 @@ try {
167
167
  for (const f of r.media.failed.slice(0, 20)) console.log(` media failed: ${f.key} — ${f.message}`);
168
168
  for (const f of r.failed.slice(0, 20)) console.log(` failed: ${f.docId} — ${f.message}`);
169
169
  if (r.failed.length || r.media.failed.length) process.exitCode = 1;
170
- else console.log("Run `kide import verify` to reconcile the CMS against the plan.");
170
+ else console.log("Run `kide-wp verify` to reconcile the CMS against the plan.");
171
171
  break;
172
172
  }
173
173
 
@@ -182,7 +182,7 @@ try {
182
182
  path.join(importDir(), "verify.md"),
183
183
  `# Verify\n\n${r.ok}/${r.checked} documents match the plan.\n\n${lines.join("\n")}\n`,
184
184
  );
185
- console.log(`[kide import] ${r.ok}/${r.checked} documents match the plan.`);
185
+ console.log(`[kide-wp] ${r.ok}/${r.checked} documents match the plan.`);
186
186
  for (const l of lines.slice(0, 30)) console.log(` ${l}`);
187
187
  if (r.problems.length) process.exitCode = 1;
188
188
  break;
@@ -203,7 +203,7 @@ try {
203
203
  const below = ok.filter((p) => score(p) < minScore);
204
204
  const mean = ok.length ? ok.reduce((a, p) => a + score(p), 0) / ok.length : 1;
205
205
  console.log(
206
- `[kide import] ${r.pages.length} live pages in ${Date.now() - started}ms · mean ${(mean * 100).toFixed(1)}% · ${below.length} below ${(minScore * 100).toFixed(0)}% · ${ok.filter((p) => p.skipped.length).length} show skipped-source text · ${ok.filter((p) => p.drift.length).length} with text not in the dump · ${r.pages.length - ok.length} not 200 · ${r.failed.length} failed`,
206
+ `[kide-wp] ${r.pages.length} live pages in ${Date.now() - started}ms · mean ${(mean * 100).toFixed(1)}% · ${below.length} below ${(minScore * 100).toFixed(0)}% · ${ok.filter((p) => p.skipped.length).length} show skipped-source text · ${ok.filter((p) => p.drift.length).length} with text not in the dump · ${r.pages.length - ok.length} not 200 · ${r.failed.length} failed`,
207
207
  );
208
208
  console.log(`Details: ${out("live.md")}`);
209
209
  if (below.length || r.failed.length) process.exitCode = 1;
package/src/live.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `kide import check-live`: the rendered source site is the judge. Every planned document with a
2
+ * `kide-wp check-live`: the rendered source site is the judge. Every planned document with a
3
3
  * WordPress permalink is fetched from the live site; its visible content blocks must be found in
4
4
  * the Kide document. Catches content a theme renders from somewhere the database checks can't
5
5
  * see (template fields, options pages, widgets). Text shared by many pages (navigation, footer,
@@ -83,7 +83,7 @@ export const checkLive = async (
83
83
  options: { baseUrl?: string; concurrency?: number; limit?: number; refresh?: boolean } = {},
84
84
  ): Promise<LiveReport> => {
85
85
  const plan = loadPlan(staging);
86
- if (!plan) throw new Error("No plan yet — run `kide import plan` first.");
86
+ if (!plan) throw new Error("No plan yet — run `kide-wp plan` first.");
87
87
  const base = (options.baseUrl ?? getMeta(staging, "siteUrl") ?? "").replace(/\/$/, "");
88
88
  if (!base) throw new Error("No site URL — pass --base <https://site>.");
89
89
  const records = new Map(loadRecords(staging).map((r) => [r.key, r]));
package/src/plan.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `kide import plan`: run every mapping over the staged source and produce
2
+ * `kide-wp plan`: run every mapping over the staged source and produce
3
3
  * - the documents to write (validated, hashed, media as placeholder tokens),
4
4
  * - a coverage ledger: every source path mapped, dropped with a reason, or unaccounted,
5
5
  * - integrity checks: dangling refs, missing media, text recall per record.
package/src/profile.ts CHANGED
@@ -91,8 +91,8 @@ export const renderProfile = (meta: Record<string, string | undefined>, types: T
91
91
  `Source: ${meta.source} · site ${meta.siteUrl || "?"} · table prefix \`${meta.prefix}\` · scouted ${meta.scoutedAt}`,
92
92
  `Media: ${media.length} attachments · uploads ${meta.uploadsDir ? `local \`${meta.uploadsDir}\`` : `download from ${meta.uploadsUrl}`}`,
93
93
  "",
94
- "Every path below must be mapped or dropped in `migration/*.map.ts` (`kide import plan` enforces it).",
95
- "Inspect real records with `kide import sample <type>`.",
94
+ "Every path below must be mapped or dropped in `migration/*.map.ts` (`kide-wp plan` enforces it).",
95
+ "Inspect real records with `kide-wp sample <type>`.",
96
96
  "",
97
97
  "| source type | records | statuses | locales |",
98
98
  "| --- | --- | --- | --- |",
package/src/report.ts CHANGED
@@ -110,7 +110,7 @@ export const renderLedger = (plan: PlanResult): string => {
110
110
  "# Import plan ledger",
111
111
  "",
112
112
  plan.blocking.length
113
- ? `**BLOCKED** — ${plan.blocking.length} problem(s). \`kide import apply\` refuses until they're fixed:`
113
+ ? `**BLOCKED** — ${plan.blocking.length} problem(s). \`kide-wp apply\` refuses until they're fixed:`
114
114
  : `**READY** — every source path is mapped or dropped; ${plan.docs.length} documents planned.`,
115
115
  "",
116
116
  ...plan.blocking.map((b) => `- ${b}`),
package/src/verify.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `kide import verify`: read every planned document back through the CMS API and
2
+ * `kide-wp verify`: read every planned document back through the CMS API and
3
3
  * reconcile it with the plan — present, every planned field still filled, media
4
4
  * resolved, translations stored, and the source text actually in the database.
5
5
  */
@@ -19,7 +19,7 @@ export type VerifyReport = {
19
19
 
20
20
  export const verifyImport = async (staging: Staging, options: { minRecall?: number } = {}): Promise<VerifyReport> => {
21
21
  const plan = loadPlan(staging);
22
- if (!plan) throw new Error("No plan yet — run `kide import plan` first.");
22
+ if (!plan) throw new Error("No plan yet — run `kide-wp plan` first.");
23
23
  const minRecall = options.minRecall ?? 0.95;
24
24
  const { cms, config, dispose } = await createCmsContext();
25
25
  const records = new Map(loadRecords(staging).map((r) => [r.key, r]));