diffwiki 0.7.0 → 0.8.0-rc.202607252154.25b2cb6
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/dist/bin.js +84 -9
- 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,64 @@ 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 path3 from "path";
|
|
202
|
+
import { spawn as spawn3 } from "child_process";
|
|
203
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
204
|
+
import { resolveProjectCollections, seedProjectHome } from "diffwiki-core";
|
|
205
|
+
function launchCommand() {
|
|
206
|
+
const override = process.env.DIFFWIKI_APP_CMD;
|
|
207
|
+
if (override) {
|
|
208
|
+
const [cmd, ...prefix] = override.split(" ");
|
|
209
|
+
return { cmd, prefix };
|
|
210
|
+
}
|
|
211
|
+
const candidates = [
|
|
212
|
+
path3.resolve(path3.dirname(fileURLToPath3(import.meta.url)), "../../../apps/wiki/bin/wiki-server.mjs"),
|
|
213
|
+
path3.resolve(process.cwd(), "apps/wiki/bin/wiki-server.mjs")
|
|
214
|
+
];
|
|
215
|
+
const local = candidates.find((p) => existsSync(p));
|
|
216
|
+
return local ? { cmd: "node", prefix: [local] } : { cmd: "npx", prefix: ["-y", "diffwiki-app@latest"] };
|
|
217
|
+
}
|
|
218
|
+
async function runPreview(opts) {
|
|
219
|
+
const root = path3.resolve(opts.cwd);
|
|
220
|
+
const entries = await resolveProjectCollections(root);
|
|
221
|
+
const home = await seedProjectHome(root);
|
|
222
|
+
const { cmd, prefix } = launchCommand();
|
|
223
|
+
const url = `http://127.0.0.1:${opts.port}`;
|
|
224
|
+
console.log(`Previewing ${entries.length} collection(s) from ${path3.join(root, "diffwiki.yaml")}`);
|
|
225
|
+
console.log(`Starting UI at ${url} \u2026 (Ctrl-C to stop)`);
|
|
226
|
+
const child = spawn3(cmd, [...prefix, "--port", String(opts.port)], {
|
|
227
|
+
env: {
|
|
228
|
+
...process.env,
|
|
229
|
+
DIFFWIKI_HOME: home,
|
|
230
|
+
DIFFWIKI_PROJECT_DIR: root,
|
|
231
|
+
PORT: String(opts.port),
|
|
232
|
+
HOST: "127.0.0.1"
|
|
233
|
+
},
|
|
234
|
+
stdio: "inherit"
|
|
235
|
+
});
|
|
236
|
+
const stop = () => child.kill("SIGINT");
|
|
237
|
+
process.on("SIGINT", stop);
|
|
238
|
+
process.on("SIGTERM", stop);
|
|
239
|
+
const ready = await waitForServer(url);
|
|
240
|
+
if (ready) openBrowser(url);
|
|
241
|
+
await new Promise((resolve) => {
|
|
242
|
+
const finish = () => {
|
|
243
|
+
process.off("SIGINT", stop);
|
|
244
|
+
process.off("SIGTERM", stop);
|
|
245
|
+
void fs3.rm(home, { recursive: true, force: true });
|
|
246
|
+
resolve();
|
|
247
|
+
};
|
|
248
|
+
child.on("close", finish);
|
|
249
|
+
child.on("error", (err) => {
|
|
250
|
+
console.error(`Failed to start preview: ${err.message}`);
|
|
251
|
+
finish();
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
194
256
|
// src/cli.ts
|
|
195
257
|
var icon = (level) => level === "ok" ? "\u2713" : level === "warn" ? "!" : "\u2716";
|
|
196
258
|
function createProgram() {
|
|
@@ -361,10 +423,18 @@ function createProgram() {
|
|
|
361
423
|
console.log("Registered globally \u2014 discoverable via: diffwiki list");
|
|
362
424
|
})
|
|
363
425
|
);
|
|
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(
|
|
366
|
-
|
|
367
|
-
|
|
426
|
+
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(
|
|
427
|
+
withErrors(
|
|
428
|
+
async (opts) => {
|
|
429
|
+
await runExport({
|
|
430
|
+
out: opts.out,
|
|
431
|
+
base: opts.base,
|
|
432
|
+
filter: opts.filter,
|
|
433
|
+
exclude: opts.exclude,
|
|
434
|
+
project: opts.project
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
)
|
|
368
438
|
);
|
|
369
439
|
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
440
|
withErrors(async (key, value) => {
|
|
@@ -432,20 +502,25 @@ function createProgram() {
|
|
|
432
502
|
console.log(`Opening ${target}`);
|
|
433
503
|
})
|
|
434
504
|
);
|
|
505
|
+
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(
|
|
506
|
+
withErrors(async (opts) => {
|
|
507
|
+
await runPreview({ cwd: process.cwd(), port: Number(opts.port) });
|
|
508
|
+
})
|
|
509
|
+
);
|
|
435
510
|
return program;
|
|
436
511
|
}
|
|
437
512
|
|
|
438
513
|
// src/logging.ts
|
|
439
514
|
import { mkdirSync } from "fs";
|
|
440
515
|
import os from "os";
|
|
441
|
-
import
|
|
516
|
+
import path4 from "path";
|
|
442
517
|
import { configureSync, getConfig } from "@logtape/logtape";
|
|
443
518
|
import { getRotatingFileSink } from "@logtape/file";
|
|
444
519
|
import { resolveLogLevel } from "diffwiki-core";
|
|
445
520
|
var configured = false;
|
|
446
521
|
function diffwikiHome() {
|
|
447
522
|
const override = process.env.DIFFWIKI_HOME;
|
|
448
|
-
return override && override.length > 0 ? override :
|
|
523
|
+
return override && override.length > 0 ? override : path4.join(os.homedir(), ".diffwiki");
|
|
449
524
|
}
|
|
450
525
|
function resolveCliLevel(argv) {
|
|
451
526
|
if (argv.includes("-v") || argv.includes("--verbose")) return "debug";
|
|
@@ -462,9 +537,9 @@ function configureCliLogging(argv = process.argv) {
|
|
|
462
537
|
if (configured || getConfig() != null) return;
|
|
463
538
|
configured = true;
|
|
464
539
|
const level = resolveCliLevel(argv);
|
|
465
|
-
const logsDir =
|
|
540
|
+
const logsDir = path4.join(diffwikiHome(), "logs");
|
|
466
541
|
mkdirSync(logsDir, { recursive: true });
|
|
467
|
-
const logFile =
|
|
542
|
+
const logFile = path4.join(logsDir, "diffwiki.log");
|
|
468
543
|
const stderrSink = (record) => {
|
|
469
544
|
process.stderr.write(formatLine(record) + "\n");
|
|
470
545
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "diffwiki",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-rc.202607252154.25b2cb6",
|
|
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.
|
|
20
|
+
"diffwiki-core": "0.8.0-rc.202607252154.25b2cb6"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "^22.0.0"
|