sdtk-spec-kit 0.8.1 → 0.9.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.
@@ -1,368 +1,79 @@
1
1
  "use strict";
2
2
 
3
- const fs = require("fs");
4
- const path = require("path");
5
- const { parseFlags } = require("../lib/args");
3
+ const { spawn } = require("child_process");
6
4
  const {
7
- resolveAtlasConfig,
8
- writeAtlasConfig,
9
- isAtlasInitialized,
10
- isAtlasBuilt,
11
- readBuildMeta,
12
- readGraphMeta,
13
- } = require("../lib/atlas-config");
14
- const { runBuild, openViewer } = require("../lib/atlas-runner");
15
- const { ValidationError } = require("../lib/errors");
16
-
17
- // ---------------------------------------------------------------------------
18
- // Shared flag definitions
19
- // ---------------------------------------------------------------------------
20
- const BASE_FLAG_DEFS = {
21
- "project-path": { type: "string" },
22
- "output-dir": { type: "string" },
23
- "scan-root": { type: "string" },
24
- verbose: { type: "boolean" },
25
- };
26
-
27
- const OPEN_FLAG_DEFS = {
28
- ...BASE_FLAG_DEFS,
29
- host: { type: "string" },
30
- port: { type: "string" },
31
- "no-open": { type: "boolean" },
32
- };
33
-
34
- const INIT_FLAG_DEFS = {
35
- ...OPEN_FLAG_DEFS,
36
- force: { type: "boolean" },
37
- "no-build": { type: "boolean" },
38
- };
39
-
40
- const WATCH_FLAG_DEFS = {
41
- ...BASE_FLAG_DEFS,
42
- port: { type: "string" },
43
- "no-open": { type: "boolean" },
44
- };
45
-
46
- // ---------------------------------------------------------------------------
47
- // Flag parsing with repeatable --scan-root support
48
- // ---------------------------------------------------------------------------
5
+ USAGE_LINES,
6
+ WIKI_BIN,
7
+ WIKI_MISSING_LINES,
8
+ planDelegation,
9
+ resolveWikiBin,
10
+ } = require("../lib/atlas-delegate");
11
+ const { CliError } = require("../lib/errors");
49
12
 
50
13
  /**
51
- * Parse args and collect repeated --scan-root values into an array.
52
- * The base parseFlags only captures the last value for string flags.
53
- * This thin wrapper collects all occurrences.
14
+ * Spawn the resolved sdtk-wiki entry script with the current Node binary rather
15
+ * than the installed shim, so Windows never has to resolve a .cmd through
16
+ * PATHEXT (BK-F).
17
+ *
18
+ * @param {string} binPath - Absolute path to the sdtk-wiki entry script.
19
+ * @param {string[]} argv - Args to forward.
20
+ * @returns {Promise<number>} Child exit code.
54
21
  */
55
- function parseAtlasFlags(args, defs) {
56
- const scanRoots = [];
57
- // Collect raw --scan-root values before parseFlags strips them
58
- const filteredArgs = [];
59
- let i = 0;
60
- while (i < args.length) {
61
- const arg = args[i];
62
- if (arg === "--scan-root") {
63
- i++;
64
- if (i < args.length) {
65
- scanRoots.push(args[i]);
66
- i++;
22
+ function runWiki(binPath, argv) {
23
+ return new Promise((resolve, reject) => {
24
+ const child = spawn(process.execPath, [binPath, ...argv], {
25
+ stdio: "inherit",
26
+ });
27
+
28
+ child.on("error", (err) => {
29
+ reject(new CliError(`Failed to start ${WIKI_BIN}: ${err.message}`));
30
+ });
31
+
32
+ child.on("close", (code, signal) => {
33
+ if (signal) {
34
+ // Ctrl+C on a long-lived `open` / `watch` run is a normal exit here.
35
+ resolve(0);
36
+ return;
67
37
  }
68
- } else if (arg.startsWith("--scan-root=")) {
69
- scanRoots.push(arg.slice("--scan-root=".length));
70
- i++;
71
- } else {
72
- filteredArgs.push(arg);
73
- i++;
74
- }
75
- }
76
-
77
- const { flags, positional } = parseFlags(filteredArgs, defs);
78
- // Inject the collected scan roots as an array
79
- flags["scan-root"] = scanRoots.length > 0 ? scanRoots : undefined;
80
- return { flags, positional };
81
- }
82
-
83
- // ---------------------------------------------------------------------------
84
- // atlas init
85
- // ---------------------------------------------------------------------------
86
- async function cmdAtlasInit(args) {
87
- const { flags } = parseAtlasFlags(args, INIT_FLAG_DEFS);
88
- const config = resolveAtlasConfig(flags);
89
-
90
- if (isAtlasInitialized(config.outputDir) && !flags.force) {
91
- console.log(`[atlas] Atlas already initialized at: ${config.outputDir}`);
92
- console.log("[atlas] Use --force to overwrite existing config.");
93
- } else {
94
- writeAtlasConfig(config);
95
- console.log(`[atlas] Initialized Atlas config: ${config.configPath}`);
96
- console.log(`[atlas] Project root: ${config.projectPath}`);
97
- console.log(`[atlas] Output dir: ${config.outputDir}`);
98
- console.log(`[atlas] Scan roots: ${config.scanRoots.join(", ")}`);
99
- }
100
-
101
- if (flags["no-build"]) {
102
- console.log("[atlas] --no-build specified; skipping initial build.");
103
- return 0;
104
- }
105
-
106
- console.log("");
107
- const buildResult = await runBuild(config);
108
- console.log(`[atlas] Build complete: ${buildResult.docCount} docs, ${buildResult.nodeCount} nodes, ${buildResult.edgeCount} edges.`);
109
-
110
- if (flags["no-open"]) {
111
- console.log("[atlas] --no-open specified; skipping viewer launch.");
112
- return 0;
113
- }
114
-
115
- const { url } = await openViewer(config, false);
116
- console.log(`[atlas] Viewer: ${url}`);
117
- return 0;
118
- }
119
-
120
- // ---------------------------------------------------------------------------
121
- // atlas build
122
- // ---------------------------------------------------------------------------
123
- async function cmdAtlasBuild(args) {
124
- const { flags } = parseAtlasFlags(args, BASE_FLAG_DEFS);
125
- const config = resolveAtlasConfig(flags);
126
-
127
- if (!isAtlasInitialized(config.outputDir)) {
128
- console.log("[atlas] Atlas not initialized. Run: sdtk-spec atlas init");
129
- console.log(`[atlas] Output dir: ${config.outputDir}`);
130
- }
131
-
132
- const startMs = Date.now();
133
- const buildResult = await runBuild(config);
134
- const durationMs = Date.now() - startMs;
135
-
136
- console.log("");
137
- console.log("[atlas] Build summary:");
138
- console.log(` Documents: ${buildResult.docCount}`);
139
- console.log(` Graph nodes: ${buildResult.nodeCount}`);
140
- console.log(` Graph edges: ${buildResult.edgeCount}`);
141
- console.log(` Output dir: ${config.outputDir}`);
142
- console.log(` Duration: ${(durationMs / 1000).toFixed(1)}s`);
143
- if (buildResult.generated) {
144
- console.log(` Generated: ${buildResult.generated}`);
145
- }
146
- return 0;
147
- }
148
-
149
- // ---------------------------------------------------------------------------
150
- // atlas open
151
- // ---------------------------------------------------------------------------
152
- async function cmdAtlasOpen(args) {
153
- const { flags } = parseAtlasFlags(args, OPEN_FLAG_DEFS);
154
- const config = resolveAtlasConfig(flags);
155
-
156
- if (!isAtlasBuilt(config.outputDir)) {
157
- console.error("[atlas] No atlas build found.");
158
- console.error(` Expected: ${config.outputDir}/viewer.html`);
159
- console.error(" Run: sdtk-spec atlas init");
160
- console.error(" Or: sdtk-spec atlas build");
161
- return 1;
162
- }
163
-
164
- const noOpen = !!flags["no-open"];
165
- const { url } = await openViewer(config, noOpen);
166
-
167
- if (!noOpen) {
168
- // If the server was started inline, keep it alive until user exits
169
- console.log("[atlas] Press Ctrl+C to stop the viewer server.");
170
- await new Promise(() => {}); // keep alive
171
- }
172
-
173
- return 0;
38
+ resolve(code === null ? 1 : code);
39
+ });
40
+ });
174
41
  }
175
42
 
176
- // ---------------------------------------------------------------------------
177
- // atlas watch
178
- // ---------------------------------------------------------------------------
179
- async function cmdAtlasWatch(args) {
180
- const { flags } = parseAtlasFlags(args, WATCH_FLAG_DEFS);
181
- const config = resolveAtlasConfig(flags);
182
-
183
- if (!isAtlasInitialized(config.outputDir)) {
184
- console.log("[atlas] Atlas not initialized. Running init first...");
185
- writeAtlasConfig(config);
186
- console.log(`[atlas] Initialized Atlas config: ${config.configPath}`);
187
- }
43
+ // `deps` = { resolveWikiBin, runWiki } — injected by tests so both the resolved
44
+ // and the not-installed branch are exercisable without a real install.
45
+ async function cmdAtlas(args, deps = {}) {
46
+ const resolve = deps.resolveWikiBin || resolveWikiBin;
47
+ const run = deps.runWiki || runWiki;
188
48
 
189
- const DEBOUNCE_MS = 800;
190
- let debounceTimer = null;
191
- let rebuilding = false;
49
+ const plan = planDelegation(args);
192
50
 
193
- async function rebuild(reason) {
194
- if (rebuilding) return;
195
- rebuilding = true;
196
- console.log(`\n[atlas] Change detected (${reason}). Rebuilding...`);
197
- try {
198
- const buildResult = await runBuild(config);
199
- console.log(`[atlas] Rebuild complete: ${buildResult.docCount} docs, ${buildResult.nodeCount} nodes.`);
200
- } catch (err) {
201
- console.error(`[atlas] Rebuild failed: ${err.message}`);
202
- } finally {
203
- rebuilding = false;
51
+ if (plan.usage) {
52
+ for (const line of USAGE_LINES) {
53
+ console.error(line);
204
54
  }
205
- }
206
-
207
- // Initial build
208
- console.log("[atlas] Running initial build...");
209
- try {
210
- const buildResult = await runBuild(config);
211
- console.log(`[atlas] Initial build complete: ${buildResult.docCount} docs.`);
212
- } catch (err) {
213
- console.error(`[atlas] Initial build failed: ${err.message}`);
214
- // Continue watching even if initial build fails
215
- }
216
-
217
- // Open viewer unless --no-open
218
- let viewerServer = null;
219
- if (!flags["no-open"] && isAtlasBuilt(config.outputDir)) {
220
- const result = await openViewer(config, false);
221
- viewerServer = result.server;
222
- }
223
-
224
- // Watch each scan root for markdown changes
225
- const watchers = [];
226
- for (const scanRoot of config.scanRoots) {
227
- if (!fs.existsSync(scanRoot)) {
228
- console.log(`[atlas] Warning: scan root does not exist, skipping watch: ${scanRoot}`);
229
- continue;
230
- }
231
-
232
- try {
233
- const watcher = fs.watch(scanRoot, { recursive: true }, (eventType, filename) => {
234
- if (!filename || !filename.endsWith(".md")) return;
235
- if (debounceTimer) clearTimeout(debounceTimer);
236
- debounceTimer = setTimeout(() => {
237
- rebuild(`${eventType}: ${filename}`);
238
- }, DEBOUNCE_MS);
239
- });
240
-
241
- watcher.on("error", (err) => {
242
- console.error(`[atlas] Watch error on ${scanRoot}: ${err.message}`);
243
- });
244
-
245
- watchers.push(watcher);
246
- console.log(`[atlas] Watching: ${scanRoot}`);
247
- } catch (err) {
248
- console.error(`[atlas] Could not watch ${scanRoot}: ${err.message}`);
249
- }
250
- }
251
-
252
- if (watchers.length === 0) {
253
- console.error("[atlas] No scan roots could be watched. Exiting.");
254
55
  return 1;
255
56
  }
256
57
 
257
- console.log("[atlas] Watching for markdown changes. Press Ctrl+C to stop.");
258
-
259
- // Graceful shutdown
260
- function shutdown() {
261
- console.log("\n[atlas] Stopping watch...");
262
- if (debounceTimer) clearTimeout(debounceTimer);
263
- for (const w of watchers) {
264
- try { w.close(); } catch (_) {}
265
- }
266
- if (viewerServer) {
267
- try { viewerServer.close(); } catch (_) {}
58
+ const binPath = resolve();
59
+ if (!binPath) {
60
+ for (const line of WIKI_MISSING_LINES) {
61
+ console.error(line);
268
62
  }
269
- process.exit(0);
63
+ return 2;
270
64
  }
271
65
 
272
- process.on("SIGINT", shutdown);
273
- process.on("SIGTERM", shutdown);
66
+ console.log(
67
+ `[atlas] Delegating to "${WIKI_BIN} ${plan.argv.join(" ")}" — sdtk-wiki owns the graph builder.`
68
+ );
69
+ console.log(
70
+ "[atlas] Graph output defaults to .sdtk/wiki/graph; pass --output-dir to choose another location."
71
+ );
274
72
 
275
- // Keep process alive
276
- await new Promise(() => {});
277
- return 0;
278
- }
279
-
280
- // ---------------------------------------------------------------------------
281
- // atlas status
282
- // ---------------------------------------------------------------------------
283
- async function cmdAtlasStatus(args) {
284
- const { flags } = parseAtlasFlags(args, BASE_FLAG_DEFS);
285
-
286
- // Use defaults-only resolution (no validation errors for status)
287
- let config;
288
- try {
289
- config = resolveAtlasConfig(flags);
290
- } catch (err) {
291
- console.error(`[atlas] Config error: ${err.message}`);
292
- return 1;
293
- }
294
-
295
- const initialized = isAtlasInitialized(config.outputDir);
296
- const built = isAtlasBuilt(config.outputDir);
297
-
298
- console.log("[atlas] Status");
299
- console.log("=".repeat(40));
300
- console.log(` Initialized: ${initialized ? "yes" : "no"}`);
301
- console.log(` Built: ${built ? "yes" : "no"}`);
302
- console.log(` Project root: ${config.projectPath}`);
303
- console.log(` Output dir: ${config.outputDir}`);
304
- console.log(` Scan roots: ${config.scanRoots.join(", ")}`);
305
- console.log(` Viewer host: ${config.host}:${config.port}`);
306
-
307
- if (built) {
308
- const meta = readBuildMeta(config.outputDir);
309
- const graphMeta = readGraphMeta(config.outputDir);
310
- if (meta) {
311
- console.log(` Last build: ${meta.generated || "unknown"}`);
312
- console.log(` Documents: ${meta.count}`);
313
- }
314
- if (graphMeta) {
315
- console.log(` Graph nodes: ${graphMeta.nodeCount}`);
316
- console.log(` Graph edges: ${graphMeta.edgeCount}`);
317
- }
318
- }
319
-
320
- if (!initialized) {
321
- console.log("");
322
- console.log("[atlas] Hint: run 'sdtk-spec atlas init' to initialize Atlas for this project.");
323
- } else if (!built) {
324
- console.log("");
325
- console.log("[atlas] Hint: run 'sdtk-spec atlas build' to build the local document graph.");
326
- }
327
-
328
- return 0;
329
- }
330
-
331
- // ---------------------------------------------------------------------------
332
- // Top-level atlas dispatcher
333
- // ---------------------------------------------------------------------------
334
- const ATLAS_SUBCOMMANDS = new Set(["init", "build", "open", "watch", "status"]);
335
-
336
- async function cmdAtlas(args) {
337
- if (!args || args.length === 0) {
338
- console.error("[atlas] Usage: sdtk-spec atlas <subcommand> [options]");
339
- console.error(" Subcommands: init, build, open, watch, status");
340
- console.error(" Run 'sdtk-spec --help' for full usage.");
341
- return 1;
342
- }
343
-
344
- const [subcommand, ...rest] = args;
345
-
346
- if (!ATLAS_SUBCOMMANDS.has(subcommand)) {
347
- throw new ValidationError(
348
- `Unknown atlas subcommand: "${subcommand}". Valid subcommands: init, build, open, watch, status.`
349
- );
350
- }
351
-
352
- switch (subcommand) {
353
- case "init":
354
- return cmdAtlasInit(rest);
355
- case "build":
356
- return cmdAtlasBuild(rest);
357
- case "open":
358
- return cmdAtlasOpen(rest);
359
- case "watch":
360
- return cmdAtlasWatch(rest);
361
- case "status":
362
- return cmdAtlasStatus(rest);
363
- }
73
+ return run(binPath, plan.argv);
364
74
  }
365
75
 
366
76
  module.exports = {
367
77
  cmdAtlas,
78
+ runWiki,
368
79
  };
@@ -111,10 +111,10 @@ function cmdHelp() {
111
111
  " --force Overwrite managed analysis artifacts",
112
112
  " --json Print result summary as JSON",
113
113
  "",
114
- "Atlas subcommands (free compatibility path):",
115
- " sdtk-spec atlas init Initialize Atlas config and run first build (opens viewer)",
114
+ "Atlas subcommands (free compatibility path; delegated to sdtk-wiki):",
115
+ " sdtk-spec atlas init Initialize the graph workspace and run the first build (opens viewer)",
116
116
  " sdtk-spec atlas build Rebuild the local document graph from project markdown",
117
- " sdtk-spec atlas open Open the last successful atlas build in a local browser",
117
+ " sdtk-spec atlas open Open the last successful build in a local browser",
118
118
  " sdtk-spec atlas watch Watch for markdown changes and rebuild automatically",
119
119
  " sdtk-spec atlas status Show initialization state and last build summary",
120
120
  "",
@@ -124,44 +124,21 @@ function cmdHelp() {
124
124
  " sdtk-spec project refresh Incremental managed refresh of .sdtk/project/ artifacts (Pro)",
125
125
  " sdtk-spec project promote Publish reviewed staged docs into /docs/ for sdtk-wiki (free; dry-run by default)",
126
126
  "",
127
- "Atlas options (init):",
128
- " --project-path <path> Target project directory (default: cwd)",
129
- " --output-dir <path> Atlas output directory (default: <project>/.sdtk/atlas)",
130
- " --scan-root <path> Scan root (repeatable; default: project root)",
131
- " --force Overwrite existing Atlas config",
132
- " --no-build Skip initial build",
133
- " --no-open Skip opening the viewer",
134
- " --verbose Show detailed build output",
135
- "",
136
- "Atlas options (build):",
137
- " --project-path <path> Target project directory (default: cwd)",
138
- " --output-dir <path> Atlas output directory (default: <project>/.sdtk/atlas)",
139
- " --scan-root <path> Scan root (repeatable; default: project root)",
140
- " --verbose Show incremental build detail",
141
- "",
142
- "Atlas options (open):",
143
- " --project-path <path> Target project directory (default: cwd)",
144
- " --output-dir <path> Atlas output directory (default: <project>/.sdtk/atlas)",
145
- " --host <host> Viewer server host (default: 127.0.0.1)",
146
- " --port <port> Viewer server port (default: 8765)",
147
- " --no-open Print viewer URL without opening browser",
148
- "",
149
- "Atlas options (watch):",
150
- " --project-path <path> Target project directory (default: cwd)",
151
- " --output-dir <path> Atlas output directory (default: <project>/.sdtk/atlas)",
152
- " --scan-root <path> Scan root (repeatable; default: project root)",
153
- " --port <port> Viewer server port (default: 8765)",
154
- " --no-open Skip opening the viewer after initial build",
127
+ "Atlas options:",
128
+ " Every flag is forwarded verbatim to sdtk-wiki, which owns the option surface:",
129
+ " --project-path, --output-dir, --scan-root (repeatable), --verbose, --host, --port,",
130
+ " --no-open; init also accepts --force and --no-build.",
131
+ " Run 'sdtk-wiki atlas <subcommand> --help' for the authoritative list.",
155
132
  "",
156
133
  "Atlas notes:",
157
134
  " - Free Atlas commands (init, build, open, watch, status) require no authentication or entitlement.",
158
135
  " - Atlas scans markdown files and builds a local document graph and static viewer.",
159
- " - sdtk-spec atlas is the R1 compatibility path; SDTK-WIKI is the canonical home for new wiki work.",
160
- " - Artifacts are written under <project>/.sdtk/atlas/ (project-local compatibility output).",
161
- " - Native SDTK-WIKI uses <project>/.sdtk/wiki/ and <project>/.sdtk/wiki/graph/.",
136
+ " - sdtk-spec atlas is the R1 compatibility namespace; it delegates to sdtk-wiki, the canonical builder.",
137
+ " - The builder is pure Node: no interpreter or extra runtime is required.",
138
+ " - Requires sdtk-wiki-kit (bundled with the sdtk-kit suite). Without it, atlas exits 2 with install steps.",
139
+ " - Graph output defaults to <project>/.sdtk/wiki/graph/; a legacy <project>/.sdtk/atlas/ is never auto-deleted.",
162
140
  " - The old SPEC ask command path is not supported; native Ask is sdtk-wiki ask with capability wiki.ask.",
163
141
  " - Viewer server binds to 127.0.0.1 by default (loopback only).",
164
- " - Requires Python 3.8+ in PATH for the build step.",
165
142
  "",
166
143
  "Project ingest options (Pro):",
167
144
  " --project-path <path> Target project directory to ingest (default: cwd)",
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ const path = require("path");
4
+ const { ValidationError } = require("./errors");
5
+
6
+ // BK-347: sdtk-wiki owns the graph builder. sdtk-spec keeps the R1 "atlas"
7
+ // namespace as a compatibility entry point and forwards every invocation to
8
+ // sdtk-wiki, which does the same job in pure Node — no interpreter prerequisite.
9
+ //
10
+ // The two flag surfaces are identical (project-path / output-dir / scan-root /
11
+ // force / no-build / no-open / host / port / verbose), so args forward verbatim
12
+ // and no translation layer exists to drift.
13
+ const WIKI_PKG = "sdtk-wiki-kit";
14
+ const WIKI_BIN = "sdtk-wiki";
15
+
16
+ const SUBCOMMAND_ARGV = {
17
+ init: ["init"],
18
+ build: ["atlas", "build"],
19
+ open: ["atlas", "open"],
20
+ watch: ["atlas", "watch"],
21
+ status: ["atlas", "status"],
22
+ };
23
+
24
+ const ATLAS_SUBCOMMANDS = new Set(Object.keys(SUBCOMMAND_ARGV));
25
+
26
+ const USAGE_LINES = [
27
+ "[atlas] Usage: sdtk-spec atlas <subcommand> [options]",
28
+ " Subcommands: init, build, open, watch, status",
29
+ " All subcommands delegate to sdtk-wiki, which owns the graph builder.",
30
+ " Run 'sdtk-wiki atlas --help' for the full option list.",
31
+ ];
32
+
33
+ const WIKI_MISSING_LINES = [
34
+ "[atlas] sdtk-spec atlas delegates to sdtk-wiki, which is not installed.",
35
+ "[atlas] Install the wiki kit, then rerun:",
36
+ `[atlas] npm install -g ${WIKI_PKG}`,
37
+ `[atlas] ${WIKI_BIN} atlas build`,
38
+ "[atlas] Or install the whole suite at once: npm install -g sdtk-kit",
39
+ ];
40
+
41
+ /**
42
+ * Map an `sdtk-spec atlas ...` invocation onto the sdtk-wiki argv that performs
43
+ * the same work. Pure: no filesystem or process access.
44
+ *
45
+ * @param {string[]} args - Args after the `atlas` verb.
46
+ * @returns {{ usage: true } | { usage: false, subcommand: string, argv: string[] }}
47
+ * @throws {ValidationError} When the subcommand is not part of the atlas family.
48
+ */
49
+ function planDelegation(args) {
50
+ if (!args || args.length === 0) {
51
+ return { usage: true };
52
+ }
53
+
54
+ const [subcommand, ...rest] = args;
55
+
56
+ if (!ATLAS_SUBCOMMANDS.has(subcommand)) {
57
+ throw new ValidationError(
58
+ `Unknown atlas subcommand: "${subcommand}". Valid subcommands: init, build, open, watch, status.`
59
+ );
60
+ }
61
+
62
+ return {
63
+ usage: false,
64
+ subcommand,
65
+ argv: [...SUBCOMMAND_ARGV[subcommand], ...rest],
66
+ };
67
+ }
68
+
69
+ /**
70
+ * Resolve the sdtk-wiki entry script through its package.json `bin` map, the
71
+ * same drift-safe path the umbrella uses to reach sub-kits.
72
+ *
73
+ * @returns {string | null} Absolute path to the sdtk-wiki entry script, or null
74
+ * when sdtk-wiki-kit is not installed alongside sdtk-spec-kit.
75
+ */
76
+ function resolveWikiBin() {
77
+ let pkgJsonPath;
78
+ try {
79
+ pkgJsonPath = require.resolve(`${WIKI_PKG}/package.json`);
80
+ } catch (_) {
81
+ return null;
82
+ }
83
+
84
+ // eslint-disable-next-line global-require
85
+ const pkg = require(pkgJsonPath);
86
+ const binField = pkg.bin;
87
+ let rel;
88
+ if (typeof binField === "string") {
89
+ rel = binField;
90
+ } else if (binField && typeof binField === "object") {
91
+ rel = binField[WIKI_BIN] || Object.values(binField)[0];
92
+ }
93
+ if (!rel) {
94
+ return null;
95
+ }
96
+
97
+ return path.resolve(path.dirname(pkgJsonPath), rel);
98
+ }
99
+
100
+ module.exports = {
101
+ ATLAS_SUBCOMMANDS,
102
+ SUBCOMMAND_ARGV,
103
+ USAGE_LINES,
104
+ WIKI_BIN,
105
+ WIKI_MISSING_LINES,
106
+ WIKI_PKG,
107
+ planDelegation,
108
+ resolveWikiBin,
109
+ };