novel-writer-cli 0.2.0 → 0.2.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/dist/__tests__/cli-version-flag.test.js +38 -0
- package/dist/cli.js +14 -1
- package/package.json +1 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
import { main } from "../cli.js";
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
const pkg = require("../../package.json");
|
|
7
|
+
async function runCli(argv) {
|
|
8
|
+
let stdout = "";
|
|
9
|
+
let stderr = "";
|
|
10
|
+
const origOut = process.stdout.write;
|
|
11
|
+
const origErr = process.stderr.write;
|
|
12
|
+
process.stdout.write = (chunk) => {
|
|
13
|
+
stdout += typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
|
|
14
|
+
return true;
|
|
15
|
+
};
|
|
16
|
+
process.stderr.write = (chunk) => {
|
|
17
|
+
stderr += typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
const prevExitCode = process.exitCode;
|
|
21
|
+
try {
|
|
22
|
+
const code = await main(argv);
|
|
23
|
+
return { code, stdout, stderr };
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
process.exitCode = prevExitCode;
|
|
27
|
+
process.stdout.write = origOut;
|
|
28
|
+
process.stderr.write = origErr;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
test("novel --version prints the package version", async () => {
|
|
32
|
+
const expected = typeof pkg.version === "string" ? pkg.version : null;
|
|
33
|
+
assert.ok(expected, "Expected package.json to contain a string version.");
|
|
34
|
+
const res = await runCli(["--version"]);
|
|
35
|
+
assert.equal(res.code, 0);
|
|
36
|
+
assert.equal(res.stdout.trim(), expected);
|
|
37
|
+
assert.equal(res.stderr, "");
|
|
38
|
+
});
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command, CommanderError } from "commander";
|
|
3
3
|
import { realpathSync } from "node:fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
4
5
|
import { join, resolve } from "node:path";
|
|
5
6
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
7
|
import { buildCharacterVoiceProfiles, clearCharacterVoiceDriftFile, computeCharacterVoiceDrift, loadActiveCharacterVoiceDriftIds, loadCharacterVoiceProfiles, writeCharacterVoiceDriftFile, writeCharacterVoiceProfilesFile } from "./character-voice.js";
|
|
@@ -25,6 +26,17 @@ import { isPlainObject } from "./type-guards.js";
|
|
|
25
26
|
import { validateStep } from "./validate.js";
|
|
26
27
|
import { VOL_REVIEW_RELS, collectVolumeData, computeBridgeCheck, computeForeshadowingAudit, computeStorylineRhythm } from "./volume-review.js";
|
|
27
28
|
import { tryResolveVolumeChapterRange } from "./consistency-auditor.js";
|
|
29
|
+
const require = createRequire(import.meta.url);
|
|
30
|
+
function resolveCliVersion() {
|
|
31
|
+
try {
|
|
32
|
+
const pkg = require("../package.json");
|
|
33
|
+
return typeof pkg.version === "string" ? pkg.version : "0.0.0";
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return "0.0.0";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const CLI_VERSION = resolveCliVersion();
|
|
28
40
|
function detectCommandName(argv) {
|
|
29
41
|
for (let i = 0; i < argv.length; i++) {
|
|
30
42
|
const token = argv[i];
|
|
@@ -49,6 +61,7 @@ function buildProgram(argv) {
|
|
|
49
61
|
const jsonMode = isJsonMode(argv);
|
|
50
62
|
const program = new Command();
|
|
51
63
|
program.name("novel").description("Executor-agnostic novel orchestration CLI.");
|
|
64
|
+
program.version(CLI_VERSION);
|
|
52
65
|
program.option("--json", "Emit machine-readable JSON (single object).");
|
|
53
66
|
program.option("--project <dir>", "Project root directory (defaults to auto-detect via .checkpoint.json).");
|
|
54
67
|
program.configureOutput({
|
|
@@ -870,7 +883,7 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
870
883
|
return err.exitCode;
|
|
871
884
|
}
|
|
872
885
|
if (err instanceof CommanderError) {
|
|
873
|
-
if (err.code === "commander.helpDisplayed") {
|
|
886
|
+
if (err.code === "commander.helpDisplayed" || err.code === "commander.version") {
|
|
874
887
|
return 0;
|
|
875
888
|
}
|
|
876
889
|
if (jsonMode) {
|