@topogram/cli 0.3.34
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/ARCHITECTURE.md +67 -0
- package/CHANGELOG.md +240 -0
- package/README.md +223 -0
- package/package.json +51 -0
- package/src/adoption/index.js +3 -0
- package/src/adoption/plan.js +702 -0
- package/src/adoption/reporting.js +464 -0
- package/src/adoption/review-groups.js +313 -0
- package/src/agent-ops/query-builders.js +5012 -0
- package/src/archive/archive.js +141 -0
- package/src/archive/compact.js +26 -0
- package/src/archive/jsonl.js +70 -0
- package/src/archive/resolver-bridge.js +82 -0
- package/src/archive/schema.js +87 -0
- package/src/archive/unarchive.js +108 -0
- package/src/catalog.js +752 -0
- package/src/cli/catalog-alias.js +166 -0
- package/src/cli.js +9738 -0
- package/src/component-behavior.js +173 -0
- package/src/example-implementation.js +91 -0
- package/src/format.js +19 -0
- package/src/generator/adapters.d.ts +4 -0
- package/src/generator/adapters.js +325 -0
- package/src/generator/api.d.ts +1 -0
- package/src/generator/api.js +1196 -0
- package/src/generator/check.js +355 -0
- package/src/generator/component-conformance.js +767 -0
- package/src/generator/components.js +39 -0
- package/src/generator/context/bundle.js +291 -0
- package/src/generator/context/diff.js +256 -0
- package/src/generator/context/digest.js +182 -0
- package/src/generator/context/domain-coverage.js +94 -0
- package/src/generator/context/domain-page.js +137 -0
- package/src/generator/context/index.js +42 -0
- package/src/generator/context/report.js +121 -0
- package/src/generator/context/shared.js +1397 -0
- package/src/generator/context/slice.js +703 -0
- package/src/generator/context/task-mode.js +466 -0
- package/src/generator/docs.js +327 -0
- package/src/generator/index.js +161 -0
- package/src/generator/native/parity-bundle.js +311 -0
- package/src/generator/output.js +300 -0
- package/src/generator/registry.js +482 -0
- package/src/generator/runtime/app-bundle.js +456 -0
- package/src/generator/runtime/bundle-shared.js +166 -0
- package/src/generator/runtime/compile-check.js +163 -0
- package/src/generator/runtime/deployment.js +287 -0
- package/src/generator/runtime/environment.js +635 -0
- package/src/generator/runtime/index.js +32 -0
- package/src/generator/runtime/runtime-check.js +554 -0
- package/src/generator/runtime/shared.js +515 -0
- package/src/generator/runtime/smoke.js +219 -0
- package/src/generator/schema.js +204 -0
- package/src/generator/sdlc/board.js +66 -0
- package/src/generator/sdlc/doc-page.js +53 -0
- package/src/generator/sdlc/index.js +23 -0
- package/src/generator/sdlc/release-notes.js +62 -0
- package/src/generator/sdlc/traceability-matrix.js +65 -0
- package/src/generator/shared.js +29 -0
- package/src/generator/surfaces/contracts.js +146 -0
- package/src/generator/surfaces/databases/contract.js +40 -0
- package/src/generator/surfaces/databases/index.js +84 -0
- package/src/generator/surfaces/databases/lifecycle-shared.d.ts +1 -0
- package/src/generator/surfaces/databases/lifecycle-shared.js +612 -0
- package/src/generator/surfaces/databases/migration-plan.js +281 -0
- package/src/generator/surfaces/databases/postgres/capabilities.js +14 -0
- package/src/generator/surfaces/databases/postgres/drizzle.js +99 -0
- package/src/generator/surfaces/databases/postgres/index.js +9 -0
- package/src/generator/surfaces/databases/postgres/lifecycle.js +16 -0
- package/src/generator/surfaces/databases/postgres/prisma.js +159 -0
- package/src/generator/surfaces/databases/postgres/sql-migration.js +102 -0
- package/src/generator/surfaces/databases/postgres/sql-schema.js +34 -0
- package/src/generator/surfaces/databases/shared.d.ts +1 -0
- package/src/generator/surfaces/databases/shared.js +350 -0
- package/src/generator/surfaces/databases/snapshot.js +96 -0
- package/src/generator/surfaces/databases/sqlite/capabilities.js +14 -0
- package/src/generator/surfaces/databases/sqlite/index.js +8 -0
- package/src/generator/surfaces/databases/sqlite/lifecycle.js +16 -0
- package/src/generator/surfaces/databases/sqlite/prisma.js +143 -0
- package/src/generator/surfaces/databases/sqlite/sql-migration.js +65 -0
- package/src/generator/surfaces/databases/sqlite/sql-schema.js +27 -0
- package/src/generator/surfaces/index.js +25 -0
- package/src/generator/surfaces/native/swiftui-app.js +38 -0
- package/src/generator/surfaces/native/swiftui-templates/Package.swift.txt +20 -0
- package/src/generator/surfaces/native/swiftui-templates/README.generated.md +26 -0
- package/src/generator/surfaces/native/swiftui-templates/runtime/DynamicScreens.swift +682 -0
- package/src/generator/surfaces/native/swiftui-templates/runtime/TodoAPIClient.swift +156 -0
- package/src/generator/surfaces/native/swiftui-templates/runtime/TodoSwiftUIApp.swift +44 -0
- package/src/generator/surfaces/native/swiftui-templates/runtime/Visibility.swift +183 -0
- package/src/generator/surfaces/services/express.d.ts +1 -0
- package/src/generator/surfaces/services/express.js +766 -0
- package/src/generator/surfaces/services/hono.d.ts +1 -0
- package/src/generator/surfaces/services/hono.js +204 -0
- package/src/generator/surfaces/services/index.js +42 -0
- package/src/generator/surfaces/services/persistence-wiring.js +240 -0
- package/src/generator/surfaces/services/runtime-helpers.js +631 -0
- package/src/generator/surfaces/services/server-contract.js +80 -0
- package/src/generator/surfaces/services/stateless.d.ts +1 -0
- package/src/generator/surfaces/services/stateless.js +97 -0
- package/src/generator/surfaces/shared.js +64 -0
- package/src/generator/surfaces/web/api-client.js +1 -0
- package/src/generator/surfaces/web/forms.js +1 -0
- package/src/generator/surfaces/web/index.d.ts +2 -0
- package/src/generator/surfaces/web/index.js +53 -0
- package/src/generator/surfaces/web/react-components.js +248 -0
- package/src/generator/surfaces/web/react.js +538 -0
- package/src/generator/surfaces/web/routes.js +1 -0
- package/src/generator/surfaces/web/screens.js +1 -0
- package/src/generator/surfaces/web/shared.js +369 -0
- package/src/generator/surfaces/web/sveltekit-actions.js +28 -0
- package/src/generator/surfaces/web/sveltekit-components.js +234 -0
- package/src/generator/surfaces/web/sveltekit.js +426 -0
- package/src/generator/surfaces/web/ui-web-contract.js +65 -0
- package/src/generator/surfaces/web/vanilla.js +239 -0
- package/src/generator/verification.js +84 -0
- package/src/generator.js +1 -0
- package/src/import/core/context.js +52 -0
- package/src/import/core/contracts.js +23 -0
- package/src/import/core/registry.js +81 -0
- package/src/import/core/runner.js +646 -0
- package/src/import/core/shared.js +910 -0
- package/src/import/enrichers/auth-session.js +18 -0
- package/src/import/enrichers/django-rest.js +226 -0
- package/src/import/enrichers/doc-linking.js +20 -0
- package/src/import/enrichers/rails-controllers.js +246 -0
- package/src/import/enrichers/rails-models.js +130 -0
- package/src/import/enrichers/workflow-target-state.js +10 -0
- package/src/import/extractors/api/aspnet-core.js +304 -0
- package/src/import/extractors/api/django-routes.js +318 -0
- package/src/import/extractors/api/express.js +154 -0
- package/src/import/extractors/api/fastify.js +371 -0
- package/src/import/extractors/api/flutter-dio.js +135 -0
- package/src/import/extractors/api/generic-route-fallback.js +90 -0
- package/src/import/extractors/api/graphql-code-first.js +565 -0
- package/src/import/extractors/api/graphql-sdl.js +309 -0
- package/src/import/extractors/api/jaxrs.js +303 -0
- package/src/import/extractors/api/micronaut.js +213 -0
- package/src/import/extractors/api/next-route.js +50 -0
- package/src/import/extractors/api/next-server-action.js +51 -0
- package/src/import/extractors/api/nextauth.js +52 -0
- package/src/import/extractors/api/openapi-code.js +242 -0
- package/src/import/extractors/api/openapi.js +232 -0
- package/src/import/extractors/api/rails-routes.js +230 -0
- package/src/import/extractors/api/react-native-repository.js +128 -0
- package/src/import/extractors/api/retrofit.js +103 -0
- package/src/import/extractors/api/spring-web.js +372 -0
- package/src/import/extractors/api/swift-webapi.js +116 -0
- package/src/import/extractors/api/trpc.js +212 -0
- package/src/import/extractors/db/django-models.js +232 -0
- package/src/import/extractors/db/dotnet-models.js +93 -0
- package/src/import/extractors/db/drizzle.js +242 -0
- package/src/import/extractors/db/ef-core.js +221 -0
- package/src/import/extractors/db/flutter-entities.js +120 -0
- package/src/import/extractors/db/jpa.js +120 -0
- package/src/import/extractors/db/liquibase.js +180 -0
- package/src/import/extractors/db/mybatis-xml.js +145 -0
- package/src/import/extractors/db/prisma.js +185 -0
- package/src/import/extractors/db/rails-schema.js +175 -0
- package/src/import/extractors/db/react-native-entities.js +95 -0
- package/src/import/extractors/db/room.js +193 -0
- package/src/import/extractors/db/snapshot.js +112 -0
- package/src/import/extractors/db/sql.js +180 -0
- package/src/import/extractors/db/swiftdata.js +137 -0
- package/src/import/extractors/ui/android-compose.js +230 -0
- package/src/import/extractors/ui/backend-only.js +70 -0
- package/src/import/extractors/ui/blazor.js +227 -0
- package/src/import/extractors/ui/flutter-screens.js +152 -0
- package/src/import/extractors/ui/maui-xaml.js +135 -0
- package/src/import/extractors/ui/next-app-router.js +83 -0
- package/src/import/extractors/ui/next-pages-router.js +141 -0
- package/src/import/extractors/ui/razor-pages.js +181 -0
- package/src/import/extractors/ui/react-native-screens.js +166 -0
- package/src/import/extractors/ui/react-router.js +139 -0
- package/src/import/extractors/ui/sveltekit.js +123 -0
- package/src/import/extractors/ui/swiftui.js +193 -0
- package/src/import/extractors/ui/uikit.js +175 -0
- package/src/import/extractors/verification/generic.js +290 -0
- package/src/import/extractors/workflows/generic.js +137 -0
- package/src/import/index.js +7 -0
- package/src/import/provenance.js +158 -0
- package/src/new-project.js +2107 -0
- package/src/parser.js +439 -0
- package/src/policy/review-boundaries.js +165 -0
- package/src/project-config.js +535 -0
- package/src/proofs/backend-parity.js +19 -0
- package/src/proofs/contract-audit.js +220 -0
- package/src/proofs/ios-parity.js +7 -0
- package/src/proofs/issues-parity.js +10 -0
- package/src/proofs/web-parity.js +50 -0
- package/src/realization/api/build-api-realization.js +5 -0
- package/src/realization/api/index.js +1 -0
- package/src/realization/backend/build-backend-runtime-realization.js +82 -0
- package/src/realization/backend/index.d.ts +1 -0
- package/src/realization/backend/index.js +4 -0
- package/src/realization/db/build-db-realization.js +17 -0
- package/src/realization/db/index.js +3 -0
- package/src/realization/db/migration-plan.js +5 -0
- package/src/realization/db/snapshot.js +5 -0
- package/src/realization/ui/build-ui-shared-realization.js +305 -0
- package/src/realization/ui/build-web-realization.js +189 -0
- package/src/realization/ui/index.js +2 -0
- package/src/reconcile/docs.js +280 -0
- package/src/reconcile/index.js +3 -0
- package/src/reconcile/journeys.js +441 -0
- package/src/resolver/docs.js +1 -0
- package/src/resolver/enrich/acceptance-criterion.js +14 -0
- package/src/resolver/enrich/bug.js +12 -0
- package/src/resolver/enrich/component.js +2 -0
- package/src/resolver/enrich/index.js +1 -0
- package/src/resolver/enrich/pitch.js +18 -0
- package/src/resolver/enrich/requirement.js +20 -0
- package/src/resolver/enrich/task.js +16 -0
- package/src/resolver/expressions.js +1 -0
- package/src/resolver/index.js +2422 -0
- package/src/resolver/normalize.js +1 -0
- package/src/resolver.js +1 -0
- package/src/sdlc/adopt.js +65 -0
- package/src/sdlc/check.js +86 -0
- package/src/sdlc/dod/acceptance-criterion.js +22 -0
- package/src/sdlc/dod/bug.js +26 -0
- package/src/sdlc/dod/document.js +23 -0
- package/src/sdlc/dod/index.js +25 -0
- package/src/sdlc/dod/pitch.js +23 -0
- package/src/sdlc/dod/requirement.js +34 -0
- package/src/sdlc/dod/task.js +39 -0
- package/src/sdlc/explain.js +116 -0
- package/src/sdlc/history.js +80 -0
- package/src/sdlc/paths.js +11 -0
- package/src/sdlc/release.js +106 -0
- package/src/sdlc/scaffold.js +89 -0
- package/src/sdlc/status-filter.js +54 -0
- package/src/sdlc/transition.js +112 -0
- package/src/sdlc/transitions/acceptance-criterion.js +28 -0
- package/src/sdlc/transitions/bug.js +31 -0
- package/src/sdlc/transitions/document.js +29 -0
- package/src/sdlc/transitions/index.js +56 -0
- package/src/sdlc/transitions/pitch.js +34 -0
- package/src/sdlc/transitions/requirement.js +31 -0
- package/src/sdlc/transitions/task.js +34 -0
- package/src/template-trust.js +597 -0
- package/src/validator/expressions.js +1 -0
- package/src/validator/index.js +3424 -0
- package/src/validator/kinds.js +346 -0
- package/src/validator/per-kind/acceptance-criterion.js +91 -0
- package/src/validator/per-kind/bug.js +77 -0
- package/src/validator/per-kind/component.js +274 -0
- package/src/validator/per-kind/domain.js +205 -0
- package/src/validator/per-kind/pitch.js +101 -0
- package/src/validator/per-kind/requirement.js +75 -0
- package/src/validator/per-kind/task.js +96 -0
- package/src/validator/registry.js +1 -0
- package/src/validator/utils.js +12 -0
- package/src/validator.js +1 -0
- package/src/workflows.js +7597 -0
- package/src/workspace-docs.js +265 -0
- package/template-helpers/react.js +5 -0
- package/template-helpers/sveltekit.js +5 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
export const DOC_KINDS = new Set([
|
|
5
|
+
"glossary",
|
|
6
|
+
"workflow",
|
|
7
|
+
"journey",
|
|
8
|
+
"report",
|
|
9
|
+
// Phase 2 SDLC document kinds. Documents are markdown-only (vs. SDLC `.tg`
|
|
10
|
+
// kinds like pitch/task/bug); `kind:` in frontmatter selects which
|
|
11
|
+
// template/template-validation applies.
|
|
12
|
+
"user-guide",
|
|
13
|
+
"api",
|
|
14
|
+
"architecture",
|
|
15
|
+
"operations",
|
|
16
|
+
"getting-started",
|
|
17
|
+
"reference",
|
|
18
|
+
"development"
|
|
19
|
+
]);
|
|
20
|
+
export const DOC_STATUSES = new Set([
|
|
21
|
+
"canonical",
|
|
22
|
+
"draft",
|
|
23
|
+
"inferred",
|
|
24
|
+
"deprecated",
|
|
25
|
+
// Phase 2 SDLC document lifecycle statuses (per the SDLC plan).
|
|
26
|
+
"review",
|
|
27
|
+
"published",
|
|
28
|
+
"archived"
|
|
29
|
+
]);
|
|
30
|
+
export const DOC_CONFIDENCE = new Set(["low", "medium", "high"]);
|
|
31
|
+
export const DOC_AUDIENCES = new Set(["developers", "operators", "end-users", "all"]);
|
|
32
|
+
export const DOC_PRIORITIES = new Set(["critical", "high", "medium", "low"]);
|
|
33
|
+
export const DOC_ARRAY_FIELDS = new Set([
|
|
34
|
+
"aliases",
|
|
35
|
+
"actors",
|
|
36
|
+
"related_actors",
|
|
37
|
+
"related_roles",
|
|
38
|
+
"related_entities",
|
|
39
|
+
"related_capabilities",
|
|
40
|
+
"related_rules",
|
|
41
|
+
"related_workflows",
|
|
42
|
+
"related_decisions",
|
|
43
|
+
"related_shapes",
|
|
44
|
+
"related_projections",
|
|
45
|
+
"related_docs",
|
|
46
|
+
"failure_signals",
|
|
47
|
+
"provenance",
|
|
48
|
+
"tags",
|
|
49
|
+
// Phase 2 SDLC array fields. `affects` lets a document declare which
|
|
50
|
+
// graph statements it documents; `satisfies` lets a document satisfy a
|
|
51
|
+
// requirement directly (lightweight alternative to a task).
|
|
52
|
+
"affects",
|
|
53
|
+
"satisfies",
|
|
54
|
+
"approvals"
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
// Singular reference fields recognized in doc frontmatter. These are validated
|
|
58
|
+
// as references to specific statement kinds in `validator/index.js`. The
|
|
59
|
+
// `domain` field (singular id) was added in the Phase 1 domain-support work
|
|
60
|
+
// and is validated against `domain` kind statements.
|
|
61
|
+
export const DOC_REFERENCE_FIELDS = {
|
|
62
|
+
domain: "domain"
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Scalar fields recognized in doc frontmatter beyond the DOC_KINDS/STATUSES
|
|
66
|
+
// keys. Listed here primarily for documentation purposes — the parser
|
|
67
|
+
// accepts any scalar key, but validators use this list to know which fields
|
|
68
|
+
// are first-class.
|
|
69
|
+
export const DOC_SCALAR_FIELDS = new Set([
|
|
70
|
+
"id",
|
|
71
|
+
"kind",
|
|
72
|
+
"title",
|
|
73
|
+
"status",
|
|
74
|
+
"summary",
|
|
75
|
+
"success_outcome",
|
|
76
|
+
"source_of_truth",
|
|
77
|
+
"confidence",
|
|
78
|
+
"review_required",
|
|
79
|
+
"domain",
|
|
80
|
+
"app_version",
|
|
81
|
+
"audience",
|
|
82
|
+
"priority",
|
|
83
|
+
"version"
|
|
84
|
+
]);
|
|
85
|
+
|
|
86
|
+
function docLoc(filePath, line = 1, column = 1) {
|
|
87
|
+
const offset = 0;
|
|
88
|
+
return {
|
|
89
|
+
file: filePath,
|
|
90
|
+
start: { line, column, offset },
|
|
91
|
+
end: { line, column, offset }
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function parseScalar(rawValue) {
|
|
96
|
+
const trimmed = rawValue.trim();
|
|
97
|
+
if (
|
|
98
|
+
(trimmed.startsWith("\"") && trimmed.endsWith("\"")) ||
|
|
99
|
+
(trimmed.startsWith("'") && trimmed.endsWith("'"))
|
|
100
|
+
) {
|
|
101
|
+
return trimmed.slice(1, -1);
|
|
102
|
+
}
|
|
103
|
+
if (trimmed === "true") {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
if (trimmed === "false") {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return trimmed;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function parseFrontmatter(frontmatter, filePath) {
|
|
113
|
+
const metadata = {};
|
|
114
|
+
const lines = frontmatter.split(/\r?\n/);
|
|
115
|
+
|
|
116
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
117
|
+
const line = lines[index];
|
|
118
|
+
if (!line.trim()) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const match = line.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(.*)$/);
|
|
123
|
+
if (!match) {
|
|
124
|
+
return {
|
|
125
|
+
metadata,
|
|
126
|
+
error: {
|
|
127
|
+
message: "Invalid YAML frontmatter line",
|
|
128
|
+
loc: docLoc(filePath, index + 2, 1)
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const [, key, rawValue] = match;
|
|
134
|
+
if (Object.hasOwn(metadata, key)) {
|
|
135
|
+
return {
|
|
136
|
+
metadata,
|
|
137
|
+
error: {
|
|
138
|
+
message: `Duplicate doc metadata field '${key}'`,
|
|
139
|
+
loc: docLoc(filePath, index + 2, 1)
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (rawValue.trim() === "") {
|
|
145
|
+
const items = [];
|
|
146
|
+
let cursor = index + 1;
|
|
147
|
+
while (cursor < lines.length) {
|
|
148
|
+
const candidate = lines[cursor];
|
|
149
|
+
if (!candidate.trim()) {
|
|
150
|
+
cursor += 1;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const itemMatch = candidate.match(/^\s*-\s*(.*)$/);
|
|
154
|
+
if (!itemMatch) {
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
items.push(parseScalar(itemMatch[1]));
|
|
158
|
+
cursor += 1;
|
|
159
|
+
}
|
|
160
|
+
metadata[key] = items;
|
|
161
|
+
index = cursor - 1;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
metadata[key] = parseScalar(rawValue);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
metadata,
|
|
170
|
+
error: null
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function collectTopogramDocFiles(inputPath) {
|
|
175
|
+
const absolutePath = path.resolve(inputPath);
|
|
176
|
+
let docsRoot = null;
|
|
177
|
+
|
|
178
|
+
if (fs.existsSync(path.join(absolutePath, "docs")) && fs.statSync(path.join(absolutePath, "docs")).isDirectory()) {
|
|
179
|
+
docsRoot = path.join(absolutePath, "docs");
|
|
180
|
+
} else if (path.basename(absolutePath) === "docs" && fs.existsSync(absolutePath) && fs.statSync(absolutePath).isDirectory()) {
|
|
181
|
+
docsRoot = absolutePath;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (!docsRoot) {
|
|
185
|
+
return [];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const files = [];
|
|
189
|
+
const walk = (currentDir) => {
|
|
190
|
+
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
191
|
+
for (const entry of entries) {
|
|
192
|
+
const childPath = path.join(currentDir, entry.name);
|
|
193
|
+
if (entry.isDirectory()) {
|
|
194
|
+
walk(childPath);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
198
|
+
files.push(childPath);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
walk(docsRoot);
|
|
204
|
+
return files.sort();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function parseDocFile(filePath, workspaceRoot) {
|
|
208
|
+
const source = fs.readFileSync(filePath, "utf8");
|
|
209
|
+
const normalized = source.replace(/\r\n/g, "\n");
|
|
210
|
+
const lines = normalized.split("\n");
|
|
211
|
+
|
|
212
|
+
if (lines[0]?.trim() !== "---") {
|
|
213
|
+
return {
|
|
214
|
+
type: "doc",
|
|
215
|
+
file: filePath,
|
|
216
|
+
relativePath: path.relative(workspaceRoot, filePath),
|
|
217
|
+
metadata: {},
|
|
218
|
+
body: normalized,
|
|
219
|
+
loc: docLoc(filePath),
|
|
220
|
+
parseError: {
|
|
221
|
+
message: "Topogram docs must start with YAML frontmatter delimited by '---'",
|
|
222
|
+
loc: docLoc(filePath, 1, 1)
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
let closingIndex = -1;
|
|
228
|
+
for (let index = 1; index < lines.length; index += 1) {
|
|
229
|
+
if (lines[index].trim() === "---") {
|
|
230
|
+
closingIndex = index;
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (closingIndex === -1) {
|
|
236
|
+
return {
|
|
237
|
+
type: "doc",
|
|
238
|
+
file: filePath,
|
|
239
|
+
relativePath: path.relative(workspaceRoot, filePath),
|
|
240
|
+
metadata: {},
|
|
241
|
+
body: "",
|
|
242
|
+
loc: docLoc(filePath),
|
|
243
|
+
parseError: {
|
|
244
|
+
message: "Unterminated YAML frontmatter in Topogram doc",
|
|
245
|
+
loc: docLoc(filePath, 1, 1)
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const { metadata, error } = parseFrontmatter(lines.slice(1, closingIndex).join("\n"), filePath);
|
|
251
|
+
return {
|
|
252
|
+
type: "doc",
|
|
253
|
+
file: filePath,
|
|
254
|
+
relativePath: path.relative(workspaceRoot, filePath),
|
|
255
|
+
metadata,
|
|
256
|
+
body: lines.slice(closingIndex + 1).join("\n").replace(/^\n+/, ""),
|
|
257
|
+
loc: docLoc(filePath),
|
|
258
|
+
parseError: error
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function parseDocsPath(inputPath) {
|
|
263
|
+
const workspaceRoot = path.resolve(inputPath);
|
|
264
|
+
return collectTopogramDocFiles(inputPath).map((filePath) => parseDocFile(filePath, workspaceRoot));
|
|
265
|
+
}
|