sdtk-spec-kit 0.8.1 → 0.9.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.
@@ -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
+ };