stego-cli 0.4.0 → 0.4.2
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/.vscode/extensions.json +7 -0
- package/README.md +41 -0
- package/dist/shared/src/contracts/cli/envelopes.js +19 -0
- package/dist/shared/src/contracts/cli/errors.js +14 -0
- package/dist/shared/src/contracts/cli/exit-codes.js +15 -0
- package/dist/shared/src/contracts/cli/index.js +6 -0
- package/dist/shared/src/contracts/cli/metadata.js +1 -0
- package/dist/shared/src/contracts/cli/operations.js +1 -0
- package/dist/shared/src/domain/comments/anchors.js +1 -0
- package/dist/shared/src/domain/comments/index.js +4 -0
- package/dist/shared/src/domain/comments/serializer.js +1 -0
- package/dist/shared/src/domain/comments/thread-key.js +21 -0
- package/dist/shared/src/domain/frontmatter/index.js +3 -0
- package/dist/shared/src/domain/frontmatter/parser.js +34 -0
- package/dist/shared/src/domain/frontmatter/serializer.js +32 -0
- package/dist/shared/src/domain/frontmatter/validators.js +47 -0
- package/dist/shared/src/domain/project/index.js +4 -0
- package/dist/shared/src/domain/stages/index.js +20 -0
- package/dist/shared/src/index.js +6 -0
- package/dist/shared/src/utils/guards.js +6 -0
- package/dist/shared/src/utils/index.js +3 -0
- package/dist/shared/src/utils/invariant.js +5 -0
- package/dist/shared/src/utils/result.js +6 -0
- package/dist/stego-cli/src/app/cli-version.js +32 -0
- package/dist/stego-cli/src/app/command-context.js +1 -0
- package/dist/stego-cli/src/app/command-registry.js +121 -0
- package/dist/stego-cli/src/app/create-cli-app.js +42 -0
- package/dist/stego-cli/src/app/error-boundary.js +42 -0
- package/dist/stego-cli/src/app/index.js +6 -0
- package/dist/stego-cli/src/app/output-renderer.js +6 -0
- package/dist/stego-cli/src/main.js +14 -0
- package/dist/stego-cli/src/modules/comments/application/comment-operations.js +457 -0
- package/dist/stego-cli/src/modules/comments/commands/comments-add.js +40 -0
- package/dist/stego-cli/src/modules/comments/commands/comments-clear-resolved.js +32 -0
- package/dist/stego-cli/src/modules/comments/commands/comments-delete.js +33 -0
- package/dist/stego-cli/src/modules/comments/commands/comments-read.js +32 -0
- package/dist/stego-cli/src/modules/comments/commands/comments-reply.js +36 -0
- package/dist/stego-cli/src/modules/comments/commands/comments-set-status.js +35 -0
- package/dist/stego-cli/src/modules/comments/commands/comments-sync-anchors.js +33 -0
- package/dist/stego-cli/src/modules/comments/domain/comment-policy.js +14 -0
- package/dist/stego-cli/src/modules/comments/index.js +20 -0
- package/dist/stego-cli/src/modules/comments/infra/comments-repo.js +68 -0
- package/dist/stego-cli/src/modules/comments/types.js +1 -0
- package/dist/stego-cli/src/modules/compile/application/compile-manuscript.js +16 -0
- package/dist/stego-cli/src/modules/compile/commands/build.js +51 -0
- package/dist/stego-cli/src/modules/compile/domain/compile-structure.js +105 -0
- package/dist/stego-cli/src/modules/compile/index.js +8 -0
- package/dist/stego-cli/src/modules/compile/infra/dist-writer.js +8 -0
- package/dist/stego-cli/src/modules/compile/types.js +1 -0
- package/dist/stego-cli/src/modules/export/application/run-export.js +29 -0
- package/dist/stego-cli/src/modules/export/commands/export.js +61 -0
- package/dist/stego-cli/src/modules/export/domain/exporter.js +6 -0
- package/dist/stego-cli/src/modules/export/index.js +8 -0
- package/dist/stego-cli/src/modules/export/types.js +1 -0
- package/dist/stego-cli/src/modules/index.js +22 -0
- package/dist/stego-cli/src/modules/manuscript/application/create-manuscript.js +107 -0
- package/dist/stego-cli/src/modules/manuscript/application/order-inference.js +56 -0
- package/dist/stego-cli/src/modules/manuscript/commands/new-manuscript.js +54 -0
- package/dist/stego-cli/src/modules/manuscript/domain/manuscript.js +1 -0
- package/dist/stego-cli/src/modules/manuscript/index.js +9 -0
- package/dist/stego-cli/src/modules/manuscript/infra/manuscript-repo.js +39 -0
- package/dist/stego-cli/src/modules/manuscript/types.js +1 -0
- package/dist/stego-cli/src/modules/metadata/application/apply-metadata.js +45 -0
- package/dist/stego-cli/src/modules/metadata/application/read-metadata.js +18 -0
- package/dist/stego-cli/src/modules/metadata/commands/metadata-apply.js +38 -0
- package/dist/stego-cli/src/modules/metadata/commands/metadata-read.js +33 -0
- package/dist/stego-cli/src/modules/metadata/domain/metadata.js +1 -0
- package/dist/stego-cli/src/modules/metadata/index.js +11 -0
- package/dist/stego-cli/src/modules/metadata/infra/metadata-repo.js +68 -0
- package/dist/stego-cli/src/modules/metadata/types.js +1 -0
- package/dist/stego-cli/src/modules/project/application/create-project.js +203 -0
- package/dist/stego-cli/src/modules/project/application/infer-project.js +72 -0
- package/dist/stego-cli/src/modules/project/commands/new-project.js +86 -0
- package/dist/stego-cli/src/modules/project/domain/project.js +1 -0
- package/dist/stego-cli/src/modules/project/index.js +9 -0
- package/dist/stego-cli/src/modules/project/infra/project-repo.js +27 -0
- package/dist/stego-cli/src/modules/project/types.js +1 -0
- package/dist/stego-cli/src/modules/quality/application/inspect-project.js +603 -0
- package/dist/stego-cli/src/modules/quality/application/lint-runner.js +313 -0
- package/dist/stego-cli/src/modules/quality/application/stage-check.js +87 -0
- package/dist/stego-cli/src/modules/quality/commands/check-stage.js +54 -0
- package/dist/stego-cli/src/modules/quality/commands/lint.js +51 -0
- package/dist/stego-cli/src/modules/quality/commands/validate.js +50 -0
- package/dist/stego-cli/src/modules/quality/domain/issues.js +1 -0
- package/dist/stego-cli/src/modules/quality/domain/policies.js +1 -0
- package/dist/stego-cli/src/modules/quality/index.js +14 -0
- package/dist/stego-cli/src/modules/quality/infra/cspell-adapter.js +1 -0
- package/dist/stego-cli/src/modules/quality/infra/markdownlint-adapter.js +1 -0
- package/dist/stego-cli/src/modules/quality/types.js +1 -0
- package/dist/stego-cli/src/modules/scaffold/application/scaffold-workspace.js +307 -0
- package/dist/stego-cli/src/modules/scaffold/commands/init.js +34 -0
- package/dist/stego-cli/src/modules/scaffold/domain/templates.js +182 -0
- package/dist/stego-cli/src/modules/scaffold/index.js +8 -0
- package/dist/stego-cli/src/modules/scaffold/infra/template-repo.js +33 -0
- package/dist/stego-cli/src/modules/scaffold/types.js +1 -0
- package/dist/stego-cli/src/modules/spine/application/create-category.js +14 -0
- package/dist/stego-cli/src/modules/spine/application/create-entry.js +9 -0
- package/dist/stego-cli/src/modules/spine/application/read-catalog.js +13 -0
- package/dist/stego-cli/src/modules/spine/commands/spine-deprecated-aliases.js +33 -0
- package/dist/stego-cli/src/modules/spine/commands/spine-new-category.js +64 -0
- package/dist/stego-cli/src/modules/spine/commands/spine-new-entry.js +65 -0
- package/dist/stego-cli/src/modules/spine/commands/spine-read.js +49 -0
- package/dist/{spine/spine-domain.js → stego-cli/src/modules/spine/domain/spine.js} +13 -7
- package/dist/stego-cli/src/modules/spine/index.js +16 -0
- package/dist/stego-cli/src/modules/spine/infra/spine-repo.js +46 -0
- package/dist/stego-cli/src/modules/spine/types.js +1 -0
- package/dist/stego-cli/src/modules/workspace/application/discover-projects.js +18 -0
- package/dist/stego-cli/src/modules/workspace/application/resolve-workspace.js +73 -0
- package/dist/stego-cli/src/modules/workspace/commands/list-projects.js +40 -0
- package/dist/stego-cli/src/modules/workspace/index.js +9 -0
- package/dist/stego-cli/src/modules/workspace/infra/workspace-repo.js +37 -0
- package/dist/stego-cli/src/modules/workspace/types.js +1 -0
- package/dist/stego-cli/src/platform/clock.js +3 -0
- package/dist/stego-cli/src/platform/fs.js +13 -0
- package/dist/stego-cli/src/platform/index.js +3 -0
- package/dist/stego-cli/src/platform/temp-files.js +6 -0
- package/package.json +20 -11
- package/dist/comments/comments-command.js +0 -499
- package/dist/comments/errors.js +0 -20
- package/dist/metadata/metadata-command.js +0 -127
- package/dist/metadata/metadata-domain.js +0 -209
- package/dist/spine/spine-command.js +0 -129
- package/dist/stego-cli.js +0 -2107
- /package/dist/{exporters/exporter-types.js → shared/src/contracts/cli/comments.js} +0 -0
- /package/dist/{comments/comment-domain.js → shared/src/domain/comments/parser.js} +0 -0
- /package/dist/{exporters → stego-cli/src/modules/export/infra}/markdown-exporter.js +0 -0
- /package/dist/{exporters → stego-cli/src/modules/export/infra}/pandoc-exporter.js +0 -0
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
export function parseMarkdownDocument(raw) {
|
|
3
|
-
const lineEnding = raw.includes("\r\n") ? "\r\n" : "\n";
|
|
4
|
-
if (!raw.startsWith("---\n") && !raw.startsWith("---\r\n")) {
|
|
5
|
-
return {
|
|
6
|
-
lineEnding,
|
|
7
|
-
hasFrontmatter: false,
|
|
8
|
-
frontmatter: {},
|
|
9
|
-
body: raw
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/);
|
|
13
|
-
if (!match) {
|
|
14
|
-
throw new Error("Metadata opening delimiter found, but closing delimiter is missing.");
|
|
15
|
-
}
|
|
16
|
-
const frontmatterText = match[1];
|
|
17
|
-
const body = raw.slice(match[0].length);
|
|
18
|
-
const frontmatter = {};
|
|
19
|
-
const lines = frontmatterText.split(/\r?\n/);
|
|
20
|
-
for (let i = 0; i < lines.length; i += 1) {
|
|
21
|
-
const line = lines[i].trim();
|
|
22
|
-
if (!line || line.startsWith("#")) {
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
const separatorIndex = line.indexOf(":");
|
|
26
|
-
if (separatorIndex < 0) {
|
|
27
|
-
throw new Error(`Invalid metadata line '${line}'. Expected 'key: value'.`);
|
|
28
|
-
}
|
|
29
|
-
const key = line.slice(0, separatorIndex).trim();
|
|
30
|
-
const value = line.slice(separatorIndex + 1).trim();
|
|
31
|
-
if (!key) {
|
|
32
|
-
throw new Error(`Invalid metadata line '${line}'. Missing key.`);
|
|
33
|
-
}
|
|
34
|
-
if (!value) {
|
|
35
|
-
let lookahead = i + 1;
|
|
36
|
-
while (lookahead < lines.length) {
|
|
37
|
-
const nextTrimmed = lines[lookahead].trim();
|
|
38
|
-
if (!nextTrimmed || nextTrimmed.startsWith("#")) {
|
|
39
|
-
lookahead += 1;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
if (lookahead < lines.length) {
|
|
45
|
-
const firstItemLine = lines[lookahead];
|
|
46
|
-
const firstItemTrimmed = firstItemLine.trim();
|
|
47
|
-
const firstItemIndent = firstItemLine.length - firstItemLine.trimStart().length;
|
|
48
|
-
if (firstItemIndent > 0 && firstItemTrimmed.startsWith("- ")) {
|
|
49
|
-
const items = [];
|
|
50
|
-
let j = lookahead;
|
|
51
|
-
while (j < lines.length) {
|
|
52
|
-
const rawCandidate = lines[j];
|
|
53
|
-
const trimmed = rawCandidate.trim();
|
|
54
|
-
if (!trimmed || trimmed.startsWith("#")) {
|
|
55
|
-
j += 1;
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
const indent = rawCandidate.length - rawCandidate.trimStart().length;
|
|
59
|
-
if (indent === 0) {
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
if (!trimmed.startsWith("- ")) {
|
|
63
|
-
throw new Error(`Unsupported metadata list line '${trimmed}'. Expected '- value'.`);
|
|
64
|
-
}
|
|
65
|
-
items.push(coerceScalarValue(trimmed.slice(2).trim()));
|
|
66
|
-
j += 1;
|
|
67
|
-
}
|
|
68
|
-
frontmatter[key] = items;
|
|
69
|
-
i = j - 1;
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
frontmatter[key] = coerceScalarValue(value);
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
lineEnding,
|
|
78
|
-
hasFrontmatter: true,
|
|
79
|
-
frontmatter,
|
|
80
|
-
body
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
export function serializeMarkdownDocument(parsed) {
|
|
84
|
-
const lineEnding = parsed.lineEnding || "\n";
|
|
85
|
-
const includeFrontmatter = parsed.hasFrontmatter || Object.keys(parsed.frontmatter).length > 0;
|
|
86
|
-
const normalizedBody = normalizeBodyLineEndings(parsed.body || "", lineEnding);
|
|
87
|
-
if (!includeFrontmatter) {
|
|
88
|
-
return normalizedBody;
|
|
89
|
-
}
|
|
90
|
-
const ordered = orderFrontmatterStatusFirst(parsed.frontmatter);
|
|
91
|
-
const yamlLines = [];
|
|
92
|
-
for (const key of Object.keys(ordered)) {
|
|
93
|
-
const value = ordered[key];
|
|
94
|
-
if (Array.isArray(value)) {
|
|
95
|
-
yamlLines.push(`${key}:`);
|
|
96
|
-
for (const item of value) {
|
|
97
|
-
yamlLines.push(` - ${formatScalar(item)}`);
|
|
98
|
-
}
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
yamlLines.push(`${key}: ${formatScalar(value)}`);
|
|
102
|
-
}
|
|
103
|
-
const frontmatterBlock = yamlLines.length > 0
|
|
104
|
-
? `---${lineEnding}${yamlLines.join(lineEnding)}${lineEnding}---`
|
|
105
|
-
: `---${lineEnding}---`;
|
|
106
|
-
if (!normalizedBody.trim()) {
|
|
107
|
-
return `${frontmatterBlock}${lineEnding}`;
|
|
108
|
-
}
|
|
109
|
-
const trimmedBody = normalizedBody.replace(/^(\r?\n)+/, "");
|
|
110
|
-
return `${frontmatterBlock}${lineEnding}${lineEnding}${trimmedBody}`;
|
|
111
|
-
}
|
|
112
|
-
export function normalizeFrontmatterRecord(raw) {
|
|
113
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
114
|
-
throw new Error("Input payload 'frontmatter' must be a JSON object.");
|
|
115
|
-
}
|
|
116
|
-
const result = {};
|
|
117
|
-
for (const [key, value] of Object.entries(raw)) {
|
|
118
|
-
const normalizedKey = key.trim();
|
|
119
|
-
if (!normalizedKey) {
|
|
120
|
-
throw new Error("Frontmatter keys cannot be empty.");
|
|
121
|
-
}
|
|
122
|
-
result[normalizedKey] = normalizeFrontmatterValue(value, normalizedKey);
|
|
123
|
-
}
|
|
124
|
-
return result;
|
|
125
|
-
}
|
|
126
|
-
export function deriveDefaultLabelFromFilename(filePath) {
|
|
127
|
-
const basename = path.basename(filePath, path.extname(filePath));
|
|
128
|
-
const normalized = basename
|
|
129
|
-
.replace(/[_-]+/g, " ")
|
|
130
|
-
.trim();
|
|
131
|
-
if (!normalized) {
|
|
132
|
-
return "New Entry";
|
|
133
|
-
}
|
|
134
|
-
return normalized.replace(/\b\w/g, (value) => value.toUpperCase());
|
|
135
|
-
}
|
|
136
|
-
function orderFrontmatterStatusFirst(frontmatter) {
|
|
137
|
-
if (!Object.hasOwn(frontmatter, "status")) {
|
|
138
|
-
return { ...frontmatter };
|
|
139
|
-
}
|
|
140
|
-
const ordered = {
|
|
141
|
-
status: frontmatter.status
|
|
142
|
-
};
|
|
143
|
-
for (const [key, value] of Object.entries(frontmatter)) {
|
|
144
|
-
if (key === "status") {
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
ordered[key] = value;
|
|
148
|
-
}
|
|
149
|
-
return ordered;
|
|
150
|
-
}
|
|
151
|
-
function normalizeBodyLineEndings(body, lineEnding) {
|
|
152
|
-
return body.replace(/\r?\n/g, lineEnding);
|
|
153
|
-
}
|
|
154
|
-
function normalizeFrontmatterValue(value, key) {
|
|
155
|
-
if (Array.isArray(value)) {
|
|
156
|
-
return value.map((item) => normalizeFrontmatterScalar(item, key));
|
|
157
|
-
}
|
|
158
|
-
return normalizeFrontmatterScalar(value, key);
|
|
159
|
-
}
|
|
160
|
-
function normalizeFrontmatterScalar(value, key) {
|
|
161
|
-
if (value === null) {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
165
|
-
return value;
|
|
166
|
-
}
|
|
167
|
-
throw new Error(`Metadata key '${key}' must be a scalar or array of scalars.`);
|
|
168
|
-
}
|
|
169
|
-
function coerceScalarValue(rawValue) {
|
|
170
|
-
const value = rawValue.trim();
|
|
171
|
-
if (!value) {
|
|
172
|
-
return "";
|
|
173
|
-
}
|
|
174
|
-
if ((value.startsWith("\"") && value.endsWith("\"")) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
175
|
-
return value.slice(1, -1);
|
|
176
|
-
}
|
|
177
|
-
if (value === "null") {
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
if (value === "true") {
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
if (value === "false") {
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
if (/^-?\d+$/.test(value)) {
|
|
187
|
-
return Number(value);
|
|
188
|
-
}
|
|
189
|
-
return value;
|
|
190
|
-
}
|
|
191
|
-
function formatScalar(value) {
|
|
192
|
-
if (value === null) {
|
|
193
|
-
return "null";
|
|
194
|
-
}
|
|
195
|
-
if (typeof value === "number" || typeof value === "boolean") {
|
|
196
|
-
return String(value);
|
|
197
|
-
}
|
|
198
|
-
const normalized = value.trim();
|
|
199
|
-
if (!normalized) {
|
|
200
|
-
return "\"\"";
|
|
201
|
-
}
|
|
202
|
-
if (/^-?\d+$/.test(normalized) || normalized === "true" || normalized === "false" || normalized === "null") {
|
|
203
|
-
return JSON.stringify(normalized);
|
|
204
|
-
}
|
|
205
|
-
if (/^[A-Za-z0-9._/@:+-]+$/.test(normalized)) {
|
|
206
|
-
return normalized;
|
|
207
|
-
}
|
|
208
|
-
return JSON.stringify(normalized);
|
|
209
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import process from "node:process";
|
|
4
|
-
import { createSpineCategory, createSpineEntry, readSpineCatalog } from "./spine-domain.js";
|
|
5
|
-
export function runSpineCommand(options, project) {
|
|
6
|
-
const [subcommand] = options._;
|
|
7
|
-
if (!subcommand) {
|
|
8
|
-
throw new Error("Spine subcommand is required. Use: read, new-category, new.");
|
|
9
|
-
}
|
|
10
|
-
if (subcommand === "add-category") {
|
|
11
|
-
throw new Error("`stego spine add-category` is deprecated. Use `stego spine new-category`.");
|
|
12
|
-
}
|
|
13
|
-
if (subcommand === "new-entry") {
|
|
14
|
-
throw new Error("`stego spine new-entry` is deprecated. Use `stego spine new`.");
|
|
15
|
-
}
|
|
16
|
-
const outputFormat = parseOutputFormat(readString(options, "format"));
|
|
17
|
-
switch (subcommand) {
|
|
18
|
-
case "read": {
|
|
19
|
-
const catalog = readSpineCatalog(project.root, project.spineDir);
|
|
20
|
-
emit({
|
|
21
|
-
ok: true,
|
|
22
|
-
operation: "read",
|
|
23
|
-
state: {
|
|
24
|
-
projectId: project.id,
|
|
25
|
-
categories: catalog.categories,
|
|
26
|
-
issues: catalog.issues
|
|
27
|
-
}
|
|
28
|
-
}, outputFormat);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
case "new-category": {
|
|
32
|
-
const key = readString(options, "key");
|
|
33
|
-
if (!key) {
|
|
34
|
-
throw new Error("--key is required for `stego spine new-category`.");
|
|
35
|
-
}
|
|
36
|
-
const label = readString(options, "label");
|
|
37
|
-
const requireMetadata = options["require-metadata"] === true;
|
|
38
|
-
const requiredMetadata = readRequiredMetadata(project.meta);
|
|
39
|
-
const result = createSpineCategory(project.root, project.spineDir, key, label, requiredMetadata, requireMetadata);
|
|
40
|
-
if (requireMetadata && result.requiredMetadataUpdated) {
|
|
41
|
-
writeRequiredMetadata(project.root, project.meta, requiredMetadata);
|
|
42
|
-
}
|
|
43
|
-
emit({
|
|
44
|
-
ok: true,
|
|
45
|
-
operation: "new-category",
|
|
46
|
-
result
|
|
47
|
-
}, outputFormat);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
case "new": {
|
|
51
|
-
const category = readString(options, "category");
|
|
52
|
-
if (!category) {
|
|
53
|
-
throw new Error("--category is required for `stego spine new`.");
|
|
54
|
-
}
|
|
55
|
-
if (options.entry !== undefined) {
|
|
56
|
-
throw new Error("Unknown option '--entry' for `stego spine new`. Use `--filename`.");
|
|
57
|
-
}
|
|
58
|
-
const filename = readString(options, "filename");
|
|
59
|
-
const result = createSpineEntry(project.root, project.spineDir, category, filename);
|
|
60
|
-
emit({
|
|
61
|
-
ok: true,
|
|
62
|
-
operation: "new",
|
|
63
|
-
result
|
|
64
|
-
}, outputFormat);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
default:
|
|
68
|
-
throw new Error(`Unknown spine subcommand '${subcommand}'. Use: read, new-category, new.`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function emit(payload, outputFormat) {
|
|
72
|
-
if (outputFormat === "json") {
|
|
73
|
-
process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
switch (payload.operation) {
|
|
77
|
-
case "read":
|
|
78
|
-
process.stdout.write(`Spine categories: ${payload.state.categories.length}. ` +
|
|
79
|
-
`Entries: ${payload.state.categories.reduce((sum, category) => sum + category.entries.length, 0)}.\n`);
|
|
80
|
-
return;
|
|
81
|
-
case "new-category":
|
|
82
|
-
process.stdout.write(`Created spine category '${payload.result.key}' (${payload.result.metadataPath}).\n`);
|
|
83
|
-
return;
|
|
84
|
-
case "new":
|
|
85
|
-
process.stdout.write(`Created spine entry: ${payload.result.filePath}\n`);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function parseOutputFormat(raw) {
|
|
90
|
-
if (!raw || raw === "text") {
|
|
91
|
-
return "text";
|
|
92
|
-
}
|
|
93
|
-
if (raw === "json") {
|
|
94
|
-
return "json";
|
|
95
|
-
}
|
|
96
|
-
throw new Error("Invalid --format value. Use 'text' or 'json'.");
|
|
97
|
-
}
|
|
98
|
-
function readString(options, key) {
|
|
99
|
-
const value = options[key];
|
|
100
|
-
return typeof value === "string" ? value : undefined;
|
|
101
|
-
}
|
|
102
|
-
function readRequiredMetadata(projectMeta) {
|
|
103
|
-
const raw = projectMeta.requiredMetadata;
|
|
104
|
-
if (!Array.isArray(raw)) {
|
|
105
|
-
return [];
|
|
106
|
-
}
|
|
107
|
-
const seen = new Set();
|
|
108
|
-
const keys = [];
|
|
109
|
-
for (const entry of raw) {
|
|
110
|
-
if (typeof entry !== "string") {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
const key = entry.trim();
|
|
114
|
-
if (!key || seen.has(key)) {
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
seen.add(key);
|
|
118
|
-
keys.push(key);
|
|
119
|
-
}
|
|
120
|
-
return keys;
|
|
121
|
-
}
|
|
122
|
-
function writeRequiredMetadata(projectRoot, projectMeta, requiredMetadata) {
|
|
123
|
-
const projectJsonPath = path.join(projectRoot, "stego-project.json");
|
|
124
|
-
const next = {
|
|
125
|
-
...projectMeta,
|
|
126
|
-
requiredMetadata
|
|
127
|
-
};
|
|
128
|
-
fs.writeFileSync(projectJsonPath, `${JSON.stringify(next, null, 2)}\n`, "utf8");
|
|
129
|
-
}
|