@sorane/core 0.2.1 → 0.2.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/package.json +1 -1
- package/src/index.ts +7 -0
- package/src/validate-site.ts +131 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,6 +2,13 @@ export { runBuild, type BuildOptions, type BuildResult } from "./build.ts";
|
|
|
2
2
|
export { mergeConfig, DEFAULT_CONFIG, resolvePermalink, type SoraneConfig } from "./config.ts";
|
|
3
3
|
export { migrateToOkf, parseBumpProfileArg, type MigrateToOkfOptions } from "./migrate.ts";
|
|
4
4
|
export { validateHeadingWarnings } from "./validate-heading-structure.ts";
|
|
5
|
+
export {
|
|
6
|
+
validateSiteContent,
|
|
7
|
+
VALIDATE_JSON_SCHEMA_VERSION,
|
|
8
|
+
type ValidateSiteReport,
|
|
9
|
+
type ValidateFileReport,
|
|
10
|
+
type ValidateFinding,
|
|
11
|
+
} from "./validate-site.ts";
|
|
5
12
|
export { processStaticAssets, type StaticAssetPassResult } from "./static-assets.ts";
|
|
6
13
|
export {
|
|
7
14
|
signRasterWithC2pa,
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { join, relative, resolve } from "node:path";
|
|
3
|
+
import { extract, validateSource, type ValidationIssue } from "@sorane/okf";
|
|
4
|
+
import type { SoraneConfig } from "./config.ts";
|
|
5
|
+
import { validateDiagramAltWarnings } from "./diagrams/validate-diagram-alt.ts";
|
|
6
|
+
import { validateHeadingWarnings } from "./validate-heading-structure.ts";
|
|
7
|
+
|
|
8
|
+
export const VALIDATE_JSON_SCHEMA_VERSION = 1 as const;
|
|
9
|
+
|
|
10
|
+
export type ValidateFindingSeverity = "error" | "warning";
|
|
11
|
+
export type ValidateFindingCategory = "okf" | "diagram" | "heading";
|
|
12
|
+
|
|
13
|
+
export interface ValidateFinding {
|
|
14
|
+
readonly severity: ValidateFindingSeverity;
|
|
15
|
+
readonly category: ValidateFindingCategory;
|
|
16
|
+
readonly message: string;
|
|
17
|
+
readonly where?: ValidationIssue["where"];
|
|
18
|
+
readonly instancePath?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ValidateFileReport {
|
|
22
|
+
readonly file: string;
|
|
23
|
+
readonly ok: boolean;
|
|
24
|
+
readonly type?: string;
|
|
25
|
+
readonly profile?: string;
|
|
26
|
+
readonly findings: readonly ValidateFinding[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ValidateSiteReport {
|
|
30
|
+
readonly schema_version: typeof VALIDATE_JSON_SCHEMA_VERSION;
|
|
31
|
+
readonly ok: boolean;
|
|
32
|
+
readonly error_count: number;
|
|
33
|
+
readonly warning_count: number;
|
|
34
|
+
readonly files: readonly ValidateFileReport[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function walkMarkdown(root: string): string[] {
|
|
38
|
+
const out: string[] = [];
|
|
39
|
+
function visit(dir: string): void {
|
|
40
|
+
for (const name of readdirSync(dir).sort()) {
|
|
41
|
+
const abs = join(dir, name);
|
|
42
|
+
if (statSync(abs).isDirectory()) visit(abs);
|
|
43
|
+
else if (name.endsWith(".md")) out.push(abs);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
visit(root);
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function okfIssueToFinding(issue: ValidationIssue): ValidateFinding {
|
|
51
|
+
return {
|
|
52
|
+
severity: "error",
|
|
53
|
+
category: "okf",
|
|
54
|
+
message: issue.message,
|
|
55
|
+
where: issue.where,
|
|
56
|
+
instancePath: issue.instancePath,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function warningToFinding(category: "okf" | "diagram" | "heading", message: string): ValidateFinding {
|
|
61
|
+
return { severity: "warning", category, message };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function profileFromSource(source: string): string | undefined {
|
|
65
|
+
const { frontmatter } = extract(source);
|
|
66
|
+
if (frontmatter === null || typeof frontmatter !== "object") return undefined;
|
|
67
|
+
const profile = (frontmatter as Record<string, unknown>).profile;
|
|
68
|
+
return typeof profile === "string" ? profile : undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** `content/` 配下の Markdown を検証し、エージェント向けレポートを返す。 */
|
|
72
|
+
export function validateSiteContent(
|
|
73
|
+
cwd: string,
|
|
74
|
+
config: SoraneConfig,
|
|
75
|
+
): ValidateSiteReport {
|
|
76
|
+
const contentDir = resolve(cwd, config.build.content_dir);
|
|
77
|
+
if (!existsSync(contentDir)) {
|
|
78
|
+
throw new Error(`content directory not found: ${contentDir}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const files: ValidateFileReport[] = [];
|
|
82
|
+
let errorCount = 0;
|
|
83
|
+
let warningCount = 0;
|
|
84
|
+
|
|
85
|
+
for (const abs of walkMarkdown(contentDir)) {
|
|
86
|
+
const rel = relative(contentDir, abs);
|
|
87
|
+
const source = readFileSync(abs, "utf8");
|
|
88
|
+
const result = validateSource(rel, source);
|
|
89
|
+
const findings: ValidateFinding[] = [];
|
|
90
|
+
|
|
91
|
+
for (const w of result.warnings) {
|
|
92
|
+
findings.push(warningToFinding("okf", w));
|
|
93
|
+
warningCount++;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const { body } = extract(source);
|
|
97
|
+
if (body !== null) {
|
|
98
|
+
for (const w of validateDiagramAltWarnings(body, config.build.diagrams ?? {})) {
|
|
99
|
+
findings.push(warningToFinding("diagram", w));
|
|
100
|
+
warningCount++;
|
|
101
|
+
}
|
|
102
|
+
for (const w of validateHeadingWarnings(body)) {
|
|
103
|
+
findings.push(warningToFinding("heading", w));
|
|
104
|
+
warningCount++;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!result.ok) {
|
|
109
|
+
for (const issue of result.issues) {
|
|
110
|
+
findings.push(okfIssueToFinding(issue));
|
|
111
|
+
errorCount++;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
files.push({
|
|
116
|
+
file: rel,
|
|
117
|
+
ok: result.ok,
|
|
118
|
+
type: result.type,
|
|
119
|
+
profile: profileFromSource(source),
|
|
120
|
+
findings,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
schema_version: VALIDATE_JSON_SCHEMA_VERSION,
|
|
126
|
+
ok: errorCount === 0,
|
|
127
|
+
error_count: errorCount,
|
|
128
|
+
warning_count: warningCount,
|
|
129
|
+
files,
|
|
130
|
+
};
|
|
131
|
+
}
|