diffwiki 0.7.0 → 0.8.0-rc.202607252213.c724769

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.
Files changed (2) hide show
  1. package/dist/bin.js +99 -9
  2. package/package.json +2 -2
package/dist/bin.js CHANGED
@@ -171,7 +171,7 @@ async function runExport(opts) {
171
171
  const out = path2.resolve(opts.out);
172
172
  const filter = splitGlobs(opts.filter);
173
173
  const exclude = splitGlobs(opts.exclude);
174
- if (filter.length > 0 || exclude.length > 0) {
174
+ if (!opts.project && (filter.length > 0 || exclude.length > 0)) {
175
175
  const names = (await listCollections()).map((c) => c.name);
176
176
  const { errors } = resolveCollectionSelection(names, { filter, exclude });
177
177
  if (errors.length > 0) throw new InvalidExportSelectionError(errors);
@@ -182,6 +182,10 @@ async function runExport(opts) {
182
182
  const args = [...prefix, "export", "--out", out, "--base", opts.base];
183
183
  if (opts.filter) args.push("--filter", opts.filter);
184
184
  if (opts.exclude) args.push("--exclude", opts.exclude);
185
+ if (opts.project) {
186
+ args.push("--project");
187
+ if (typeof opts.project === "string") args.push(opts.project);
188
+ }
185
189
  if (override) console.log(`Exporting via ${override}`);
186
190
  await new Promise((resolve, reject) => {
187
191
  const child = spawn2(cmd, args, { stdio: "inherit", env: process.env });
@@ -191,6 +195,79 @@ async function runExport(opts) {
191
195
  console.log(`Static site written to ${out}`);
192
196
  }
193
197
 
198
+ // src/preview.ts
199
+ import { existsSync } from "fs";
200
+ import fs3 from "fs/promises";
201
+ import net from "net";
202
+ import path3 from "path";
203
+ import { spawn as spawn3 } from "child_process";
204
+ import { fileURLToPath as fileURLToPath3 } from "url";
205
+ import { resolveProjectCollections, seedProjectHome } from "diffwiki-core";
206
+ async function findFreePort(start, host = "127.0.0.1") {
207
+ const isFree = (port) => new Promise((resolve) => {
208
+ const srv = net.createServer();
209
+ srv.once("error", () => resolve(false));
210
+ srv.once("listening", () => srv.close(() => resolve(true)));
211
+ srv.listen(port, host);
212
+ });
213
+ for (let port = start; port < start + 100; port += 1) {
214
+ if (await isFree(port)) return port;
215
+ }
216
+ throw new Error(`No free port available in ${start}..${start + 99}`);
217
+ }
218
+ function launchCommand() {
219
+ const override = process.env.DIFFWIKI_APP_CMD;
220
+ if (override) {
221
+ const [cmd, ...prefix] = override.split(" ");
222
+ return { cmd, prefix };
223
+ }
224
+ const candidates = [
225
+ path3.resolve(path3.dirname(fileURLToPath3(import.meta.url)), "../../../apps/wiki/bin/wiki-server.mjs"),
226
+ path3.resolve(process.cwd(), "apps/wiki/bin/wiki-server.mjs")
227
+ ];
228
+ const local = candidates.find((p) => existsSync(p));
229
+ return local ? { cmd: "node", prefix: [local] } : { cmd: "npx", prefix: ["-y", "diffwiki-app@latest"] };
230
+ }
231
+ async function runPreview(opts) {
232
+ const root = path3.resolve(opts.cwd);
233
+ const entries = await resolveProjectCollections(root);
234
+ const home = await seedProjectHome(root);
235
+ const { cmd, prefix } = launchCommand();
236
+ const port = await findFreePort(opts.port);
237
+ const url = `http://127.0.0.1:${port}`;
238
+ console.log(`Previewing ${entries.length} collection(s) from ${path3.join(root, "diffwiki.yaml")}`);
239
+ if (port !== opts.port) console.log(`Port ${opts.port} is in use \u2014 using ${port} instead.`);
240
+ console.log(`Starting UI at ${url} \u2026 (Ctrl-C to stop)`);
241
+ const child = spawn3(cmd, [...prefix, "--port", String(port)], {
242
+ env: {
243
+ ...process.env,
244
+ DIFFWIKI_HOME: home,
245
+ DIFFWIKI_PROJECT_DIR: root,
246
+ PORT: String(port),
247
+ HOST: "127.0.0.1"
248
+ },
249
+ stdio: "inherit"
250
+ });
251
+ const stop = () => child.kill("SIGINT");
252
+ process.on("SIGINT", stop);
253
+ process.on("SIGTERM", stop);
254
+ const ready = await waitForServer(url);
255
+ if (ready) openBrowser(url);
256
+ await new Promise((resolve) => {
257
+ const finish = () => {
258
+ process.off("SIGINT", stop);
259
+ process.off("SIGTERM", stop);
260
+ void fs3.rm(home, { recursive: true, force: true });
261
+ resolve();
262
+ };
263
+ child.on("close", finish);
264
+ child.on("error", (err) => {
265
+ console.error(`Failed to start preview: ${err.message}`);
266
+ finish();
267
+ });
268
+ });
269
+ }
270
+
194
271
  // src/cli.ts
195
272
  var icon = (level) => level === "ok" ? "\u2713" : level === "warn" ? "!" : "\u2716";
196
273
  function createProgram() {
@@ -361,10 +438,18 @@ function createProgram() {
361
438
  console.log("Registered globally \u2014 discoverable via: diffwiki list");
362
439
  })
363
440
  );
364
- program.command("export").description("Generate a static site (deployable to GitHub Pages)").requiredOption("-o, --out <dir>", "output directory").option("-b, --base <path>", "base URL path (e.g. /my-repo/ for GitHub Pages)", "/").option("-f, --filter <globs>", "only export collections matching these globs (comma-separated)").option("-e, --exclude <globs>", "exclude collections matching these globs (comma-separated)").action(
365
- withErrors(async (opts) => {
366
- await runExport({ out: opts.out, base: opts.base, filter: opts.filter, exclude: opts.exclude });
367
- })
441
+ program.command("export").description("Generate a static site (deployable to GitHub Pages)").requiredOption("-o, --out <dir>", "output directory").option("-b, --base <path>", "base URL path (e.g. /my-repo/ for GitHub Pages)", "/").option("-f, --filter <globs>", "only export collections matching these globs (comma-separated)").option("-e, --exclude <globs>", "exclude collections matching these globs (comma-separated)").option("--project [dir]", "build only the repo project from its diffwiki.yaml (default: cwd)").action(
442
+ withErrors(
443
+ async (opts) => {
444
+ await runExport({
445
+ out: opts.out,
446
+ base: opts.base,
447
+ filter: opts.filter,
448
+ exclude: opts.exclude,
449
+ project: opts.project
450
+ });
451
+ }
452
+ )
368
453
  );
369
454
  program.command("config-set").description("Set a config value (e.g. defaultCollection, or defaultSearch <engine[:type]>)").argument("<key>", "config key").argument("<value>", "config value").action(
370
455
  withErrors(async (key, value) => {
@@ -432,20 +517,25 @@ function createProgram() {
432
517
  console.log(`Opening ${target}`);
433
518
  })
434
519
  );
520
+ program.command("preview").description("Preview the site from the repo diffwiki.yaml (ignores global collections)").option("-p, --port <port>", "port to serve on", "4321").action(
521
+ withErrors(async (opts) => {
522
+ await runPreview({ cwd: process.cwd(), port: Number(opts.port) });
523
+ })
524
+ );
435
525
  return program;
436
526
  }
437
527
 
438
528
  // src/logging.ts
439
529
  import { mkdirSync } from "fs";
440
530
  import os from "os";
441
- import path3 from "path";
531
+ import path4 from "path";
442
532
  import { configureSync, getConfig } from "@logtape/logtape";
443
533
  import { getRotatingFileSink } from "@logtape/file";
444
534
  import { resolveLogLevel } from "diffwiki-core";
445
535
  var configured = false;
446
536
  function diffwikiHome() {
447
537
  const override = process.env.DIFFWIKI_HOME;
448
- return override && override.length > 0 ? override : path3.join(os.homedir(), ".diffwiki");
538
+ return override && override.length > 0 ? override : path4.join(os.homedir(), ".diffwiki");
449
539
  }
450
540
  function resolveCliLevel(argv) {
451
541
  if (argv.includes("-v") || argv.includes("--verbose")) return "debug";
@@ -462,9 +552,9 @@ function configureCliLogging(argv = process.argv) {
462
552
  if (configured || getConfig() != null) return;
463
553
  configured = true;
464
554
  const level = resolveCliLevel(argv);
465
- const logsDir = path3.join(diffwikiHome(), "logs");
555
+ const logsDir = path4.join(diffwikiHome(), "logs");
466
556
  mkdirSync(logsDir, { recursive: true });
467
- const logFile = path3.join(logsDir, "diffwiki.log");
557
+ const logFile = path4.join(logsDir, "diffwiki.log");
468
558
  const stderrSink = (record) => {
469
559
  process.stderr.write(formatLine(record) + "\n");
470
560
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diffwiki",
3
- "version": "0.7.0",
3
+ "version": "0.8.0-rc.202607252213.c724769",
4
4
  "description": "diffwiki command-line interface",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,7 +17,7 @@
17
17
  "@logtape/logtape": "^2.2.4",
18
18
  "@logtape/file": "^2.2.4",
19
19
  "commander": "^13.0.0",
20
- "diffwiki-core": "0.7.0"
20
+ "diffwiki-core": "0.8.0-rc.202607252213.c724769"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/node": "^22.0.0"