sysprom 1.1.0 → 1.2.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.
- package/dist/src/cli/shared.d.ts +6 -2
- package/dist/src/cli/shared.js +54 -15
- package/package.json +1 -1
package/dist/src/cli/shared.d.ts
CHANGED
|
@@ -8,8 +8,12 @@ export declare const noArgs: z.ZodObject<{}, z.core.$strict>;
|
|
|
8
8
|
/**
|
|
9
9
|
* Resolve a SysProM document path. If no explicit path is given, search the
|
|
10
10
|
* working directory by priority:
|
|
11
|
-
* 1. .spm.json
|
|
12
|
-
* 4.
|
|
11
|
+
* 1. .spm.json 2. .spm.md 3. .spm/
|
|
12
|
+
* 4. .sysprom.json 5. .sysprom.md 6. .sysprom/
|
|
13
|
+
* 7. *.spm.json 8. *.spm.md 9. *.spm/
|
|
14
|
+
* 10. *.sysprom.json 11. *.sysprom.md 12. *.sysprom/
|
|
15
|
+
*
|
|
16
|
+
* All matching is case-insensitive. Glob tiers must have exactly one match.
|
|
13
17
|
*/
|
|
14
18
|
export declare function resolveInput(input?: string, cwd?: string): string;
|
|
15
19
|
/** Common output/persistence options for read-only commands. */
|
package/dist/src/cli/shared.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { readdirSync, statSync } from "node:fs";
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
4
|
import { loadDocument, saveDocument } from "../io.js";
|
|
5
5
|
import { jsonToMarkdownMultiDoc } from "../json-to-md.js";
|
|
@@ -23,29 +23,68 @@ const pathOpt = z
|
|
|
23
23
|
/**
|
|
24
24
|
* Resolve a SysProM document path. If no explicit path is given, search the
|
|
25
25
|
* working directory by priority:
|
|
26
|
-
* 1. .spm.json
|
|
27
|
-
* 4.
|
|
26
|
+
* 1. .spm.json 2. .spm.md 3. .spm/
|
|
27
|
+
* 4. .sysprom.json 5. .sysprom.md 6. .sysprom/
|
|
28
|
+
* 7. *.spm.json 8. *.spm.md 9. *.spm/
|
|
29
|
+
* 10. *.sysprom.json 11. *.sysprom.md 12. *.sysprom/
|
|
30
|
+
*
|
|
31
|
+
* All matching is case-insensitive. Glob tiers must have exactly one match.
|
|
28
32
|
*/
|
|
29
33
|
export function resolveInput(input, cwd) {
|
|
30
34
|
if (input)
|
|
31
35
|
return input;
|
|
32
36
|
const dir = resolve(cwd ?? ".");
|
|
33
|
-
//
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
// Exact names to check, in priority order (case-insensitive)
|
|
38
|
+
const exactNames = [
|
|
39
|
+
".spm.json",
|
|
40
|
+
".spm.md",
|
|
41
|
+
".spm",
|
|
42
|
+
".sysprom.json",
|
|
43
|
+
".sysprom.md",
|
|
44
|
+
".sysprom",
|
|
45
|
+
];
|
|
41
46
|
const entries = readdirSync(dir);
|
|
42
|
-
const
|
|
43
|
-
|
|
47
|
+
for (const name of exactNames) {
|
|
48
|
+
const isDirSuffix = name.endsWith(".spm") || name.endsWith(".sysprom");
|
|
49
|
+
const found = entries.filter((e) => e.toLowerCase() === name);
|
|
50
|
+
if (found.length > 1) {
|
|
51
|
+
throw new Error(`Multiple SysProM documents found: ${found.join(", ")}. Specify one explicitly.`);
|
|
52
|
+
}
|
|
53
|
+
if (found.length === 1) {
|
|
54
|
+
const candidate = join(dir, found[0]);
|
|
55
|
+
if (isDirSuffix) {
|
|
56
|
+
try {
|
|
57
|
+
if (statSync(candidate).isDirectory())
|
|
58
|
+
return candidate;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
/* skip */
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return candidate;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Glob suffixes in priority order (case-insensitive)
|
|
70
|
+
const globSuffixes = [
|
|
71
|
+
".spm.json",
|
|
72
|
+
".spm.md",
|
|
73
|
+
".spm",
|
|
74
|
+
".sysprom.json",
|
|
75
|
+
".sysprom.md",
|
|
76
|
+
".sysprom",
|
|
77
|
+
];
|
|
78
|
+
for (const suffix of globSuffixes) {
|
|
79
|
+
const isDirSuffix = suffix === ".spm" || suffix === ".sysprom";
|
|
44
80
|
const matches = entries
|
|
45
|
-
.filter((e) =>
|
|
81
|
+
.filter((e) => {
|
|
82
|
+
const lower = e.toLowerCase();
|
|
83
|
+
return lower.endsWith(suffix) && lower !== suffix;
|
|
84
|
+
})
|
|
46
85
|
.map((e) => join(dir, e))
|
|
47
86
|
.filter((p) => {
|
|
48
|
-
if (
|
|
87
|
+
if (isDirSuffix) {
|
|
49
88
|
try {
|
|
50
89
|
return statSync(p).isDirectory();
|
|
51
90
|
}
|